#!/usr/bin/perl -w

# $Id: draw-box,v 1.4 2000/03/29 17:48:20 daniel Exp $

use strict;
use ExtUtils::testlib;
use Term::Slang qw(:all);

SLtt_get_terminfo();
SLang_init_tty(-1,0,1);
SLsig_block_signals();
SLsmg_init_smg();
SLsmg_cls();
SLsig_unblock_signals();
SLkp_init();

my $q = 'oink.';

my $dc = (length $q) + 2;
my $dr = 7;
   $dc = 36 if $dc < 32;

my ($s_rows,$s_cols) = SLtt_get_screen_size();

my $r = ($s_rows - $dr)/2;
my $c = ($s_cols - $dc)/2;

my $box_color = 2;
my $button_color = 3;

define_color($button_color,'white','green');
define_color($box_color,'yellow','blue');

SLsmg_set_color($box_color);
SLsmg_draw_box($r,$c,$dr,$dc);

SLsmg_set_color(0);

$r += 2;
draw_centered_string($q,$r,$c,$dc);
$r += 2;

display_button('Yes',$r,$c + 4);
display_button('No', $r,$c + 14);
display_button('Cancel',$r,$c + 24);

SLsmg_refresh();

while(my $k = SLkp_getkey()) {

	if ($k eq SL_KEY_LEFT) {
		SLsmg_write_string("foo");
		last;
	}
}

SLang_reset_tty();
SLsmg_reset_smg();

##########################
sub draw_centered_string {
	my ($s,$r,$c,$dc) = @_;
	SLsig_block_signals();
	SLsmg_gotorc($r,$c + ($dc - (length $s))/2);
	SLsmg_write_string($s);
	SLsig_unblock_signals();
}

sub display_button {
	my ($name,$r,$c) = @_;
	SLsig_block_signals();
	SLsmg_gotorc($r,$c);
	SLsmg_set_color($button_color);
	SLsmg_write_string(" $name ");
	SLsmg_set_color(0);
	SLsig_unblock_signals();
}

sub define_color {
	my ($obj,$fg,$bg) = @_;
	SLtt_set_color($obj,'',$fg,$bg);
}

__END__
