--- deliantra/Deliantra-Client/DC/UI.pm 2006/04/24 06:40:29 1.163 +++ deliantra/Deliantra-Client/DC/UI.pm 2006/04/25 11:18:49 1.174 @@ -26,8 +26,16 @@ $tip = $tip->($widget) if CODE:: eq ref $tip; $TOOLTIP->set_markup ($widget->{tooltip}); - $TOOLTIP->move ($widget->coord2global ($widget->{w}, 0)); + $TOOLTIP->show; + + my ($x, $y) = $widget->coord2global ($widget->{w}, 0); + + if ($x + $TOOLTIP->{w} > $::WIDTH) { + ($x, $y) = $widget->coord2global (-$TOOLTIP->{w}, 0); + } + + $TOOLTIP->move ($x, $y); } return; @@ -139,9 +147,9 @@ my $class = shift; my $self = bless { - x => 0, - y => 0, - z => 0, + x => 0, + y => 0, + z => 0, can_events => 1, @_ }, $class; @@ -238,6 +246,19 @@ # nothing to be done } +sub children { +} + +# call when resoltuion changes etc. +sub reconfigure { + my ($self) = @_; + + $_->reconfigure + for $self->children; + + $_->check_size; +} + sub set_max_size { my ($self, $w, $h) = @_; @@ -249,6 +270,9 @@ sub _topleft { my ($self, $x, $y) = @_; + $self->{parent} + or Carp::confess "no parent widget in _topleft\n";#d# + $self->{parent}->_topleft ($x + $self->{x}, $y + $self->{y}); } @@ -494,7 +518,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 @@ -515,6 +543,10 @@ $child->check_size; } +sub children { + @{ $_[0]{children} } +} + sub remove { my ($self, $child) = @_; @@ -621,29 +653,27 @@ sub update { my ($self) = @_; - # we want to do this delayed... - $self->render_chld; + $ROOT->on_refresh ($self => sub { $self->render_child }); $self->SUPER::update; } -sub render_chld { +sub size_allocate { + my ($self, $w, $h) = @_; + + $self->SUPER::size_allocate ($w, $h); + $self->update; +} + +sub render_child { my ($self) = @_; $self->{texture} = new_from_opengl CFClient::Texture $self->{w}, $self->{h}, sub { - glClearColor 0, 0, 0, 1; + glClearColor 0, 0, 0, 0; glClear GL_COLOR_BUFFER_BIT; $self->child->draw; }; } -sub size_allocate { - my ($self, $w, $h) = @_; - - $self->child->configure (0, 0, $w, $h); - - $self->render_chld; -} - sub _draw { my ($self) = @_; @@ -653,9 +683,10 @@ or return; glEnable GL_BLEND; - glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; + glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; glEnable GL_TEXTURE_2D; glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; + glColor 0, 0, 0, 1; $tex->draw_quad (0, 0, $w, $h); @@ -750,9 +781,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, @_ ); @@ -910,13 +941,18 @@ $child->check_size; } +sub children { + grep $_, map @$_, grep $_, @{ $_[0]{children} } +} + # TODO: move to container class maybe? send childs a signal on removal? sub clear { my ($self) = @_; - my $children = delete $self->{children}; + my @children = $self->children; + delete $self->{children}; - for (grep $_, map @$_, grep $_, @$children) { + for (@children) { delete $_->{parent}; $_->hide; } @@ -1153,14 +1189,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 ); @@ -1187,24 +1223,43 @@ $_[1] } +sub update { + my ($self) = @_; + + delete $self->{texture}; + $self->SUPER::update; +} + +sub reconfigure { + my ($self) = @_; + + delete $self->{texture}; +} + sub set_text { my ($self, $text) = @_; + return if $self->{text} eq "T$text"; + $self->{text} = "T$text"; + $self->{layout}->set_text ($text); delete $self->{texture}; - $self->check_size; $self->update; + $self->check_size; } sub set_markup { my ($self, $markup) = @_; + return if $self->{text} eq "M$markup"; + $self->{text} = "M$markup"; + $self->{layout}->set_markup ($markup); delete $self->{texture}; - $self->check_size; $self->update; + $self->check_size; } sub size_request { @@ -1294,13 +1349,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, @_ ) @@ -1464,9 +1519,35 @@ my $sym = $ev->{sym}; if ($sym == 13) { - $self->emit (activate => $self->get_text); + unshift @{$self->{history}}, + my $txt = $self->get_text; + $self->{history_pointer} = -1; + $self->{history_saveback} = ''; + $self->emit (activate => $txt); $self->update; + } elsif ($sym == CFClient::SDLK_UP) { + if ($self->{history_pointer} < 0) { + $self->{history_saveback} = $self->get_text; + } + if (@{$self->{history} || []} > 0) { + $self->{history_pointer}++; + if ($self->{history_pointer} >= @{$self->{history} || []}) { + $self->{history_pointer} = @{$self->{history} || []} - 1; + } + $self->set_text ($self->{history}->[$self->{history_pointer}]); + } + + } elsif ($sym == CFClient::SDLK_DOWN) { + $self->{history_pointer}--; + $self->{history_pointer} = -1 if $self->{history_pointer} < 0; + + if ($self->{history_pointer} >= 0) { + $self->set_text ($self->{history}->[$self->{history_pointer}]); + } else { + $self->set_text ($self->{history_saveback}); + } + } else { $self->SUPER::key_down ($ev); } @@ -1489,13 +1570,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, @_ ) @@ -1712,7 +1793,10 @@ sub set_max { my ($self, $max) = @_; + return if $self->{max_val} == $max; + $self->{max_val} = $max; + $self->update; } sub set_value { @@ -1721,9 +1805,9 @@ $self->set_max ($max) if defined $max; - $max = $self->{max_val}; - $self->{val} = $val; + return if $self->{val} == $val; + $self->{val} = $val; $self->update; } @@ -1796,9 +1880,9 @@ my ($class, %arg) = @_; my $self = $class->SUPER::new ( - tooltip => $arg{type}, + tooltip => $arg{type}, + can_hover => 1, can_events => 1, - can_hover => 1, %arg, ); @@ -1816,6 +1900,13 @@ $self->{max} ->set_fontsize ($fsize); } +sub set_max { + my ($self, $max) = @_; + + $self->{gauge}->set_max ($max); + $self->{max}->set_text ($max); +} + sub set_value { my ($self, $val, $max) = @_; @@ -1826,13 +1917,6 @@ $self->{value}->set_text ($val); } -sub set_max { - my ($self, $max) = @_; - - $self->{gauge}->set_max ($max); - $self->{max}->set_text ($max); -} - ############################################################################# package CFClient::UI::Slider; @@ -1980,14 +2064,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), ], @@ -2122,6 +2207,7 @@ if ($self->{texture}) { glEnable GL_TEXTURE_2D; glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; + glColor 1, 1, 1, 1; $self->{texture}->draw_quad (0, 0, $self->{w}, $self->{h}); glDisable GL_TEXTURE_2D; } @@ -2182,9 +2268,8 @@ my $class = shift; my $self = $class->SUPER::new ( - state => 0, + state => 0, connect_activate => \&toggle_flopper, - can_events => 1, @_ );