--- deliantra/Deliantra-Client/DC/UI.pm 2006/04/24 06:05:35 1.162 +++ deliantra/Deliantra-Client/DC/UI.pm 2006/04/24 08:38:36 1.166 @@ -41,11 +41,13 @@ # class methods for events sub feed_sdl_key_down_event { - $FOCUS->key_down ($_[0]) if $FOCUS; + $FOCUS->emit (key_down => $_[0]) || $FOCUS->key_down ($_[0]) + if $FOCUS; } sub feed_sdl_key_up_event { - $FOCUS->key_up ($_[0]) if $FOCUS; + $FOCUS->emit (key_up => $_[0]) || $FOCUS->key_up ($_[0]) + if $FOCUS; } sub feed_sdl_button_down_event { @@ -63,7 +65,10 @@ $BUTTON_STATE |= 1 << ($ev->{button} - 1); - $GRAB->button_down ($ev, $GRAB->coord2local ($x, $y)) if $GRAB; + if ($GRAB) { + ($x, $y) = $GRAB->coord2local ($x, $y); + $GRAB->emit (button_down => $ev, $x, $y) || $GRAB->button_down ($ev, $x, $y); + } } sub feed_sdl_button_up_event { @@ -74,7 +79,10 @@ $BUTTON_STATE &= ~(1 << ($ev->{button} - 1)); - $GRAB->button_up ($ev, $GRAB->coord2local ($x, $y)) if $GRAB; + if ($GRAB) { + ($x, $y) = $GRAB->coord2local ($x, $y); + $GRAB->emit (button_up => $ev, $x, $y) || $GRAB->button_up ($ev, $x, $y); + } if (!$BUTTON_STATE) { my $grab = $GRAB; undef $GRAB; @@ -100,7 +108,10 @@ check_tooltip; } - $HOVER->mouse_motion ($ev, $HOVER->coord2local ($x, $y)) if $HOVER; + if ($HOVER) { + ($x, $y) = $HOVER->coord2local ($x, $y); + $HOVER->emit (mouse_motion => $ev, $x, $y) || $HOVER->mouse_motion ($ev, $x, $y); + } } # convert position array to integers @@ -128,9 +139,9 @@ my $class = shift; my $self = bless { - x => 0, - y => 0, - z => 0, + x => 0, + y => 0, + z => 0, can_events => 1, @_ }, $class; @@ -162,9 +173,11 @@ sub hide { my ($self) = @_; - return unless $self->{parent}; + undef $GRAB if $GRAB == $self; + undef $HOVER if $HOVER == $self; - $self->{parent}->remove ($self); + $self->{parent}->remove ($self) + if $self->{parent}; } sub move { @@ -404,9 +417,7 @@ sub emit { my ($self, $signal, @args) = @_; - for my $cb (@{$self->{signal_cb}{$signal} || []}) { - $cb->($self, @args); - } + List::Util::sum map $_->($self, @args), @{$self->{signal_cb}{$signal} || []} } sub DESTROY { @@ -483,7 +494,11 @@ my $children = delete $arg{children} || []; - my $self = $class->SUPER::new (children => [], can_events => 0, %arg); + my $self = $class->SUPER::new ( + children => [], + can_events => 0, + %arg, + ); $self->add ($_) for @$children; $self @@ -508,6 +523,7 @@ my ($self, $child) = @_; delete $child->{parent}; + $child->hide; $self->{children} = [ grep $_ != $child, @{ $self->{children} } ]; @@ -518,10 +534,13 @@ sub clear { my ($self) = @_; - delete $_->{parent} - for @{ delete $self->{children} }; - + my $children = delete $self->{children}; $self->{children} = []; + + for (@$children) { + delete $_->{parent}; + $_->hide; + } } sub find_widget { @@ -735,9 +754,9 @@ # TODO: user_x, user_y, overwrite moveto? my $self = $class->SUPER::new ( - bg => [1, 1, 1, 1], - border_bg => [1, 1, 1, 1], - border => 0.8, + bg => [1, 1, 1, 1], + border_bg => [1, 1, 1, 1], + border => 0.8, can_events => 1, @_ ); @@ -899,7 +918,13 @@ sub clear { my ($self) = @_; - delete $self->{children}; + my $children = delete $self->{children}; + + for (grep $_, map @$_, grep $_, @$children) { + delete $_->{parent}; + $_->hide; + } + $self->update; } @@ -1132,14 +1157,14 @@ my ($class, %arg) = @_; my $self = $class->SUPER::new ( - fg => [1, 1, 1], - #font => default_font - fontsize => 1, - text => "", - align => -1, - valign => -1, - padding => 2, - layout => new CFClient::Layout, + fg => [1, 1, 1], + #font => default_font + fontsize => 1, + text => "", + align => -1, + valign => -1, + padding => 2, + layout => new CFClient::Layout, can_events => 0, %arg ); @@ -1273,13 +1298,13 @@ my $class = shift; $class->SUPER::new ( - fg => [1, 1, 1], - bg => [0, 0, 0, 0.2], - active_bg => [1, 1, 1, 0.5], - active_fg => [0, 0, 0], - can_hover => 1, - can_focus => 1, - valign => 0, + fg => [1, 1, 1], + bg => [0, 0, 0, 0.2], + active_bg => [1, 1, 1, 0.5], + active_fg => [0, 0, 0], + can_hover => 1, + can_focus => 1, + valign => 0, can_events => 1, @_ ) @@ -1468,13 +1493,13 @@ my $class = shift; $class->SUPER::new ( - padding => 4, - fg => [1, 1, 1], - bg => [1, 1, 1, 0.2], - active_fg => [0, 0, 1], - can_hover => 1, - align => 0, - valign => 0, + padding => 4, + fg => [1, 1, 1], + bg => [1, 1, 1, 0.2], + active_fg => [0, 0, 1], + can_hover => 1, + align => 0, + valign => 0, can_events => 1, @_ ) @@ -1775,8 +1800,7 @@ my ($class, %arg) = @_; my $self = $class->SUPER::new ( - tooltip => $arg{type}, - can_events => 1, + tooltip => $arg{type}, can_hover => 1, %arg, ); @@ -1959,14 +1983,15 @@ my $class = shift; my $self = $class->SUPER::new ( - fontsize => 1, - #font => default_font + fontsize => 1, + can_events => 0, + #font => default_font @_, - - layout => (new CFClient::Layout), - par => [], - height => 0, - children => [ + + layout => (new CFClient::Layout), + par => [], + height => 0, + children => [ (new CFClient::UI::Empty expand => 1), (new CFClient::UI::Slider vertical => 1), ], @@ -2161,9 +2186,8 @@ my $class = shift; my $self = $class->SUPER::new ( - state => 0, + state => 0, connect_activate => \&toggle_flopper, - can_events => 1, @_ );