From d2d06c9f73b7885acf43ba59d4c508cc498faf4e Mon Sep 17 00:00:00 2001 From: Enrico Turri Date: Thu, 25 Apr 2019 10:21:24 +0200 Subject: [PATCH] Rectangle selection in 3D scene -> refactored GLVolume member varialbe for hovering --- src/slic3r/GUI/3DScene.cpp | 7 +++---- src/slic3r/GUI/3DScene.hpp | 13 +++++++++---- src/slic3r/GUI/GLCanvas3D.cpp | 11 +++++------ src/slic3r/GUI/GLSelectionRectangle.hpp | 2 +- 4 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/slic3r/GUI/3DScene.cpp b/src/slic3r/GUI/3DScene.cpp index 9d1407b00..873c8b9e6 100644 --- a/src/slic3r/GUI/3DScene.cpp +++ b/src/slic3r/GUI/3DScene.cpp @@ -252,8 +252,7 @@ GLVolume::GLVolume(float r, float g, float b, float a) , zoom_to_volumes(true) , shader_outside_printer_detection_enabled(false) , is_outside(false) - , hover_select(false) - , hover_deselect(false) + , hover(None) , is_modifier(false) , is_wipe_tower(false) , is_extrusion_path(false) @@ -293,9 +292,9 @@ void GLVolume::set_render_color() if (force_native_color) set_render_color(color, 4); else { - if (hover_select) + if (hover == Select) set_render_color(HOVER_SELECT_COLOR, 4); - else if (hover_deselect) + else if (hover == Deselect) set_render_color(HOVER_DESELECT_COLOR, 4); else if (selected) set_render_color(is_outside ? SELECTED_OUTSIDE_COLOR : SELECTED_COLOR, 4); diff --git a/src/slic3r/GUI/3DScene.hpp b/src/slic3r/GUI/3DScene.hpp index fa7d6f7d1..8ed8da43f 100644 --- a/src/slic3r/GUI/3DScene.hpp +++ b/src/slic3r/GUI/3DScene.hpp @@ -234,6 +234,13 @@ public: static const float SLA_SUPPORT_COLOR[4]; static const float SLA_PAD_COLOR[4]; + enum EHoverState : unsigned char + { + None, + Select, + Deselect + }; + GLVolume(float r = 1.f, float g = 1.f, float b = 1.f, float a = 1.f); GLVolume(const float *rgba) : GLVolume(rgba[0], rgba[1], rgba[2], rgba[3]) {} ~GLVolume(); @@ -297,10 +304,8 @@ public: bool shader_outside_printer_detection_enabled; // Wheter or not this volume is outside print volume. bool is_outside; - // Boolean: Is mouse over this object to select it ? - bool hover_select; - // Boolean: Is mouse over this object to deselect it ? - bool hover_deselect; + // Is mouse or rectangle selection over this object to select/deselect it ? + EHoverState hover; // Wheter or not this volume has been generated from a modifier bool is_modifier; // Wheter or not this volume has been generated from the wipe tower diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index 621a726b9..9798efecb 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -4246,8 +4246,7 @@ void GLCanvas3D::_update_volumes_hover_state() const { for (GLVolume* v : m_volumes.volumes) { - v->hover_select = false; - v->hover_deselect = false; + v->hover = GLVolume::None; } if (m_hover_volume_idxs.empty()) @@ -4268,9 +4267,9 @@ void GLCanvas3D::_update_volumes_hover_state() const if (volume->is_modifier && (!deselect || ((volume->object_idx() == m_selection.get_object_idx()) && (volume->instance_idx() == m_selection.get_instance_idx())))) { if (deselect) - volume->hover_deselect = true; + volume->hover = GLVolume::Deselect; else - volume->hover_select = true; + volume->hover = GLVolume::Select; } else { @@ -4282,9 +4281,9 @@ void GLCanvas3D::_update_volumes_hover_state() const if ((v->object_idx() == object_idx) && (v->instance_idx() == instance_idx)) { if (deselect) - v->hover_deselect = true; + v->hover = GLVolume::Deselect; else - v->hover_select = true; + v->hover = GLVolume::Select; } } } diff --git a/src/slic3r/GUI/GLSelectionRectangle.hpp b/src/slic3r/GUI/GLSelectionRectangle.hpp index db72d9415..d9869771e 100644 --- a/src/slic3r/GUI/GLSelectionRectangle.hpp +++ b/src/slic3r/GUI/GLSelectionRectangle.hpp @@ -34,7 +34,7 @@ public: bool is_dragging() const { return m_state != Off; } EState get_state() const { return m_state; } - + float get_width() const { return std::abs(m_start_corner(0) - m_end_corner(0)); } float get_height() const { return std::abs(m_start_corner(1) - m_end_corner(1)); } float get_left() const { return std::min(m_start_corner(0), m_end_corner(0)); }