--- deliantra/Deliantra-Client/DC/UI.pm 2007/07/16 12:36:48 1.374 +++ deliantra/Deliantra-Client/DC/UI.pm 2007/07/16 20:22:39 1.378 @@ -946,6 +946,8 @@ package CFPlus::UI::ViewPort; +use List::Util qw(min max); + our @ISA = CFPlus::UI::Window::; sub new { @@ -986,10 +988,16 @@ sub set_offset { my ($self, $x, $y) = @_; - $self->{view_x} = int $x; - $self->{view_y} = int $y; + my $x = max 0, min $self->child->{w} - $self->{w}, int $x; + my $y = max 0, min $self->child->{h} - $self->{h}, int $y; - $self->update; + if ($x != $self->{view_x} or $y != $self->{view_y}) { + $self->{view_x} = $x; + $self->{view_y} = $y; + + $self->emit (changed => $x, $y); + $self->update; + } } # hmm, this does not work for topleft of $self... but we should not ask for that @@ -1074,9 +1082,17 @@ ); $self->{vp} = new CFPlus::UI::ViewPort - expand => 1, - scroll_x => $self->{scroll_x}, - scroll_y => $self->{scroll_y}, + expand => 1, + scroll_x => $self->{scroll_x}, + scroll_y => $self->{scroll_y}, + on_changed => sub { + my ($vp, $x, $y) = @_; + + $vp->{parent}{hslider}->set_value ($x); + $vp->{parent}{vslider}->set_value ($y); + + 0 + }, ; $self->SUPER::add (0, 0, $self->{vp}); @@ -1094,16 +1110,6 @@ $self->{vp}->add ($self->{child} = $widget); } -sub invoke_mouse_wheel { - my ($self, $ev) = @_; - - return 0 unless $ev->{dy}; # only vertical movements for now - - $self->{vslider}->emit (mouse_wheel => $ev); - - 1 -} - sub update_slider { my ($self) = @_; @@ -1135,6 +1141,59 @@ $self->update_slider; } +sub invoke_mouse_wheel { + my ($self, $ev) = @_; + + return 0 unless $ev->{dy}; # only vertical movements for now + + $self->{vslider}->emit (mouse_wheel => $ev); + + 1 +} + +sub invoke_button_down { + my ($self, $ev, $x, $y) = @_; + + if ($ev->{button} == 2) { + $self->grab_focus; + + my $ox = $self->{vp}{view_x} + $ev->{x}; + my $oy = $self->{vp}{view_y} + $ev->{y}; + + $self->{motion} = sub { + my ($ev, $x, $y) = @_; + + $self->{vp}->set_offset ($ox - $ev->{x}, $oy - $ev->{y}); + $self->update; + }; + + return 1; + } + + 0 +} + +sub invoke_button_up { + my ($self, $ev, $x, $y) = @_; + + if (delete $self->{motion}) { + return 1; + } + + 0 +} + +sub invoke_mouse_motion { + my ($self, $ev, $x, $y) = @_; + + if ($self->{motion}) { + $self->{motion}->($ev, $x, $y); + return 1; + } + + 0 +} + sub invoke_size_allocate { my ($self, $w, $h) = @_;