From 7a1fa3d847b0a672b048784995c73005b191a1d4 Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Tue, 17 Mar 2020 13:01:38 +0100 Subject: [PATCH] Canvas' tooltip using ImGUI --- src/libslic3r/Technologies.hpp | 9 +++++ src/slic3r/GUI/GLCanvas3D.cpp | 72 ++++++++++++++++++++++++++++------ src/slic3r/GUI/GLCanvas3D.hpp | 14 +++++++ 3 files changed, 82 insertions(+), 13 deletions(-) diff --git a/src/libslic3r/Technologies.hpp b/src/libslic3r/Technologies.hpp index 75e0866b7..02a519064 100644 --- a/src/libslic3r/Technologies.hpp +++ b/src/libslic3r/Technologies.hpp @@ -60,4 +60,13 @@ // while 3D mouse is connected and free camera is not selected #define ENABLE_AUTO_CONSTRAINED_CAMERA (1 && ENABLE_2_2_0) + +//================== +// 2.2.0.final techs +//================== +#define ENABLE_2_2_0_FINAL 1 + +// Enable tooltips for GLCanvas3D using ImGUI +#define ENABLE_CANVAS_TOOLTIP_USING_IMGUI (1 && ENABLE_2_2_0_FINAL) + #endif // _technologies_h_ diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index 424e367b2..5ada24fa9 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -1370,6 +1370,22 @@ void GLCanvas3D::Labels::render(const std::vector& sorted_ } } +#if ENABLE_CANVAS_TOOLTIP_USING_IMGUI +void GLCanvas3D::Tooltip::render(const Vec2d& mouse_position) const +{ + if (m_text.empty()) + return; + + ImGuiWrapper& imgui = *wxGetApp().imgui(); + ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f); + imgui.set_next_window_pos(mouse_position(0), mouse_position(1) + 16, ImGuiCond_Always, 0.0f, 0.0f); + imgui.begin(_(L("canvas_tooltip")), ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoMouseInputs | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoDecoration); + imgui.text(m_text); + imgui.end(); + ImGui::PopStyleVar(); +} +#endif // ENABLE_CANVAS_TOOLTIP_USING_IMGUI + wxDEFINE_EVENT(EVT_GLCANVAS_SCHEDULE_BACKGROUND_PROCESS, SimpleEvent); wxDEFINE_EVENT(EVT_GLCANVAS_OBJECT_SELECT, SimpleEvent); wxDEFINE_EVENT(EVT_GLCANVAS_RIGHT_CLICK, RBtnEvent); @@ -1941,17 +1957,7 @@ void GLCanvas3D::render() m_camera.debug_render(); #endif // ENABLE_CAMERA_STATISTICS - wxGetApp().plater()->get_mouse3d_controller().render_settings_dialog(*this); - - wxGetApp().imgui()->render(); - - m_canvas->SwapBuffers(); - -#if ENABLE_RENDER_STATISTICS - 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 - +#if ENABLE_CANVAS_TOOLTIP_USING_IMGUI std::string tooltip = ""; if (tooltip.empty()) @@ -1970,6 +1976,41 @@ void GLCanvas3D::render() tooltip = m_view_toolbar.get_tooltip(); set_tooltip(tooltip); + + m_tooltip.render(m_mouse.position); +#endif // ENABLE_CANVAS_TOOLTIP_USING_IMGUI + + wxGetApp().plater()->get_mouse3d_controller().render_settings_dialog(*this); + + wxGetApp().imgui()->render(); + + m_canvas->SwapBuffers(); + +#if ENABLE_RENDER_STATISTICS + 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 + +#if !ENABLE_CANVAS_TOOLTIP_USING_IMGUI + 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); +#endif // !ENABLE_CANVAS_TOOLTIP_USING_IMGUI } #if ENABLE_THUMBNAIL_GENERATOR @@ -3279,6 +3320,9 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) mouse_up_cleanup(); m_mouse.set_start_position_3D_as_invalid(); +#if ENABLE_CANVAS_TOOLTIP_USING_IMGUI + m_mouse.position = pos.cast(); +#endif /// ENABLE_CANVAS_TOOLTIP_USING_IMGUI return; } @@ -3680,7 +3724,9 @@ void GLCanvas3D::set_tooltip(const std::string& tooltip) const { if (m_canvas != nullptr) { -//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +#if ENABLE_CANVAS_TOOLTIP_USING_IMGUI + m_tooltip.set_text(std::string((_(L(tooltip))).ToUTF8())); +#else wxString txt = wxString::FromUTF8(tooltip.data()); if (m_canvas->GetToolTipText() != txt) m_canvas->SetToolTip(txt); @@ -3695,7 +3741,7 @@ void GLCanvas3D::set_tooltip(const std::string& tooltip) const // } // else if (!tooltip.empty()) // Avoid "empty" tooltips => unset of the empty tooltip leads to application crash under OSX // m_canvas->SetToolTip(wxString::FromUTF8(tooltip.data())); -//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +#endif // ENABLE_CANVAS_TOOLTIP_USING_IMGUI } } diff --git a/src/slic3r/GUI/GLCanvas3D.hpp b/src/slic3r/GUI/GLCanvas3D.hpp index 9ae127880..bedcadbdc 100644 --- a/src/slic3r/GUI/GLCanvas3D.hpp +++ b/src/slic3r/GUI/GLCanvas3D.hpp @@ -389,6 +389,17 @@ private: void render(const std::vector& sorted_instances) const; }; +#if ENABLE_CANVAS_TOOLTIP_USING_IMGUI + class Tooltip + { + std::string m_text; + + public: + void set_text(const std::string& text) { m_text = text; } + void render(const Vec2d& mouse_position) const; + }; +#endif // ENABLE_CANVAS_TOOLTIP_USING_IMGUI + public: enum ECursorType : unsigned char { @@ -467,6 +478,9 @@ private: int m_selected_extruder; Labels m_labels; +#if ENABLE_CANVAS_TOOLTIP_USING_IMGUI + mutable Tooltip m_tooltip; +#endif // ENABLE_CANVAS_TOOLTIP_USING_IMGUI public: GLCanvas3D(wxGLCanvas* canvas, Bed3D& bed, Camera& camera, GLToolbar& view_toolbar);