diff --git a/src/libslic3r/Technologies.hpp b/src/libslic3r/Technologies.hpp index 02a519064..3b8987930 100644 --- a/src/libslic3r/Technologies.hpp +++ b/src/libslic3r/Technologies.hpp @@ -68,5 +68,7 @@ // Enable tooltips for GLCanvas3D using ImGUI #define ENABLE_CANVAS_TOOLTIP_USING_IMGUI (1 && ENABLE_2_2_0_FINAL) +#define ENABLE_CANVAS_DELAYED_TOOLTIP_USING_IMGUI (1 && ENABLE_CANVAS_TOOLTIP_USING_IMGUI) + #endif // _technologies_h_ diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index 5ada24fa9..e808ea0c3 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -61,9 +61,11 @@ #include #include #include "DoubleSlider.hpp" +#if !ENABLE_CANVAS_DELAYED_TOOLTIP_USING_IMGUI #if ENABLE_RENDER_STATISTICS #include #endif // ENABLE_RENDER_STATISTICS +#endif // !ENABLE_CANVAS_DELAYED_TOOLTIP_USING_IMGUI #include @@ -1371,16 +1373,52 @@ void GLCanvas3D::Labels::render(const std::vector& sorted_ } #if ENABLE_CANVAS_TOOLTIP_USING_IMGUI -void GLCanvas3D::Tooltip::render(const Vec2d& mouse_position) const +#if ENABLE_CANVAS_DELAYED_TOOLTIP_USING_IMGUI +void GLCanvas3D::Tooltip::set_text(const std::string& text) { + if (m_text != text) + { + if (m_text.empty()) + m_start_time = std::chrono::high_resolution_clock::now(); + + m_text = text; + } +} +#endif // ENABLE_CANVAS_DELAYED_TOOLTIP_USING_IMGUI + +#if ENABLE_CANVAS_DELAYED_TOOLTIP_USING_IMGUI +void GLCanvas3D::Tooltip::render(const Vec2d& mouse_position, GLCanvas3D& canvas) const +#else +void GLCanvas3D::Tooltip::render(const Vec2d& mouse_position) const +#endif // ENABLE_CANVAS_DELAYED_TOOLTIP_USING_IMGUI +{ +#if ENABLE_CANVAS_DELAYED_TOOLTIP_USING_IMGUI + if (m_text.empty() || std::chrono::duration_cast(std::chrono::high_resolution_clock::now() - m_start_time).count() < 500) + { + if (!m_text.empty()) + // request another frame to show up later + canvas.request_extra_frame(); + + return; + } +#else if (m_text.empty()) return; +#endif // ENABLE_CANVAS_DELAYED_TOOLTIP_USING_IMGUI 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::BringWindowToDisplayFront(ImGui::GetCurrentWindow()); imgui.text(m_text); + +#if ENABLE_CANVAS_DELAYED_TOOLTIP_USING_IMGUI + // force re-render while the windows gets to its final size (it may take several frames) + if (ImGui::GetWindowContentRegionWidth() + 2.0f * ImGui::GetStyle().WindowPadding.x != ImGui::CalcWindowExpectedSize(ImGui::GetCurrentWindow()).x) + canvas.request_extra_frame(); +#endif // ENABLE_CANVAS_DELAYED_TOOLTIP_USING_IMGUI + imgui.end(); ImGui::PopStyleVar(); } @@ -1977,7 +2015,11 @@ void GLCanvas3D::render() set_tooltip(tooltip); +#if ENABLE_CANVAS_DELAYED_TOOLTIP_USING_IMGUI + m_tooltip.render(m_mouse.position, *this); +#else m_tooltip.render(m_mouse.position); +#endif // ENABLE_CANVAS_DELAYED_TOOLTIP_USING_IMGUI #endif // ENABLE_CANVAS_TOOLTIP_USING_IMGUI wxGetApp().plater()->get_mouse3d_controller().render_settings_dialog(*this); diff --git a/src/slic3r/GUI/GLCanvas3D.hpp b/src/slic3r/GUI/GLCanvas3D.hpp index bedcadbdc..9495600a5 100644 --- a/src/slic3r/GUI/GLCanvas3D.hpp +++ b/src/slic3r/GUI/GLCanvas3D.hpp @@ -3,6 +3,9 @@ #include #include +#if ENABLE_CANVAS_DELAYED_TOOLTIP_USING_IMGUI +#include +#endif // ENABLE_CANVAS_DELAYED_TOOLTIP_USING_IMGUI #include "3DScene.hpp" #include "GLToolbar.hpp" @@ -393,10 +396,18 @@ private: class Tooltip { std::string m_text; +#if ENABLE_CANVAS_DELAYED_TOOLTIP_USING_IMGUI + std::chrono::steady_clock::time_point m_start_time; +#endif // ENABLE_CANVAS_DELAYED_TOOLTIP_USING_IMGUI public: +#if ENABLE_CANVAS_DELAYED_TOOLTIP_USING_IMGUI + void set_text(const std::string& text); + void render(const Vec2d& mouse_position, GLCanvas3D& canvas) const; +#else void set_text(const std::string& text) { m_text = text; } void render(const Vec2d& mouse_position) const; +#endif // ENABLE_CANVAS_DELAYED_TOOLTIP_USING_IMGUI }; #endif // ENABLE_CANVAS_TOOLTIP_USING_IMGUI