DoubleSlider: ImGui rendering (WIP)

This commit is contained in:
YuSanka 2023-03-07 09:37:48 +01:00 committed by Lukas Matena
parent 46e08ca9f1
commit a5322ef970
7 changed files with 60 additions and 1 deletions

View File

@ -26,6 +26,7 @@
#include <wx/statline.h>
#include <wx/dcclient.h>
#include <wx/colordlg.h>
#include <wx/glcanvas.h>
#include <cmath>
#include <boost/algorithm/string/replace.hpp>
@ -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())

View File

@ -7,6 +7,7 @@
#include "libslic3r/CustomGCode.hpp"
#include "wxExtensions.hpp"
#include "GLCanvas3D.hpp"
#include <wx/window.h>
#include <wx/control.h>
@ -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<double> m_alternate_values;
ExtrudersSequence m_extruders_sequence;
// control's view variables
wxCoord SLIDER_MARGIN; // margin around slider

View File

@ -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();

View File

@ -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);

View File

@ -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<int> visible_range_min = std::nullopt, std::optional<int> visible_range_max = std::nullopt);

View File

@ -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<std::string> &strings,
const std::string &delim = "\n")
{

View File

@ -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);