From 2501cf64c0840771299dac90cdff54193cdbec68 Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Thu, 19 Mar 2020 14:05:49 +0100 Subject: [PATCH] Modified mouse events handling for gizmobar The gizmobar was consuming the mouse up event preventing the gizmos to update their tooltip The gizmobar was also consuming the mouse dragging event transforming a gizmo manipulation into a scene rotation --- src/libslic3r/Technologies.hpp | 7 ++ src/slic3r/GUI/Gizmos/GLGizmosManager.cpp | 127 ++++++++++++++++++++++ 2 files changed, 134 insertions(+) diff --git a/src/libslic3r/Technologies.hpp b/src/libslic3r/Technologies.hpp index ad8442bc56..76625d626c 100644 --- a/src/libslic3r/Technologies.hpp +++ b/src/libslic3r/Technologies.hpp @@ -68,9 +68,16 @@ // Enable tooltips for GLCanvas3D using ImGUI #define ENABLE_CANVAS_TOOLTIP_USING_IMGUI (1 && ENABLE_2_2_0_FINAL) +// Enable constraining tooltips for GLCanvas3D using ImGUI into canvas area #define ENABLE_CANVAS_CONSTRAINED_TOOLTIP_USING_IMGUI (1 && ENABLE_CANVAS_TOOLTIP_USING_IMGUI) +// Enable delay for showing tooltips for GLCanvas3D using ImGUI #define ENABLE_CANVAS_DELAYED_TOOLTIP_USING_IMGUI (1 && ENABLE_CANVAS_TOOLTIP_USING_IMGUI) +// Enable modified mouse events handling for toolbars #define ENABLE_MODIFIED_TOOLBAR_MOUSE_EVENT_HANDLING (1 && ENABLE_CANVAS_TOOLTIP_USING_IMGUI) +// Enable modified mouse events handling for gizmobar +#define ENABLE_MODIFIED_GIZMOBAR_MOUSE_EVENT_HANDLING (1 && ENABLE_CANVAS_TOOLTIP_USING_IMGUI) +// Enable fix for dragging mouse event handling for gizmobar +#define ENABLE_GIZMO_TOOLBAR_DRAGGING_FIX (1 && ENABLE_2_2_0_FINAL) #endif // _technologies_h_ diff --git a/src/slic3r/GUI/Gizmos/GLGizmosManager.cpp b/src/slic3r/GUI/Gizmos/GLGizmosManager.cpp index 9559bc28eb..3df079a4d3 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmosManager.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmosManager.cpp @@ -456,6 +456,7 @@ bool GLGizmosManager::on_mouse(wxMouseEvent& evt) int selected_object_idx = selection.get_object_idx(); bool processed = false; +#if !ENABLE_MODIFIED_GIZMOBAR_MOUSE_EVENT_HANDLING // mouse anywhere if (!evt.Dragging() && !evt.Leaving() && !evt.Entering() && (m_mouse_capture.parent != nullptr)) { @@ -465,10 +466,81 @@ bool GLGizmosManager::on_mouse(wxMouseEvent& evt) m_mouse_capture.reset(); } +#endif // !ENABLE_MODIFIED_GIZMOBAR_MOUSE_EVENT_HANDLING // mouse anywhere if (evt.Moving()) m_tooltip = update_hover_state(mouse_pos); +#if ENABLE_MODIFIED_GIZMOBAR_MOUSE_EVENT_HANDLING + else if (evt.LeftUp()) + { + if (m_mouse_capture.left) + { + processed = true; + m_mouse_capture.left = false; + } + else if (is_dragging()) + { + switch (m_current) { + case Move: m_parent.do_move(L("Gizmo-Move")); break; + case Scale: m_parent.do_scale(L("Gizmo-Scale")); break; + case Rotate: m_parent.do_rotate(L("Gizmo-Rotate")); break; + default: break; + } + + stop_dragging(); + update_data(); + + wxGetApp().obj_manipul()->set_dirty(); + // Let the plater know that the dragging finished, so a delayed refresh + // of the scene with the background processing data should be performed. + m_parent.post_event(SimpleEvent(EVT_GLCANVAS_MOUSE_DRAGGING_FINISHED)); + // updates camera target constraints + m_parent.refresh_camera_scene_box(); + + processed = true; + } +// else +// return false; + } + else if (evt.MiddleUp()) + { + if (m_mouse_capture.middle) + { + processed = true; + m_mouse_capture.middle = false; + } + else + return false; + } + else if (evt.RightUp()) + { + if (pending_right_up) + { + pending_right_up = false; + return true; + } + if (m_mouse_capture.right) + { + processed = true; + m_mouse_capture.right = false; + } + else + return false; + } +#if ENABLE_GIZMO_TOOLBAR_DRAGGING_FIX + else if (evt.Dragging() && !is_dragging()) +#else + else if (evt.Dragging())) +#endif // ENABLE_GIZMO_TOOLBAR_DRAGGING_FIX + { + if (m_mouse_capture.any()) + // if the button down was done on this toolbar, prevent from dragging into the scene + processed = true; +// else +// return false; + } +#else else if (evt.LeftUp()) m_mouse_capture.left = false; else if (evt.MiddleUp()) @@ -485,6 +557,55 @@ bool GLGizmosManager::on_mouse(wxMouseEvent& evt) else if (evt.Dragging() && m_mouse_capture.any()) // if the button down was done on this toolbar, prevent from dragging into the scene processed = true; +#endif // ENABLE_MODIFIED_GIZMOBAR_MOUSE_EVENT_HANDLING +#if ENABLE_GIZMO_TOOLBAR_DRAGGING_FIX + else if (evt.Dragging() && is_dragging()) + { + if (!m_parent.get_wxglcanvas()->HasCapture()) + m_parent.get_wxglcanvas()->CaptureMouse(); + + m_parent.set_mouse_as_dragging(); + update(m_parent.mouse_ray(pos), pos); + + switch (m_current) + { + case Move: + { + // Apply new temporary offset + selection.translate(get_displacement()); + wxGetApp().obj_manipul()->set_dirty(); + break; + } + case Scale: + { + // Apply new temporary scale factors + TransformationType transformation_type(TransformationType::Local_Absolute_Joint); + if (evt.AltDown()) + transformation_type.set_independent(); + selection.scale(get_scale(), transformation_type); + if (evt.ControlDown()) + selection.translate(get_scale_offset(), true); + wxGetApp().obj_manipul()->set_dirty(); + break; + } + case Rotate: + { + // Apply new temporary rotations + TransformationType transformation_type(TransformationType::World_Relative_Joint); + if (evt.AltDown()) + transformation_type.set_independent(); + selection.rotate(get_rotation(), transformation_type); + wxGetApp().obj_manipul()->set_dirty(); + break; + } + default: + break; + } + + m_parent.set_as_dirty(); + processed = true; + } +#endif // ENABLE_GIZMO_TOOLBAR_DRAGGING_FIX if (get_gizmo_idx_from_mouse(mouse_pos) == Undefined) { @@ -527,6 +648,7 @@ bool GLGizmosManager::on_mouse(wxMouseEvent& evt) m_parent.set_as_dirty(); processed = true; } +#if !ENABLE_GIZMO_TOOLBAR_DRAGGING_FIX else if (evt.Dragging() && is_dragging()) { if (!m_parent.get_wxglcanvas()->HasCapture()) @@ -573,6 +695,8 @@ bool GLGizmosManager::on_mouse(wxMouseEvent& evt) m_parent.set_as_dirty(); processed = true; } +#endif // !ENABLE_GIZMO_TOOLBAR_DRAGGING_FIX +#if !ENABLE_MODIFIED_GIZMOBAR_MOUSE_EVENT_HANDLING else if (evt.LeftUp() && is_dragging()) { switch (m_current) { @@ -594,6 +718,7 @@ bool GLGizmosManager::on_mouse(wxMouseEvent& evt) processed = true; } +#endif // !ENABLE_MODIFIED_GIZMOBAR_MOUSE_EVENT_HANDLING else if (evt.LeftUp() && (m_current == SlaSupports || m_current == Hollow) && !m_parent.is_mouse_dragging()) { // in case SLA gizmo is selected, we just pass the LeftUp event and stop processing - neither @@ -632,8 +757,10 @@ bool GLGizmosManager::on_mouse(wxMouseEvent& evt) m_mouse_capture.right = true; m_mouse_capture.parent = &m_parent; } +#if !ENABLE_MODIFIED_GIZMOBAR_MOUSE_EVENT_HANDLING else if (evt.LeftUp()) processed = true; +#endif // !ENABLE_MODIFIED_GIZMOBAR_MOUSE_EVENT_HANDLING } return processed;