--- deliantra/Deliantra-Client/DC/UI.pm 2006/04/18 02:04:23 1.131 +++ deliantra/Deliantra-Client/DC/UI.pm 2006/04/19 06:06:45 1.134 @@ -98,8 +98,6 @@ x => 0, y => 0, z => 0, - w => -1, - h => -1, @_ }, $class; @@ -112,6 +110,22 @@ $self } +sub show { + my ($self) = @_; + + return if $self->{parent}; + + $CFClient::UI::ROOT->add ($self); +} + +sub hide { + my ($self) = @_; + + return unless $self->{parent}; + + $self->{parent}->remove ($self); +} + sub move { my ($self, $x, $y, $z) = @_; @@ -143,6 +157,7 @@ $self->{h} = $h; $self->size_allocate ($w, $h); + $self->update; } sub size_allocate { @@ -274,9 +289,6 @@ $self->{parent}->check_size if $self->{parent}; - - $self->size_allocate ($w, $h); - $self->update; } } @@ -290,14 +302,15 @@ sub connect { my ($self, $signal, $cb) = @_; - push @{ $self->{cb}{$signal} }, $cb; + push @{ $self->{signal_cb}{$signal} }, $cb; } sub emit { my ($self, $signal, @args) = @_; - $_->($self, @args) - for @{$self->{cb}{$signal} || []}; + for my $cb (@{$self->{signal_cb}{$signal} || []}) { + $cb->($self, @args); + } } sub DESTROY { @@ -387,15 +400,15 @@ @{$self->{children}}, $child ]; - $self->{w} = $self->{h} = -1; - $child->check_size; } sub remove { - my ($self, $widget) = @_; + my ($self, $child) = @_; + + delete $child->{parent}; - $self->{children} = [ grep $_ != $widget, @{ $self->{children} } ]; + $self->{children} = [ grep $_ != $child, @{ $self->{children} } ]; $self->check_size; } @@ -437,11 +450,11 @@ } sub add { - my ($self, $widget) = @_; + my ($self, $child) = @_; $self->{children} = []; - $self->SUPER::add ($widget); + $self->SUPER::add ($child); } sub remove { @@ -610,11 +623,15 @@ $class->SUPER::new ( bg => [1, 1, 1, 1], border_bg => [1, 1, 1, 1], - border => int $::FONTSIZE * 0.8, + border => 0.8, @_ ) } +sub border { + int $_[0]{border} * $::FONTSIZE +} + sub size_request { my ($self) = @_; @@ -623,25 +640,27 @@ my ($w, $h) = $self->SUPER::size_request; ( - $w + $self->{border} * 2, - $h + $self->{border} * 2, + $w + $self->border * 2, + $h + $self->border * 2, ) } sub size_allocate { my ($self, $w, $h) = @_; - $h -= List::Util::max 0, $self->{border} * 2; - $w -= List::Util::max 0, $self->{border} * 2; + $h -= List::Util::max 0, $self->border * 2; + $w -= List::Util::max 0, $self->border * 2; - $self->child->configure ($self->{border}, $self->{border}, $w, $h); + $self->child->configure ($self->border, $self->border, $w, $h); } sub button_down { my ($self, $ev, $x, $y) = @_; - if ($x < $self->{w} && $x >= $self->{w} - $self->{border} - && $y < $self->{h} && $y >= $self->{h} - $self->{border}) { + my $border = $self->border; + + if ($x < $self->{w} && $x >= $self->{w} - $border + && $y < $self->{h} && $y >= $self->{h} - $border) { my ($ox, $oy) = ($ev->button_x, $ev->button_y); my ($bw, $bh) = ($self->{w}, $self->{h}); @@ -657,7 +676,7 @@ }; } elsif ($x >= 0 && $x < $self->{w} - && $y >= 0 && $y < $self->{border}) { + && $y >= 0 && $y < $border) { my ($ox, $oy) = ($ev->button_x, $ev->button_y); my ($bx, $by) = ($self->{x}, $self->{y}); @@ -696,11 +715,13 @@ glEnable GL_TEXTURE_2D; glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; + my $border = $self->border; + glColor @{ $self->{border_bg} }; - $tex[1]->draw_quad (0, 0, $w, $self->{border}); - $tex[3]->draw_quad (0, $self->{border}, $self->{border}, $ch); - $tex[2]->draw_quad ($w - $self->{border}, $self->{border}, $self->{border}, $ch); - $tex[4]->draw_quad (0, $h - $self->{border}, $w, $self->{border}); + $tex[1]->draw_quad (0, 0, $w, $border); + $tex[3]->draw_quad (0, $border, $border, $ch); + $tex[2]->draw_quad ($w - $border, $border, $border, $ch); + $tex[4]->draw_quad (0, $h - $border, $w, $border); my $bg = $tex[0]; @@ -713,7 +734,7 @@ $bg->{s} = $rep_x; $bg->{t} = $rep_y; $bg->{wrap_mode} = 1; - $bg->draw_quad ($self->{border}, $self->{border}, $cw, $ch); + $bg->draw_quad ($border, $border, $cw, $ch); glDisable GL_TEXTURE_2D; glDisable GL_BLEND; @@ -746,8 +767,6 @@ $child->set_parent ($self); $self->{children}[$y][$x] = $child; - $self->{w} = $self->{h} = -1; - $child->check_size; } @@ -989,7 +1008,7 @@ my $self = $class->SUPER::new ( fg => [1, 1, 1], - fontsize => $::FONTSIZE, + fontsize => 1, text => "", align => -1, valign => -1, @@ -1038,7 +1057,7 @@ my ($self) = @_; $self->{layout}->set_width; - $self->{layout}->set_height ($self->{fontsize}); + $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); my ($w, $h) = $self->{layout}->size; @@ -1054,19 +1073,12 @@ delete $self->{texture}; } -sub update { - my ($self) = @_; - - delete $self->{texture}; - $self->SUPER::update; -} - sub _draw { my ($self) = @_; my $tex = $self->{texture} ||= do { $self->{layout}->set_width ($self->{w}); - $self->{layout}->set_height (List::Util::min $self->{h}, $self->{fontsize}); + $self->{layout}->set_height (List::Util::min $self->{h}, $self->{fontsize} * $::FONTSIZE); new_from_layout CFClient::Texture $self->{layout} }; @@ -1126,6 +1138,8 @@ return if $self->{text} eq $text; + delete $self->{texture}; + $self->{last_activity} = $::NOW; $self->{text} = $text; @@ -1544,8 +1558,8 @@ fg => [1, 1, 1], active_fg => [0, 0, 0], range => [0, 0, 100, 10], - req_w => 40, - req_h => 13, + req_w => 20, + req_h => 20, vertical => 0, can_hover => 1, inner_pad => 5, @@ -1665,9 +1679,7 @@ my $class = shift; my $self = $class->SUPER::new ( - req_w => $::WIDTH / 6, - req_h => $::HEIGHT / 6, - fontsize => $::FONTSIZE, + fontsize => 1, @_, layout => (new CFClient::Layout), @@ -1698,7 +1710,7 @@ my $layout = $self->{layout}; - $layout->set_height ($self->{fontsize}); + $layout->set_height ($self->{fontsize} * $::FONTSIZE); $layout->set_width ($self->{w}); $layout->set_text ($text); @@ -1712,20 +1724,15 @@ $self->update; } -sub size_request { - my ($self) = @_; - - ($self->{req_w}, $self->{req_h}) -} - sub size_allocate { my ($self, $w, $h) = @_; - $self->{layout}->set_height ($self->{fontsize}); - $self->{layout}->set_width ($self->{w}); + $self->SUPER::size_allocate ($w, $h); + + $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); + $self->{layout}->set_width ($self->{children}[0]{w}); $self->reflow; - $self->update; } sub add_paragraph { @@ -1915,7 +1922,7 @@ my ($w, $h, $data) = $::MAP->draw ($sx, $sy, 0, 0, $sw + 1, $sh + 1); if ($::CFG->{fow_enable}) { - if ($::CFG->{fow_smooth}) { # smooth fog of war + if ($::CFG->{fow_smooth} && $CFClient::GL_VERSION >= 1.2) { # smooth fog of war glConvolutionParameter (GL_CONVOLUTION_2D, GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER); glConvolutionFilter2D ( GL_CONVOLUTION_2D,