diff --git a/src/slic3r/GUI/GLSelectionRectangle.cpp b/src/slic3r/GUI/GLSelectionRectangle.cpp index 39b92ff8f..03ee7e1f6 100644 --- a/src/slic3r/GUI/GLSelectionRectangle.cpp +++ b/src/slic3r/GUI/GLSelectionRectangle.cpp @@ -1,116 +1,119 @@ #include "GLSelectionRectangle.hpp" #include "Camera.hpp" #include "3DScene.hpp" +#include "GLCanvas3D.hpp" #include namespace Slic3r { namespace GUI { -void GLSelectionRectangle::start_dragging(const Vec2d& mouse_position, float width, float height, EState status) -{ - if (is_dragging() || status == Off) - return; + void GLSelectionRectangle::start_dragging(const Vec2d& mouse_position, EState state) + { + if (is_dragging() || (state == Off)) + return; - m_width = width; - m_height = height; - m_status = status; - m_start_corner = mouse_position; - m_end_corner = mouse_position; -} - - - -void GLSelectionRectangle::dragging(const Vec2d& mouse_position) -{ - if (is_dragging()) + m_state = state; + m_start_corner = mouse_position; m_end_corner = mouse_position; -} - - - -std::vector GLSelectionRectangle::end_dragging(const Camera& camera, const std::vector& points) -{ - if (!is_dragging()) - return std::vector(); - - m_status = Off; - std::vector out; - - const std::array& viewport = camera.get_viewport(); - const Transform3d& modelview_matrix = camera.get_view_matrix(); - const Transform3d& projection_matrix = camera.get_projection_matrix(); - - // bounding box created from the rectangle corners - will take care of order of the corners - BoundingBox rectangle(Points{Point(m_start_corner.cast()), Point(m_end_corner.cast())}); - - // Iterate over all points and determine whether they're in the rectangle. - for (unsigned int i=0; i GLSelectionRectangle::stop_dragging(const GLCanvas3D& canvas, const std::vector& points) + { + std::vector out; - glsafe(::glPushAttrib(GL_TRANSFORM_BIT)); // remember current MatrixMode + if (!is_dragging()) + return out; - glsafe(::glMatrixMode(GL_MODELVIEW)); // cache modelview matrix and set to identity - glsafe(::glPushMatrix()); - glsafe(::glLoadIdentity()); + m_state = Off; - glsafe(::glMatrixMode(GL_PROJECTION)); // cache projection matrix and set to identity - glsafe(::glPushMatrix()); - glsafe(::glLoadIdentity()); + const Camera& camera = canvas.get_camera(); + const std::array& viewport = camera.get_viewport(); + const Transform3d& modelview_matrix = camera.get_view_matrix(); + const Transform3d& projection_matrix = camera.get_projection_matrix(); - glsafe(::glOrtho(0.f, m_width, m_height, 0.f, -1.f, 1.f)); // set projection matrix so that world coords = window coords + // bounding box created from the rectangle corners - will take care of order of the corners + BoundingBox rectangle(Points{ Point(m_start_corner.cast()), Point(m_end_corner.cast()) }); - // render the selection rectangle (window coordinates): - glsafe(::glPushAttrib(GL_ENABLE_BIT)); - glsafe(::glLineStipple(4, 0xAAAA)); - glsafe(::glEnable(GL_LINE_STIPPLE)); + // Iterate over all points and determine whether they're in the rectangle. + for (unsigned int i = 0; i end_dragging(const Camera& camera, const std::vector& points); + std::vector stop_dragging(const GLCanvas3D& canvas, const std::vector& points); - void render() const; + // Disables the rectangle. + void stop_dragging(); - bool is_dragging() const { return m_status != Off; } - EState get_status() const { return m_status; } + void render(const GLCanvas3D& canvas) const; + + bool is_dragging() const { return m_state != Off; } + EState get_state() const { return m_state; } - - private: - EState m_status = Off; + EState m_state = Off; Vec2d m_start_corner; Vec2d m_end_corner; - float m_width; - float m_height; }; diff --git a/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp b/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp index ebb7df138..5be5e9a89 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp @@ -100,7 +100,7 @@ void GLGizmoSlaSupports::on_render(const Selection& selection) const if (m_quadric != nullptr && selection.is_from_single_instance()) render_points(selection, false); - m_selection_rectangle.render(); + m_selection_rectangle.render(m_parent); render_clipping_plane(selection); glsafe(::glDisable(GL_BLEND)); @@ -467,9 +467,7 @@ bool GLGizmoSlaSupports::gizmo_event(SLAGizmoEventType action, const Vec2d& mous if (action == SLAGizmoEventType::LeftDown && (shift_down || alt_down || control_down)) { if (m_hover_id == -1) { if (shift_down || alt_down) { - Size size = m_parent.get_canvas_size(); - m_selection_rectangle.start_dragging(mouse_position, size.get_width(), size.get_height(), - shift_down ? GLSelectionRectangle::SlaSelect : GLSelectionRectangle::SlaDeselect); + m_selection_rectangle.start_dragging(mouse_position, shift_down ? GLSelectionRectangle::Select : GLSelectionRectangle::Deselect); } } else { @@ -512,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_dragging()) { // Is this a selection or deselection rectangle? - GLSelectionRectangle::EState rectangle_status = m_selection_rectangle.get_status(); + GLSelectionRectangle::EState rectangle_status = m_selection_rectangle.get_state(); // First collect positions of all the points in world coordinates. const Transform3d& instance_matrix = m_model_object->instances[m_active_instance]->get_transformation().get_matrix(); @@ -524,7 +522,7 @@ bool GLGizmoSlaSupports::gizmo_event(SLAGizmoEventType action, const Vec2d& mous } // Now ask the rectangle which of the points are inside. const Camera& camera = m_parent.get_camera(); - std::vector selected_idxs = m_selection_rectangle.end_dragging(camera, points); + std::vector selected_idxs = m_selection_rectangle.stop_dragging(m_parent, points); // we'll recover current look direction (in world coords) and transform it to model coords. const Selection& selection = m_parent.get_selection(); @@ -577,7 +575,7 @@ bool GLGizmoSlaSupports::gizmo_event(SLAGizmoEventType action, const Vec2d& mous } if (!is_obscured) { - if (rectangle_status == GLSelectionRectangle::SlaDeselect) + if (rectangle_status == GLSelectionRectangle::Deselect) unselect_point(i); else select_point(i);