--- deliantra/Deliantra-Client/DC/UI.pm 2006/04/22 03:50:25 1.147 +++ deliantra/Deliantra-Client/DC/UI.pm 2006/04/23 00:57:39 1.151 @@ -10,8 +10,30 @@ our ($FOCUS, $HOVER, $GRAB); # various widgets our $ROOT; +our $TOOLTIP; our $BUTTON_STATE; +sub check_tooltip { + if (!$GRAB) { + for (my $widget = $HOVER; $widget; $widget = $widget->{parent}) { + if (exists $widget->{tooltip}) { + + if ($TOOLTIP->{owner} != $widget) { + $TOOLTIP->{owner} = $widget; + $TOOLTIP->set_text ($widget->{tooltip}); + $TOOLTIP->move ($widget->coord2global ($widget->{w}, 0)); + $TOOLTIP->show; + } + + return; + } + } + } + + $TOOLTIP->hide; + delete $TOOLTIP->{owner}; +} + # class methods for events sub feed_sdl_key_down_event { $FOCUS->key_down ($_[0]) if $FOCUS; @@ -30,6 +52,8 @@ $GRAB = $widget; $GRAB->update if $GRAB; + + check_tooltip; } $BUTTON_STATE |= 1 << ($ev->{button} - 1); @@ -51,6 +75,8 @@ my $grab = $GRAB; undef $GRAB; $grab->update if $grab; $GRAB->update if $GRAB; + + check_tooltip; } } @@ -65,6 +91,8 @@ $hover->update if $hover && $hover->{can_hover}; $HOVER->update if $HOVER && $HOVER->{can_hover}; + + check_tooltip; } $HOVER->mouse_motion ($ev, $HOVER->coord2local ($x, $y)) if $HOVER; @@ -98,6 +126,7 @@ x => 0, y => 0, z => 0, + can_events => 1, @_ }, $class; @@ -280,6 +309,8 @@ sub find_widget { my ($self, $x, $y) = @_; + return () unless $self->{can_events}; + return $self if $x >= $self->{x} && $x < $self->{x} + $self->{w} && $y >= $self->{y} && $y < $self->{y} + $self->{h}; @@ -296,14 +327,15 @@ sub check_size { my ($self) = @_; + return unless $self->{parent}; + my ($w, $h) = $self->size_request; if ($w != $self->{req_w} || $h != $self->{req_h}) { $self->{req_w} = $w; $self->{req_h} = $h; - $self->{parent}->check_size - if $self->{parent}; + $self->{parent}->check_size; } } @@ -380,6 +412,11 @@ our @ISA = CFClient::UI::Base::; +sub new { + my ($class, %arg) = @_; + $class->SUPER::new (can_events => 0, %arg); +} + sub size_request { (0, 0) } @@ -397,7 +434,7 @@ my $children = delete $arg{children} || []; - my $self = $class->SUPER::new (children => [], %arg); + my $self = $class->SUPER::new (children => [], can_events => 0, %arg); $self->add ($_) for @$children; $self @@ -426,6 +463,7 @@ $self->{children} = [ grep $_ != $child, @{ $self->{children} } ]; $self->check_size; + $self->update; } sub find_widget { @@ -563,7 +601,7 @@ sub size_request { my ($self) = @_; - @$self{qw(child_w child_h)} = $self->child->size_request; + @$self{qw(child_w child_h)} = @{$self->child}{qw(req_w req_h)}; $self->child->size_allocate (0, 0, @$self{qw(child_w child_h)}); @$self{qw(child_w child_h)} @@ -584,38 +622,60 @@ use CFClient::OpenGL; -sub size_request { - my ($self) = @_; - my $chld = $self->child - or return (0, 0); +sub new { + my $class = shift; + + my $self = $class->SUPER::new ( + bg => [1, 1, 1, 1], + border_bg => [1, 1, 1, 1], + border => 0.8, + @_ + ); - $chld->move (2, 2); + $self +} + +sub set_size { + my ($self, $w, $h) = @_; + $self->{req_w} = $w; + $self->{req_h} = $h; + $self->check_size; +} - map { $_ + 4 } $chld->size_request; +sub size_request { + my ($self) = @_; + ($self->{req_w}, $self->{req_h}) } sub size_allocate { - my ($self, $x, $y, $w, $h) = @_; - - $self->child->configure (2, 2, $w - 4, $h - 4); + my ($self, $w, $h) = @_; + $self->{w} = $w; + $self->{h} = $h; + $self->child->configure (0, 0, $w, $h); } sub _draw { my ($self) = @_; - my $chld = $self->child; + my ($w, $h) = ($self->{w}, $self->{h}); + + glEnable GL_BLEND; + glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; + glEnable GL_TEXTURE_2D; + glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; - my ($w, $h) = $chld->size_request; +# glBegin GL_QUADS; +# glColor 0, 0, 0, 0; +# glVertex 0 , 0; +# glVertex 0 , $h; +# glVertex $w, $h; +# glVertex $w, 0; +# glEnd; - glBegin GL_QUADS; - glColor 0, 0, 0; - glVertex 0 , 0; - glVertex 0 , $h + 4; - glVertex $w + 4 , $h + 4; - glVertex $w + 4 , 0; - glEnd; - $chld->draw; + $self->child->draw; + glDisable GL_BLEND; + glDisable GL_TEXTURE_2D; } ############################################################################# @@ -639,6 +699,7 @@ bg => [1, 1, 1, 1], border_bg => [1, 1, 1, 1], border => 0.8, + can_events => 1, @_ ); @@ -817,7 +878,7 @@ for my $x (0 .. $#$row) { my $widget = $row->[$x] or next; - my ($w, $h) = $widget->size_request; + my ($w, $h) = @$widget{qw(req_w req_h)}; $w[$x] = max $w[$x], $w; $h[$y] = max $h[$y], $h; @@ -932,7 +993,7 @@ my $children = $self->{children}; - my @h = map +($_->size_request)[0], @$children; + my @h = map $_->{req_w}, @$children; my $req_h = List::Util::sum @h; @@ -990,7 +1051,7 @@ my $children = $self->{children}; - my @h = map +($_->size_request)[1], @$children; + my @h = map $_->{req_h}, @$children; my $req_h = List::Util::sum @h; @@ -1041,6 +1102,7 @@ valign => -1, padding => 2, layout => new CFClient::Layout, + can_events => 0, %arg ); @@ -1072,6 +1134,7 @@ $self->{layout}->set_text ($text); delete $self->{texture}; + $self->check_size; $self->update; } @@ -1081,6 +1144,7 @@ $self->{layout}->set_markup ($markup); delete $self->{texture}; + $self->check_size; $self->update; } @@ -1173,6 +1237,7 @@ can_hover => 1, can_focus => 1, valign => 0, + can_events => 1, @_ ) } @@ -1210,7 +1275,7 @@ sub size_allocate { my ($self, $w, $h) = @_; - $self->_set_text ($self->{text}); + $self->_set_text (delete $self->{text});#d# don't check for == inside _set_text } sub set_text { @@ -1367,6 +1432,7 @@ can_hover => 1, align => 0, valign => 0, + can_events => 1, @_ ) } @@ -1481,7 +1547,7 @@ sub new { my $class = shift; - my $self = $class->SUPER::new (@_); + my $self = $class->SUPER::new (can_events => 0, @_); $self->{image} or confess "Image has 'image' not set. This is a fatal error!"; @@ -1650,15 +1716,16 @@ our @ISA = CFClient::UI::VBox::; sub new { - my ($class, %arg) = shift; + my ($class, %arg) = @_; my $self = $class->SUPER::new ( - @_, + tooltip => $arg{type}, + %arg, ); - $self->add ($self->{value} = new CFClient::UI::Label valign => 1, align => 0, template => "999"); + $self->add ($self->{value} = new CFClient::UI::Label valign => +1, align => 0, template => "999"); $self->add ($self->{gauge} = new CFClient::UI::VGauge type => $self->{type}, expand => 1); - $self->add ($self->{max} = new CFClient::UI::Label valign => 1, align => 0, template => "999"); + $self->add ($self->{max} = new CFClient::UI::Label valign => -1, align => 0, template => "999"); $self } @@ -2034,6 +2101,7 @@ my $self = $class->SUPER::new ( state => 0, connect_activate => \&toggle_flopper, + can_events => 1, @_ ); @@ -2072,7 +2140,7 @@ sub check_size { my ($self) = @_; - $self->configure (0, 0, $::WITH, $::HEIGHT); + $self->configure (0, 0, $::WIDTH, $::HEIGHT); } sub size_request { @@ -2084,8 +2152,13 @@ $self->SUPER::configure ($x, $y, $w, $h); - $_->configure ($_->{x}, $_->{y}, $_->size_request) - for @{$self->{children}}; + for my $child (@{$self->{children}}) { + my ($X, $Y, $W, $H) = @$child{qw(x y req_w req_h)}; + + $X = List::Util::max 0, List::Util::min $w - $W, $X; + $Y = List::Util::max 0, List::Util::min $h - $H, $Y; + $child->configure ($X, $Y, $W,$H); + } } sub _topleft { @@ -2142,6 +2215,7 @@ package CFClient::UI; $ROOT = new CFClient::UI::Root; +$TOOLTIP = new CFClient::UI::Label fontsize => 0.8, can_events => 0; 1