--- deliantra/Deliantra-Client/DC/UI.pm 2006/05/28 02:31:03 1.250 +++ deliantra/Deliantra-Client/DC/UI.pm 2006/05/28 23:21:28 1.252 @@ -49,7 +49,6 @@ $tip = $tip->($widget) if CODE:: eq ref $tip; $TOOLTIP->set_tooltip_from ($widget); - $TOOLTIP->show; my ($x, $y) = $widget->coord2global ($widget->{w}, 0); @@ -57,8 +56,7 @@ if $x + $TOOLTIP->{w} > $::WIDTH; $TOOLTIP->move ($x, $y); - $TOOLTIP->check_size; - $TOOLTIP->update; + $TOOLTIP->show; } return; @@ -259,6 +257,10 @@ $self->{visible} = $self->{parent}{visible} + 1; $self->emit (visibility_change => 1); + + $self->realloc if !exists $self->{req_w}; + + $_->set_visible for $self->children; } sub set_invisible { @@ -266,7 +268,7 @@ return unless $self->{visible}; - # broken show/hide model + $_->set_invisible for $self->children; delete $self->{root}; delete $self->{visible}; @@ -275,7 +277,7 @@ undef $HOVER if $HOVER == $self; CFClient::UI::check_tooltip - if $CFClient::UI::TOOLTIP->{owner} == $self; + if $TOOLTIP->{owner} == $self; $self->focus_out; @@ -324,7 +326,7 @@ $self->{def_w} = $w; $self->{def_h} = $h; - $self->check_size; + $self->realloc; } sub size_request { @@ -354,7 +356,9 @@ } if ($self->{w} != $w || $self->{h} != $h) { - $CFClient::UI::ROOT->{size_alloc}{$self+0} = [$self, $w, $h]; + return unless $self->{visible}; + + $self->{root}->{size_alloc}{$self+0} = [$self, $w, $h]; } } @@ -362,13 +366,6 @@ # nothing to be done } -sub reconfigure { - my ($self) = @_; - - $self->check_size (1); - $self->update; -} - sub children { } @@ -455,6 +452,69 @@ sub y { $_[0]{y} = $_[1] if @_ > 1; $_[0]{y} } sub z { $_[0]{z} = $_[1] if @_ > 1; $_[0]{z} } +sub find_widget { + my ($self, $x, $y) = @_; + + return () unless $self->{can_events}; + + return $self + if $x >= $self->{x} && $x < $self->{x} + $self->{w} + && $y >= $self->{y} && $y < $self->{y} + $self->{h}; + + () +} + +sub set_parent { + my ($self, $parent) = @_; + + Scalar::Util::weaken ($self->{parent} = $parent); + + $self->set_visible if $parent->{visible}; +} + +sub connect { + my ($self, $signal, $cb) = @_; + + push @{ $self->{signal_cb}{$signal} }, $cb; +} + +sub _emit { + my ($self, $signal, @args) = @_; + + List::Util::sum map $_->($self, @args), @{$self->{signal_cb}{$signal} || []} +} + +sub emit { + my ($self, $signal, @args) = @_; + + $self->_emit ($signal, @args) + || $self->$signal (@args); +} + +sub visibility_change { + #my ($self, $visible) = @_; +} + +sub realloc { + my ($self) = @_; + + if ($self->{visible}) { + return if $self->{root}{realloc}{$self}; + + $self->{root}{realloc}{$self} = $self; + $self->{root}->update; + } else { + delete $self->{req_w}; + } +} + +sub update { + my ($self) = @_; + + $self->{parent}->update + if $self->{parent}; +} + sub draw { my ($self) = @_; @@ -501,65 +561,6 @@ warn "no draw defined for $self\n"; } -sub find_widget { - my ($self, $x, $y) = @_; - - return () unless $self->{can_events}; - - return $self - if $x >= $self->{x} && $x < $self->{x} + $self->{w} - && $y >= $self->{y} && $y < $self->{y} + $self->{h}; - - () -} - -sub set_parent { - my ($self, $parent) = @_; - - Scalar::Util::weaken ($self->{parent} = $parent); - - $self->set_visible; #TODO why breakssssss borked damn if $parent->{visible}; - - $self->check_size; -} - -sub check_size { - my ($self, $forced) = @_; - - $self->{force_alloc} = 1 if $forced; - $CFClient::UI::ROOT->{check_size}{$self} = $self; -} - -sub update { - my ($self) = @_; - - $self->{parent}->update - if $self->{parent}; -} - -sub connect { - my ($self, $signal, $cb) = @_; - - push @{ $self->{signal_cb}{$signal} }, $cb; -} - -sub _emit { - my ($self, $signal, @args) = @_; - - List::Util::sum map $_->($self, @args), @{$self->{signal_cb}{$signal} || []} -} - -sub emit { - my ($self, $signal, @args) = @_; - - $self->_emit ($signal, @args) - || $self->$signal (@args); -} - -sub visibility_change { - #my ($self, $visible) = @_; -} - sub DESTROY { my ($self) = @_; @@ -664,8 +665,7 @@ @{$self->{children}}, @widgets ]; - $self->check_size (1); - $self->update; + $self->realloc; } sub children { @@ -680,8 +680,7 @@ $self->{children} = [ grep $_ != $child, @{ $self->{children} } ]; - $self->check_size (1); - $self->update; + $self->realloc; } sub clear { @@ -695,8 +694,7 @@ $_->hide; } - $self->check_size; - $self->update; + $self->realloc; } sub find_widget { @@ -759,7 +757,7 @@ } sub size_allocate { - my ($self, $w, $h) = @_; + my ($self, $w, $h, $changed) = @_; $self->{children}[0]->configure (0, 0, $w, $h); } @@ -786,10 +784,11 @@ } sub size_allocate { - my ($self, $w, $h) = @_; + my ($self, $w, $h, $changed) = @_; - $self->SUPER::size_allocate ($w, $h); - $self->update; + $self->SUPER::size_allocate ($w, $h, $changed); + $self->update + if $changed; } sub _render { @@ -852,7 +851,7 @@ } sub size_allocate { - my ($self, $w, $h) = @_; + my ($self, $w, $h, $changed) = @_; $w = $self->{child_w} if $self->{scroll_x} && $self->{child_w}; $h = $self->{child_h} if $self->{scroll_y} && $self->{child_h}; @@ -949,9 +948,9 @@ } sub size_allocate { - my ($self, $w, $h) = @_; + my ($self, $w, $h, $changed) = @_; - $self->SUPER::size_allocate ($w, $h); + $self->SUPER::size_allocate ($w, $h, $changed); my $child = $self->{vp}->child; $self->{slider}->set_range ([$self->{slider}{range}[0], 0, $child->{h}, $self->{vp}{h}, 1]); @@ -1049,7 +1048,9 @@ } sub size_allocate { - my ($self, $w, $h) = @_; + my ($self, $w, $h, $changed) = @_; + + return unless $changed; $h -= List::Util::max 0, $self->border * 2; $w -= List::Util::max 0, $self->border * 2; @@ -1088,7 +1089,7 @@ $self->{def_w} = $bw + $dx * ($mx ? -1 : 1); $self->{def_h} = $bh + $dy * ($my ? -1 : 1); $self->move ($self->{user_x}, $self->{user_y}); - $self->check_size; + $self->realloc; }; } elsif ($lr ^ $td) { @@ -1104,7 +1105,7 @@ $self->{user_y} = $by + $y - $oy; $self->move ($self->{user_x}, $self->{user_y}); - $self->update; + $self->realloc; }; } } @@ -1189,7 +1190,7 @@ $child->set_parent ($self); $self->{children}[$y][$x] = $child; - $self->check_size (1); + $self->realloc; } # TODO: move to container class maybe? send children a signal on removal? @@ -1204,8 +1205,7 @@ $_->hide; } - $self->check_size (1); - $self->update; + $self->realloc; } sub get_wh { @@ -1242,7 +1242,7 @@ } sub size_allocate { - my ($self, $w, $h) = @_; + my ($self, $w, $h, $changed) = @_; my ($ws, $hs) = $self->get_wh; @@ -1330,7 +1330,7 @@ } sub size_allocate { - my ($self, $w, $h) = @_; + my ($self, $w, $h, $changed) = @_; my $space = $self->{vertical} ? $h : $w; my $children = $self->{children}; @@ -1469,8 +1469,8 @@ $self->{layout} = new CFClient::Layout if $self->{layout}->is_rgba; $self->{layout}->set_text ($text); + $self->realloc; $self->update; - $self->check_size; } sub set_markup { @@ -1484,8 +1484,8 @@ $self->{layout} = new CFClient::Layout $rgba if $self->{layout}->is_rgba != $rgba; $self->{layout}->set_markup ($markup); + $self->realloc; $self->update; - $self->check_size; } sub size_request { @@ -1516,9 +1516,10 @@ } sub size_allocate { - my ($self, $w, $h) = @_; + my ($self, $w, $h, $changed) = @_; - delete $self->{texture}; + delete $self->{texture} + if $changed; } sub set_fontsize { @@ -1527,8 +1528,7 @@ $self->{fontsize} = $fontsize; delete $self->{texture}; - $self->update; - $self->check_size; + $self->realloc; } sub _draw { @@ -1618,8 +1618,8 @@ $self->{cursor} = length $text; $self->_set_text ($text); - $self->update; - $self->check_size; + + $self->realloc; } sub get_text { @@ -1662,8 +1662,8 @@ } $self->_set_text ($text); - $self->update; - $self->check_size; + + $self->realloc; } sub focus_in { @@ -2180,6 +2180,8 @@ $self } +sub changed { } + sub set_range { my ($self, $range) = @_; @@ -2378,9 +2380,11 @@ } sub size_allocate { - my ($self, $w, $h) = @_; + my ($self, $w, $h, $changed) = @_; + + $self->SUPER::size_allocate ($w, $h, $changed); - $self->SUPER::size_allocate ($w, $h); + return unless $changed; $self->{layout}->set_font ($self->{font}) if $self->{font}; $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); @@ -2632,9 +2636,11 @@ } sub size_allocate { - my ($self, $w, $h) = @_; + my ($self, $w, $h, $changed) = @_; + + return unless $changed; - $self->SUPER::size_allocate ($w - 4, $h - 4); + $self->SUPER::size_allocate ($w - 4, $h - 4, $changed); } sub _draw { @@ -2661,6 +2667,7 @@ glEnd; glTranslate 2 - 0.375, 2 - 0.375; + $self->SUPER::_draw; } @@ -2979,10 +2986,14 @@ sub new { my $class = shift; - $class->SUPER::new ( + my $self = $class->SUPER::new ( visible => 1, @_, - ) + ); + + Scalar::Util::weaken ($self->{root} = $self); + + $self } sub configure { @@ -2992,10 +3003,12 @@ $self->{h} = $h; } -sub check_size { +sub reconfigure { my ($self) = @_; - $self->size_allocate ($self->{w}, $self->{h}) + $self->SUPER::reconfigure; + + $self->size_allocate ($self->{w}, $self->{h}, 1) if $self->{w}; } @@ -3006,7 +3019,7 @@ } sub size_allocate { - my ($self, $w, $h) = @_; + my ($self, $w, $h, $changed) = @_; for my $child ($self->children) { my ($X, $Y, $W, $H) = @$child{qw(x y req_w req_h)}; @@ -3041,7 +3054,6 @@ sub update { my ($self) = @_; - $self->check_size; $::WANT_REFRESH++; } @@ -3057,12 +3069,6 @@ } $self->SUPER::add (@children); - - for (my @widgets = @children; my $w = pop @widgets; ) { - push @widgets, $w->children; - $w->set_visible; - } - } sub remove { @@ -3097,37 +3103,34 @@ for values %{delete $self->{refresh_hook}}; } - if ($self->{check_size}) { + if ($self->{realloc}) { my @queue; while () { - if ($self->{check_size}) { + if ($self->{realloc}) { #TODO use array-of-depth approach @queue = sort { $a->{visible} <=> $b->{visible} } - @queue, values %{delete $self->{check_size}}; + @queue, values %{delete $self->{realloc}}; } my $widget = pop @queue || last; - defined $widget->{visible} or last; # do not resize invisible widgets + $widget->{visible} or last; # do not resize invisible widgets my ($w, $h) = $widget->{def_w} && $widget->{def_h} ? @$widget{qw(def_w def_h)} : $widget->size_request; - if (delete $widget->{force_alloc} - or $w != $widget->{req_w} or $h != $widget->{req_h}) { - Carp::confess "$widget: size_request is negative" if $w < 0 || $h < 0;#d# + Carp::confess "$widget: size_request is negative" if $w < 0 || $h < 0;#d# - $widget->{req_w} = $w; - $widget->{req_h} = $h; + $widget->{req_w} = $w; + $widget->{req_h} = $h; - $self->{size_alloc}{$widget} = [$widget, $widget->{w} || $w, $widget->{h} || $h]; + $self->{size_alloc}{$widget} = [$widget, $widget->{w} || $w, $widget->{h} || $h]; - $widget->{parent}->check_size - if $widget->{parent}; - } + push @queue, $widget->{parent} + if $widget->{parent}; } } @@ -3141,9 +3144,12 @@ $w = 0 if $w < 0; $h = 0 if $h < 0; + my $changed = $widget->{w} != $w || $widget->{h} != $h; + $widget->{w} = $w; $widget->{h} = $h; - $widget->emit (size_allocate => $w, $h); + + $widget->emit (size_allocate => $w, $h, $changed); } }