diff --git a/src/libslic3r/Technologies.hpp b/src/libslic3r/Technologies.hpp index 4af839054..629407ee2 100644 --- a/src/libslic3r/Technologies.hpp +++ b/src/libslic3r/Technologies.hpp @@ -56,3 +56,5 @@ // Changed algorithm to extract euler angles from rotation matrix #define ENABLE_NEW_EULER_ANGLES (1 && ENABLE_1_42_0_ALPHA4) +// Added minimum threshold for click and drag movements +#define ENABLE_MOVE_MIN_THRESHOLD (1 && ENABLE_1_42_0_ALPHA4) diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index ad59ad8c5..27f0d54c3 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -1122,11 +1122,18 @@ void GLCanvas3D::LayersEditing::_render_profile(const PrintObject& print_object, const Point GLCanvas3D::Mouse::Drag::Invalid_2D_Point(INT_MAX, INT_MAX); const Vec3d GLCanvas3D::Mouse::Drag::Invalid_3D_Point(DBL_MAX, DBL_MAX, DBL_MAX); +#if ENABLE_MOVE_MIN_THRESHOLD +const int GLCanvas3D::Mouse::Drag::MoveThresholdPx = 5; +#endif // ENABLE_MOVE_MIN_THRESHOLD GLCanvas3D::Mouse::Drag::Drag() : start_position_2D(Invalid_2D_Point) , start_position_3D(Invalid_3D_Point) , move_volume_idx(-1) +#if ENABLE_MOVE_MIN_THRESHOLD + , move_requires_threshold(false) + , move_start_threshold_position_2D(Invalid_2D_Point) +#endif // ENABLE_MOVE_MIN_THRESHOLD { } @@ -1139,26 +1146,6 @@ GLCanvas3D::Mouse::Mouse() { } -void GLCanvas3D::Mouse::set_start_position_2D_as_invalid() -{ - drag.start_position_2D = Drag::Invalid_2D_Point; -} - -void GLCanvas3D::Mouse::set_start_position_3D_as_invalid() -{ - drag.start_position_3D = Drag::Invalid_3D_Point; -} - -bool GLCanvas3D::Mouse::is_start_position_2D_defined() const -{ - return (drag.start_position_2D != Drag::Invalid_2D_Point); -} - -bool GLCanvas3D::Mouse::is_start_position_3D_defined() const -{ - return (drag.start_position_3D != Drag::Invalid_3D_Point); -} - GLCanvas3D::Selection::VolumeCache::TransformCache::TransformCache() : position(Vec3d::Zero()) , rotation(Vec3d::Zero()) @@ -4955,6 +4942,14 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) int toolbar_contains_mouse = m_toolbar.contains_mouse(m_mouse.position, *this); int view_toolbar_contains_mouse = (m_view_toolbar != nullptr) ? m_view_toolbar->contains_mouse(m_mouse.position, *this) : -1; +#if ENABLE_MOVE_MIN_THRESHOLD + if (m_mouse.drag.move_requires_threshold && m_mouse.is_move_start_threshold_position_2D_defined() && m_mouse.is_move_threshold_met(pos)) + { + m_mouse.drag.move_requires_threshold = false; + m_mouse.set_move_start_threshold_position_2D_as_invalid(); + } +#endif // ENABLE_MOVE_MIN_THRESHOLD + if (evt.Entering()) { //#if defined(__WXMSW__) || defined(__linux__) @@ -5087,6 +5082,13 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) { bool add_as_single = !already_selected && !shift_down; m_selection.add(m_hover_volume_id, add_as_single); +#if ENABLE_MOVE_MIN_THRESHOLD + m_mouse.drag.move_requires_threshold = !already_selected; + if (already_selected) + m_mouse.set_move_start_threshold_position_2D_as_invalid(); + else + m_mouse.drag.move_start_threshold_position_2D = pos; +#endif // ENABLE_MOVE_MIN_THRESHOLD } #if ENABLE_IMPROVED_SIDEBAR_OBJECTS_MANIPULATION @@ -5153,19 +5155,26 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) } else if (evt.Dragging() && evt.LeftIsDown() && !gizmos_overlay_contains_mouse && (m_layers_editing.state == LayersEditing::Unknown) && (m_mouse.drag.move_volume_idx != -1)) { - m_mouse.dragging = true; +#if ENABLE_MOVE_MIN_THRESHOLD + if (!m_mouse.drag.move_requires_threshold) + { +#endif // ENABLE_MOVE_MIN_THRESHOLD + m_mouse.dragging = true; - // Get new position at the same Z of the initial click point. - float z0 = 0.0f; - float z1 = 1.0f; - // we do not want to translate objects if the user just clicked on an object while pressing shift to remove it from the selection and then drag - Vec3d cur_pos = m_selection.contains_volume(m_hover_volume_id) ? Linef3(_mouse_to_3d(pos, &z0), _mouse_to_3d(pos, &z1)).intersect_plane(m_mouse.drag.start_position_3D(2)) : m_mouse.drag.start_position_3D; + // Get new position at the same Z of the initial click point. + float z0 = 0.0f; + float z1 = 1.0f; + // we do not want to translate objects if the user just clicked on an object while pressing shift to remove it from the selection and then drag + Vec3d cur_pos = m_selection.contains_volume(m_hover_volume_id) ? Linef3(_mouse_to_3d(pos, &z0), _mouse_to_3d(pos, &z1)).intersect_plane(m_mouse.drag.start_position_3D(2)) : m_mouse.drag.start_position_3D; - m_regenerate_volumes = false; - m_selection.translate(cur_pos - m_mouse.drag.start_position_3D); - wxGetApp().obj_manipul()->update_settings_value(m_selection); + m_regenerate_volumes = false; + m_selection.translate(cur_pos - m_mouse.drag.start_position_3D); + wxGetApp().obj_manipul()->update_settings_value(m_selection); - m_dirty = true; + m_dirty = true; +#if ENABLE_MOVE_MIN_THRESHOLD + } +#endif // ENABLE_MOVE_MIN_THRESHOLD } else if (evt.Dragging() && m_gizmos.is_dragging()) { @@ -5216,7 +5225,11 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) else if (evt.LeftIsDown()) { // if dragging over blank area with left button, rotate +#if ENABLE_MOVE_MIN_THRESHOLD + if ((m_hover_volume_id == -1) && m_mouse.is_start_position_3D_defined()) +#else if (m_mouse.is_start_position_3D_defined()) +#endif // ENABLE_MOVE_MIN_THRESHOLD { const Vec3d& orig = m_mouse.drag.start_position_3D; m_camera.phi += (((float)pos(0) - (float)orig(0)) * TRACKBALLSIZE); diff --git a/src/slic3r/GUI/GLCanvas3D.hpp b/src/slic3r/GUI/GLCanvas3D.hpp index f00c2b649..f1ccdf54b 100644 --- a/src/slic3r/GUI/GLCanvas3D.hpp +++ b/src/slic3r/GUI/GLCanvas3D.hpp @@ -347,10 +347,17 @@ class GLCanvas3D { static const Point Invalid_2D_Point; static const Vec3d Invalid_3D_Point; +#if ENABLE_MOVE_MIN_THRESHOLD + static const int MoveThresholdPx; +#endif // ENABLE_MOVE_MIN_THRESHOLD Point start_position_2D; Vec3d start_position_3D; int move_volume_idx; +#if ENABLE_MOVE_MIN_THRESHOLD + bool move_requires_threshold; + Point move_start_threshold_position_2D; +#endif // ENABLE_MOVE_MIN_THRESHOLD public: Drag(); @@ -365,11 +372,21 @@ class GLCanvas3D Mouse(); - void set_start_position_2D_as_invalid(); - void set_start_position_3D_as_invalid(); + void set_start_position_2D_as_invalid() { drag.start_position_2D = Drag::Invalid_2D_Point; } + void set_start_position_3D_as_invalid() { drag.start_position_3D = Drag::Invalid_3D_Point; } +#if ENABLE_MOVE_MIN_THRESHOLD + void set_move_start_threshold_position_2D_as_invalid() { drag.move_start_threshold_position_2D = Drag::Invalid_2D_Point; } +#endif // ENABLE_MOVE_MIN_THRESHOLD - bool is_start_position_2D_defined() const; - bool is_start_position_3D_defined() const; + bool is_start_position_2D_defined() const { return (drag.start_position_2D != Drag::Invalid_2D_Point); } + bool is_start_position_3D_defined() const { return (drag.start_position_3D != Drag::Invalid_3D_Point); } +#if ENABLE_MOVE_MIN_THRESHOLD + bool is_move_start_threshold_position_2D_defined() const { return (drag.move_start_threshold_position_2D != Drag::Invalid_2D_Point); } + bool is_move_threshold_met(const Point& mouse_pos) const { + return (std::abs(mouse_pos(0) - drag.move_start_threshold_position_2D(0)) > Drag::MoveThresholdPx) + || (std::abs(mouse_pos(1) - drag.move_start_threshold_position_2D(1)) > Drag::MoveThresholdPx); + } +#endif // ENABLE_MOVE_MIN_THRESHOLD }; public: