diff options
author | YuSanka <yusanka@gmail.com> | 2019-07-08 19:01:14 +0300 |
---|---|---|
committer | YuSanka <yusanka@gmail.com> | 2019-07-08 19:01:14 +0300 |
commit | fbf14b42e9831b5fc99be555668e126df37f9d58 (patch) | |
tree | b80d8de5a5767378a72800ecee7243e178a33277 /src/slic3r/GUI | |
parent | 7b6229289d144d1f24feb53cda31973a64e34ff8 (diff) |
Added undo/redo icons. Fist step to implementation Undo/Redo list for toolbar
Diffstat (limited to 'src/slic3r/GUI')
-rw-r--r-- | src/slic3r/GUI/GLCanvas3D.cpp | 58 | ||||
-rw-r--r-- | src/slic3r/GUI/GLToolbar.cpp | 4 | ||||
-rw-r--r-- | src/slic3r/GUI/GLToolbar.hpp | 7 | ||||
-rw-r--r-- | src/slic3r/GUI/ImGuiWrapper.cpp | 21 | ||||
-rw-r--r-- | src/slic3r/GUI/ImGuiWrapper.hpp | 1 | ||||
-rw-r--r-- | src/slic3r/GUI/MainFrame.cpp | 2 |
6 files changed, 92 insertions, 1 deletions
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 <std::string> 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<void()> ActionCallback; typedef std::function<bool()> VisibilityCallback; typedef std::function<bool()> EnabledStateCallback; + typedef std::function<void()> 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<std::string>& return res; } +// Getter for the const char*[] +static bool StringGetter(void* data, int i, const char** out_text) +{ + const std::vector<std::string>* v = (std::vector<std::string>*)data; + if (out_text) + *out_text = (*v)[i].c_str(); + return true; +} + +bool ImGuiWrapper::multi_sel_list(const wxString& label, const std::vector<std::string>& 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<std::string>& options, int& selection); // Use -1 to not mark any option as selected + bool multi_sel_list(const wxString& label, const std::vector<std::string>& 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", |