--- deliantra/Deliantra-Client/DC/UI.pm 2007/07/16 12:36:48 1.374 +++ deliantra/Deliantra-Client/DC/UI.pm 2007/07/16 20:12:19 1.375 @@ -946,6 +946,8 @@ package CFPlus::UI::ViewPort; +use List::Util qw(min max); + our @ISA = CFPlus::UI::Window::; sub new { @@ -986,8 +988,8 @@ sub set_offset { my ($self, $x, $y) = @_; - $self->{view_x} = int $x; - $self->{view_y} = int $y; + $self->{view_x} = max 0, min $self->child->{w} - $self->{w}, int $x; + $self->{view_y} = max 0, min $self->child->{h} - $self->{h}, int $y; $self->update; } @@ -1094,16 +1096,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 +1127,58 @@ $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; + + $self->{motion} = sub { + my ($ev, $x, $y) = @_; + + $self->{vp}->set_offset ( + $self->{vp}{view_x} - $ev->{xrel}, + $self->{vp}{view_y} - $ev->{yrel}, + ); + }; + + 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) = @_;