--- deliantra/Deliantra-Client/DC/UI.pm 2006/05/13 23:17:49 1.201 +++ deliantra/Deliantra-Client/DC/UI.pm 2006/05/15 00:15:08 1.205 @@ -14,6 +14,8 @@ our $TOOLTIP; our $BUTTON_STATE; +our %WIDGET; # all widgets, weak-referenced + sub check_tooltip { if (!$GRAB) { for (my $widget = $HOVER; $widget; $widget = $widget->{parent}) { @@ -31,9 +33,8 @@ my ($x, $y) = $widget->coord2global ($widget->{w}, 0); - if ($x + $TOOLTIP->{w} > $::WIDTH) { - ($x, $y) = $widget->coord2global (-$TOOLTIP->{w}, 0); - } + ($x, $y) = $widget->coord2global (-$TOOLTIP->{w}, 0) + if $x + $TOOLTIP->{w} > $::WIDTH; $TOOLTIP->move ($x, $y); $TOOLTIP->check_size; @@ -137,6 +138,26 @@ } } +# call when resolution changes etc. +sub rescale_widgets { + my ($sx, $sy) = @_; + + for my $widget (values %WIDGET) { + if ($widget->{toplevel}) { + $widget->{x} = int 0.5 + $widget->{x} * $sx if exists $widget->{x}; + $widget->{w} = int 0.5 + $widget->{w} * $sx if exists $widget->{w}; + $widget->{req_w} = int 0.5 + $widget->{req_w} * $sx if exists $widget->{req_w}; + $widget->{user_w} = int 0.5 + $widget->{user_w} * $sx if exists $widget->{user_w}; + $widget->{y} = int 0.5 + $widget->{y} * $sy if exists $widget->{y}; + $widget->{h} = int 0.5 + $widget->{h} * $sy if exists $widget->{h}; + $widget->{req_h} = int 0.5 + $widget->{req_h} * $sy if exists $widget->{req_h}; + $widget->{user_h} = int 0.5 + $widget->{user_h} * $sy if exists $widget->{user_h}; + } + + $widget->reconfigure; + } +} + ############################################################################# package CFClient::UI::Base; @@ -162,6 +183,8 @@ } } + Scalar::Util::weaken ($CFClient::UI::WIDGET{$self+0} = $self); + $self } @@ -244,20 +267,16 @@ # nothing to be done } -sub children { -} - -# call when resolution changes etc. sub reconfigure { my ($self) = @_; - $_->reconfigure - for $self->children; - $self->check_size (1); $self->update; } +sub children { +} + sub set_max_size { my ($self, $w, $h) = @_; @@ -358,7 +377,7 @@ glVertex 0 , $self->{h}; glEnd; glPopMatrix; - CFClient::UI::Label->new (w => $self->{w}, h => $self->{h}, text => $self, fontsize => 0)->_draw; + #CFClient::UI::Label->new (w => $self->{w}, h => $self->{h}, text => $self, fontsize => 0)->_draw; } } @@ -419,6 +438,7 @@ sub DESTROY { my ($self) = @_; + delete $WIDGET{$self+0}; #$self->deactivate; } @@ -842,6 +862,7 @@ bg => [1, 1, 1, 1], border_bg => [1, 1, 1, 1], border => 0.6, + toplevel => 1, can_events => 1, @_ ); @@ -2670,7 +2691,7 @@ for ($short) { s/^\s+//; - s/\012.*/…/s; + s/\s+/ /g; my $len = int 40 / $item->{fontsize}; substr $_, $len, length, "…" if $len < length; } @@ -2681,7 +2702,7 @@ tooltip_font => $::FONT_PROP, tooltip_width => 0.67, fontsize => $item->{fontsize}, - color => $item->{color}, + fg => $item->{fg}, can_events => 1, can_hover => 1 }; @@ -2718,7 +2739,7 @@ timeout => $timeout, tooltip => $text, fontsize => 0.8, - color => [0.8, 0.8, 0.8, 0.8], + fg => [0.8, 0.8, 0.8, 0.8], pri => 0, count => 1, %arg, @@ -2767,32 +2788,26 @@ sub size_allocate { my ($self, $w, $h) = @_; - my $old_w = $self->{old_w}; - my $old_h = $self->{old_h}; + my $old_w = $self->{old_w}; $self->{old_w} = $w; + my $old_h = $self->{old_h}; $self->{old_h} = $h; - if ($old_w && $old_h) { - for my $child ($self->children) { - $child->{x} = int 0.5 + $child->{x} * $w / $old_w; - $child->{w} = int 0.5 + $child->{w} * $w / $old_w; - $child->{req_w} = int 0.5 + $child->{req_w} * $w / $old_w if exists $child->{req_w}; - $child->{user_w} = int 0.5 + $child->{user_w} * $w / $old_w if exists $child->{user_w}; - $child->{y} = int 0.5 + $child->{y} * $h / $old_h; - $child->{h} = int 0.5 + $child->{h} * $h / $old_h; - $child->{req_h} = int 0.5 + $child->{req_h} * $h / $old_h if exists $child->{req_h}; - $child->{user_h} = int 0.5 + $child->{user_h} * $h / $old_h if exists $child->{user_h}; - } - } + CFClient::UI::rescale_widgets $w / $old_w, $h / $old_h + if $old_w && $old_h && ($old_w != $w || $old_h != $h); for my $child ($self->children) { my ($X, $Y, $W, $H) = @$child{qw(x y req_w req_h)}; - $X = List::Util::max 0, List::Util::min $w - $W, $X; - $Y = List::Util::max 0, List::Util::min $h - $H, $Y; + $X = $child->{req_x} > 0 ? $child->{req_x} : $w - $W - $child->{req_x} + 1 + if exists $child->{req_x}; + + $Y = $child->{req_y} > 0 ? $child->{req_y} : $h - $H - $child->{req_y} + 1 + if exists $child->{req_y}; + + $X = List::Util::max 0, List::Util::min $w - $W, int $X + 0.5; + $Y = List::Util::max 0, List::Util::min $h - $H, int $Y + 0.5; + $child->configure ($X, $Y, $W, $H); } - - $self->{old_w} = $w; - $self->{old_h} = $h; } sub coord2local { @@ -2815,13 +2830,17 @@ } sub add { - my ($self, $child) = @_; + my ($self, @children) = @_; - # integerise window positions - $child->{x} = int $child->{x}; - $child->{y} = int $child->{y}; + for my $child (@children) { + $child->{toplevel} = 1; - $self->SUPER::add ($child); + # integerise window positions + $child->{x} = int $child->{x}; + $child->{y} = int $child->{y}; + } + + $self->SUPER::add (@children); } sub on_refresh {