From d79a2b8d2d0ffd6019330c41e7bb8b1ee59a2f53 Mon Sep 17 00:00:00 2001 From: Enrico Turri Date: Wed, 24 Apr 2019 15:43:52 +0200 Subject: [PATCH] GLCanvas3D -> added support for cursor change and change cursor when using SLA support gizmo rectangle selection --- src/slic3r/GUI/GLCanvas3D.cpp | 31 ++++++++++++++++++++ src/slic3r/GUI/GLCanvas3D.hpp | 11 +++++++ src/slic3r/GUI/GLSelectionRectangle.cpp | 6 ++-- src/slic3r/GUI/GLSelectionRectangle.hpp | 4 +-- src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp | 6 ++-- src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.hpp | 3 ++ src/slic3r/GUI/Gizmos/GLGizmosManager.cpp | 31 ++++++++++++++++---- 7 files changed, 79 insertions(+), 13 deletions(-) diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index 09b4b2e14..af0aa9a69 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -1213,6 +1213,7 @@ GLCanvas3D::GLCanvas3D(wxGLCanvas* canvas, Bed3D& bed, Camera& camera, GLToolbar , m_regenerate_volumes(true) , m_moving(false) , m_tab_down(false) + , m_cursor_type(Standard) , m_color_by("volume") , m_reload_delayed(false) , m_render_sla_auxiliaries(true) @@ -2323,9 +2324,25 @@ void GLCanvas3D::on_key(wxKeyEvent& evt) // m_canvas->HandleAsNavigationKey(evt); // XXX: Doesn't work in some cases / on Linux post_event(SimpleEvent(EVT_GLCANVAS_TAB)); } + else if (keyCode == WXK_SHIFT) + { + set_cursor(Standard); + } + else if (keyCode == WXK_ALT) + { + set_cursor(Standard); + } } else if (evt.GetEventType() == wxEVT_KEY_DOWN) { m_tab_down = keyCode == WXK_TAB && !evt.HasAnyModifiers(); + if (keyCode == WXK_SHIFT) + { + set_cursor(Cross); + } + else if (keyCode == WXK_ALT) + { + set_cursor(Cross); + } } } } @@ -3173,6 +3190,20 @@ double GLCanvas3D::get_size_proportional_to_max_bed_size(double factor) const return factor * m_bed.get_bounding_box().max_size(); } +void GLCanvas3D::set_cursor(ECursorType type) +{ + if ((m_canvas != nullptr) && (m_cursor_type != type)) + { + switch (type) + { + case Standard: { m_canvas->SetCursor(*wxSTANDARD_CURSOR); break; } + case Cross: { m_canvas->SetCursor(*wxCROSS_CURSOR); break; } + } + + m_cursor_type = type; + } +} + bool GLCanvas3D::_is_shown_on_screen() const { return (m_canvas != nullptr) ? m_canvas->IsShownOnScreen() : false; diff --git a/src/slic3r/GUI/GLCanvas3D.hpp b/src/slic3r/GUI/GLCanvas3D.hpp index 8a5c34a2c..fa55dc683 100644 --- a/src/slic3r/GUI/GLCanvas3D.hpp +++ b/src/slic3r/GUI/GLCanvas3D.hpp @@ -392,6 +392,14 @@ private: void render(const GLCanvas3D& canvas) const; }; +public: + enum ECursorType : unsigned char + { + Standard, + Cross + }; + +private: wxGLCanvas* m_canvas; wxGLContext* m_context; #if ENABLE_RETINA_GL @@ -436,6 +444,7 @@ private: bool m_regenerate_volumes; bool m_moving; bool m_tab_down; + ECursorType m_cursor_type; // Following variable is obsolete and it should be safe to remove it. // I just don't want to do it now before a release (Lukas Matena 24.3.2019) @@ -587,6 +596,8 @@ public: double get_size_proportional_to_max_bed_size(double factor) const; + void set_cursor(ECursorType type); + private: bool _is_shown_on_screen() const; diff --git a/src/slic3r/GUI/GLSelectionRectangle.cpp b/src/slic3r/GUI/GLSelectionRectangle.cpp index a908d13ec..39b92ff8f 100644 --- a/src/slic3r/GUI/GLSelectionRectangle.cpp +++ b/src/slic3r/GUI/GLSelectionRectangle.cpp @@ -9,7 +9,7 @@ namespace GUI { void GLSelectionRectangle::start_dragging(const Vec2d& mouse_position, float width, float height, EState status) { - if (is_active() || status==Off) + if (is_dragging() || status == Off) return; m_width = width; @@ -23,7 +23,7 @@ void GLSelectionRectangle::start_dragging(const Vec2d& mouse_position, float wid void GLSelectionRectangle::dragging(const Vec2d& mouse_position) { - if (is_active()) + if (is_dragging()) m_end_corner = mouse_position; } @@ -31,7 +31,7 @@ void GLSelectionRectangle::dragging(const Vec2d& mouse_position) std::vector GLSelectionRectangle::end_dragging(const Camera& camera, const std::vector& points) { - if (!is_active()) + if (!is_dragging()) return std::vector(); m_status = Off; diff --git a/src/slic3r/GUI/GLSelectionRectangle.hpp b/src/slic3r/GUI/GLSelectionRectangle.hpp index 2422066e0..f7d5bbdc7 100644 --- a/src/slic3r/GUI/GLSelectionRectangle.hpp +++ b/src/slic3r/GUI/GLSelectionRectangle.hpp @@ -27,8 +27,8 @@ public: std::vector end_dragging(const Camera& camera, const std::vector& points); void render() const; - - bool is_active() const { return m_status != Off; } + + bool is_dragging() const { return m_status != Off; } EState get_status() const { return m_status; } diff --git a/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp b/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp index b31eb272b..ebb7df138 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp @@ -485,7 +485,7 @@ bool GLGizmoSlaSupports::gizmo_event(SLAGizmoEventType action, const Vec2d& mous } // left down without selection rectangle - place point on the mesh: - if (action == SLAGizmoEventType::LeftDown && !m_selection_rectangle.is_active() && !shift_down) { + if (action == SLAGizmoEventType::LeftDown && !m_selection_rectangle.is_dragging() && !shift_down) { // If any point is in hover state, this should initiate its move - return control back to GLCanvas: if (m_hover_id != -1) return false; @@ -510,7 +510,7 @@ bool GLGizmoSlaSupports::gizmo_event(SLAGizmoEventType action, const Vec2d& mous } // left up with selection rectangle - select points inside the rectangle: - if ((action == SLAGizmoEventType::LeftUp || action == SLAGizmoEventType::ShiftUp || action == SLAGizmoEventType::AltUp) && m_selection_rectangle.is_active()) { + if ((action == SLAGizmoEventType::LeftUp || action == SLAGizmoEventType::ShiftUp || action == SLAGizmoEventType::AltUp) && m_selection_rectangle.is_dragging()) { // Is this a selection or deselection rectangle? GLSelectionRectangle::EState rectangle_status = m_selection_rectangle.get_status(); @@ -601,7 +601,7 @@ bool GLGizmoSlaSupports::gizmo_event(SLAGizmoEventType action, const Vec2d& mous return true; // point has been placed and the button not released yet // this prevents GLCanvas from starting scene rotation - if (m_selection_rectangle.is_active()) { + if (m_selection_rectangle.is_dragging()) { m_selection_rectangle.dragging(mouse_position); return true; } diff --git a/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.hpp b/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.hpp index 92d80b6eb..ab5dc8d67 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.hpp @@ -68,6 +68,9 @@ public: void delete_selected_points(bool force = false); ClippingPlane get_sla_clipping_plane() const; + bool is_in_editing_mode() const { return m_editing_mode; } + bool is_selection_rectangle_dragging() const { return m_selection_rectangle.is_dragging(); } + private: bool on_init(); void on_update(const UpdateData& data, const Selection& selection); diff --git a/src/slic3r/GUI/Gizmos/GLGizmosManager.cpp b/src/slic3r/GUI/Gizmos/GLGizmosManager.cpp index 88e374792..b7e1b3f07 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmosManager.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmosManager.cpp @@ -843,13 +843,34 @@ bool GLGizmosManager::on_key(wxKeyEvent& evt, GLCanvas3D& canvas) if (evt.GetEventType() == wxEVT_KEY_UP) { - if ((m_current == SlaSupports) && (keyCode == WXK_SHIFT) && gizmo_event(SLAGizmoEventType::ShiftUp)) - // shift has been just released - SLA gizmo might want to close rectangular selection. - processed = true; + if (m_current == SlaSupports) + { + GLGizmoSlaSupports* gizmo = reinterpret_cast(get_current()); - if ((m_current == SlaSupports) && (keyCode == WXK_ALT) && gizmo_event(SLAGizmoEventType::AltUp)) - // alt has been just released - SLA gizmo might want to close rectangular selection. + if (keyCode == WXK_SHIFT) + { + // shift has been just released - SLA gizmo might want to close rectangular selection. + if (gizmo_event(SLAGizmoEventType::ShiftUp) || (gizmo->is_in_editing_mode() && gizmo->is_selection_rectangle_dragging())) + processed = true; + } + else if (keyCode == WXK_ALT) + { + // alt has been just released - SLA gizmo might want to close rectangular selection. + if (gizmo_event(SLAGizmoEventType::AltUp) || (gizmo->is_in_editing_mode() && gizmo->is_selection_rectangle_dragging())) + processed = true; + } + } + + if (processed) + canvas.set_cursor(GLCanvas3D::Standard); + } + else if (evt.GetEventType() == wxEVT_KEY_DOWN) + { + if ((m_current == SlaSupports) && ((keyCode == WXK_SHIFT) || (keyCode == WXK_ALT)) && reinterpret_cast(get_current())->is_in_editing_mode()) + { + canvas.set_cursor(GLCanvas3D::Cross); processed = true; + } } if (processed)