Improving Zoom by keyboardShortcut

This commit is contained in:
Samir55 2017-04-19 15:33:42 +02:00
parent 4961b74c3e
commit 75291772ce
5 changed files with 38 additions and 16 deletions

View File

@ -332,7 +332,6 @@ sub set_viewport_from_scene {
sub zoom{
my ($self, $direction) = @_;
print ($direction);
if( $direction eq 'in'){
$self->_zoom($self->_zoom / (1-0.3));
}

View File

@ -183,6 +183,8 @@ sub _init_menubar {
$self->_append_menu_item($self->{plater_menu}, "Select Prev Object\tCtrl+Left", 'Select Previous Object in the plater', sub {
$plater->select_prev;
}, undef, 'arrow_left.png');
$self->_append_menu_item($self->{plater_menu}, "Zoom In\tCtrl+up" , 'Zoom In' , sub { $self->{plater}->zoom('in' ); });
$self->_append_menu_item($self->{plater_menu}, "Zoom Out\tCtrl+down" , 'Zoom Out' , sub { $self->{plater}->zoom('out' ); });
$self->{plater_menu}->AppendSeparator();
$self->_append_menu_item($self->{plater_menu}, "Export G-code...", 'Export current plate as G-code', sub {
$plater->export_gcode;
@ -193,8 +195,6 @@ sub _init_menubar {
$self->_append_menu_item($self->{plater_menu}, "Export plate with modifiers as AMF...", 'Export current plate as AMF, including all modifier meshes', sub {
$plater->export_amf;
}, undef, 'brick_go.png');
$self->_append_menu_item($self->{plater_menu}, "Zoom In\tCtrl+up" , 'Zoom In' , sub { $self->zoom('in' ); });
$self->_append_menu_item($self->{plater_menu}, "Zoom Out\tCtrl+down" , 'Zoom Out' , sub { $self->zoom('out' ); });
$self->{object_menu} = $self->{plater}->object_menu;
$self->on_plater_selection_changed(0);
}
@ -628,13 +628,8 @@ sub select_tab {
# Set a camera direction, zoom to all objects.
sub select_view {
my ($self, $direction) = @_;
$self->{plater}->select_view($direction);
}
sub zoom{
my($self, $direction) = @_;
$self->{plater}->zoom($direction);
$self->{plater}->select_view($direction);
}
sub _append_menu_item {

View File

@ -91,7 +91,7 @@ sub new {
my $on_instances_moved = sub {
$self->on_model_change;
};
# Initialize 3D plater
if ($Slic3r::GUI::have_OpenGL) {
$self->{canvas3D} = Slic3r::GUI::Plater::3D->new($self->{preview_notebook}, $self->{objects}, $self->{model}, $self->{config});
@ -2434,7 +2434,21 @@ sub select_view {
sub zoom{
my ($self, $direction) = @_;
$self->{canvas3D}->zoom($direction);
#Apply Zoom to the current active tab
my ($currentSelection) = $self->{preview_notebook}->GetSelection;
if($currentSelection == 0){
$self->{canvas3D}->zoom($direction) if($self->{canvas3D});
}
# elsif($currentSelection == 1) { #2D platter should zomobe applied here or not ?
# }
elsif($currentSelection == 2){ #3d Preview tab
$self->{preview3D}->canvas->zoom($direction) if($self->{preview3D});
}
elsif($currentSelection == 3) { #2D toolpaths tab
$self->{toolpaths2D}->{canvas}->zoom($direction) if($self->{toolpaths2D});
}
else {#Do Nothing
}
}
package Slic3r::GUI::Plater::DropTarget;

View File

@ -187,21 +187,21 @@ sub new {
$zoom /= 10;
$self->_zoom($self->_zoom / (1-$zoom));
$self->_zoom(1) if $self->_zoom > 1; # prevent from zooming out too much
{
# In order to zoom around the mouse point we need to translate
# the camera target. This math is almost there but not perfect yet...
my $camera_bb_size = $self->_camera_bb->size;
my $size = Slic3r::Pointf->new($self->GetSizeWH);
my $pos = Slic3r::Pointf->new($e->GetPositionXY);
# calculate the zooming center in pixel coordinates relative to the viewport center
my $vec = Slic3r::Pointf->new($pos->x - $size->x/2, $pos->y - $size->y/2); #-
# calculate where this point will end up after applying the new zoom
my $vec2 = $vec->clone;
$vec2->scale($old_zoom / $self->_zoom);
# move the camera target by the difference of the two positions
$self->_camera_target->translate(
-($vec->x - $vec2->x) * $camera_bb_size->x / $size->x,
@ -217,6 +217,20 @@ sub new {
return $self;
}
sub zoom{
my($self, $direction) = @_;
if( $direction eq 'in'){
$self->_zoom($self->_zoom / (1+0.3));
}
elsif($direction eq 'out'){
$self->_zoom($self->_zoom / (1-0.3));
$self->_zoom(1) if $self->_zoom > 1; # prevent from zooming out too much
}
#apply changes
$self->_dirty(1);
$self->Refresh;
}
sub mouse_event {
my ($self, $e) = @_;

View File

@ -6,7 +6,7 @@ use warnings;
BEGIN {
use FindBin;
use lib "$FindBin::Bin/lib";
use local::lib '--no-create', "$FindBin::Bin/local-lib";
use local::lib "$FindBin::Bin/local-lib";
}
use File::Basename qw(basename);