diff --git a/src/slic3r/GUI/Gizmos/GLGizmoBase.cpp b/src/slic3r/GUI/Gizmos/GLGizmoBase.cpp index d2bad5d53..46abe8a95 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoBase.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoBase.cpp @@ -262,12 +262,6 @@ void GLGizmoBase::render_grabbers_for_picking(const BoundingBoxf3& box) const } } - -void GLGizmoBase::set_tooltip(const std::string& tooltip) const -{ - m_tooltip = tooltip; -} - std::string GLGizmoBase::format(float value, unsigned int decimals) const { return Slic3r::string_printf("%.*f", decimals, value); diff --git a/src/slic3r/GUI/Gizmos/GLGizmoBase.hpp b/src/slic3r/GUI/Gizmos/GLGizmoBase.hpp index e25fb248f..bddd84d7d 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoBase.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoBase.hpp @@ -100,7 +100,6 @@ protected: mutable std::vector m_grabbers; ImGuiWrapper* m_imgui; bool m_first_input_window_render; - mutable std::string m_tooltip; public: GLGizmoBase(GLCanvas3D& parent, @@ -146,11 +145,11 @@ public: void update(const UpdateData& data); - void render() const { m_tooltip.clear(); on_render(); } + void render() const { on_render(); } void render_for_picking() const { on_render_for_picking(); } void render_input_window(float x, float y, float bottom_limit); - virtual const std::string& get_tooltip() const { return m_tooltip; } + virtual std::string get_tooltip() const { return ""; } protected: virtual bool on_init() = 0; @@ -177,7 +176,6 @@ protected: void render_grabbers(float size) const; void render_grabbers_for_picking(const BoundingBoxf3& box) const; - void set_tooltip(const std::string& tooltip) const; std::string format(float value, unsigned int decimals) const; }; diff --git a/src/slic3r/GUI/Gizmos/GLGizmoCut.cpp b/src/slic3r/GUI/Gizmos/GLGizmoCut.cpp index 2122a01af..9382579ea 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoCut.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoCut.cpp @@ -30,6 +30,11 @@ GLGizmoCut::GLGizmoCut(GLCanvas3D& parent, const std::string& icon_filename, uns , m_rotate_lower(false) {} +std::string GLGizmoCut::get_tooltip() const +{ + return (m_hover_id == 0 || m_grabbers[0].dragging) ? "Z: " + format(m_cut_z, 2) : ""; +} + bool GLGizmoCut::on_init() { m_grabbers.emplace_back(); @@ -79,9 +84,6 @@ void GLGizmoCut::on_update(const UpdateData& data) void GLGizmoCut::on_render() const { - if (m_hover_id == 0 || m_grabbers[0].dragging) - set_tooltip("Z: " + format(m_cut_z, 2)); - const Selection& selection = m_parent.get_selection(); update_max_z(selection); diff --git a/src/slic3r/GUI/Gizmos/GLGizmoCut.hpp b/src/slic3r/GUI/Gizmos/GLGizmoCut.hpp index b6e10861f..633069089 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoCut.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoCut.hpp @@ -28,6 +28,8 @@ public: double get_cut_z() const { return m_cut_z; } void set_cut_z(double cut_z) const; + virtual std::string get_tooltip() const; + protected: virtual bool on_init(); virtual void on_load(cereal::BinaryInputArchive& ar) { ar(m_cut_z, m_keep_upper, m_keep_lower, m_rotate_lower); } diff --git a/src/slic3r/GUI/Gizmos/GLGizmoMove.cpp b/src/slic3r/GUI/Gizmos/GLGizmoMove.cpp index 6be108c85..f349776ab 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoMove.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoMove.cpp @@ -31,6 +31,22 @@ GLGizmoMove3D::~GLGizmoMove3D() ::gluDeleteQuadric(m_quadric); } +std::string GLGizmoMove3D::get_tooltip() const +{ + const Selection& selection = m_parent.get_selection(); + bool show_position = selection.is_single_full_instance(); + const Vec3d& position = selection.get_bounding_box().center(); + + if (m_hover_id == 0 || m_grabbers[0].dragging) + return "X: " + format(show_position ? position(0) : m_displacement(0), 2); + else if (m_hover_id == 1 || m_grabbers[1].dragging) + return "Y: " + format(show_position ? position(1) : m_displacement(1), 2); + else if (m_hover_id == 2 || m_grabbers[2].dragging) + return "Z: " + format(show_position ? position(2) : m_displacement(2), 2); + else + return ""; +} + bool GLGizmoMove3D::on_init() { for (int i = 0; i < 3; ++i) @@ -85,22 +101,6 @@ void GLGizmoMove3D::on_render() const { const Selection& selection = m_parent.get_selection(); - bool show_position = selection.is_single_full_instance(); - const Vec3d& position = selection.get_bounding_box().center(); - - if ((show_position && (m_hover_id == 0)) || m_grabbers[0].dragging) - set_tooltip("X: " + format(show_position ? position(0) : m_displacement(0), 2)); - else if (!m_grabbers[0].dragging && (m_hover_id == 0)) - set_tooltip("X"); - else if ((show_position && (m_hover_id == 1)) || m_grabbers[1].dragging) - set_tooltip("Y: " + format(show_position ? position(1) : m_displacement(1), 2)); - else if (!m_grabbers[1].dragging && (m_hover_id == 1)) - set_tooltip("Y"); - else if ((show_position && (m_hover_id == 2)) || m_grabbers[2].dragging) - set_tooltip("Z: " + format(show_position ? position(2) : m_displacement(2), 2)); - else if (!m_grabbers[2].dragging && (m_hover_id == 2)) - set_tooltip("Z"); - glsafe(::glClear(GL_DEPTH_BUFFER_BIT)); glsafe(::glEnable(GL_DEPTH_TEST)); diff --git a/src/slic3r/GUI/Gizmos/GLGizmoMove.hpp b/src/slic3r/GUI/Gizmos/GLGizmoMove.hpp index b2367ac68..d8de08200 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoMove.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoMove.hpp @@ -30,6 +30,8 @@ public: const Vec3d& get_displacement() const { return m_displacement; } + virtual std::string get_tooltip() const; + protected: virtual bool on_init(); virtual std::string on_get_name() const; diff --git a/src/slic3r/GUI/Gizmos/GLGizmoRotate.cpp b/src/slic3r/GUI/Gizmos/GLGizmoRotate.cpp index e830103a1..f3e565686 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoRotate.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoRotate.cpp @@ -67,6 +67,18 @@ void GLGizmoRotate::set_angle(double angle) m_angle = angle; } +std::string GLGizmoRotate::get_tooltip() const +{ + std::string axis; + switch (m_axis) + { + case X: { axis = "X"; break; } + case Y: { axis = "Y"; break; } + case Z: { axis = "Z"; break; } + } + return (m_hover_id == 0 || m_grabbers[0].dragging) ? axis + ": " + format((float)Geometry::rad2deg(m_angle), 4) : ""; +} + bool GLGizmoRotate::on_init() { m_grabbers.push_back(Grabber()); @@ -127,17 +139,7 @@ void GLGizmoRotate::on_render() const const Selection& selection = m_parent.get_selection(); const BoundingBoxf3& box = selection.get_bounding_box(); - std::string axis; - switch (m_axis) - { - case X: { axis = "X"; break; } - case Y: { axis = "Y"; break; } - case Z: { axis = "Z"; break; } - } - - if (m_hover_id == 0 || m_grabbers[0].dragging) - set_tooltip(axis + ": " + format((float)Geometry::rad2deg(m_angle), 4)); - else + if (m_hover_id != 0 && !m_grabbers[0].dragging) { m_center = box.center(); m_radius = Offset + box.radius(); diff --git a/src/slic3r/GUI/Gizmos/GLGizmoRotate.hpp b/src/slic3r/GUI/Gizmos/GLGizmoRotate.hpp index 53cf93ad2..d666c324d 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoRotate.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoRotate.hpp @@ -49,6 +49,8 @@ public: double get_angle() const { return m_angle; } void set_angle(double angle); + virtual std::string get_tooltip() const; + protected: virtual bool on_init(); virtual std::string on_get_name() const { return ""; } @@ -81,14 +83,14 @@ public: Vec3d get_rotation() const { return Vec3d(m_gizmos[X].get_angle(), m_gizmos[Y].get_angle(), m_gizmos[Z].get_angle()); } void set_rotation(const Vec3d& rotation) { m_gizmos[X].set_angle(rotation(0)); m_gizmos[Y].set_angle(rotation(1)); m_gizmos[Z].set_angle(rotation(2)); } - virtual const std::string& get_tooltip() const + virtual std::string get_tooltip() const { - m_tooltip = m_gizmos[X].get_tooltip(); - if (m_tooltip.empty()) - m_tooltip = m_gizmos[Y].get_tooltip(); - if (m_tooltip.empty()) - m_tooltip = m_gizmos[Z].get_tooltip(); - return m_tooltip; + std::string tooltip = m_gizmos[X].get_tooltip(); + if (tooltip.empty()) + tooltip = m_gizmos[Y].get_tooltip(); + if (tooltip.empty()) + tooltip = m_gizmos[Z].get_tooltip(); + return tooltip; } protected: diff --git a/src/slic3r/GUI/Gizmos/GLGizmoScale.cpp b/src/slic3r/GUI/Gizmos/GLGizmoScale.cpp index b4972e6fa..80cc16ba2 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoScale.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoScale.cpp @@ -20,6 +20,38 @@ GLGizmoScale3D::GLGizmoScale3D(GLCanvas3D& parent, const std::string& icon_filen { } +std::string GLGizmoScale3D::get_tooltip() const +{ + const Selection& selection = m_parent.get_selection(); + + bool single_instance = selection.is_single_full_instance(); + bool single_volume = selection.is_single_modifier() || selection.is_single_volume(); + bool single_selection = single_instance || single_volume; + + Vec3f scale = 100.0f * Vec3f::Ones(); + if (single_instance) + scale = 100.0f * selection.get_volume(*selection.get_volume_idxs().begin())->get_instance_scaling_factor().cast(); + else if (single_volume) + scale = 100.0f * selection.get_volume(*selection.get_volume_idxs().begin())->get_volume_scaling_factor().cast(); + + if (m_hover_id == 0 || m_hover_id == 1 || m_grabbers[0].dragging || m_grabbers[1].dragging) + return "X: " + format(scale(0), 4) + "%"; + else if (m_hover_id == 2 || m_hover_id == 3 || m_grabbers[2].dragging || m_grabbers[3].dragging) + return "Y: " + format(scale(1), 4) + "%"; + else if (m_hover_id == 4 || m_hover_id == 5 || m_grabbers[4].dragging || m_grabbers[5].dragging) + return "Z: " + format(scale(2), 4) + "%"; + else if (m_hover_id == 6 || m_hover_id == 7 || m_hover_id == 8 || m_hover_id == 9 || + m_grabbers[6].dragging || m_grabbers[7].dragging || m_grabbers[8].dragging || m_grabbers[9].dragging) + { + std::string tooltip = "X: " + format(scale(0), 4) + "%\n"; + tooltip += "Y: " + format(scale(1), 4) + "%\n"; + tooltip += "Z: " + format(scale(2), 4) + "%"; + return tooltip; + } + else + return ""; +} + bool GLGizmoScale3D::on_init() { for (int i = 0; i < 10; ++i) @@ -89,37 +121,6 @@ void GLGizmoScale3D::on_render() const bool single_instance = selection.is_single_full_instance(); bool single_volume = selection.is_single_modifier() || selection.is_single_volume(); - bool single_selection = single_instance || single_volume; - - Vec3f scale = 100.0f * Vec3f::Ones(); - if (single_instance) - scale = 100.0f * selection.get_volume(*selection.get_volume_idxs().begin())->get_instance_scaling_factor().cast(); - else if (single_volume) - scale = 100.0f * selection.get_volume(*selection.get_volume_idxs().begin())->get_volume_scaling_factor().cast(); - - if ((single_selection && ((m_hover_id == 0) || (m_hover_id == 1))) || m_grabbers[0].dragging || m_grabbers[1].dragging) - set_tooltip("X: " + format(scale(0), 4) + "%"); - else if (!m_grabbers[0].dragging && !m_grabbers[1].dragging && ((m_hover_id == 0) || (m_hover_id == 1))) - set_tooltip("X"); - else if ((single_selection && ((m_hover_id == 2) || (m_hover_id == 3))) || m_grabbers[2].dragging || m_grabbers[3].dragging) - set_tooltip("Y: " + format(scale(1), 4) + "%"); - else if (!m_grabbers[2].dragging && !m_grabbers[3].dragging && ((m_hover_id == 2) || (m_hover_id == 3))) - set_tooltip("Y"); - else if ((single_selection && ((m_hover_id == 4) || (m_hover_id == 5))) || m_grabbers[4].dragging || m_grabbers[5].dragging) - set_tooltip("Z: " + format(scale(2), 4) + "%"); - else if (!m_grabbers[4].dragging && !m_grabbers[5].dragging && ((m_hover_id == 4) || (m_hover_id == 5))) - set_tooltip("Z"); - else if ((single_selection && ((m_hover_id == 6) || (m_hover_id == 7) || (m_hover_id == 8) || (m_hover_id == 9))) - || m_grabbers[6].dragging || m_grabbers[7].dragging || m_grabbers[8].dragging || m_grabbers[9].dragging) - { - std::string tooltip = "X: " + format(scale(0), 4) + "%\n"; - tooltip += "Y: " + format(scale(1), 4) + "%\n"; - tooltip += "Z: " + format(scale(2), 4) + "%"; - set_tooltip(tooltip); - } - else if (!m_grabbers[6].dragging && !m_grabbers[7].dragging && !m_grabbers[8].dragging && !m_grabbers[9].dragging && - ((m_hover_id == 6) || (m_hover_id == 7) || (m_hover_id == 8) || (m_hover_id == 9))) - set_tooltip("X/Y/Z"); glsafe(::glClear(GL_DEPTH_BUFFER_BIT)); glsafe(::glEnable(GL_DEPTH_TEST)); diff --git a/src/slic3r/GUI/Gizmos/GLGizmoScale.hpp b/src/slic3r/GUI/Gizmos/GLGizmoScale.hpp index d49770dce..2a3348716 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoScale.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoScale.hpp @@ -42,6 +42,8 @@ public: const Vec3d& get_offset() const { return m_offset; } + virtual std::string get_tooltip() const; + protected: virtual bool on_init(); virtual std::string on_get_name() const;