Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/prusa3d/PrusaSlicer.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEnrico Turri <enricoturri@seznam.cz>2019-07-12 10:26:19 +0300
committerEnrico Turri <enricoturri@seznam.cz>2019-07-12 10:26:19 +0300
commit2f57f756e54151721e9be4b5f0bbe2788830ad20 (patch)
tree3556024bc30666c4850c76808175fc920aeebe55
parenteced3dcea86fc247ee926bcbe982eb05e0c918bf (diff)
Follow-up of 4c6c608342e92d6769205ea8b68bde7ebbef04d6 -> refactoring
-rw-r--r--src/slic3r/GUI/GLCanvas3D.cpp40
-rw-r--r--src/slic3r/GUI/GLToolbar.cpp31
-rw-r--r--src/slic3r/GUI/GLToolbar.hpp45
-rw-r--r--src/slic3r/GUI/Plater.cpp4
4 files changed, 63 insertions, 57 deletions
diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp
index ceca4e0ff..86aab33be 100644
--- a/src/slic3r/GUI/GLCanvas3D.cpp
+++ b/src/slic3r/GUI/GLCanvas3D.cpp
@@ -3550,7 +3550,7 @@ bool GLCanvas3D::_init_toolbar()
#endif // ENABLE_SVG_ICONS
item.tooltip = _utf8(L("Add...")) + " [" + GUI::shortkey_ctrl_prefix() + "I]";
item.sprite_id = 0;
- item.left_action_callback = [this]() { if (m_canvas != nullptr) wxPostEvent(m_canvas, SimpleEvent(EVT_GLTOOLBAR_ADD)); };
+ item.left.action_callback = [this]() { if (m_canvas != nullptr) wxPostEvent(m_canvas, SimpleEvent(EVT_GLTOOLBAR_ADD)); };
if (!m_toolbar.add_item(item))
return false;
@@ -3560,7 +3560,7 @@ bool GLCanvas3D::_init_toolbar()
#endif // ENABLE_SVG_ICONS
item.tooltip = _utf8(L("Delete")) + " [Del]";
item.sprite_id = 1;
- item.left_action_callback = [this]() { if (m_canvas != nullptr) wxPostEvent(m_canvas, SimpleEvent(EVT_GLTOOLBAR_DELETE)); };
+ item.left.action_callback = [this]() { if (m_canvas != nullptr) wxPostEvent(m_canvas, SimpleEvent(EVT_GLTOOLBAR_DELETE)); };
item.enabling_callback = []()->bool { return wxGetApp().plater()->can_delete(); };
if (!m_toolbar.add_item(item))
return false;
@@ -3571,7 +3571,7 @@ bool GLCanvas3D::_init_toolbar()
#endif // ENABLE_SVG_ICONS
item.tooltip = _utf8(L("Delete all")) + " [" + GUI::shortkey_ctrl_prefix() + "Del]";
item.sprite_id = 2;
- item.left_action_callback = [this]() { if (m_canvas != nullptr) wxPostEvent(m_canvas, SimpleEvent(EVT_GLTOOLBAR_DELETE_ALL)); };
+ item.left.action_callback = [this]() { if (m_canvas != nullptr) wxPostEvent(m_canvas, SimpleEvent(EVT_GLTOOLBAR_DELETE_ALL)); };
item.enabling_callback = []()->bool { return wxGetApp().plater()->can_delete_all(); };
if (!m_toolbar.add_item(item))
return false;
@@ -3582,7 +3582,7 @@ bool GLCanvas3D::_init_toolbar()
#endif // ENABLE_SVG_ICONS
item.tooltip = _utf8(L("Arrange")) + " [A]";
item.sprite_id = 3;
- item.left_action_callback = [this]() { if (m_canvas != nullptr) wxPostEvent(m_canvas, SimpleEvent(EVT_GLTOOLBAR_ARRANGE)); };
+ item.left.action_callback = [this]() { if (m_canvas != nullptr) wxPostEvent(m_canvas, SimpleEvent(EVT_GLTOOLBAR_ARRANGE)); };
item.enabling_callback = []()->bool { return wxGetApp().plater()->can_arrange(); };
if (!m_toolbar.add_item(item))
return false;
@@ -3596,7 +3596,7 @@ bool GLCanvas3D::_init_toolbar()
#endif // ENABLE_SVG_ICONS
item.tooltip = _utf8(L("Copy")) + " [" + GUI::shortkey_ctrl_prefix() + "C]";
item.sprite_id = 4;
- item.left_action_callback = [this]() { if (m_canvas != nullptr) wxPostEvent(m_canvas, SimpleEvent(EVT_GLTOOLBAR_COPY)); };
+ item.left.action_callback = [this]() { if (m_canvas != nullptr) wxPostEvent(m_canvas, SimpleEvent(EVT_GLTOOLBAR_COPY)); };
item.enabling_callback = []()->bool { return wxGetApp().plater()->can_copy_to_clipboard(); };
if (!m_toolbar.add_item(item))
return false;
@@ -3607,7 +3607,7 @@ bool GLCanvas3D::_init_toolbar()
#endif // ENABLE_SVG_ICONS
item.tooltip = _utf8(L("Paste")) + " [" + GUI::shortkey_ctrl_prefix() + "V]";
item.sprite_id = 5;
- item.left_action_callback = [this]() { if (m_canvas != nullptr) wxPostEvent(m_canvas, SimpleEvent(EVT_GLTOOLBAR_PASTE)); };
+ item.left.action_callback = [this]() { if (m_canvas != nullptr) wxPostEvent(m_canvas, SimpleEvent(EVT_GLTOOLBAR_PASTE)); };
item.enabling_callback = []()->bool { return wxGetApp().plater()->can_paste_from_clipboard(); };
if (!m_toolbar.add_item(item))
return false;
@@ -3621,7 +3621,7 @@ bool GLCanvas3D::_init_toolbar()
#endif // ENABLE_SVG_ICONS
item.tooltip = _utf8(L("Add instance")) + " [+]";
item.sprite_id = 6;
- item.left_action_callback = [this]() { if (m_canvas != nullptr) wxPostEvent(m_canvas, SimpleEvent(EVT_GLTOOLBAR_MORE)); };
+ item.left.action_callback = [this]() { if (m_canvas != nullptr) wxPostEvent(m_canvas, SimpleEvent(EVT_GLTOOLBAR_MORE)); };
item.visibility_callback = []()->bool { return wxGetApp().get_mode() != comSimple; };
item.enabling_callback = []()->bool { return wxGetApp().plater()->can_increase_instances(); };
@@ -3634,7 +3634,7 @@ bool GLCanvas3D::_init_toolbar()
#endif // ENABLE_SVG_ICONS
item.tooltip = _utf8(L("Remove instance")) + " [-]";
item.sprite_id = 7;
- item.left_action_callback = [this]() { if (m_canvas != nullptr) wxPostEvent(m_canvas, SimpleEvent(EVT_GLTOOLBAR_FEWER)); };
+ item.left.action_callback = [this]() { if (m_canvas != nullptr) wxPostEvent(m_canvas, SimpleEvent(EVT_GLTOOLBAR_FEWER)); };
item.visibility_callback = []()->bool { return wxGetApp().get_mode() != comSimple; };
item.enabling_callback = []()->bool { return wxGetApp().plater()->can_decrease_instances(); };
if (!m_toolbar.add_item(item))
@@ -3649,7 +3649,7 @@ bool GLCanvas3D::_init_toolbar()
#endif // ENABLE_SVG_ICONS
item.tooltip = _utf8(L("Split to objects"));
item.sprite_id = 8;
- item.left_action_callback = [this]() { if (m_canvas != nullptr) wxPostEvent(m_canvas, SimpleEvent(EVT_GLTOOLBAR_SPLIT_OBJECTS)); };
+ item.left.action_callback = [this]() { if (m_canvas != nullptr) wxPostEvent(m_canvas, SimpleEvent(EVT_GLTOOLBAR_SPLIT_OBJECTS)); };
item.visibility_callback = GLToolbarItem::Default_Visibility_Callback;
item.enabling_callback = []()->bool { return wxGetApp().plater()->can_split_to_objects(); };
if (!m_toolbar.add_item(item))
@@ -3661,7 +3661,7 @@ bool GLCanvas3D::_init_toolbar()
#endif // ENABLE_SVG_ICONS
item.tooltip = _utf8(L("Split to parts"));
item.sprite_id = 9;
- item.left_action_callback = [this]() { if (m_canvas != nullptr) wxPostEvent(m_canvas, SimpleEvent(EVT_GLTOOLBAR_SPLIT_VOLUMES)); };
+ item.left.action_callback = [this]() { if (m_canvas != nullptr) wxPostEvent(m_canvas, SimpleEvent(EVT_GLTOOLBAR_SPLIT_VOLUMES)); };
item.visibility_callback = []()->bool { return wxGetApp().get_mode() != comSimple; };
item.enabling_callback = []()->bool { return wxGetApp().plater()->can_split_to_volumes(); };
if (!m_toolbar.add_item(item))
@@ -3676,8 +3676,8 @@ bool GLCanvas3D::_init_toolbar()
#endif // ENABLE_SVG_ICONS
item.tooltip = _utf8(L("Layers editing"));
item.sprite_id = 10;
- item.left_toggable = true;
- item.left_action_callback = [this]() { if (m_canvas != nullptr) wxPostEvent(m_canvas, SimpleEvent(EVT_GLTOOLBAR_LAYERSEDITING)); };
+ item.left.toggable = true;
+ item.left.action_callback = [this]() { if (m_canvas != nullptr) wxPostEvent(m_canvas, SimpleEvent(EVT_GLTOOLBAR_LAYERSEDITING)); };
item.visibility_callback = [this]()->bool { return m_process->current_printer_technology() == ptFFF; };
item.enabling_callback = []()->bool { return wxGetApp().plater()->can_layers_editing(); };
if (!m_toolbar.add_item(item))
@@ -3692,13 +3692,13 @@ bool GLCanvas3D::_init_toolbar()
#endif // ENABLE_SVG_ICONS
item.tooltip = _utf8(L("Undo")) + " [" + GUI::shortkey_ctrl_prefix() + "Z]";
item.sprite_id = 11;
- item.left_toggable = false;
- item.right_toggable = true;
- item.left_action_callback = [this]() { post_event(SimpleEvent(EVT_GLCANVAS_UNDO)); };
- item.right_action_callback = [this]() { m_imgui_undo_redo_hovered_pos = -1; };
+ item.left.toggable = false;
+ item.left.action_callback = [this]() { post_event(SimpleEvent(EVT_GLCANVAS_UNDO)); };
+ item.right.toggable = true;
+ item.right.action_callback = [this]() { m_imgui_undo_redo_hovered_pos = -1; };
+ item.right.render_callback = [this](float left, float right, float, float) { if (m_canvas != nullptr) _render_undo_redo_stack(true, 0.5f * (left + right)); };
item.visibility_callback = []()->bool { return true; };
item.enabling_callback = [this]()->bool { return wxGetApp().plater()->can_undo(); };
- item.right_render_callback = [this](float left, float right, float, float) { if (m_canvas != nullptr) _render_undo_redo_stack(true, 0.5f * (left + right)); };
if (!m_toolbar.add_item(item))
return false;
@@ -3708,10 +3708,10 @@ bool GLCanvas3D::_init_toolbar()
#endif // ENABLE_SVG_ICONS
item.tooltip = _utf8(L("Redo")) + " [" + GUI::shortkey_ctrl_prefix() + "Y]";
item.sprite_id = 12;
- item.left_action_callback = [this]() { post_event(SimpleEvent(EVT_GLCANVAS_REDO)); };
- item.right_action_callback = [this]() { m_imgui_undo_redo_hovered_pos = -1; };
+ item.left.action_callback = [this]() { post_event(SimpleEvent(EVT_GLCANVAS_REDO)); };
+ item.right.action_callback = [this]() { m_imgui_undo_redo_hovered_pos = -1; };
+ item.right.render_callback = [this](float left, float right, float, float) { if (m_canvas != nullptr) _render_undo_redo_stack(false, 0.5f * (left + right)); };
item.enabling_callback = [this]()->bool { return wxGetApp().plater()->can_redo(); };
- item.right_render_callback = [this](float left, float right, float, float) { if (m_canvas != nullptr) _render_undo_redo_stack(false, 0.5f * (left + right)); };
if (!m_toolbar.add_item(item))
return false;
diff --git a/src/slic3r/GUI/GLToolbar.cpp b/src/slic3r/GUI/GLToolbar.cpp
index 862805f8d..5093eb5d4 100644
--- a/src/slic3r/GUI/GLToolbar.cpp
+++ b/src/slic3r/GUI/GLToolbar.cpp
@@ -37,6 +37,13 @@ const GLToolbarItem::VisibilityCallback GLToolbarItem::Default_Visibility_Callba
const GLToolbarItem::EnablingCallback GLToolbarItem::Default_Enabling_Callback = []()->bool { return true; };
const GLToolbarItem::RenderCallback GLToolbarItem::Default_Render_Callback = [](float, float, float, float){};
+GLToolbarItem::Data::Option::Option()
+ : toggable(false)
+ , action_callback(Default_Action_Callback)
+ , render_callback(nullptr)
+{
+}
+
GLToolbarItem::Data::Data()
: name("")
#if ENABLE_SVG_ICONS
@@ -44,15 +51,9 @@ GLToolbarItem::Data::Data()
#endif // ENABLE_SVG_ICONS
, tooltip("")
, sprite_id(-1)
- , left_toggable(false)
- , right_toggable(false)
, visible(true)
- , left_action_callback(Default_Action_Callback)
- , right_action_callback(Default_Action_Callback)
, visibility_callback(Default_Visibility_Callback)
, enabling_callback(Default_Enabling_Callback)
- , left_render_callback(nullptr)
- , right_render_callback(nullptr)
{
}
@@ -60,7 +61,7 @@ GLToolbarItem::GLToolbarItem(GLToolbarItem::EType type, const GLToolbarItem::Dat
: m_type(type)
, m_state(Normal)
, m_data(data)
- , m_last_action(Undefined)
+ , m_last_action_type(Undefined)
{
}
@@ -90,10 +91,10 @@ void GLToolbarItem::render(unsigned int tex_id, float left, float right, float b
if (is_pressed())
{
- if ((m_last_action == Left) && m_data.left_toggable && (m_data.left_render_callback != nullptr))
- m_data.left_render_callback(left, right, bottom, top);
- else if ((m_last_action == Right) && m_data.right_toggable && (m_data.right_render_callback != nullptr))
- m_data.right_render_callback(left, right, bottom, top);
+ if ((m_last_action_type == Left) && m_data.left.can_render())
+ m_data.left.render_callback(left, right, bottom, top);
+ else if ((m_last_action_type == Right) && m_data.right.can_render())
+ m_data.right.render_callback(left, right, bottom, top);
}
}
@@ -490,7 +491,7 @@ bool GLToolbar::on_mouse(wxMouseEvent& evt, GLCanvas3D& parent)
m_mouse_capture.left = true;
m_mouse_capture.parent = &parent;
processed = true;
- if ((item_id != -2) && !m_items[item_id]->is_separator() && ((m_pressed_toggable_id == -1) || (m_items[item_id]->get_last_action() == GLToolbarItem::Left)))
+ if ((item_id != -2) && !m_items[item_id]->is_separator() && ((m_pressed_toggable_id == -1) || (m_items[item_id]->get_last_action_type() == GLToolbarItem::Left)))
{
// mouse is inside an icon
do_action(GLToolbarItem::Left, (unsigned int)item_id, parent, true);
@@ -507,7 +508,7 @@ bool GLToolbar::on_mouse(wxMouseEvent& evt, GLCanvas3D& parent)
m_mouse_capture.right = true;
m_mouse_capture.parent = &parent;
processed = true;
- if ((item_id != -2) && !m_items[item_id]->is_separator() && ((m_pressed_toggable_id == -1) || (m_items[item_id]->get_last_action() == GLToolbarItem::Right)))
+ if ((item_id != -2) && !m_items[item_id]->is_separator() && ((m_pressed_toggable_id == -1) || (m_items[item_id]->get_last_action_type() == GLToolbarItem::Right)))
{
// mouse is inside an icon
do_action(GLToolbarItem::Right, (unsigned int)item_id, parent, true);
@@ -633,7 +634,7 @@ void GLToolbar::do_action(GLToolbarItem::EActionType type, unsigned int item_id,
item->set_state(GLToolbarItem::Pressed);
m_pressed_toggable_id = item->is_pressed() ? item_id : -1;
- item->reset_last_action();
+ item->reset_last_action_type();
parent.render();
switch (type)
@@ -650,7 +651,7 @@ void GLToolbar::do_action(GLToolbarItem::EActionType type, unsigned int item_id,
else
item->set_state(item->is_hovered() ? GLToolbarItem::HoverPressed : GLToolbarItem::Pressed);
- item->reset_last_action();
+ item->reset_last_action_type();
parent.render();
switch (type)
{
diff --git a/src/slic3r/GUI/GLToolbar.hpp b/src/slic3r/GUI/GLToolbar.hpp
index 86cd1a7fc..34a92ea34 100644
--- a/src/slic3r/GUI/GLToolbar.hpp
+++ b/src/slic3r/GUI/GLToolbar.hpp
@@ -66,25 +66,30 @@ public:
struct Data
{
+ struct Option
+ {
+ bool toggable;
+ ActionCallback action_callback;
+ RenderCallback render_callback;
+
+ Option();
+
+ bool can_render() const { return toggable && (render_callback != nullptr); }
+ };
+
std::string name;
#if ENABLE_SVG_ICONS
std::string icon_filename;
#endif // ENABLE_SVG_ICONS
std::string tooltip;
unsigned int sprite_id;
- bool left_toggable;
- bool right_toggable;
+ // mouse left click
+ Option left;
+ // mouse right click
+ Option right;
bool visible;
- // action on left click
- ActionCallback left_action_callback;
- // action on right click
- ActionCallback right_action_callback;
VisibilityCallback visibility_callback;
EnablingCallback enabling_callback;
- // render callback on left click
- RenderCallback left_render_callback;
- // render callback on right click
- RenderCallback right_render_callback;
Data();
};
@@ -98,7 +103,7 @@ private:
EType m_type;
EState m_state;
Data m_data;
- EActionType m_last_action;
+ EActionType m_last_action_type;
public:
GLToolbarItem(EType type, const Data& data);
@@ -112,24 +117,24 @@ public:
#endif // ENABLE_SVG_ICONS
const std::string& get_tooltip() const { return m_data.tooltip; }
- void do_left_action() { m_last_action = Left; m_data.left_action_callback(); }
- void do_right_action() { m_last_action = Right; m_data.right_action_callback(); }
+ void do_left_action() { m_last_action_type = Left; m_data.left.action_callback(); }
+ void do_right_action() { m_last_action_type = Right; m_data.right.action_callback(); }
bool is_enabled() const { return m_state != Disabled; }
bool is_disabled() const { return m_state == Disabled; }
bool is_hovered() const { return (m_state == Hover) || (m_state == HoverPressed); }
bool is_pressed() const { return (m_state == Pressed) || (m_state == HoverPressed); }
-
- bool is_left_toggable() const { return m_data.left_toggable; }
- bool is_right_toggable() const { return m_data.right_toggable; }
bool is_visible() const { return m_data.visible; }
bool is_separator() const { return m_type == Separator; }
- bool has_left_render_callback() const { return m_data.left_render_callback != nullptr; }
- bool has_right_render_callback() const { return m_data.right_render_callback != nullptr; }
+ bool is_left_toggable() const { return m_data.left.toggable; }
+ bool is_right_toggable() const { return m_data.right.toggable; }
+
+ bool has_left_render_callback() const { return m_data.left.render_callback != nullptr; }
+ bool has_right_render_callback() const { return m_data.right.render_callback != nullptr; }
- EActionType get_last_action() const { return m_last_action; }
- void reset_last_action() { m_last_action = Undefined; }
+ EActionType get_last_action_type() const { return m_last_action_type; }
+ void reset_last_action_type() { m_last_action_type = Undefined; }
// returns true if the state changes
bool update_visibility();
diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp
index 06252e1e7..e826d748e 100644
--- a/src/slic3r/GUI/Plater.cpp
+++ b/src/slic3r/GUI/Plater.cpp
@@ -3432,7 +3432,7 @@ void Plater::priv::init_view_toolbar()
#endif // ENABLE_SVG_ICONS
item.tooltip = _utf8(L("3D editor view")) + " [" + GUI::shortkey_ctrl_prefix() + "5]";
item.sprite_id = 0;
- item.left_action_callback = [this]() { if (this->q != nullptr) wxPostEvent(this->q, SimpleEvent(EVT_GLVIEWTOOLBAR_3D)); };
+ item.left.action_callback = [this]() { if (this->q != nullptr) wxPostEvent(this->q, SimpleEvent(EVT_GLVIEWTOOLBAR_3D)); };
if (!view_toolbar.add_item(item))
return;
@@ -3442,7 +3442,7 @@ void Plater::priv::init_view_toolbar()
#endif // ENABLE_SVG_ICONS
item.tooltip = _utf8(L("Preview")) + " [" + GUI::shortkey_ctrl_prefix() + "6]";
item.sprite_id = 1;
- item.left_action_callback = [this]() { if (this->q != nullptr) wxPostEvent(this->q, SimpleEvent(EVT_GLVIEWTOOLBAR_PREVIEW)); };
+ item.left.action_callback = [this]() { if (this->q != nullptr) wxPostEvent(this->q, SimpleEvent(EVT_GLVIEWTOOLBAR_PREVIEW)); };
if (!view_toolbar.add_item(item))
return;