--- deliantra/Deliantra-Client/DC/UI.pm 2006/04/24 08:22:22 1.165 +++ 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; @@ -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); @@ -753,6 +784,7 @@ bg => [1, 1, 1, 1], border_bg => [1, 1, 1, 1], border => 0.8, + can_events => 1, @_ ); @@ -909,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; } @@ -1186,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 { @@ -1463,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); } @@ -1711,7 +1793,10 @@ sub set_max { my ($self, $max) = @_; + return if $self->{max_val} == $max; + $self->{max_val} = $max; + $self->update; } sub set_value { @@ -1720,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; } @@ -1795,8 +1880,9 @@ my ($class, %arg) = @_; my $self = $class->SUPER::new ( - tooltip => $arg{type}, - can_hover => 1, + tooltip => $arg{type}, + can_hover => 1, + can_events => 1, %arg, ); @@ -1814,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) = @_; @@ -1824,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; @@ -2121,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; }