--- deliantra/Deliantra-Client/DC/UI.pm 2006/04/11 21:24:09 1.76 +++ deliantra/Deliantra-Client/DC/UI.pm 2006/04/11 22:14:13 1.77 @@ -45,7 +45,7 @@ $BUTTON_STATE &= ~(1 << ($ev->button - 1)); - $GRAB->button_down ($ev, $GRAB->translate ($x, $y)) if $GRAB; + $GRAB->button_up ($ev, $GRAB->translate ($x, $y)) if $GRAB; if (!$BUTTON_STATE) { my $grab = $GRAB; undef $GRAB; @@ -332,9 +332,8 @@ } sub add { - my ($self, $chld, $expand) = @_; + my ($self, $chld) = @_; - $chld->{expand} = $expand; $chld->set_parent ($self); $self->{children} = [ @@ -540,7 +539,10 @@ sub size_request { my ($self) = @_; - my ($w, $h) = $self->SUPER::size_request; + my ($w, $h) = + $self->{user_w} && $self->{user_h} + ? ($self->{user_w}, $self->{user_h}) + : ($self->SUPER::size_request); $h += $tex[1]->{h}; $h += $tex[4]->{h}; @@ -555,10 +557,10 @@ $self->_size_allocate ($x, $y, $w, $h) or return; - $h -= $tex[1]->{h}; - $h -= $tex[4]->{h}; - $w -= $tex[2]->{w}; - $w -= $tex[3]->{w}; + $h -= $tex[1]{h}; + $h -= $tex[4]{h}; + $w -= $tex[2]{w}; + $w -= $tex[3]{w}; $h = $h < 0 ? 0 : $h; $w = $w < 0 ? 0 : $w; @@ -568,6 +570,54 @@ $child->size_allocate ($tex[3]->{w}, $tex[1]->{h}, $w, $h); } +sub button_down { + my ($self, $ev, $x, $y) = @_; + + if ($x < $self->{w} && $x >= $self->{w} - $tex[2]{w} + && $y < $self->{h} && $y >= $self->{h} - $tex[4]{h}) { + + my ($ox, $oy) = ($ev->button_x, $ev->button_y); + my ($bw, $bh) = ($self->{w}, $self->{h}); + + $self->{motion} = sub { + my ($ev, $x, $y) = @_; + + ($x, $y) = ($ev->motion_x, $ev->motion_y); + + $self->{user_w} = $bw + $x - $ox; + $self->{user_h} = $bh + $y - $oy; + $self->update; + }; + + } elsif ($x >= 0 && $x < $self->{w} + && $y >= 0 && $y < $tex[1]{h}) { + + my ($ox, $oy) = ($ev->button_x, $ev->button_y); + my ($bx, $by) = ($self->{x}, $self->{y}); + + $self->{motion} = sub { + my ($ev, $x, $y) = @_; + + ($x, $y) = ($ev->motion_x, $ev->motion_y); + + $self->move ($bx + $x - $ox, $by + $y - $oy); + $self->update; + }; + } +} + +sub button_up { + my ($self, $ev, $x, $y) = @_; + + delete $self->{motion}; +} + +sub mouse_motion { + my ($self, $ev, $x, $y) = @_; + + $self->{motion}->($ev, $x, $y) if $self->{motion}; +} + sub _draw { my ($self) = @_; @@ -674,8 +724,8 @@ my $req_h = List::Util::sum @$hs; # linearly scale sizes - $_ *= $req_w / $w for @$ws; - $_ *= $req_h / $h for @$hs; + $_ *= $w / $req_w for @$ws; + $_ *= $h / $req_h for @$hs; my $y; @@ -764,16 +814,14 @@ # ah well, not enough space $_ = $h[$_] * $h / $req_h for @h; } else { - my @exp = grep $_->{expand}, @$children; - @exp = @$children unless @exp; + my $exp = List::Util::sum map $_->{expand}, @$children; + $exp ||= 1; - my %exp = map +($_ => 1), @exp; - for (0 .. $#$children) { my $child = $children->[$_]; my $alloc_h = $h[$_]; - $alloc_h += ($h - $req_h) / @exp if $exp{$child}; + $alloc_h += ($h - $req_h) * $child->{expand} / $exp; $h[$_] = $alloc_h; } } @@ -824,17 +872,13 @@ # ah well, not enough space $_ = $h[$_] * $h / $req_h for @h; } else { - my @exp = grep $_->{expand}, @$children; - @exp = @$children unless @exp; + my $exp = List::Util::sum map $_->{expand}, @$children; + $exp ||= 1; - my %exp = map +($_ => 1), @exp; - for (0 .. $#$children) { my $child = $children->[$_]; - my $alloc_h = $h[$_]; - $alloc_h += ($h - $req_h) / @exp if $exp{$child}; - $h[$_] = $alloc_h; + $h[$_] += ($h - $req_h) * $child->{expand} / $exp; } } @@ -948,7 +992,7 @@ : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding} : ($self->{w} - $tex->{w}) * 0.5; - $tex->draw_quad ($x, 0); + $tex->draw_quad ($x, $self->{padding}); glDisable GL_TEXTURE_2D; glDisable GL_BLEND; @@ -1259,8 +1303,8 @@ sub size_request { ( - 1 + int $::WIDTH / 32, - 1 + int $::HEIGHT / 32, + 1 + 32 * int $::WIDTH / 32, + 1 + 32 * int $::HEIGHT / 32, ) } @@ -1271,7 +1315,7 @@ $self->SUPER::update; } -sub _draw { +sub draw { my ($self) = @_; if (delete $self->{need_update}) {