--- deliantra/Deliantra-Client/DC/UI.pm 2006/04/21 15:03:46 1.146 +++ deliantra/Deliantra-Client/DC/UI.pm 2006/04/22 23:11:32 1.149 @@ -142,7 +142,7 @@ sub size_request { require Carp; - Carp::confess "size_request is abtract"; + Carp::confess "size_request is abstract"; } sub configure { @@ -154,8 +154,8 @@ # use alignment to adjust x, y - $x += ($w - $w2) * 0.5; - $y += ($h - $h2) * 0.5; + $x += int +($w - $w2) * 0.5; + $y += int +($h - $h2) * 0.5; ($w, $h) = ($w2, $h2); } @@ -296,14 +296,15 @@ sub check_size { my ($self) = @_; + return unless $self->{parent}; + my ($w, $h) = $self->size_request; if ($w != $self->{req_w} || $h != $self->{req_h}) { $self->{req_w} = $w; $self->{req_h} = $h; - $self->{parent}->check_size - if $self->{parent}; + $self->{parent}->check_size; } } @@ -563,7 +564,7 @@ sub size_request { my ($self) = @_; - @$self{qw(child_w child_h)} = $self->child->size_request; + @$self{qw(child_w child_h)} = @{$self->child}{qw(req_w req_h)}; $self->child->size_allocate (0, 0, @$self{qw(child_w child_h)}); @$self{qw(child_w child_h)} @@ -584,38 +585,60 @@ use CFClient::OpenGL; -sub size_request { - my ($self) = @_; - my $chld = $self->child - or return (0, 0); +sub new { + my $class = shift; + + my $self = $class->SUPER::new ( + bg => [1, 1, 1, 1], + border_bg => [1, 1, 1, 1], + border => 0.8, + @_ + ); - $chld->move (2, 2); + $self +} - map { $_ + 4 } $chld->size_request; +sub set_size { + my ($self, $w, $h) = @_; + $self->{req_w} = $w; + $self->{req_h} = $h; + $self->check_size; +} + +sub size_request { + my ($self) = @_; + ($self->{req_w}, $self->{req_h}) } sub size_allocate { - my ($self, $x, $y, $w, $h) = @_; - - $self->child->configure (2, 2, $w - 4, $h - 4); + my ($self, $w, $h) = @_; + $self->{w} = $w; + $self->{h} = $h; + $self->child->configure (0, 0, $w, $h); } sub _draw { my ($self) = @_; - my $chld = $self->child; + my ($w, $h) = ($self->{w}, $self->{h}); - my ($w, $h) = $chld->size_request; + glEnable GL_BLEND; + glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; + glEnable GL_TEXTURE_2D; + glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; - glBegin GL_QUADS; - glColor 0, 0, 0; - glVertex 0 , 0; - glVertex 0 , $h + 4; - glVertex $w + 4 , $h + 4; - glVertex $w + 4 , 0; - glEnd; +# glBegin GL_QUADS; +# glColor 0, 0, 0, 0; +# glVertex 0 , 0; +# glVertex 0 , $h; +# glVertex $w, $h; +# glVertex $w, 0; +# glEnd; - $chld->draw; + + $self->child->draw; + glDisable GL_BLEND; + glDisable GL_TEXTURE_2D; } ############################################################################# @@ -817,7 +840,7 @@ for my $x (0 .. $#$row) { my $widget = $row->[$x] or next; - my ($w, $h) = $widget->size_request; + my ($w, $h) = @$widget{qw(req_w req_h)}; $w[$x] = max $w[$x], $w; $h[$y] = max $h[$y], $h; @@ -932,7 +955,7 @@ my $children = $self->{children}; - my @h = map +($_->size_request)[0], @$children; + my @h = map $_->{req_w}, @$children; my $req_h = List::Util::sum @h; @@ -990,7 +1013,7 @@ my $children = $self->{children}; - my @h = map +($_->size_request)[1], @$children; + my @h = map $_->{req_h}, @$children; my $req_h = List::Util::sum @h; @@ -1072,6 +1095,7 @@ $self->{layout}->set_text ($text); delete $self->{texture}; + $self->check_size; $self->update; } @@ -1081,6 +1105,7 @@ $self->{layout}->set_markup ($markup); delete $self->{texture}; + $self->check_size; $self->update; } @@ -1117,7 +1142,7 @@ my ($self, $fontsize) = @_; $self->{fontsize} = $fontsize; - $self->update; + $self->check_size; } sub _draw { @@ -1210,7 +1235,7 @@ sub size_allocate { my ($self, $w, $h) = @_; - $self->_set_text ($self->{text}); + $self->_set_text (delete $self->{text});#d# don't check for == inside _set_text } sub set_text { @@ -1490,6 +1515,8 @@ my $tex = $self->{tex} = $loaded_images{$self->{image}}; + Scalar::Util::weaken $loaded_images{$self->{image}}; + $self->{aspect} = $tex->{w} / $tex->{h}; $self @@ -1666,7 +1693,6 @@ $self->{value}->set_fontsize ($fsize); $self->{max} ->set_fontsize ($fsize); - $self->update; } sub set_value { @@ -2071,7 +2097,7 @@ sub check_size { my ($self) = @_; - $self->configure (0, 0, $::WITH, $::HEIGHT); + $self->configure (0, 0, $::WIDTH, $::HEIGHT); } sub size_request { @@ -2083,8 +2109,13 @@ $self->SUPER::configure ($x, $y, $w, $h); - $_->configure ($_->{x}, $_->{y}, $_->size_request) - for @{$self->{children}}; + 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; + $child->configure ($X, $Y, $W,$H); + } } sub _topleft {