From 917702f252126f909c1d5d556a307042c0a6c07c Mon Sep 17 00:00:00 2001 From: YuSanka Date: Tue, 18 Jun 2019 11:40:26 +0200 Subject: [PATCH] Fixed DoubleSlider manipulation from Preview scene --- src/slic3r/GUI/GLCanvas3D.cpp | 27 +++++++++++++++++---------- src/slic3r/GUI/GLCanvas3D.hpp | 1 + src/slic3r/GUI/GUI_Preview.cpp | 6 ++++++ src/slic3r/GUI/GUI_Preview.hpp | 1 + src/slic3r/GUI/Plater.cpp | 1 + src/slic3r/GUI/wxExtensions.cpp | 13 +++++++++++-- src/slic3r/GUI/wxExtensions.hpp | 1 + 7 files changed, 38 insertions(+), 12 deletions(-) diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index ca05f1695..d7b62cbf7 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -17,6 +17,7 @@ #include "slic3r/GUI/GUI.hpp" #include "slic3r/GUI/PresetBundle.hpp" #include "slic3r/GUI/Tab.hpp" +#include "slic3r/GUI/GUI_Preview.hpp" #include "GUI_App.hpp" #include "GUI_ObjectList.hpp" #include "GUI_ObjectManipulation.hpp" @@ -1209,6 +1210,7 @@ wxDEFINE_EVENT(EVT_GLCANVAS_UPDATE_BED_SHAPE, SimpleEvent); wxDEFINE_EVENT(EVT_GLCANVAS_TAB, SimpleEvent); wxDEFINE_EVENT(EVT_GLCANVAS_RESETGIZMOS, SimpleEvent); wxDEFINE_EVENT(EVT_GLCANVAS_MOVE_DOUBLE_SLIDER, wxKeyEvent); +wxDEFINE_EVENT(EVT_GLCANVAS_EDIT_COLOR_CHANGE, wxKeyEvent); GLCanvas3D::GLCanvas3D(wxGLCanvas* canvas, Bed3D& bed, Camera& camera, GLToolbar& view_toolbar) : m_canvas(canvas) @@ -2387,8 +2389,18 @@ void GLCanvas3D::on_char(wxKeyEvent& evt) case '4': { select_view("rear"); break; } case '5': { select_view("left"); break; } case '6': { select_view("right"); break; } - case '+': { post_event(Event(EVT_GLCANVAS_INCREASE_INSTANCES, +1)); break; } - case '-': { post_event(Event(EVT_GLCANVAS_INCREASE_INSTANCES, -1)); break; } + case '+': { + if (dynamic_cast(m_canvas->GetParent()) != nullptr) + post_event(wxKeyEvent(EVT_GLCANVAS_EDIT_COLOR_CHANGE, evt)); + else + post_event(Event(EVT_GLCANVAS_INCREASE_INSTANCES, +1)); + break; } + case '-': { + if (dynamic_cast(m_canvas->GetParent()) != nullptr) + post_event(wxKeyEvent(EVT_GLCANVAS_EDIT_COLOR_CHANGE, evt)); + else + post_event(Event(EVT_GLCANVAS_INCREASE_INSTANCES, -1)); + break; } case '?': { post_event(SimpleEvent(EVT_GLCANVAS_QUESTION_MARK)); break; } case 'A': case 'a': { post_event(SimpleEvent(EVT_GLCANVAS_ARRANGE)); break; } @@ -2472,15 +2484,10 @@ void GLCanvas3D::on_key(wxKeyEvent& evt) else if (keyCode == WXK_LEFT || keyCode == WXK_RIGHT || keyCode == WXK_UP || - keyCode == WXK_DOWN || - keyCode == '+' || - keyCode == WXK_NUMPAD_ADD || - keyCode == '-' || - keyCode == 390 || - keyCode == WXK_DELETE || - keyCode == WXK_BACK ) + keyCode == WXK_DOWN ) { - post_event(wxKeyEvent(EVT_GLCANVAS_MOVE_DOUBLE_SLIDER, evt)); + if (dynamic_cast(m_canvas->GetParent()) != nullptr) + post_event(wxKeyEvent(EVT_GLCANVAS_MOVE_DOUBLE_SLIDER, evt)); } } } diff --git a/src/slic3r/GUI/GLCanvas3D.hpp b/src/slic3r/GUI/GLCanvas3D.hpp index 96bb56bd9..fc7dddd46 100644 --- a/src/slic3r/GUI/GLCanvas3D.hpp +++ b/src/slic3r/GUI/GLCanvas3D.hpp @@ -125,6 +125,7 @@ wxDECLARE_EVENT(EVT_GLCANVAS_UPDATE_BED_SHAPE, SimpleEvent); wxDECLARE_EVENT(EVT_GLCANVAS_TAB, SimpleEvent); wxDECLARE_EVENT(EVT_GLCANVAS_RESETGIZMOS, SimpleEvent); wxDECLARE_EVENT(EVT_GLCANVAS_MOVE_DOUBLE_SLIDER, wxKeyEvent); +wxDECLARE_EVENT(EVT_GLCANVAS_EDIT_COLOR_CHANGE, wxKeyEvent); class GLCanvas3D { diff --git a/src/slic3r/GUI/GUI_Preview.cpp b/src/slic3r/GUI/GUI_Preview.cpp index ec7308382..2f5e10962 100644 --- a/src/slic3r/GUI/GUI_Preview.cpp +++ b/src/slic3r/GUI/GUI_Preview.cpp @@ -420,6 +420,12 @@ void Preview::move_double_slider(wxKeyEvent& evt) m_slider->OnKeyDown(evt); } +void Preview::edit_double_slider(wxKeyEvent& evt) +{ + if (m_slider) + m_slider->OnChar(evt); +} + void Preview::bind_event_handlers() { this->Bind(wxEVT_SIZE, &Preview::on_size, this); diff --git a/src/slic3r/GUI/GUI_Preview.hpp b/src/slic3r/GUI/GUI_Preview.hpp index ed4555f5c..93038b0e5 100644 --- a/src/slic3r/GUI/GUI_Preview.hpp +++ b/src/slic3r/GUI/GUI_Preview.hpp @@ -123,6 +123,7 @@ public: void msw_rescale(); void move_double_slider(wxKeyEvent& evt); + void edit_double_slider(wxKeyEvent& evt); private: bool init(wxWindow* parent, Bed3D& bed, Camera& camera, GLToolbar& view_toolbar, Model* model); diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 557b12377..da638fa9f 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -1518,6 +1518,7 @@ Plater::priv::priv(Plater *q, MainFrame *main_frame) preview->get_wxglcanvas()->Bind(EVT_GLCANVAS_UPDATE_BED_SHAPE, [this](SimpleEvent&) { set_bed_shape(config->option("bed_shape")->values); }); preview->get_wxglcanvas()->Bind(EVT_GLCANVAS_TAB, [this](SimpleEvent&) { select_next_view_3D(); }); preview->get_wxglcanvas()->Bind(EVT_GLCANVAS_MOVE_DOUBLE_SLIDER, [this](wxKeyEvent& evt) { preview->move_double_slider(evt); }); + preview->get_wxglcanvas()->Bind(EVT_GLCANVAS_EDIT_COLOR_CHANGE, [this](wxKeyEvent& evt) { preview->edit_double_slider(evt); }); q->Bind(EVT_SLICING_COMPLETED, &priv::on_slicing_completed, this); q->Bind(EVT_PROCESS_COMPLETED, &priv::on_process_completed, this); diff --git a/src/slic3r/GUI/wxExtensions.cpp b/src/slic3r/GUI/wxExtensions.cpp index 06cf9b7d5..fc3449760 100644 --- a/src/slic3r/GUI/wxExtensions.cpp +++ b/src/slic3r/GUI/wxExtensions.cpp @@ -2366,9 +2366,9 @@ void DoubleSlider::OnWheel(wxMouseEvent& event) void DoubleSlider::OnKeyDown(wxKeyEvent &event) { const int key = event.GetKeyCode(); - if (key == '+' || key == WXK_NUMPAD_ADD) + if (key == WXK_NUMPAD_ADD) action_tick(taAdd); - else if (key == '-' || key == 390 || key == WXK_DELETE || key == WXK_BACK) + else if (key == 390 || key == WXK_DELETE || key == WXK_BACK) action_tick(taDel); else if (is_horizontal()) { @@ -2398,6 +2398,15 @@ void DoubleSlider::OnKeyUp(wxKeyEvent &event) event.Skip(); } +void DoubleSlider::OnChar(wxKeyEvent& event) +{ + const int key = event.GetKeyCode(); + if (key == '+') + action_tick(taAdd); + else if (key == '-') + action_tick(taDel); +} + void DoubleSlider::OnRightDown(wxMouseEvent& event) { this->CaptureMouse(); diff --git a/src/slic3r/GUI/wxExtensions.hpp b/src/slic3r/GUI/wxExtensions.hpp index 78fb7be55..c496c28a0 100644 --- a/src/slic3r/GUI/wxExtensions.hpp +++ b/src/slic3r/GUI/wxExtensions.hpp @@ -727,6 +727,7 @@ public: void OnWheel(wxMouseEvent& event); void OnKeyDown(wxKeyEvent &event); void OnKeyUp(wxKeyEvent &event); + void OnChar(wxKeyEvent &event); void OnRightDown(wxMouseEvent& event); void OnRightUp(wxMouseEvent& event);