From a5322ef970bce5489f242aa5c86c2c997c0d4984 Mon Sep 17 00:00:00 2001 From: YuSanka Date: Tue, 7 Mar 2023 09:37:48 +0100 Subject: [PATCH] DoubleSlider: ImGui rendering (WIP) --- src/slic3r/GUI/DoubleSlider.cpp | 31 +++++++++++++++++++++++++++++++ src/slic3r/GUI/DoubleSlider.hpp | 5 ++++- src/slic3r/GUI/GLCanvas3D.cpp | 2 ++ src/slic3r/GUI/GUI_Preview.cpp | 7 +++++++ src/slic3r/GUI/GUI_Preview.hpp | 2 ++ src/slic3r/GUI/Plater.cpp | 12 ++++++++++++ src/slic3r/GUI/Plater.hpp | 2 ++ 7 files changed, 60 insertions(+), 1 deletion(-) diff --git a/src/slic3r/GUI/DoubleSlider.cpp b/src/slic3r/GUI/DoubleSlider.cpp index 96313e19b1..623601fd12 100644 --- a/src/slic3r/GUI/DoubleSlider.cpp +++ b/src/slic3r/GUI/DoubleSlider.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include #include @@ -34,6 +35,8 @@ #include "format.hpp" #include "NotificationManager.hpp" +#include "ImGuiPureWrap.hpp" + namespace Slic3r { using GUI::from_u8; @@ -560,6 +563,34 @@ void Control::render() } } +void Control::imgui_render(GUI::GLCanvas3D& canvas) +{ + GUI::Size cnv_size = canvas.get_canvas_size(); + ImVec2 mouse_pos = ImGui::GetMousePos(); + const float width = get_min_size().x*5; + const float height = float(cnv_size.get_height()); + + ImVec2 win_pos(1.0f * (float)cnv_size.get_width(), 1.0f); + ImGuiPureWrap::set_next_window_pos(win_pos.x, win_pos.y, ImGuiCond_Always, 1.0f, 0.0f); + ImGuiPureWrap::set_next_window_size(width, height - 2.f, ImGuiCond_Always); + + ImGui::PushStyleColor(ImGuiCol_WindowBg, ImGui::GetStyleColorVec4(ImGuiCol_WindowBg)); + + // name of window indentifies window - has to be unique string + std::string name = "DblSlider"; + + int flags = ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoTitleBar | + ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize | + ImGuiWindowFlags_NoScrollbar | + ImGuiWindowFlags_NoScrollWithMouse | + ImGuiWindowFlags_NoFocusOnAppearing; + + if (ImGuiPureWrap::begin(name, flags)) { + + } + ImGuiPureWrap::end(); +} + bool Control::is_wipe_tower_layer(int tick) const { if (!m_is_wipe_tower || tick >= (int)m_values.size()) diff --git a/src/slic3r/GUI/DoubleSlider.hpp b/src/slic3r/GUI/DoubleSlider.hpp index f7b370f730..1e20a4b6e8 100644 --- a/src/slic3r/GUI/DoubleSlider.hpp +++ b/src/slic3r/GUI/DoubleSlider.hpp @@ -7,6 +7,7 @@ #include "libslic3r/CustomGCode.hpp" #include "wxExtensions.hpp" +#include "GLCanvas3D.hpp" #include #include @@ -302,7 +303,7 @@ public: void show_cog_icon_context_menu(); void auto_color_change(); - ExtrudersSequence m_extruders_sequence; + void imgui_render(GUI::GLCanvas3D& canvas); protected: @@ -431,6 +432,8 @@ private: std::vector m_alternate_values; + ExtrudersSequence m_extruders_sequence; + // control's view variables wxCoord SLIDER_MARGIN; // margin around slider diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index 42e743bc88..f00660708d 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -1950,6 +1950,8 @@ void GLCanvas3D::render() wxGetApp().plater()->get_notification_manager()->render_notifications(*this, get_overlay_window_width()); + wxGetApp().plater()->render_imgui_double_slider(*this); + wxGetApp().imgui()->render(); m_canvas->SwapBuffers(); diff --git a/src/slic3r/GUI/GUI_Preview.cpp b/src/slic3r/GUI/GUI_Preview.cpp index 3765bb2cc3..ed20c4cb64 100644 --- a/src/slic3r/GUI/GUI_Preview.cpp +++ b/src/slic3r/GUI/GUI_Preview.cpp @@ -347,6 +347,13 @@ void Preview::sys_color_changed() m_layers_slider->sys_color_changed(); } + +void Preview::render_imgui_double_slider(GLCanvas3D& canvas) +{ + if (m_layers_slider && m_layers_slider->IsShown()) + m_layers_slider->imgui_render(canvas); +} + void Preview::jump_layers_slider(wxKeyEvent& evt) { if (m_layers_slider) m_layers_slider->OnChar(evt); diff --git a/src/slic3r/GUI/GUI_Preview.hpp b/src/slic3r/GUI/GUI_Preview.hpp index 6141318845..c720cf771d 100644 --- a/src/slic3r/GUI/GUI_Preview.hpp +++ b/src/slic3r/GUI/GUI_Preview.hpp @@ -140,6 +140,8 @@ public: void move_layers_slider(wxKeyEvent& evt); void edit_layers_slider(wxKeyEvent& evt); + void render_imgui_double_slider(GLCanvas3D& canvas); + bool is_loaded() const { return m_loaded; } void update_moves_slider(std::optional visible_range_min = std::nullopt, std::optional visible_range_max = std::nullopt); diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index f3b289f519..1db3fac3f4 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -385,6 +385,7 @@ struct Plater::priv void set_current_canvas_as_dirty(); GLCanvas3D* get_current_canvas3D(); + void render_imgui_double_slider(GLCanvas3D& canvas); void unbind_canvas_event_handlers(); void reset_canvas_volumes(); @@ -3189,6 +3190,12 @@ GLCanvas3D* Plater::priv::get_current_canvas3D() return (current_panel == view3D) ? view3D->get_canvas3d() : ((current_panel == preview) ? preview->get_canvas3d() : nullptr); } +void Plater::priv::render_imgui_double_slider(GLCanvas3D& canvas) +{ + if (current_panel == preview) + preview->render_imgui_double_slider(canvas); +} + void Plater::priv::unbind_canvas_event_handlers() { if (view3D != nullptr) @@ -6402,6 +6409,11 @@ GLCanvas3D* Plater::get_current_canvas3D() return p->get_current_canvas3D(); } +void Plater::render_imgui_double_slider(GLCanvas3D& canvas) +{ + p->render_imgui_double_slider(canvas); +} + static std::string concat_strings(const std::set &strings, const std::string &delim = "\n") { diff --git a/src/slic3r/GUI/Plater.hpp b/src/slic3r/GUI/Plater.hpp index eec067d612..97c6c18772 100644 --- a/src/slic3r/GUI/Plater.hpp +++ b/src/slic3r/GUI/Plater.hpp @@ -271,6 +271,8 @@ public: GLCanvas3D* canvas3D(); const GLCanvas3D * canvas3D() const; GLCanvas3D* get_current_canvas3D(); + + void render_imgui_double_slider(GLCanvas3D& canvas); void arrange(); void arrange(Worker &w, bool selected);