From 2a2ba156654d4b92d562de8f2ac74d9e8aebb7bc Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Fri, 25 Apr 2014 18:36:08 +0200 Subject: [PATCH] Use a slider for the cutting GUI --- lib/Slic3r/GUI/OptionsGroup.pm | 18 ++++++++++++++++-- lib/Slic3r/GUI/Plater/ObjectCutDialog.pm | 4 +++- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/lib/Slic3r/GUI/OptionsGroup.pm b/lib/Slic3r/GUI/OptionsGroup.pm index 87f6b4779..f6e63fab8 100644 --- a/lib/Slic3r/GUI/OptionsGroup.pm +++ b/lib/Slic3r/GUI/OptionsGroup.pm @@ -3,7 +3,7 @@ use Moo; use List::Util qw(first); use Wx qw(:combobox :font :misc :sizer :systemsettings :textctrl); -use Wx::Event qw(EVT_CHECKBOX EVT_COMBOBOX EVT_SPINCTRL EVT_TEXT EVT_KILL_FOCUS); +use Wx::Event qw(EVT_CHECKBOX EVT_COMBOBOX EVT_SPINCTRL EVT_TEXT EVT_KILL_FOCUS EVT_SLIDER); =head1 NAME @@ -184,7 +184,7 @@ sub _build_field { my $field; my $tooltip = $opt->{tooltip}; - if ($opt->{type} =~ /^(i|f|s|s@|percent)$/) { + if ($opt->{type} =~ /^(i|f|s|s@|percent|slider)$/) { my $style = 0; $style = wxTE_MULTILINE if $opt->{multiline}; # default width on Windows is too large @@ -215,6 +215,20 @@ sub _build_field { }); EVT_TEXT($self->parent, $field, $on_change); EVT_KILL_FOCUS($field, $on_kill_focus); + } elsif ($opt->{type} eq 'slider') { + my $scale = 10; + $field = Wx::BoxSizer->new(wxHORIZONTAL); + my $slider = Wx::Slider->new($self->parent, -1, ($opt->{default} // $opt->{min})*$scale, ($opt->{min} // 0)*$scale, ($opt->{max} // 100)*$scale, wxDefaultPosition, $size); + my $statictext = Wx::StaticText->new($self->parent, -1, $slider->GetValue/$scale); + $field->Add($_, 0, wxALIGN_CENTER_VERTICAL, 0) for $slider, $statictext; + $self->_setters->{$opt_key} = sub { + $field->SetValue($_[0]*$scale); + }; + EVT_SLIDER($self->parent, $slider, sub { + my $value = $slider->GetValue/$scale; + $statictext->SetLabel($value); + $self->_on_change($opt_key, $value); + }); } else { $field = Wx::TextCtrl->new($self->parent, -1, $opt->{default}, wxDefaultPosition, $size, $style); $self->_setters->{$opt_key} = sub { $field->ChangeValue($_[0]) }; diff --git a/lib/Slic3r/GUI/Plater/ObjectCutDialog.pm b/lib/Slic3r/GUI/Plater/ObjectCutDialog.pm index 454ba5d11..b647debc2 100644 --- a/lib/Slic3r/GUI/Plater/ObjectCutDialog.pm +++ b/lib/Slic3r/GUI/Plater/ObjectCutDialog.pm @@ -34,9 +34,11 @@ sub new { options => [ { opt_key => 'z', - type => 'f', + type => 'slider', label => 'Z', default => $self->{cut_options}{z}, + min => 0, + max => $self->{model_object}->bounding_box->size->z, }, { opt_key => 'keep_upper',