diff --git a/src/libslic3r/Technologies.hpp b/src/libslic3r/Technologies.hpp index be37e1694..b6b69ae27 100644 --- a/src/libslic3r/Technologies.hpp +++ b/src/libslic3r/Technologies.hpp @@ -56,3 +56,12 @@ #define ENABLE_ANISOTROPIC_FILTER_ON_BED_TEXTURES (1 && ENABLE_1_42_0_ALPHA4) // Bunch of fixes related to volumes centering #define ENABLE_VOLUMES_CENTERING_FIXES (1 && ENABLE_1_42_0_ALPHA4) + + +//==================== +// 1.42.0.alpha5 techs +//==================== +#define ENABLE_1_42_0_ALPHA5 1 + +// Toolbar items hidden/shown in dependence of the user mode +#define ENABLE_MODE_AWARE_TOOLBAR_ITEMS (1 && ENABLE_1_42_0_ALPHA5) 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