From 36ba2eb5d69dd51cc8619a65d3e4bc79e6f70a25 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Sun, 17 May 2015 21:29:57 +0200 Subject: [PATCH] Improved zoom/pan for toolpaths preview --- lib/Slic3r/GUI/Plater/2DToolpaths.pm | 59 ++++++++++++++++------------ 1 file changed, 34 insertions(+), 25 deletions(-) diff --git a/lib/Slic3r/GUI/Plater/2DToolpaths.pm b/lib/Slic3r/GUI/Plater/2DToolpaths.pm index 2149d0205..a68661099 100644 --- a/lib/Slic3r/GUI/Plater/2DToolpaths.pm +++ b/lib/Slic3r/GUI/Plater/2DToolpaths.pm @@ -84,7 +84,7 @@ sub reload_print { } $self->{canvas}->bb($self->print->total_bounding_box); - $self->{canvas}->Resize; + $self->{canvas}->_dirty(1); my %z = (); # z => 1 foreach my $object (@{$self->{print}->objects}) { @@ -169,14 +169,18 @@ sub new { $zoom = max(min($zoom, 4), -4); $zoom /= 10; $self->_zoom($self->_zoom / (1-$zoom)); - $self->_zoom(1) if $self->_zoom > 1; + $self->_zoom(1) if $self->_zoom > 1; # prevent from zooming out too much + + if (0) { + # In order to zoom around the mouse point we need to translate + # the camera target + my $camera_bb_size = $self->_camera_bb->size; + my $size = Slic3r::Pointf->new($self->GetSizeWH); + my $pos = Slic3r::Pointf->new($e->GetPositionXY); + # TODO... + } - # In order to zoom around the mouse point we need to translate - # the camera target - my $size = Slic3r::Pointf->new($self->GetSizeWH); - my $pos = Slic3r::Pointf->new($e->GetX, $size->y - $e->GetY); #- $self->_dirty(1); - $self->Resize; $self->Refresh; }); EVT_MOUSE_EVENTS($self, \&mouse_event); @@ -202,28 +206,13 @@ sub mouse_event { my ($x, $y) = $self->GetSizeWH; my $camera_bb_size = $self->_camera_bb->size; - my @translate = ( + # compute translation in model units + $self->_camera_target->translate( -$move->x * $camera_bb_size->x / $x, $move->y * $camera_bb_size->y / $y, # /** ); - # keep camera_bb within total bb - if ($self->_camera_bb->x_min < $self->bb->x_min) { - $translate[X] += $self->bb->x_min - $self->_camera_bb->x_min; - } - if ($self->_camera_bb->y_min < $self->bb->y_min) { - $translate[Y] += $self->bb->y_min - $self->_camera_bb->y_min; - } - if ($self->_camera_bb->x_max > $self->bb->x_max) { - $translate[X] -= $self->_camera_bb->x_max - $self->bb->x_max; - } - if ($self->_camera_bb->y_max > $self->bb->y_max) { - $translate[Y] -= $self->_camera_bb->y_max - $self->bb->y_max; - } - - $self->_camera_target->translate(@translate); - - $self->Resize; + $self->_dirty(1); $self->Refresh; } $self->_drag_start_xy($pos); @@ -495,6 +484,26 @@ sub Resize { # translate camera $bb->translate(@{$self->_camera_target}); + # keep camera_bb within total bb + # (i.e. prevent user from panning outside the bounding box) + { + my @translate = (0,0); + if ($bb->x_min < $self->bb->x_min) { + $translate[X] += $self->bb->x_min - $bb->x_min; + } + if ($bb->y_min < $self->bb->y_min) { + $translate[Y] += $self->bb->y_min - $bb->y_min; + } + if ($bb->x_max > $self->bb->x_max) { + $translate[X] -= $bb->x_max - $self->bb->x_max; + } + if ($bb->y_max > $self->bb->y_max) { + $translate[Y] -= $bb->y_max - $self->bb->y_max; + } + $self->_camera_target->translate(@translate); + $bb->translate(@translate); + } + # save camera $self->_camera_bb($bb);