--- deliantra/Deliantra-Client/DC/UI.pm 2006/04/24 08:38:36 1.166 +++ deliantra/Deliantra-Client/DC/UI.pm 2006/04/25 11:48:31 1.175 @@ -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}); } @@ -519,6 +543,10 @@ $child->check_size; } +sub children { + @{ $_[0]{children} } +} + sub remove { my ($self, $child) = @_; @@ -625,29 +653,34 @@ 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; +# glColorMask 1, 1, 1, 0; +# glEnable GL_BLEND; +# glBlendFunc GL_SRC_ALPHA, GL_ZERO; +# glRasterPos 0, 0; +# glCopyPixels 0, 0, $self->{w}, $self->{h}; +# glDisable GL_BLEND; +# glColorMask 1, 1, 1, 1; }; } -sub size_allocate { - my ($self, $w, $h) = @_; - - $self->child->configure (0, 0, $w, $h); - - $self->render_chld; -} - sub _draw { my ($self) = @_; @@ -657,9 +690,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); @@ -914,13 +948,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; } @@ -1191,24 +1230,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 { @@ -1468,9 +1526,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); } @@ -1716,7 +1800,10 @@ sub set_max { my ($self, $max) = @_; + return if $self->{max_val} == $max; + $self->{max_val} = $max; + $self->update; } sub set_value { @@ -1725,9 +1812,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; } @@ -1800,8 +1887,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, ); @@ -1819,6 +1907,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) = @_; @@ -1829,13 +1924,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; @@ -2081,7 +2169,7 @@ } $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; glEnable GL_BLEND; @@ -2124,10 +2212,14 @@ my ($self) = @_; if ($self->{texture}) { + glEnable GL_BLEND; + glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; 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; + glDisable GL_BLEND; } $self->{children}[1]->draw;