--- deliantra/Deliantra-Client/DC/UI.pm 2006/05/30 02:22:02 1.257 +++ deliantra/Deliantra-Client/DC/UI.pm 2006/05/30 02:55:45 1.258 @@ -28,6 +28,8 @@ $win->{y} = ($_->{y} + $_->{h} * 0.5) / $::HEIGHT if $_->{y} =~ /^[0-9.]+$/; $win->{w} = $_->{w} / $::WIDTH if defined $_->{w}; $win->{h} = $_->{h} / $::HEIGHT if defined $_->{h}; + + $win->{show} = $_->{visible} && $_->{is_toplevel}; } $layout @@ -35,6 +37,7 @@ sub set_layout { my ($layout) = @_; + $LAYOUT = $layout; } @@ -209,6 +212,14 @@ @_ }, $class; + Scalar::Util::weaken ($CFClient::UI::WIDGET{$self+0} = $self); + + for (keys %$self) { + if (/^on_(.*)$/) { + $self->connect ($1 => delete $self->{$_}); + } + } + if (my $layout = $CFClient::UI::LAYOUT->{$self->{name}}) { $self->{x} = $layout->{x} * $CFClient::UI::ROOT->{w} if exists $layout->{x}; $self->{y} = $layout->{y} * $CFClient::UI::ROOT->{h} if exists $layout->{y}; @@ -217,14 +228,8 @@ $self->{x} -= $self->{force_w} * 0.5 if exists $layout->{x}; $self->{y} -= $self->{force_h} * 0.5 if exists $layout->{y}; - } - - Scalar::Util::weaken ($CFClient::UI::WIDGET{$self+0} = $self); - for (keys %$self) { - if (/^on_(.*)$/) { - $self->connect ($1 => delete $self->{$_}); - } + $self->show if $layout->{show}; } $self @@ -465,7 +470,6 @@ my ($self, $parent) = @_; Scalar::Util::weaken ($self->{parent} = $parent); - $self->set_visible if $parent->{visible}; } @@ -1029,6 +1033,8 @@ border_bg => [1, 1, 1, 1], border => 0.6, can_events => 1, + min_w => 16, + min_h => 16, @_ ); @@ -1422,7 +1428,8 @@ fontsize => 1, align => -1, valign => -1, - padding => 2, + padding_x => 2, + padding_y => 2, can_events => 0, %arg ); @@ -1508,10 +1515,7 @@ $h = List::Util::max $h, $h2; } - ( - $w + $self->{padding} * 2, - $h + $self->{padding} * 2, - ) + ($w, $h) } sub size_allocate { @@ -1545,12 +1549,12 @@ my $tex = new_from_layout CFClient::Texture $self->{layout}; - $self->{ox} = int ($self->{align} < 0 ? $self->{padding} - : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding} + $self->{ox} = int ($self->{align} < 0 ? $self->{padding_x} + : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding_x} : ($self->{w} - $tex->{w}) * 0.5); - $self->{oy} = int ($self->{valign} < 0 ? $self->{padding} - : $self->{valign} > 0 ? $self->{h} - $tex->{h} - $self->{padding} + $self->{oy} = int ($self->{valign} < 0 ? $self->{padding_y} + : $self->{valign} > 0 ? $self->{h} - $tex->{h} - $self->{padding_y} : ($self->{h} - $tex->{h}) * 0.5); $tex @@ -1799,7 +1803,8 @@ my $class = shift; $class->SUPER::new ( - padding => 4, + padding_x => 4, + padding_y => 4, fg => [1, 1, 1], active_fg => [0, 0, 1], can_hover => 1, @@ -1856,7 +1861,8 @@ my $class = shift; $class->SUPER::new ( - padding => 2, + padding_x => 2, + padding_y => 2, fg => [1, 1, 1], active_fg => [1, 1, 0], bg => [0, 0, 0, 0.2], @@ -1870,14 +1876,14 @@ sub size_request { my ($self) = @_; - ($self->{padding} * 2 + 6) x 2 + (6) x 2 } sub button_down { my ($self, $ev, $x, $y) = @_; - if ($x >= $self->{padding} && $x < $self->{w} - $self->{padding} - && $y >= $self->{padding} && $y < $self->{h} - $self->{padding}) { + if ($x >= $self->{padding_x} && $x < $self->{w} - $self->{padding_x} + && $y >= $self->{padding_y} && $y < $self->{h} - $self->{padding_y}) { $self->{state} = !$self->{state}; $self->_emit (changed => $self->{state}); } @@ -1888,9 +1894,11 @@ $self->SUPER::_draw; - glTranslate $self->{padding} + 0.375, $self->{padding} + 0.375, 0; + glTranslate $self->{padding_x} + 0.375, $self->{padding_y} + 0.375, 0; - my $s = (List::Util::min @$self{qw(w h)}) - $self->{padding} * 2; + my ($w, $h) = @$self{qw(w h)}; + + my $s = List::Util::min $w - $self->{padding_x} * 2, $h - $self->{padding_y} * 2; glColor @{ $FOCUS == $self ? $self->{active_fg} : $self->{fg} }; @@ -2856,7 +2864,7 @@ $self->{button} = $ev->{button}; $self->show; - $self->move ($ev->{x} - $self->{w} * 0.5, $ev->{y} - $self->{h} * 0.5); + $self->move_abs ($ev->{x} - $self->{w} * 0.5, $ev->{y} - $self->{h} * 0.5); } sub mouse_motion { @@ -3141,10 +3149,8 @@ my ($w, $h) = $widget->size_request; - my $min_size = $widget->{is_toplevel} ? 16 : 0; - - $w = List::Util::max $widget->{min_w} || $widget->{is_toplevel} * 16, $w; - $h = List::Util::max $widget->{min_h} || $widget->{is_toplevel} * 16, $h; + $w = List::Util::max $widget->{min_w}, $w + $widget->{padding_x} * 2; + $h = List::Util::max $widget->{min_h}, $h + $widget->{padding_y} * 2; $w = $widget->{force_w} if exists $widget->{force_w}; $h = $widget->{force_h} if exists $widget->{force_h};