diff --git a/src/libslic3r/Technologies.hpp b/src/libslic3r/Technologies.hpp index f7ab20088..17459dde5 100644 --- a/src/libslic3r/Technologies.hpp +++ b/src/libslic3r/Technologies.hpp @@ -31,6 +31,8 @@ #define ENABLE_NEW_MENU_LAYOUT (1 && ENABLE_1_42_0) // All rotations made using the rotate gizmo are done with respect to the world reference system #define ENABLE_WORLD_ROTATIONS (1 && ENABLE_1_42_0) +// Enables shortcut keys for gizmos +#define ENABLE_GIZMOS_SHORTCUT (1 && ENABLE_1_42_0) #endif // _technologies_h_ diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index 17959af03..25a927850 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -2659,6 +2659,43 @@ bool GLCanvas3D::Gizmos::is_running() const return (curr != nullptr) ? (curr->get_state() == GLGizmoBase::On) : false; } +#if ENABLE_GIZMOS_SHORTCUT +bool GLCanvas3D::Gizmos::handle_shortcut(int key, const Selection& selection) +{ + if (!m_enabled) + return false; + + bool handled = false; + for (GizmosMap::iterator it = m_gizmos.begin(); it != m_gizmos.end(); ++it) + { + if ((it->second == nullptr) || !it->second->is_selectable()) + continue; + + int it_key = it->second->get_shortcut_key(); + + if (it->second->is_activable(selection) && ((it_key == key - 64) || (it_key == key - 96))) + { + if ((it->second->get_state() == GLGizmoBase::On)) + { + it->second->set_state(GLGizmoBase::Off); + m_current = Undefined; + handled = true; + } + else if ((it->second->get_state() == GLGizmoBase::Off)) + { + it->second->set_state(GLGizmoBase::On); + m_current = it->first; + handled = true; + } + } + else + it->second->set_state(GLGizmoBase::Off); + } + + return handled; +} +#endif // ENABLE_GIZMOS_SHORTCUT + bool GLCanvas3D::Gizmos::is_dragging() const { if (!m_enabled) @@ -4273,7 +4310,16 @@ void GLCanvas3D::on_char(wxKeyEvent& evt) #endif // ENABLE_MODIFIED_CAMERA_TARGET default: { - evt.Skip(); +#if ENABLE_GIZMOS_SHORTCUT + if (evt.ShiftDown() && m_gizmos.handle_shortcut(keyCode, m_selection)) + { + _update_gizmos_data(); + render(); + } + else +#endif // ENABLE_GIZMOS_SHORTCUT + evt.Skip(); + break; } } @@ -4761,16 +4807,14 @@ void GLCanvas3D::on_key_down(wxKeyEvent& evt) else { int key = evt.GetKeyCode(); +#ifdef __WXOSX__ + if (key == WXK_BACK) +#else if (key == WXK_DELETE) +#endif // __WXOSX__ post_event(SimpleEvent(EVT_GLCANVAS_REMOVE_OBJECT)); else - { -#ifdef __WXOSX__ - if (key == WXK_BACK) - post_event(SimpleEvent(EVT_GLCANVAS_REMOVE_OBJECT)); -#endif - evt.Skip(); - } + evt.Skip(); } } diff --git a/src/slic3r/GUI/GLCanvas3D.hpp b/src/slic3r/GUI/GLCanvas3D.hpp index 5404701f8..489f367e1 100644 --- a/src/slic3r/GUI/GLCanvas3D.hpp +++ b/src/slic3r/GUI/GLCanvas3D.hpp @@ -611,6 +611,9 @@ private: EType get_current_type() const; bool is_running() const; +#if ENABLE_GIZMOS_SHORTCUT + bool handle_shortcut(int key, const Selection& selection); +#endif // ENABLE_GIZMOS_SHORTCUT bool is_dragging() const; void start_dragging(const Selection& selection); diff --git a/src/slic3r/GUI/GLGizmo.cpp b/src/slic3r/GUI/GLGizmo.cpp index 906e064e0..40c1f09fe 100644 --- a/src/slic3r/GUI/GLGizmo.cpp +++ b/src/slic3r/GUI/GLGizmo.cpp @@ -30,6 +30,10 @@ #include "GUI_Utils.hpp" #include "GUI_App.hpp" +#if ENABLE_GIZMOS_SHORTCUT +#include +#endif // ENABLE_GIZMOS_SHORTCUT + // TODO: Display tooltips quicker on Linux static const float DEFAULT_BASE_COLOR[3] = { 0.625f, 0.625f, 0.625f }; @@ -161,6 +165,9 @@ GLGizmoBase::GLGizmoBase(GLCanvas3D& parent) : m_parent(parent) , m_group_id(-1) , m_state(Off) +#if ENABLE_GIZMOS_SHORTCUT + , m_shortcut_key(0) +#endif // ENABLE_GIZMOS_SHORTCUT , m_hover_id(-1) , m_dragging(false) { @@ -639,6 +646,10 @@ bool GLGizmoRotate3D::on_init() if (!m_textures[On].load_from_file(path + "rotate_on.png", false)) return false; +#if ENABLE_GIZMOS_SHORTCUT + m_shortcut_key = WXK_CONTROL_R; +#endif // ENABLE_GIZMOS_SHORTCUT + return true; } @@ -713,6 +724,10 @@ bool GLGizmoScale3D::on_init() m_grabbers[2].angles(0) = half_pi; m_grabbers[3].angles(0) = half_pi; +#if ENABLE_GIZMOS_SHORTCUT + m_shortcut_key = WXK_CONTROL_S; +#endif // ENABLE_GIZMOS_SHORTCUT + return true; } @@ -1057,6 +1072,10 @@ bool GLGizmoMove3D::on_init() m_grabbers.push_back(Grabber()); } +#if ENABLE_GIZMOS_SHORTCUT + m_shortcut_key = WXK_CONTROL_M; +#endif // ENABLE_GIZMOS_SHORTCUT + return true; } @@ -1213,6 +1232,10 @@ bool GLGizmoFlatten::on_init() if (!m_textures[On].load_from_file(path + "layflat_on.png", false)) return false; +#if ENABLE_GIZMOS_SHORTCUT + m_shortcut_key = WXK_CONTROL_F; +#endif // ENABLE_GIZMOS_SHORTCUT + return true; } @@ -1542,6 +1565,10 @@ bool GLGizmoSlaSupports::on_init() if (!m_textures[On].load_from_file(path + "sla_support_points_on.png", false)) return false; +#if ENABLE_GIZMOS_SHORTCUT + m_shortcut_key = WXK_CONTROL_L; +#endif // ENABLE_GIZMOS_SHORTCUT + return true; } @@ -1893,6 +1920,10 @@ bool GLGizmoCut::on_init() m_grabbers.emplace_back(); +#if ENABLE_GIZMOS_SHORTCUT + m_shortcut_key = WXK_CONTROL_C; +#endif // ENABLE_GIZMOS_SHORTCUT + return true; } diff --git a/src/slic3r/GUI/GLGizmo.hpp b/src/slic3r/GUI/GLGizmo.hpp index 647d870e4..a8073bd78 100644 --- a/src/slic3r/GUI/GLGizmo.hpp +++ b/src/slic3r/GUI/GLGizmo.hpp @@ -77,6 +77,9 @@ protected: int m_group_id; EState m_state; +#if ENABLE_GIZMOS_SHORTCUT + int m_shortcut_key; +#endif // ENABLE_GIZMOS_SHORTCUT // textures are assumed to be square and all with the same size in pixels, no internal check is done GLTexture m_textures[Num_States]; int m_hover_id; @@ -100,6 +103,11 @@ public: EState get_state() const { return m_state; } void set_state(EState state) { m_state = state; on_set_state(); } +#if ENABLE_GIZMOS_SHORTCUT + int get_shortcut_key() const { return m_shortcut_key; } + void set_shortcut_key(int key) { m_shortcut_key = key; } +#endif // ENABLE_GIZMOS_SHORTCUT + bool is_activable(const GLCanvas3D::Selection& selection) const { return on_is_activable(selection); } bool is_selectable() const { return on_is_selectable(); }