From fbf14b42e9831b5fc99be555668e126df37f9d58 Mon Sep 17 00:00:00 2001 From: YuSanka Date: Mon, 8 Jul 2019 18:01:14 +0200 Subject: [PATCH] Added undo/redo icons. Fist step to implementation Undo/Redo list for toolbar --- resources/icons/redo.svg | 12 +++++++ resources/icons/redo_toolbar.svg | 12 +++++++ resources/icons/undo_toolbar.svg | 12 +++++++ src/slic3r/GUI/GLCanvas3D.cpp | 58 ++++++++++++++++++++++++++++++++ src/slic3r/GUI/GLToolbar.cpp | 4 +++ src/slic3r/GUI/GLToolbar.hpp | 7 ++++ src/slic3r/GUI/ImGuiWrapper.cpp | 21 ++++++++++++ src/slic3r/GUI/ImGuiWrapper.hpp | 1 + src/slic3r/GUI/MainFrame.cpp | 2 +- 9 files changed, 128 insertions(+), 1 deletion(-) create mode 100644 resources/icons/redo.svg create mode 100644 resources/icons/redo_toolbar.svg create mode 100644 resources/icons/undo_toolbar.svg diff --git a/resources/icons/redo.svg b/resources/icons/redo.svg new file mode 100644 index 000000000..9109779bb --- /dev/null +++ b/resources/icons/redo.svg @@ -0,0 +1,12 @@ + + + + + + + + + diff --git a/resources/icons/redo_toolbar.svg b/resources/icons/redo_toolbar.svg new file mode 100644 index 000000000..ad073244f --- /dev/null +++ b/resources/icons/redo_toolbar.svg @@ -0,0 +1,12 @@ + + + + + + + + + diff --git a/resources/icons/undo_toolbar.svg b/resources/icons/undo_toolbar.svg new file mode 100644 index 000000000..699ccd807 --- /dev/null +++ b/resources/icons/undo_toolbar.svg @@ -0,0 +1,12 @@ + + + + + + + + + diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index 1d5cec04a..970b349cb 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -3618,6 +3618,64 @@ bool GLCanvas3D::_init_toolbar() if (!m_toolbar.add_item(item)) return false; + if (!m_toolbar.add_separator()) + return false; + + item.name = "undo"; +#if ENABLE_SVG_ICONS + item.icon_filename = "undo_toolbar.svg"; +#endif // ENABLE_SVG_ICONS + item.tooltip = _utf8(L("Undo")) + " [" + GUI::shortkey_ctrl_prefix() + "Z]"; + item.sprite_id = 11; + item.action_callback = [this]() + { + if (m_canvas != nullptr) { + wxPostEvent(m_canvas, SimpleEvent(EVT_GLCANVAS_UNDO)); + m_toolbar.set_imgui_visible(); + } + }; + item.visibility_callback = []()->bool { return true; }; + item.enabled_state_callback = []()->bool { return wxGetApp().plater()->can_undo(); }; + item.render_callback = [this]() + { + if (m_canvas != nullptr && m_toolbar.get_imgui_visible()) { + ImGuiWrapper* imgui = wxGetApp().imgui(); + + const float approx_height = m_toolbar.get_height(); + imgui->set_next_window_pos(600, approx_height, ImGuiCond_Always); + + imgui->set_next_window_bg_alpha(0.5f); + imgui->begin(_(L("Undo Stack")), ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse); + + std::vector undo_stack = {"A", "B", "C", "D","A", "B", "C", "D","A", "B", "C", "D",}; + int sel = 4; + imgui->multi_sel_list("", undo_stack, sel); + + const bool undo_clicked = imgui->button(_(L("Undo N Action"))); + + imgui->end(); + if (undo_clicked) + m_toolbar.set_imgui_visible(false); + } + }; + if (!m_toolbar.add_item(item)) + return false; + + item.name = "redo"; +#if ENABLE_SVG_ICONS + item.icon_filename = "redo_toolbar.svg"; +#endif // ENABLE_SVG_ICONS + item.tooltip = _utf8(L("Redo")) + " [" + GUI::shortkey_ctrl_prefix() + "Y]"; + item.sprite_id = 12; + item.action_callback = [this]() { if (m_canvas != nullptr) wxPostEvent(m_canvas, SimpleEvent(EVT_GLCANVAS_REDO)); }; + item.enabled_state_callback = []()->bool { return wxGetApp().plater()->can_redo(); }; + item.render_callback = []() {}; + if (!m_toolbar.add_item(item)) + return false; + + if (!m_toolbar.add_separator()) + return false; + return true; } diff --git a/src/slic3r/GUI/GLToolbar.cpp b/src/slic3r/GUI/GLToolbar.cpp index f8082ad7e..a851e3a4c 100644 --- a/src/slic3r/GUI/GLToolbar.cpp +++ b/src/slic3r/GUI/GLToolbar.cpp @@ -35,6 +35,7 @@ wxDEFINE_EVENT(EVT_GLVIEWTOOLBAR_PREVIEW, SimpleEvent); const GLToolbarItem::ActionCallback GLToolbarItem::Default_Action_Callback = [](){}; const GLToolbarItem::VisibilityCallback GLToolbarItem::Default_Visibility_Callback = []()->bool { return true; }; const GLToolbarItem::EnabledStateCallback GLToolbarItem::Default_Enabled_State_Callback = []()->bool { return true; }; +const GLToolbarItem::RenderCallback GLToolbarItem::Default_Render_Callback = [](){}; GLToolbarItem::Data::Data() : name("") @@ -48,6 +49,7 @@ GLToolbarItem::Data::Data() , action_callback(Default_Action_Callback) , visibility_callback(Default_Visibility_Callback) , enabled_state_callback(Default_Enabled_State_Callback) + , render_callback(Default_Render_Callback) { } @@ -81,6 +83,8 @@ bool GLToolbarItem::update_enabled_state() void GLToolbarItem::render(unsigned int tex_id, float left, float right, float bottom, float top, unsigned int tex_width, unsigned int tex_height, unsigned int icon_size) const { GLTexture::render_sub_texture(tex_id, left, right, bottom, top, get_uvs(tex_width, tex_height, icon_size)); + + m_data.render_callback(); } GLTexture::Quad_UVs GLToolbarItem::get_uvs(unsigned int tex_width, unsigned int tex_height, unsigned int icon_size) const diff --git a/src/slic3r/GUI/GLToolbar.hpp b/src/slic3r/GUI/GLToolbar.hpp index 24314d60f..aa68fae38 100644 --- a/src/slic3r/GUI/GLToolbar.hpp +++ b/src/slic3r/GUI/GLToolbar.hpp @@ -37,6 +37,7 @@ public: typedef std::function ActionCallback; typedef std::function VisibilityCallback; typedef std::function EnabledStateCallback; + typedef std::function RenderCallback; enum EType : unsigned char { @@ -68,6 +69,7 @@ public: ActionCallback action_callback; VisibilityCallback visibility_callback; EnabledStateCallback enabled_state_callback; + RenderCallback render_callback; Data(); }; @@ -75,6 +77,7 @@ public: static const ActionCallback Default_Action_Callback; static const VisibilityCallback Default_Visibility_Callback; static const EnabledStateCallback Default_Enabled_State_Callback; + static const RenderCallback Default_Render_Callback; private: EType m_type; @@ -249,6 +252,7 @@ private: MouseCapture m_mouse_capture; std::string m_tooltip; + bool m_imgui_visible {false}; public: #if ENABLE_SVG_ICONS @@ -305,6 +309,9 @@ public: bool on_mouse(wxMouseEvent& evt, GLCanvas3D& parent); + void set_imgui_visible(bool visible = true) { m_imgui_visible = visible; } + bool get_imgui_visible() { return m_imgui_visible; } + private: void calc_layout() const; float get_width_horizontal() const; diff --git a/src/slic3r/GUI/ImGuiWrapper.cpp b/src/slic3r/GUI/ImGuiWrapper.cpp index b6abf641a..cbcf33f77 100644 --- a/src/slic3r/GUI/ImGuiWrapper.cpp +++ b/src/slic3r/GUI/ImGuiWrapper.cpp @@ -342,6 +342,27 @@ bool ImGuiWrapper::combo(const wxString& label, const std::vector& return res; } +// Getter for the const char*[] +static bool StringGetter(void* data, int i, const char** out_text) +{ + const std::vector* v = (std::vector*)data; + if (out_text) + *out_text = (*v)[i].c_str(); + return true; +} + +bool ImGuiWrapper::multi_sel_list(const wxString& label, const std::vector& options, int& selection) +{ + // this is to force the label to the left of the widget: + if (!label.IsEmpty()) + text(label); + + bool res = false; + ImGui::ListBox("", &selection, StringGetter, (void*)&options, (int)options.size()); + + return res; +} + void ImGuiWrapper::disabled_begin(bool disabled) { wxCHECK_RET(!m_disabled, "ImGUI: Unbalanced disabled_begin() call"); diff --git a/src/slic3r/GUI/ImGuiWrapper.hpp b/src/slic3r/GUI/ImGuiWrapper.hpp index 0479e4743..42c562b72 100644 --- a/src/slic3r/GUI/ImGuiWrapper.hpp +++ b/src/slic3r/GUI/ImGuiWrapper.hpp @@ -67,6 +67,7 @@ public: void text(const std::string &label); void text(const wxString &label); bool combo(const wxString& label, const std::vector& options, int& selection); // Use -1 to not mark any option as selected + bool multi_sel_list(const wxString& label, const std::vector& options, int& selection); // Use -1 to not mark any option as selected void disabled_begin(bool disabled); void disabled_end(); diff --git a/src/slic3r/GUI/MainFrame.cpp b/src/slic3r/GUI/MainFrame.cpp index 67b336a0e..cca6e02e6 100644 --- a/src/slic3r/GUI/MainFrame.cpp +++ b/src/slic3r/GUI/MainFrame.cpp @@ -508,7 +508,7 @@ void MainFrame::init_menubar() "undo", nullptr, [this](){return m_plater->can_undo(); }, this); append_menu_item(editMenu, wxID_ANY, _(L("&Redo")) + sep + GUI::shortkey_ctrl_prefix() + sep_space + "Y", _(L("Redo")), [this](wxCommandEvent&) { m_plater->redo(); }, - "undo", nullptr, [this](){return m_plater->can_redo(); }, this); + "redo", nullptr, [this](){return m_plater->can_redo(); }, this); editMenu->AppendSeparator(); append_menu_item(editMenu, wxID_ANY, _(L("&Copy")) + sep + GUI::shortkey_ctrl_prefix() + sep_space + "C",