Added undo/redo icons. Fist step to implementation Undo/Redo list for toolbar

This commit is contained in:
YuSanka 2019-07-08 18:01:14 +02:00
parent 7b6229289d
commit fbf14b42e9
9 changed files with 128 additions and 1 deletions

12
resources/icons/redo.svg Normal file
View file

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 23.0.4, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<svg version="1.0" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
viewBox="0 0 16 16" enable-background="new 0 0 16 16" xml:space="preserve">
<g id="redo">
<path fill="none" stroke="#ED6B21" stroke-width="2" stroke-linecap="round" stroke-miterlimit="10" d="M13.39,11
c-0.91,1.78-2.76,3-4.89,3C5.46,14,3,11.54,3,8.5C3,5.46,5.46,3,8.5,3C8.67,3,8.84,3.01,9,3.03"/>
<polygon fill="#ED6B21" stroke="#ED6B21" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" stroke-miterlimit="10" points="
9,1 9,5 12,3 "/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 734 B

View file

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 23.0.4, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<svg version="1.0" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
viewBox="0 0 16 16" enable-background="new 0 0 16 16" xml:space="preserve">
<g id="redo">
<path fill="none" stroke="#ED6B21" stroke-width="1" stroke-linecap="round" stroke-miterlimit="10" d="M13.39,11
c-0.91,1.78-2.76,3-4.89,3C5.46,14,3,11.54,3,8.5C3,5.46,5.46,3,8.5,3C8.67,3,8.84,3.01,9,3.03"/>
<polygon fill="#ED6B21" stroke="#ED6B21" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" stroke-miterlimit="10" points="
9,1 9,5 12,3 "/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 734 B

View file

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 23.0.3, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<svg version="1.0" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
viewBox="0 0 16 16" enable-background="new 0 0 16 16" xml:space="preserve">
<g id="undo">
<path fill="none" stroke="#ED6B21" stroke-width="1" stroke-linecap="round" stroke-miterlimit="10" d="M3,11
c0.91,1.78,2.76,3,4.89,3c3.04,0,5.5-2.46,5.5-5.5c0-3.04-2.46-5.5-5.5-5.5c-0.17,0-0.34,0.01-0.5,0.03"/>
<polygon fill="#ED6B21" stroke="#ED6B21" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" stroke-miterlimit="10" points="
7.39,1 7.39,5 4.39,3 "/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 746 B

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -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",