--- deliantra/Deliantra-Client/DC/UI.pm 2007/12/28 11:44:02 1.456 +++ deliantra/Deliantra-Client/DC/UI.pm 2007/12/29 13:44:30 1.459 @@ -370,10 +370,18 @@ sub get_max_wh { my ($self) = @_; - return $self->{parent}->get_max_wh - if $self->{parent}; + my ($w, $h) = @$self{qw(max_w max_h)}; + + if ($w <= 0 || $h <= 0) { + my ($mw, $mh) = $self->{parent} + ? $self->{parent}->get_max_wh + : ($::WIDTH, $::HEIGHT); + + $w = $mw if $w <= 0; + $h = $mh if $h <= 0; + } - ($::WIDTH, $::HEIGHT) + ($w, $h) } sub size_request { @@ -1243,7 +1251,7 @@ if ((exists $arg{label}) && !ref $arg{label}) { $arg{label} = new DC::UI::Label align => 1, - valign => 0, + valign => 0.5, text => $arg{label}, fontsize => ($arg{border} || 0.8) * 0.75; } @@ -1363,7 +1371,7 @@ ); $self->{title_widget} = new DC::UI::Label - align => 0, + align => 0.5, valign => 1, text => $self->{title}, fontsize => $self->{border}, @@ -1891,9 +1899,9 @@ ellipsise => 3, # end layout => (new DC::Layout), fontsize => 1, - align => -1, - valign => -1, - padding_x => 2, + align => 0.5, + valign => 0.5, + padding_x => 4, padding_y => 2, can_events => 0, %arg @@ -1969,7 +1977,7 @@ my ($max_w, $max_h) = $self->get_max_wh; $self->{layout}->set_font ($self->{font}) if $self->{font}; - $self->{layout}->set_width ($self->{max_w} || $max_w || -1); + $self->{layout}->set_width ($max_w); $self->{layout}->set_ellipsise ($self->{ellipsise}); $self->{layout}->set_single_paragraph_mode ($self->{ellipsise}); $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); @@ -1978,7 +1986,7 @@ if (exists $self->{template}) { $self->{template}->set_font ($self->{font}) if $self->{font}; - $self->{template}->set_width ($self->{max_w} || -1); + $self->{template}->set_width ($max_w); $self->{template}->set_height ($self->{fontsize} * $::FONTSIZE); my ($w2, $h2) = $self->{template}->size; @@ -2044,13 +2052,8 @@ }; unless (exists $self->{ox}) { - $self->{ox} = int ($self->{align} < 0 ? $self->{padding_x} - : $self->{align} > 0 ? $self->{w} - $size->[0] - $self->{padding_x} - : ($self->{w} - $size->[0]) * 0.5); - - $self->{oy} = int ($self->{valign} < 0 ? $self->{padding_y} - : $self->{valign} > 0 ? $self->{h} - $size->[1] - $self->{padding_y} - : ($self->{h} - $size->[1]) * 0.5); + $self->{ox} = $self->{padding_x} + int $self->{align} * ($self->{w} - $size->[0] - $self->{padding_x} * 2); + $self->{oy} = $self->{padding_y} + int $self->{valign} * ($self->{h} - $size->[1] - $self->{padding_y} * 2); $self->{layout}->render ($self->{ox}, $self->{oy}, $self->{style}); }; @@ -2095,7 +2098,8 @@ active_outline => [1, 1, 0], can_hover => 1, can_focus => 1, - valign => 0, + align => 0, + valign => 0.5, can_events => 1, ellipsise => 0, padding_x => 4, @@ -2353,11 +2357,11 @@ sub move_cursor_ver { my ($self, $dy) = @_; - my ($y, $x) = $self->{layout}->index_to_line_x ($self->{cursor}); + my ($line, $x) = $self->{layout}->index_to_line_x ($self->{cursor}); - $y += $dy; + $line += $dy; - if (defined (my $index = $self->{layout}->line_x_to_index ($y, $x))) { + if (defined (my $index = $self->{layout}->line_x_to_index ($line, $x))) { $self->{cursor} = $index; delete $self->{cur_h}; $self->update; @@ -2398,8 +2402,8 @@ $class->SUPER::new ( can_hover => 1, - align => 0, - valign => 0, + align => 0.5, + valign => 0.5, can_events => 1, @_ ) @@ -2451,8 +2455,8 @@ fg => [1.0, 1.0, 1.0], active_fg => [0.8, 0.8, 0.8], can_hover => 1, - align => 0, - valign => 0, + align => 0.5, + valign => 0.5, can_events => 1, @_ ) @@ -2654,8 +2658,8 @@ fg => [1, 1, 1], active_fg => [0, 0, 1], can_hover => 1, - align => 0, - valign => 0, + align => 0.5, + valign => 0.5, can_events => 1, @_ ); @@ -2829,8 +2833,8 @@ bar => [0.7, 0.5, 0.1, 0.8], outline => [0.4, 0.3, 0], fontsize => 0.9, - valign => 0, - align => 0, + valign => 0.5, + align => 0.5, can_events => 1, ellipsise => 1, label => "%d%%", @@ -2966,9 +2970,9 @@ %arg, ); - $self->add ($self->{value} = new DC::UI::Label valign => +1, align => 0, template => "999"); + $self->add ($self->{value} = new DC::UI::Label valign => 1, align => 0.5, template => "999"); $self->add ($self->{gauge} = new DC::UI::VGauge type => $self->{type}, expand => 1, can_hover => 1); - $self->add ($self->{max} = new DC::UI::Label valign => -1, align => 0, template => "999"); + $self->add ($self->{max} = new DC::UI::Label valign => 0, align => 0.5, template => "999"); $self } @@ -3306,7 +3310,7 @@ $layout->set_shapes ( map - +(0, $_->baseline_shift +$_->{padding_y} - $_->{h}, $_->{w}, $_->{h}), + +(0, $_->baseline_shift + $_->{padding_y} - $_->{h}, $_->{w}, $_->{h}), @{$para->{widget}} ); @@ -3609,6 +3613,7 @@ $self->add (new DC::UI::Label markup => $tip, max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH, + align => 0, fontsize => 0.8, style => 1, # FLAG_INVERSE ellipsise => 0, @@ -3843,7 +3848,7 @@ tooltip => $tooltip, children => [ (new DC::UI::Label markup => $left, expand => 1), - (new DC::UI::Label markup => $right, align => +1), + (new DC::UI::Label markup => $right, align => 1), ], ; @@ -3851,6 +3856,7 @@ $widget = new DC::UI::Label can_hover => 1, can_events => 1, + align => 0, markup => $widget, tooltip => $tooltip; } @@ -4224,6 +4230,7 @@ tooltip_width => 0.67, fontsize => $item->{fontsize} || $self->{fontsize}, max_w => $::WIDTH * 0.44, + align => 0, fg => [@{ $item->{fg} }], can_events => 1, can_hover => 1 @@ -4457,8 +4464,11 @@ my ($w, $h) = $widget->size_request; - $w = max $widget->{min_w}, $w + $widget->{padding_x} * 2; - $h = max $widget->{min_h}, $h + $widget->{padding_y} * 2; + $w += $widget->{padding_x} * 2; + $h += $widget->{padding_y} * 2; + + $w = max $widget->{min_w}, $w; + $h = max $widget->{min_h}, $h; $w = min $widget->{max_w}, $w if exists $widget->{max_w}; $h = min $widget->{max_h}, $h if exists $widget->{max_h};