--- deliantra/Deliantra-Client/DC/UI.pm 2006/04/11 22:14:13 1.77 +++ deliantra/Deliantra-Client/DC/UI.pm 2006/04/12 00:36:13 1.80 @@ -81,14 +81,22 @@ sub new { my $class = shift; - bless { + my $self = bless { x => 0, y => 0, z => 0, w => -1, h => -1, @_ - }, $class + }, $class; + + for (keys %$self) { + if (/^connect_(.*)$/) { + $self->connect ($1 => delete $self->{$_}); + } + } + + $self } sub move { @@ -202,17 +210,6 @@ warn "no draw defined for $self\n"; } -sub bbox { - my ($self) = @_; - my ($w, $h) = $self->size_request; - ( - $self->{x}, - $self->{y}, - $self->{x} = $w, - $self->{y} = $h - ) -} - sub find_widget { my ($self, $x, $y) = @_; @@ -223,8 +220,6 @@ () } -sub del_parent { $_[0]->{parent} = undef } - sub set_parent { my ($self, $par) = @_; @@ -278,7 +273,7 @@ $class->SUPER::new ( bg => [0, 0, 0, 0.2], - active_bg => [1, 1, 1], + active_bg => [1, 1, 1, 0.5], @_ ) } @@ -539,10 +534,9 @@ sub size_request { my ($self) = @_; - my ($w, $h) = - $self->{user_w} && $self->{user_h} - ? ($self->{user_w}, $self->{user_h}) - : ($self->SUPER::size_request); + return ($self->{user_w}, $self->{user_h}) if $self->{user_w} && $self->{user_h}; + + my ($w, $h) = $self->SUPER::size_request; $h += $tex[1]->{h}; $h += $tex[4]->{h}; @@ -670,6 +664,15 @@ use SDL::OpenGL; +sub new { + my $class = shift; + + $class->SUPER::new ( + col_expand => [], + @_ + ) +} + sub add { my ($self, $x, $y, $chld) = @_; @@ -708,8 +711,8 @@ my ($ws, $hs) = $self->get_wh; ( - (List::Util::sum @$ws), - (List::Util::sum @$hs), + (sum @$ws), + (sum @$hs), ) } @@ -720,12 +723,17 @@ my ($ws, $hs) = $self->get_wh; - my $req_w = List::Util::sum @$ws; - my $req_h = List::Util::sum @$hs; + my $req_w = sum @$ws; + my $req_h = sum @$hs; + + # TODO: nicer code && do row_expand + my @col_expand = @{$self->{col_expand}}; + @col_expand = (1) x @$ws unless @col_expand; + my $col_expand = (sum @col_expand) || 1; # linearly scale sizes - $_ *= $w / $req_w for @$ws; - $_ *= $h / $req_h for @$hs; + $ws->[$_] += $col_expand[$_] / $col_expand * ($w - $req_w) for 0 .. $#$ws; + $hs->[$_] *= 1 * $h / $req_h for 0 .. $#$hs; my $y; @@ -812,7 +820,7 @@ if ($req_h > $h) { # ah well, not enough space - $_ = $h[$_] * $h / $req_h for @h; + $_ *= $h / $req_h for @h; } else { my $exp = List::Util::sum map $_->{expand}, @$children; $exp ||= 1; @@ -870,7 +878,7 @@ if ($req_h > $h) { # ah well, not enough space - $_ = $h[$_] * $h / $req_h for @h; + $_ *= $h / $req_h for @h; } else { my $exp = List::Util::sum map $_->{expand}, @$children; $exp ||= 1; @@ -977,6 +985,7 @@ my $tex = $self->{texture} ||= do { $self->{layout}->set_width ($self->{w}); + $self->{layout}->set_height (List::Util::min $self->{h}, $self->{height}); new_from_layout CFClient::Texture $self->{layout} }; @@ -1013,7 +1022,7 @@ $class->SUPER::new ( fg => [1, 1, 1], bg => [0, 0, 0, 0.2], - active_bg => [1, 1, 1], + active_bg => [1, 1, 1, 0.5], active_fg => [0, 0, 0], @_ ) @@ -1156,6 +1165,74 @@ ############################################################################# +package CFClient::UI::Button; + +our @ISA = CFClient::UI::Label::; + +use SDL; +use SDL::OpenGL; + +sub new { + my $class = shift; + + $class->SUPER::new ( + padding => 4, + fg => [1, 1, 1], + bg => [1, 1, 1, 0.2], + active_bg => [0, 0, 0, 0.5], + active_fg => [1, 1, 0], + border_fg => [1, 1, 0], + @_ + ) +} + +sub button_up { + my ($self, $ev, $x, $y) = @_; + + if ($x >= 0 && $x < $self->{w} + && $y >= 0 && $y < $self->{h}) { + $self->emit ("activate"); + } +} + +sub _draw { + my ($self) = @_; + + local $self->{fg} = $self->{fg}; + + glEnable GL_BLEND; + glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; + + glTranslate 0.375, 0.375, 0; # make line and polyogon coordinates behave similarly + + glBegin GL_LINE_LOOP; + glColor @{$self->{border_fg}}; + glVertex 1 , 1; + glVertex 1 , $self->{h} - 2; + glVertex $self->{w} - 2, $self->{h} - 2; + glVertex $self->{w} - 2, 1; + glEnd; + + if ($GRAB == $self) { + glColor @{$self->{active_bg}}; + $self->{fg} = $self->{active_fg}; + } else { + glColor @{$self->{bg}}; + } + + glBegin GL_QUADS; + glVertex 2 , 2; + glVertex 2 , $self->{h} - 2; + glVertex $self->{w} - 2, $self->{h} - 2; + glVertex $self->{w} - 2, 2; + glEnd; + glDisable GL_BLEND; + + $self->SUPER::_draw; +} + +############################################################################# + package CFClient::UI::Slider; use strict; @@ -1243,6 +1320,7 @@ $w -= $page; $page &= ~1; glTranslate $page * 0.5, 0, 0; + $page ||= 2; glColor @$fg; glBegin GL_LINES;