Merge remote-tracking branch 'origin/vb_undo_redo' into ys_undo_redo

This commit is contained in:
YuSanka 2019-07-10 11:38:52 +02:00
commit baece78390
2 changed files with 52 additions and 29 deletions

View file

@ -84,7 +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));
if (is_pressed())
if (is_toggable() && is_pressed())
m_data.render_callback(left, right, bottom, top);
}
@ -165,6 +165,7 @@ GLToolbar::GLToolbar(GLToolbar::EType type)
, m_icons_texture_dirty(true)
#endif // ENABLE_SVG_ICONS
, m_tooltip("")
, m_pressed_toggable_id(-1)
{
}
@ -346,7 +347,7 @@ void GLToolbar::select_item(const std::string& name)
bool GLToolbar::is_item_pressed(const std::string& name) const
{
for (GLToolbarItem* item : m_items)
for (const GLToolbarItem* item : m_items)
{
if (item->get_name() == name)
return item->is_pressed();
@ -357,7 +358,7 @@ bool GLToolbar::is_item_pressed(const std::string& name) const
bool GLToolbar::is_item_disabled(const std::string& name) const
{
for (GLToolbarItem* item : m_items)
for (const GLToolbarItem* item : m_items)
{
if (item->get_name() == name)
return item->is_disabled();
@ -368,7 +369,7 @@ bool GLToolbar::is_item_disabled(const std::string& name) const
bool GLToolbar::is_item_visible(const std::string& name) const
{
for (GLToolbarItem* item : m_items)
for (const GLToolbarItem* item : m_items)
{
if (item->get_name() == name)
return item->is_visible();
@ -377,11 +378,25 @@ bool GLToolbar::is_item_visible(const std::string& name) const
return false;
}
bool GLToolbar::is_any_item_pressed() const
{
for (const GLToolbarItem* item : m_items)
{
if (item->is_pressed())
return true;
}
return false;
}
bool GLToolbar::update_items_state()
{
bool ret = false;
ret |= update_items_visibility();
ret |= update_items_enabled_state();
if (!is_any_item_pressed())
m_pressed_toggable_id = -1;
return ret;
}
@ -558,6 +573,8 @@ float GLToolbar::get_main_size() const
}
void GLToolbar::do_action(unsigned int item_id, GLCanvas3D& parent)
{
if ((m_pressed_toggable_id == -1) || (m_pressed_toggable_id == item_id))
{
if (item_id < (unsigned int)m_items.size())
{
@ -572,6 +589,8 @@ void GLToolbar::do_action(unsigned int item_id, GLCanvas3D& parent)
else if (state == GLToolbarItem::HoverPressed)
item->set_state(GLToolbarItem::Hover);
m_pressed_toggable_id = item->is_pressed() ? item_id : -1;
parent.render();
item->do_action();
}
@ -594,6 +613,7 @@ void GLToolbar::do_action(unsigned int item_id, GLCanvas3D& parent)
}
}
}
}
std::string GLToolbar::update_hover_state(const Vec2d& mouse_pos, GLCanvas3D& parent)
{

View file

@ -253,6 +253,7 @@ private:
MouseCapture m_mouse_capture;
std::string m_tooltip;
int m_imgui_hovered_pos { -1 };
unsigned int m_pressed_toggable_id;
public:
#if ENABLE_SVG_ICONS
@ -299,6 +300,8 @@ public:
bool is_item_disabled(const std::string& name) const;
bool is_item_visible(const std::string& name) const;
bool is_any_item_pressed() const;
const std::string& get_tooltip() const { return m_tooltip; }