User mode-aware toolbar items

This commit is contained in:
Enrico Turri 2019-01-31 13:19:26 +01:00
parent 2d3da7ef33
commit 81c621716b
8 changed files with 141 additions and 61 deletions

View File

@ -56,3 +56,12 @@
#define ENABLE_ANISOTROPIC_FILTER_ON_BED_TEXTURES (1 && ENABLE_1_42_0_ALPHA4) #define ENABLE_ANISOTROPIC_FILTER_ON_BED_TEXTURES (1 && ENABLE_1_42_0_ALPHA4)
// Bunch of fixes related to volumes centering // Bunch of fixes related to volumes centering
#define ENABLE_VOLUMES_CENTERING_FIXES (1 && ENABLE_1_42_0_ALPHA4) #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)

View File

@ -4414,6 +4414,16 @@ void GLCanvas3D::update_volumes_colors_by_extruder()
m_volumes.update_colors_by_extruder(m_config); 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 a Rect object denoting size and position of the Reset button used by a gizmo.
// Returns in either screen or viewport coords. // Returns in either screen or viewport coords.
#if !ENABLE_IMGUI #if !ENABLE_IMGUI
@ -6166,6 +6176,10 @@ bool GLCanvas3D::_init_toolbar()
enable_toolbar_item("add", true); enable_toolbar_item("add", true);
#if ENABLE_MODE_AWARE_TOOLBAR_ITEMS
update_toolbar_items_visibility();
#endif // ENABLE_MODE_AWARE_TOOLBAR_ITEMS
return true; return true;
} }

View File

@ -1004,6 +1004,10 @@ public:
void update_volumes_colors_by_extruder(); 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 #if !ENABLE_IMGUI
Rect get_gizmo_reset_rect(const GLCanvas3D& canvas, bool viewport) const; Rect get_gizmo_reset_rect(const GLCanvas3D& canvas, bool viewport) const;
bool gizmo_reset_rect_contains(const GLCanvas3D& canvas, float x, float y) const; bool gizmo_reset_rect_contains(const GLCanvas3D& canvas, float x, float y) const;

View File

@ -35,6 +35,9 @@ GLToolbarItem::Data::Data()
, tooltip("") , tooltip("")
, sprite_id(-1) , sprite_id(-1)
, is_toggable(false) , 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) void GLToolbarItem::do_action(wxEvtHandler *target)
{ {
wxPostEvent(target, SimpleEvent(m_data.action_event)); 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 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)); 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; 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) std::string GLToolbar::update_hover_state(const Vec2d& mouse_pos, GLCanvas3D& parent)
{ {
if (!m_enabled) if (!m_enabled)
@ -486,6 +479,11 @@ float GLToolbar::get_main_size() const
float size = 2.0f * m_layout.border * m_layout.icons_scale; float size = 2.0f * m_layout.border * m_layout.icons_scale;
for (unsigned int i = 0; i < (unsigned int)m_items.size(); ++i) 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()) if (m_items[i]->is_separator())
size += m_layout.separator_size * m_layout.icons_scale; size += m_layout.separator_size * m_layout.icons_scale;
else else
@ -524,6 +522,11 @@ std::string GLToolbar::update_hover_state_horizontal(const Vec2d& mouse_pos, GLC
for (GLToolbarItem* item : m_items) 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()) if (item->is_separator())
left += separator_stride; left += separator_stride;
else else
@ -618,6 +621,11 @@ std::string GLToolbar::update_hover_state_vertical(const Vec2d& mouse_pos, GLCan
for (GLToolbarItem* item : m_items) 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()) if (item->is_separator())
top -= separator_stride; top -= separator_stride;
else else
@ -714,6 +722,11 @@ int GLToolbar::contains_mouse_horizontal(const Vec2d& mouse_pos, const GLCanvas3
{ {
++id; ++id;
#if ENABLE_MODE_AWARE_TOOLBAR_ITEMS
if (!item->is_visible())
continue;
#endif // ENABLE_MODE_AWARE_TOOLBAR_ITEMS
if (item->is_separator()) if (item->is_separator())
left += separator_stride; left += separator_stride;
else else
@ -759,6 +772,11 @@ int GLToolbar::contains_mouse_vertical(const Vec2d& mouse_pos, const GLCanvas3D&
{ {
++id; ++id;
#if ENABLE_MODE_AWARE_TOOLBAR_ITEMS
if (!item->is_visible())
continue;
#endif // ENABLE_MODE_AWARE_TOOLBAR_ITEMS
if (item->is_separator()) if (item->is_separator())
top -= separator_stride; top -= separator_stride;
else else
@ -892,6 +910,11 @@ void GLToolbar::render_horizontal(const GLCanvas3D& parent) const
// renders icons // renders icons
for (const GLToolbarItem* item : m_items) 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()) if (item->is_separator())
left += separator_stride; left += separator_stride;
else else
@ -1018,6 +1041,11 @@ void GLToolbar::render_vertical(const GLCanvas3D& parent) const
// renders icons // renders icons
for (const GLToolbarItem* item : m_items) 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()) if (item->is_separator())
top -= separator_stride; top -= separator_stride;
else else

View File

@ -8,7 +8,6 @@
#include "GLTexture.hpp" #include "GLTexture.hpp"
#include "Event.hpp" #include "Event.hpp"
class wxEvtHandler; class wxEvtHandler;
namespace Slic3r { namespace Slic3r {
@ -56,6 +55,9 @@ public:
unsigned int sprite_id; unsigned int sprite_id;
bool is_toggable; bool is_toggable;
wxEventType action_event; wxEventType action_event;
#if ENABLE_MODE_AWARE_TOOLBAR_ITEMS
bool visible;
#endif // ENABLE_MODE_AWARE_TOOLBAR_ITEMS
Data(); Data();
}; };
@ -68,21 +70,25 @@ private:
public: public:
GLToolbarItem(EType type, const Data& data); GLToolbarItem(EType type, const Data& data);
EState get_state() const; EState get_state() const { return m_state; }
void set_state(EState state); void set_state(EState state) { m_state = state; }
const std::string& get_name() const; const std::string& get_name() const { return m_data.name; }
const std::string& get_tooltip() const; const std::string& get_tooltip() const { return m_data.tooltip; }
void do_action(wxEvtHandler *target); void do_action(wxEvtHandler *target);
bool is_enabled() const; bool is_enabled() const { return m_state != Disabled; }
bool is_disabled() const; bool is_disabled() const { return m_state == Disabled; }
bool is_hovered() const; bool is_hovered() const { return (m_state == Hover) || (m_state == HoverPressed); }
bool is_pressed() const; bool is_pressed() const { return (m_state == Pressed) || (m_state == HoverPressed); }
bool is_toggable() const; bool is_toggable() const { return m_data.is_toggable; }
bool is_separator() const; #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; 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_pressed(const std::string& name) const;
bool is_item_disabled(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); std::string update_hover_state(const Vec2d& mouse_pos, GLCanvas3D& parent);

View File

@ -139,6 +139,14 @@ void View3D::mirror_selection(Axis axis)
m_canvas->mirror_selection(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) void View3D::enable_toolbar_item(const std::string& name, bool enable)
{ {
if (m_canvas != nullptr) if (m_canvas != nullptr)

View File

@ -58,6 +58,9 @@ public:
void delete_selected(); void delete_selected();
void mirror_selection(Axis axis); 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); void enable_toolbar_item(const std::string& name, bool enable);
int check_volumes_outside_state() const; int check_volumes_outside_state() const;

View File

@ -2648,6 +2648,10 @@ bool Plater::priv::can_mirror() const
void Plater::priv::update_object_menu() void Plater::priv::update_object_menu()
{ {
sidebar->obj_list()->append_menu_items_add_volume(&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 // Plater / Public