diff options
author | Enrico Turri <enricoturri@seznam.cz> | 2019-01-31 15:19:26 +0300 |
---|---|---|
committer | Enrico Turri <enricoturri@seznam.cz> | 2019-01-31 15:19:26 +0300 |
commit | 81c621716b451f3a2065142967d62e2e8134b6b0 (patch) | |
tree | 11cd4707f509986cab5ab5a73c6f7d07c09b24c0 /src/slic3r | |
parent | 2d3da7ef330fa458add5e034707fa331d9545fbe (diff) |
User mode-aware toolbar items
Diffstat (limited to 'src/slic3r')
-rw-r--r-- | src/slic3r/GUI/GLCanvas3D.cpp | 14 | ||||
-rw-r--r-- | src/slic3r/GUI/GLCanvas3D.hpp | 4 | ||||
-rw-r--r-- | src/slic3r/GUI/GLToolbar.cpp | 128 | ||||
-rw-r--r-- | src/slic3r/GUI/GLToolbar.hpp | 32 | ||||
-rw-r--r-- | src/slic3r/GUI/GUI_Preview.cpp | 8 | ||||
-rw-r--r-- | src/slic3r/GUI/GUI_Preview.hpp | 3 | ||||
-rw-r--r-- | src/slic3r/GUI/Plater.cpp | 4 |
7 files changed, 132 insertions, 61 deletions
diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index 0a6dd52c0..56e499376 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -4414,6 +4414,16 @@ void GLCanvas3D::update_volumes_colors_by_extruder() m_volumes.update_colors_by_extruder(m_config); } +#if ENABLE_MODE_AWARE_TOOLBAR_ITEMS +void GLCanvas3D::update_toolbar_items_visibility() +{ + ConfigOptionMode mode = wxGetApp().get_mode(); + m_toolbar.set_item_visible("more", mode != comSimple); + m_toolbar.set_item_visible("fewer", mode != comSimple); + m_dirty = true; +} +#endif // ENABLE_MODE_AWARE_TOOLBAR_ITEMS + // Returns a Rect object denoting size and position of the Reset button used by a gizmo. // Returns in either screen or viewport coords. #if !ENABLE_IMGUI @@ -6166,6 +6176,10 @@ bool GLCanvas3D::_init_toolbar() enable_toolbar_item("add", true); +#if ENABLE_MODE_AWARE_TOOLBAR_ITEMS + update_toolbar_items_visibility(); +#endif // ENABLE_MODE_AWARE_TOOLBAR_ITEMS + return true; } diff --git a/src/slic3r/GUI/GLCanvas3D.hpp b/src/slic3r/GUI/GLCanvas3D.hpp index 7d38e5128..cbc5013ea 100644 --- a/src/slic3r/GUI/GLCanvas3D.hpp +++ b/src/slic3r/GUI/GLCanvas3D.hpp @@ -1004,6 +1004,10 @@ public: void update_volumes_colors_by_extruder(); +#if ENABLE_MODE_AWARE_TOOLBAR_ITEMS + void update_toolbar_items_visibility(); +#endif // ENABLE_MODE_AWARE_TOOLBAR_ITEMS + #if !ENABLE_IMGUI Rect get_gizmo_reset_rect(const GLCanvas3D& canvas, bool viewport) const; bool gizmo_reset_rect_contains(const GLCanvas3D& canvas, float x, float y) const; diff --git a/src/slic3r/GUI/GLToolbar.cpp b/src/slic3r/GUI/GLToolbar.cpp index b15048ec6..8d04868f8 100644 --- a/src/slic3r/GUI/GLToolbar.cpp +++ b/src/slic3r/GUI/GLToolbar.cpp @@ -35,6 +35,9 @@ GLToolbarItem::Data::Data() , tooltip("") , sprite_id(-1) , is_toggable(false) +#if ENABLE_MODE_AWARE_TOOLBAR_ITEMS + , visible(true) +#endif // ENABLE_MODE_AWARE_TOOLBAR_ITEMS { } @@ -45,61 +48,11 @@ GLToolbarItem::GLToolbarItem(GLToolbarItem::EType type, const GLToolbarItem::Dat { } -GLToolbarItem::EState GLToolbarItem::get_state() const -{ - return m_state; -} - -void GLToolbarItem::set_state(GLToolbarItem::EState state) -{ - m_state = state; -} - -const std::string& GLToolbarItem::get_name() const -{ - return m_data.name; -} - -const std::string& GLToolbarItem::get_tooltip() const -{ - return m_data.tooltip; -} - void GLToolbarItem::do_action(wxEvtHandler *target) { wxPostEvent(target, SimpleEvent(m_data.action_event)); } -bool GLToolbarItem::is_enabled() const -{ - return m_state != Disabled; -} - -bool GLToolbarItem::is_disabled() const -{ - return m_state == Disabled; -} - -bool GLToolbarItem::is_hovered() const -{ - return (m_state == Hover) || (m_state == HoverPressed); -} - -bool GLToolbarItem::is_pressed() const -{ - return (m_state == Pressed) || (m_state == HoverPressed); -} - -bool GLToolbarItem::is_toggable() const -{ - return m_data.is_toggable; -} - -bool GLToolbarItem::is_separator() const -{ - return m_type == Separator; -} - void GLToolbarItem::render(unsigned int tex_id, float left, float right, float bottom, float top, unsigned int texture_size, unsigned int border_size, unsigned int icon_size, unsigned int gap_size) const { GLTexture::render_sub_texture(tex_id, left, right, bottom, top, get_uvs(texture_size, border_size, icon_size, gap_size)); @@ -355,6 +308,46 @@ bool GLToolbar::is_item_disabled(const std::string& name) const return false; } +#if ENABLE_MODE_AWARE_TOOLBAR_ITEMS +bool GLToolbar::is_item_visible(const std::string& name) const +{ + for (GLToolbarItem* item : m_items) + { + if (item->get_name() == name) + return item->is_visible(); + } + + return false; +} + +void GLToolbar::set_item_visible(const std::string& name, bool visible) +{ + for (GLToolbarItem* item : m_items) + { + if ((item->get_name() == name) && (item->is_visible() != visible)) + { + item->set_visible(visible); + m_layout.dirty = true; + break; + } + } + + // updates separators visibility to avoid having two consecutive + bool any_item_visible = false; + for (GLToolbarItem* item : m_items) + { + if (!item->is_separator()) + any_item_visible |= item->is_visible(); + else + { + item->set_visible(any_item_visible); + any_item_visible = false; + } + } + +} +#endif // ENABLE_MODE_AWARE_TOOLBAR_ITEMS + std::string GLToolbar::update_hover_state(const Vec2d& mouse_pos, GLCanvas3D& parent) { if (!m_enabled) @@ -486,6 +479,11 @@ float GLToolbar::get_main_size() const float size = 2.0f * m_layout.border * m_layout.icons_scale; for (unsigned int i = 0; i < (unsigned int)m_items.size(); ++i) { +#if ENABLE_MODE_AWARE_TOOLBAR_ITEMS + if (!m_items[i]->is_visible()) + continue; +#endif // ENABLE_MODE_AWARE_TOOLBAR_ITEMS + if (m_items[i]->is_separator()) size += m_layout.separator_size * m_layout.icons_scale; else @@ -524,6 +522,11 @@ std::string GLToolbar::update_hover_state_horizontal(const Vec2d& mouse_pos, GLC for (GLToolbarItem* item : m_items) { +#if ENABLE_MODE_AWARE_TOOLBAR_ITEMS + if (!item->is_visible()) + continue; +#endif // ENABLE_MODE_AWARE_TOOLBAR_ITEMS + if (item->is_separator()) left += separator_stride; else @@ -618,6 +621,11 @@ std::string GLToolbar::update_hover_state_vertical(const Vec2d& mouse_pos, GLCan for (GLToolbarItem* item : m_items) { +#if ENABLE_MODE_AWARE_TOOLBAR_ITEMS + if (!item->is_visible()) + continue; +#endif // ENABLE_MODE_AWARE_TOOLBAR_ITEMS + if (item->is_separator()) top -= separator_stride; else @@ -714,6 +722,11 @@ int GLToolbar::contains_mouse_horizontal(const Vec2d& mouse_pos, const GLCanvas3 { ++id; +#if ENABLE_MODE_AWARE_TOOLBAR_ITEMS + if (!item->is_visible()) + continue; +#endif // ENABLE_MODE_AWARE_TOOLBAR_ITEMS + if (item->is_separator()) left += separator_stride; else @@ -759,6 +772,11 @@ int GLToolbar::contains_mouse_vertical(const Vec2d& mouse_pos, const GLCanvas3D& { ++id; +#if ENABLE_MODE_AWARE_TOOLBAR_ITEMS + if (!item->is_visible()) + continue; +#endif // ENABLE_MODE_AWARE_TOOLBAR_ITEMS + if (item->is_separator()) top -= separator_stride; else @@ -892,6 +910,11 @@ void GLToolbar::render_horizontal(const GLCanvas3D& parent) const // renders icons for (const GLToolbarItem* item : m_items) { +#if ENABLE_MODE_AWARE_TOOLBAR_ITEMS + if (!item->is_visible()) + continue; +#endif // ENABLE_MODE_AWARE_TOOLBAR_ITEMS + if (item->is_separator()) left += separator_stride; else @@ -1018,6 +1041,11 @@ void GLToolbar::render_vertical(const GLCanvas3D& parent) const // renders icons for (const GLToolbarItem* item : m_items) { +#if ENABLE_MODE_AWARE_TOOLBAR_ITEMS + if (!item->is_visible()) + continue; +#endif // ENABLE_MODE_AWARE_TOOLBAR_ITEMS + if (item->is_separator()) top -= separator_stride; else diff --git a/src/slic3r/GUI/GLToolbar.hpp b/src/slic3r/GUI/GLToolbar.hpp index 37eef5708..951d5e072 100644 --- a/src/slic3r/GUI/GLToolbar.hpp +++ b/src/slic3r/GUI/GLToolbar.hpp @@ -8,7 +8,6 @@ #include "GLTexture.hpp" #include "Event.hpp" - class wxEvtHandler; namespace Slic3r { @@ -56,6 +55,9 @@ public: unsigned int sprite_id; bool is_toggable; wxEventType action_event; +#if ENABLE_MODE_AWARE_TOOLBAR_ITEMS + bool visible; +#endif // ENABLE_MODE_AWARE_TOOLBAR_ITEMS Data(); }; @@ -68,21 +70,25 @@ private: public: GLToolbarItem(EType type, const Data& data); - EState get_state() const; - void set_state(EState state); + EState get_state() const { return m_state; } + void set_state(EState state) { m_state = state; } - const std::string& get_name() const; - const std::string& get_tooltip() const; + const std::string& get_name() const { return m_data.name; } + const std::string& get_tooltip() const { return m_data.tooltip; } void do_action(wxEvtHandler *target); - bool is_enabled() const; - bool is_disabled() const; - bool is_hovered() const; - bool is_pressed() const; + 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_toggable() const; - bool is_separator() const; + bool is_toggable() const { return m_data.is_toggable; } +#if ENABLE_MODE_AWARE_TOOLBAR_ITEMS + bool is_visible() const { return m_data.visible; } + void set_visible(bool visible) { m_data.visible = visible; } +#endif // ENABLE_MODE_AWARE_TOOLBAR_ITEMS + bool is_separator() const { return m_type == Separator; } void render(unsigned int tex_id, float left, float right, float bottom, float top, unsigned int texture_size, unsigned int border_size, unsigned int icon_size, unsigned int gap_size) const; @@ -223,6 +229,10 @@ public: bool is_item_pressed(const std::string& name) const; bool is_item_disabled(const std::string& name) const; +#if ENABLE_MODE_AWARE_TOOLBAR_ITEMS + bool is_item_visible(const std::string& name) const; + void set_item_visible(const std::string& name, bool visible); +#endif // ENABLE_MODE_AWARE_TOOLBAR_ITEMS std::string update_hover_state(const Vec2d& mouse_pos, GLCanvas3D& parent); diff --git a/src/slic3r/GUI/GUI_Preview.cpp b/src/slic3r/GUI/GUI_Preview.cpp index b594d0fef..0ad6c3562 100644 --- a/src/slic3r/GUI/GUI_Preview.cpp +++ b/src/slic3r/GUI/GUI_Preview.cpp @@ -139,6 +139,14 @@ void View3D::mirror_selection(Axis axis) m_canvas->mirror_selection(axis); } +#if ENABLE_MODE_AWARE_TOOLBAR_ITEMS +void View3D::update_toolbar_items_visibility() +{ + if (m_canvas != nullptr) + m_canvas->update_toolbar_items_visibility(); +} +#endif // ENABLE_MODE_AWARE_TOOLBAR_ITEMS + void View3D::enable_toolbar_item(const std::string& name, bool enable) { if (m_canvas != nullptr) diff --git a/src/slic3r/GUI/GUI_Preview.hpp b/src/slic3r/GUI/GUI_Preview.hpp index d4410c589..49dbed44d 100644 --- a/src/slic3r/GUI/GUI_Preview.hpp +++ b/src/slic3r/GUI/GUI_Preview.hpp @@ -58,6 +58,9 @@ public: void delete_selected(); void mirror_selection(Axis axis); +#if ENABLE_MODE_AWARE_TOOLBAR_ITEMS + void update_toolbar_items_visibility(); +#endif // ENABLE_MODE_AWARE_TOOLBAR_ITEMS void enable_toolbar_item(const std::string& name, bool enable); int check_volumes_outside_state() const; diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 4902cf1c9..38adde8b3 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -2648,6 +2648,10 @@ bool Plater::priv::can_mirror() const void Plater::priv::update_object_menu() { sidebar->obj_list()->append_menu_items_add_volume(&object_menu); +#if ENABLE_MODE_AWARE_TOOLBAR_ITEMS + if (view3D != nullptr) + view3D->update_toolbar_items_visibility(); +#endif // ENABLE_MODE_AWARE_TOOLBAR_ITEMS } // Plater / Public |