From df6170b9bd50c2f1fb6714c0505af545eeb84dcd Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Mon, 16 Mar 2020 12:45:39 +0100 Subject: [PATCH] Fixed gizmos' tooltips --- src/slic3r/GUI/GLCanvas3D.cpp | 38 +++++++++++------------ src/slic3r/GUI/Gizmos/GLGizmoBase.cpp | 2 +- src/slic3r/GUI/Gizmos/GLGizmoBase.hpp | 5 ++- src/slic3r/GUI/Gizmos/GLGizmoCut.cpp | 3 +- src/slic3r/GUI/Gizmos/GLGizmoRotate.cpp | 6 ++-- src/slic3r/GUI/Gizmos/GLGizmoRotate.hpp | 10 ++++++ src/slic3r/GUI/Gizmos/GLGizmosManager.cpp | 9 ++++++ src/slic3r/GUI/Gizmos/GLGizmosManager.hpp | 2 +- 8 files changed, 47 insertions(+), 28 deletions(-) diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index ec89d1b42..f595aad5c 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -1951,6 +1951,25 @@ void GLCanvas3D::render() auto end_time = std::chrono::high_resolution_clock::now(); m_render_stats.last_frame = std::chrono::duration_cast(end_time - start_time).count(); #endif // ENABLE_RENDER_STATISTICS + + std::string tooltip = ""; + + if (tooltip.empty()) + tooltip = m_layers_editing.get_tooltip(*this); + + if (tooltip.empty()) + tooltip = m_gizmos.get_tooltip(); + + if (tooltip.empty()) + tooltip = m_main_toolbar.get_tooltip(); + + if (tooltip.empty()) + tooltip = m_undoredo_toolbar.get_tooltip(); + + if (tooltip.empty()) + tooltip = m_view_toolbar.get_tooltip(); + + set_tooltip(tooltip); } #if ENABLE_THUMBNAIL_GENERATOR @@ -3587,24 +3606,6 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) else if (evt.Moving()) { m_mouse.position = pos.cast(); - std::string tooltip = ""; - - if (tooltip.empty()) - tooltip = m_layers_editing.get_tooltip(*this); - - if (tooltip.empty()) - tooltip = m_gizmos.get_tooltip(); - - if (tooltip.empty()) - tooltip = m_main_toolbar.get_tooltip(); - - if (tooltip.empty()) - tooltip = m_undoredo_toolbar.get_tooltip(); - - if (tooltip.empty()) - tooltip = m_view_toolbar.get_tooltip(); - - set_tooltip(tooltip); // updates gizmos overlay if (m_selection.is_empty()) @@ -3692,7 +3693,6 @@ void GLCanvas3D::set_tooltip(const std::string& tooltip) const } } - void GLCanvas3D::do_move(const std::string& snapshot_type) { if (m_model == nullptr) diff --git a/src/slic3r/GUI/Gizmos/GLGizmoBase.cpp b/src/slic3r/GUI/Gizmos/GLGizmoBase.cpp index 2f988db12..d2bad5d53 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoBase.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoBase.cpp @@ -265,7 +265,7 @@ void GLGizmoBase::render_grabbers_for_picking(const BoundingBoxf3& box) const void GLGizmoBase::set_tooltip(const std::string& tooltip) const { - m_parent.set_tooltip(tooltip); + m_tooltip = tooltip; } std::string GLGizmoBase::format(float value, unsigned int decimals) const diff --git a/src/slic3r/GUI/Gizmos/GLGizmoBase.hpp b/src/slic3r/GUI/Gizmos/GLGizmoBase.hpp index 5f159420f..e25fb248f 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoBase.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoBase.hpp @@ -100,6 +100,7 @@ protected: mutable std::vector m_grabbers; ImGuiWrapper* m_imgui; bool m_first_input_window_render; + mutable std::string m_tooltip; public: GLGizmoBase(GLCanvas3D& parent, @@ -145,10 +146,12 @@ public: void update(const UpdateData& data); - void render() const { on_render(); } + void render() const { m_tooltip.clear(); 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; } + protected: virtual bool on_init() = 0; virtual void on_load(cereal::BinaryInputArchive& ar) {} diff --git a/src/slic3r/GUI/Gizmos/GLGizmoCut.cpp b/src/slic3r/GUI/Gizmos/GLGizmoCut.cpp index 52d710249..2122a01af 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoCut.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoCut.cpp @@ -79,9 +79,8 @@ void GLGizmoCut::on_update(const UpdateData& data) void GLGizmoCut::on_render() const { - if (m_grabbers[0].dragging) { + if (m_hover_id == 0 || m_grabbers[0].dragging) set_tooltip("Z: " + format(m_cut_z, 2)); - } const Selection& selection = m_parent.get_selection(); diff --git a/src/slic3r/GUI/Gizmos/GLGizmoRotate.cpp b/src/slic3r/GUI/Gizmos/GLGizmoRotate.cpp index 9a0d75033..e830103a1 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoRotate.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoRotate.cpp @@ -135,10 +135,8 @@ void GLGizmoRotate::on_render() const case Z: { axis = "Z"; break; } } - if (!m_dragging && (m_hover_id == 0)) - set_tooltip(axis); - else if (m_dragging) - set_tooltip(axis + ": " + format((float)Geometry::rad2deg(m_angle), 4) + "\u00B0"); + if (m_hover_id == 0 || m_grabbers[0].dragging) + set_tooltip(axis + ": " + format((float)Geometry::rad2deg(m_angle), 4)); else { m_center = box.center(); diff --git a/src/slic3r/GUI/Gizmos/GLGizmoRotate.hpp b/src/slic3r/GUI/Gizmos/GLGizmoRotate.hpp index 6e7bf1a09..53cf93ad2 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoRotate.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoRotate.hpp @@ -81,6 +81,16 @@ 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 + { + 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; + } + protected: virtual bool on_init(); virtual std::string on_get_name() const; diff --git a/src/slic3r/GUI/Gizmos/GLGizmosManager.cpp b/src/slic3r/GUI/Gizmos/GLGizmosManager.cpp index 8ff4d26c2..9559bc28e 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmosManager.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmosManager.cpp @@ -422,6 +422,15 @@ void GLGizmosManager::render_overlay() const do_render_overlay(); } +std::string GLGizmosManager::get_tooltip() const +{ + if (!m_tooltip.empty()) + return m_tooltip; + + const GLGizmoBase* curr = get_current(); + return (curr != nullptr) ? curr->get_tooltip() : ""; +} + bool GLGizmosManager::on_mouse_wheel(wxMouseEvent& evt) { bool processed = false; diff --git a/src/slic3r/GUI/Gizmos/GLGizmosManager.hpp b/src/slic3r/GUI/Gizmos/GLGizmosManager.hpp index a479b645b..614712d1d 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmosManager.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmosManager.hpp @@ -204,7 +204,7 @@ public: void render_overlay() const; - const std::string& get_tooltip() const { return m_tooltip; } + std::string get_tooltip() const; bool on_mouse(wxMouseEvent& evt); bool on_mouse_wheel(wxMouseEvent& evt);