mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-12 01:07:57 -06:00
Fixed redo_to() function and code cleaning from redundant options
This commit is contained in:
parent
f985f5190c
commit
3720e6a3a3
4 changed files with 27 additions and 60 deletions
|
@ -3473,8 +3473,6 @@ static bool string_getter(const bool is_undo, int idx, const char** out_text)
|
||||||
|
|
||||||
void GLCanvas3D::_render_undo_redo_stack(const bool is_undo, float pos_x)
|
void GLCanvas3D::_render_undo_redo_stack(const bool is_undo, float pos_x)
|
||||||
{
|
{
|
||||||
if (m_canvas != nullptr && m_toolbar.get_imgui_visible(is_undo))
|
|
||||||
{
|
|
||||||
const wxString& stack_name = _(is_undo ? L("Undo") : L("Redo"));
|
const wxString& stack_name = _(is_undo ? L("Undo") : L("Redo"));
|
||||||
ImGuiWrapper* imgui = wxGetApp().imgui();
|
ImGuiWrapper* imgui = wxGetApp().imgui();
|
||||||
|
|
||||||
|
@ -3491,13 +3489,15 @@ void GLCanvas3D::_render_undo_redo_stack(const bool is_undo, float pos_x)
|
||||||
|
|
||||||
if (imgui->undo_redo_list(ImVec2(12 * em, 20 * em), is_undo, &string_getter, hovered, selected))
|
if (imgui->undo_redo_list(ImVec2(12 * em, 20 * em), is_undo, &string_getter, hovered, selected))
|
||||||
m_toolbar.set_imgui_hovered_pos(hovered);
|
m_toolbar.set_imgui_hovered_pos(hovered);
|
||||||
|
else
|
||||||
|
m_toolbar.set_imgui_hovered_pos(-1);
|
||||||
|
|
||||||
if (selected >= 0)
|
if (selected >= 0)
|
||||||
is_undo ? wxGetApp().plater()->undo_to(selected) : wxGetApp().plater()->redo_to(selected);
|
is_undo ? wxGetApp().plater()->undo_to(selected) : wxGetApp().plater()->redo_to(selected);
|
||||||
|
|
||||||
imgui->text(wxString::Format(_(L("%s %d Action")), stack_name, hovered + 1));
|
imgui->text(wxString::Format(_(L("%s %d Action")), stack_name, hovered + 1));
|
||||||
|
|
||||||
imgui->end();
|
imgui->end();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GLCanvas3D::_init_toolbar()
|
bool GLCanvas3D::_init_toolbar()
|
||||||
|
@ -3685,19 +3685,10 @@ bool GLCanvas3D::_init_toolbar()
|
||||||
#endif // ENABLE_SVG_ICONS
|
#endif // ENABLE_SVG_ICONS
|
||||||
item.tooltip = _utf8(L("Undo")) + " [" + GUI::shortkey_ctrl_prefix() + "Z]";
|
item.tooltip = _utf8(L("Undo")) + " [" + GUI::shortkey_ctrl_prefix() + "Z]";
|
||||||
item.sprite_id = 11;
|
item.sprite_id = 11;
|
||||||
item.is_toggable = false;
|
item.action_callback = [this]() { if (m_canvas != nullptr) m_toolbar.set_imgui_hovered_pos(-1); };
|
||||||
item.action_callback = [this]() {
|
|
||||||
if (m_canvas != nullptr) {
|
|
||||||
wxPostEvent(m_canvas, SimpleEvent(EVT_GLCANVAS_UNDO));
|
|
||||||
m_toolbar.activate_imgui(true);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
item.visibility_callback = []()->bool { return true; };
|
item.visibility_callback = []()->bool { return true; };
|
||||||
item.enabled_state_callback = [this]()->bool {
|
item.enabled_state_callback = [this]()->bool { return wxGetApp().plater()->can_undo(); } ;
|
||||||
if (!wxGetApp().plater()->can_undo()) { m_toolbar.hide_imgui(true); return false; }
|
item.render_callback = [this](float pos_x, float, float, float) { if (m_canvas != nullptr) _render_undo_redo_stack(true, pos_x); };
|
||||||
return true;
|
|
||||||
};
|
|
||||||
item.render_callback = [this](float pos_x, float, float, float) { _render_undo_redo_stack(true, pos_x); };
|
|
||||||
if (!m_toolbar.add_item(item))
|
if (!m_toolbar.add_item(item))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
@ -3707,17 +3698,8 @@ bool GLCanvas3D::_init_toolbar()
|
||||||
#endif // ENABLE_SVG_ICONS
|
#endif // ENABLE_SVG_ICONS
|
||||||
item.tooltip = _utf8(L("Redo")) + " [" + GUI::shortkey_ctrl_prefix() + "Y]";
|
item.tooltip = _utf8(L("Redo")) + " [" + GUI::shortkey_ctrl_prefix() + "Y]";
|
||||||
item.sprite_id = 12;
|
item.sprite_id = 12;
|
||||||
item.action_callback = [this]() {
|
item.enabled_state_callback = [this]()->bool { return wxGetApp().plater()->can_redo(); };
|
||||||
if (m_canvas != nullptr) {
|
item.render_callback = [this](float pos_x, float, float, float) { if (m_canvas != nullptr) _render_undo_redo_stack(false, pos_x); };
|
||||||
wxPostEvent(m_canvas, SimpleEvent(EVT_GLCANVAS_REDO));
|
|
||||||
m_toolbar.activate_imgui(false);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
item.enabled_state_callback = [this]()->bool {
|
|
||||||
if (!wxGetApp().plater()->can_redo()) { m_toolbar.hide_imgui(false); return false; }
|
|
||||||
return true;
|
|
||||||
};
|
|
||||||
item.render_callback = [this](float pos_x, float, float, float) { _render_undo_redo_stack(false, pos_x); };
|
|
||||||
if (!m_toolbar.add_item(item))
|
if (!m_toolbar.add_item(item))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
|
|
@ -84,6 +84,7 @@ void GLToolbarItem::render(unsigned int tex_id, float left, float right, float b
|
||||||
{
|
{
|
||||||
GLTexture::render_sub_texture(tex_id, left, right, bottom, top, get_uvs(tex_width, tex_height, icon_size));
|
GLTexture::render_sub_texture(tex_id, left, right, bottom, top, get_uvs(tex_width, tex_height, icon_size));
|
||||||
|
|
||||||
|
if (is_pressed())
|
||||||
m_data.render_callback(left, right, bottom, top);
|
m_data.render_callback(left, right, bottom, top);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -252,10 +252,7 @@ private:
|
||||||
|
|
||||||
MouseCapture m_mouse_capture;
|
MouseCapture m_mouse_capture;
|
||||||
std::string m_tooltip;
|
std::string m_tooltip;
|
||||||
bool m_undo_imgui_visible {false};
|
|
||||||
bool m_redo_imgui_visible {false};
|
|
||||||
int m_imgui_hovered_pos { -1 };
|
int m_imgui_hovered_pos { -1 };
|
||||||
int m_imgui_selected_pos { -1 };
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
#if ENABLE_SVG_ICONS
|
#if ENABLE_SVG_ICONS
|
||||||
|
@ -312,22 +309,9 @@ public:
|
||||||
|
|
||||||
bool on_mouse(wxMouseEvent& evt, GLCanvas3D& parent);
|
bool on_mouse(wxMouseEvent& evt, GLCanvas3D& parent);
|
||||||
|
|
||||||
// undo == true => "undo" imgui is activated
|
|
||||||
// undo == false => "redo" imgui is activated
|
|
||||||
bool get_imgui_visible(const bool undo) const { return undo ? m_undo_imgui_visible : m_redo_imgui_visible; }
|
|
||||||
void hide_imgui(const bool undo) { undo ? m_undo_imgui_visible = false : m_redo_imgui_visible = false; }
|
|
||||||
void activate_imgui(const bool undo) {
|
|
||||||
m_undo_imgui_visible = undo;
|
|
||||||
m_redo_imgui_visible = !undo;
|
|
||||||
m_imgui_hovered_pos = m_imgui_selected_pos = -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
void set_imgui_hovered_pos(int pos = -1) { m_imgui_hovered_pos = pos; }
|
void set_imgui_hovered_pos(int pos = -1) { m_imgui_hovered_pos = pos; }
|
||||||
int get_imgui_hovered_pos() const { return m_imgui_hovered_pos; }
|
int get_imgui_hovered_pos() const { return m_imgui_hovered_pos; }
|
||||||
|
|
||||||
void set_imgui_selected_pos(int pos = -1) { m_imgui_selected_pos = pos; }
|
|
||||||
int get_imgui_selected_pos() const { return m_imgui_selected_pos; }
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void calc_layout() const;
|
void calc_layout() const;
|
||||||
float get_width_horizontal() const;
|
float get_width_horizontal() const;
|
||||||
|
|
|
@ -4150,7 +4150,7 @@ void Plater::redo_to(int selection)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const int idx = selection + p->get_active_snapshot_index();
|
const int idx = p->get_active_snapshot_index() + selection + 1;
|
||||||
p->redo_to(p->undo_redo_stack.snapshots()[idx].timestamp);
|
p->redo_to(p->undo_redo_stack.snapshots()[idx].timestamp);
|
||||||
}
|
}
|
||||||
bool Plater::undo_redo_string_getter(const bool is_undo, int idx, const char** out_text)
|
bool Plater::undo_redo_string_getter(const bool is_undo, int idx, const char** out_text)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue