--- deliantra/Deliantra-Client/DC/UI.pm 2006/04/22 23:11:32 1.149 +++ 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}; @@ -381,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) } @@ -398,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 @@ -427,6 +463,7 @@ $self->{children} = [ grep $_ != $child, @{ $self->{children} } ]; $self->check_size; + $self->update; } sub find_widget { @@ -662,6 +699,7 @@ bg => [1, 1, 1, 1], border_bg => [1, 1, 1, 1], border => 0.8, + can_events => 1, @_ ); @@ -1064,6 +1102,7 @@ valign => -1, padding => 2, layout => new CFClient::Layout, + can_events => 0, %arg ); @@ -1198,6 +1237,7 @@ can_hover => 1, can_focus => 1, valign => 0, + can_events => 1, @_ ) } @@ -1392,6 +1432,7 @@ can_hover => 1, align => 0, valign => 0, + can_events => 1, @_ ) } @@ -1506,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!"; @@ -1675,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 } @@ -2059,6 +2101,7 @@ my $self = $class->SUPER::new ( state => 0, connect_activate => \&toggle_flopper, + can_events => 1, @_ ); @@ -2172,6 +2215,7 @@ package CFClient::UI; $ROOT = new CFClient::UI::Root; +$TOOLTIP = new CFClient::UI::Label fontsize => 0.8, can_events => 0; 1