--- deliantra/Deliantra-Client/DC/UI.pm 2008/09/03 10:36:25 1.468 +++ deliantra/Deliantra-Client/DC/UI.pm 2009/01/11 03:19:47 1.473 @@ -191,7 +191,7 @@ my ($sx, $sy) = @_; for my $widget (values %WIDGET) { - if ($widget->{is_toplevel}) { + if ($widget->{is_toplevel} || $widget->{c_rescale}) { $widget->{x} += int $widget->{w} * 0.5 if $widget->{x} =~ /^[0-9.]+$/; $widget->{y} += int $widget->{h} * 0.5 if $widget->{y} =~ /^[0-9.]+$/; @@ -288,6 +288,9 @@ return if $self->{visible}; + $self->{parent} && $self->{parent}{root}#d# + or return ::clienterror ("set_visible called without parent ($self->{parent}) or root\n" => 1); + $self->{root} = $self->{parent}{root}; $self->{visible} = $self->{parent}{visible} + 1; @@ -295,7 +298,7 @@ $self->realloc if !exists $self->{req_w}; - $_->set_visible for $self->children; + $_->set_visible for $self->visible_children; } sub set_invisible { @@ -1363,7 +1366,7 @@ my $self = $class->SUPER::new ( bg => [1, 1, 1, 1], border_bg => [1, 1, 1, 1], - border => 1, + border => 0.8, can_events => 1, min_w => 64, min_h => 32, @@ -1542,25 +1545,27 @@ my $border = $self->border; - glColor @{ $self->{border_bg} }; - $border[0]->draw_quad_alpha ( 0, 0, $w, $border); - $border[1]->draw_quad_alpha ( 0, $border, $border, $ch); - $border[2]->draw_quad_alpha ($w - $border, $border, $border, $ch); - $border[3]->draw_quad_alpha ( 0, $h - $border, $w, $border); - - # move - my $w2 = ($w - $border) * .5; - my $h2 = ($h - $border) * .5; - $icon[0]->draw_quad_alpha ( 0, $h2, $border, $border); - $icon[0]->draw_quad_alpha ($w - $border, $h2, $border, $border); - $icon[0]->draw_quad_alpha ($w2 , $h - $border, $border, $border); - - # resize - $icon[1]->draw_quad_alpha ( 0, 0, $border, $border); - $icon[1]->draw_quad_alpha ($w - $border, 0, $border, $border) - unless $self->{has_close_button}; - $icon[1]->draw_quad_alpha ( 0, $h - $border, $border, $border); - $icon[1]->draw_quad_alpha ($w - $border, $h - $border, $border, $border); + if ($border) { + glColor @{ $self->{border_bg} }; + $border[0]->draw_quad_alpha ( 0, 0, $w, $border); + $border[1]->draw_quad_alpha ( 0, $border, $border, $ch); + $border[2]->draw_quad_alpha ($w - $border, $border, $border, $ch); + $border[3]->draw_quad_alpha ( 0, $h - $border, $w, $border); + + # move + my $w2 = ($w - $border) * .5; + my $h2 = ($h - $border) * .5; + $icon[0]->draw_quad_alpha ( 0, $h2, $border, $border); + $icon[0]->draw_quad_alpha ($w - $border, $h2, $border, $border); + $icon[0]->draw_quad_alpha ($w2 , $h - $border, $border, $border); + + # resize + $icon[1]->draw_quad_alpha ( 0, 0, $border, $border); + $icon[1]->draw_quad_alpha ($w - $border, 0, $border, $border) + unless $self->{has_close_button}; + $icon[1]->draw_quad_alpha ( 0, $h - $border, $border, $border); + $icon[1]->draw_quad_alpha ($w - $border, $h - $border, $border, $border); + } if (@{$self->{bg}} < 4 || $self->{bg}[3]) { glColor @{ $self->{bg} }; @@ -2841,6 +2846,8 @@ my ($class, %arg) = @_; my $self = $class->SUPER::new ( + padding_x => 2, + padding_y => 2, fg => [1, 1, 1], bg => [0, 0, 1, 0.2], bar => [0.7, 0.5, 0.1, 0.8], @@ -2890,17 +2897,24 @@ glEnable GL_BLEND; glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; + my $px = $self->{padding_x}; + my $py = $self->{padding_y}; + if ($self->{value} >= 0) { - my $s = int 2 + ($self->{w} - 4) * $self->{value}; + my $s = int $px + ($self->{w} - $px * 2) * $self->{value}; glColor_premultiply @{$self->{bar}}; - glRect 2, 2, $s, $self->{h} - 2; + glRect $px, $py, $s, $self->{h} - $py; glColor_premultiply @{$self->{bg}}; - glRect $s, 2, $self->{w} - 2, $self->{h} - 2; + glRect $s , $py, $self->{w} - $px, $self->{h} - $py; } glColor_premultiply @{$self->{outline}}; - glRect_lineloop 1.5, 1.5, $self->{w} - 1.5, $self->{h} - 1.5; + + $px -= .5; + $py -= .5; + + glRect_lineloop $px, $py, $self->{w} - $px, $self->{h} - $py; glDisable GL_BLEND; @@ -2919,17 +2933,20 @@ sub new { my ($class, %arg) = @_; + my $tt = exists $arg{tooltip} ? "$arg{tooltip}\n\n" : ""; + my $self = $class->SUPER::new ( + %arg, tooltip => sub { my ($self) = @_; - sprintf "level %d\n%s points\n%s next level\n%s to go", + sprintf "%slevel %d\n%s points\n%s next level\n%s to go", + $tt, $self->{lvl}, ::formsep ($self->{exp}), ::formsep ($self->{nxt}), ::formsep ($self->{nxt} - $self->{exp}), }, - %arg ); $::CONN->{on_exp_update}{$self+0} = sub { $self->set_value ($self->{value}) } @@ -3894,6 +3911,8 @@ $self->show; $self->move_abs ($ev->{x} - $self->{w} * 0.5, $ev->{y} - $self->{h} * 0.5); + + 1 # so it can be used inside event handlers } sub invoke_mouse_motion { @@ -3935,8 +3954,7 @@ @_, ); - $self->{current} = $self->{children}[0] - if @{ $self->{children} }; + $self->set_current_page (0); $self } @@ -3946,8 +3964,8 @@ $self->SUPER::add (@widgets); - $self->{current} = $self->{children}[0] - if @{ $self->{children} }; + $self->set_current_page (0) + if @widgets == @{ $self->{children} }; } sub get_current_page { @@ -3963,28 +3981,35 @@ ? $page_or_widget : $self->{children}[$page_or_widget]; - $self->{current} = $widget; - $self->{current}->configure (0, 0, $self->{w}, $self->{h}); + $self->{current}->set_invisible if $self->{current} && $self->{visible}; + + if (($self->{current} = $widget)) { + $self->{current}->set_visible if $self->{current} && $self->{visible}; + $self->{current}->configure (0, 0, $self->{w}, $self->{h}); - $self->emit (page_changed => $self->{current}); + $self->emit (page_changed => $self->{current}); + } $self->realloc; } sub visible_children { - $_[0]{current} + $_[0]{current} || () } sub size_request { my ($self) = @_; - $self->{current}->size_request + $self->{current} + ? $self->{current}->size_request + : (0, 0) } sub invoke_size_allocate { my ($self, $w, $h) = @_; - $self->{current}->configure (0, 0, $w, $h); + $self->{current}->configure (0, 0, $w, $h) + if $self->{current}; 1 } @@ -3992,7 +4017,8 @@ sub _draw { my ($self) = @_; - $self->{current}->draw; + $self->{current}->draw + if $self->{current}; } ############################################################################# @@ -4212,7 +4238,7 @@ sub reorder { my ($self) = @_; - my $NOW = Time::HiRes::time; + my $NOW = EV::time; # freeze display when hovering over any label return if $DC::UI::TOOLTIP->{owner} @@ -4273,6 +4299,10 @@ push @widgets, $label; } + my $hash = join ",", @widgets; + return if $hash eq $self->{last_widget_hash}; + $self->{last_widget_hash} = $hash; + $self->clear; $self->SUPER::add (reverse @widgets); } @@ -4586,4 +4616,3 @@ $TOOLTIP = new DC::UI::Tooltip z => 900; 1 -