Deactivate undo/redo toolbar items when leaving the 3D scene or clicking into it
This commit is contained in:
parent
1b5ab100bd
commit
dbf0eacfa7
4 changed files with 53 additions and 10 deletions
|
@ -2397,7 +2397,6 @@ void GLCanvas3D::on_char(wxKeyEvent& evt)
|
|||
#endif /* __APPLE__ */
|
||||
post_event(SimpleEvent(EVT_GLTOOLBAR_DELETE));
|
||||
break;
|
||||
|
||||
case WXK_ESCAPE: { deselect_all(); break; }
|
||||
case '0': { select_view("iso"); break; }
|
||||
case '1': { select_view("top"); break; }
|
||||
|
@ -2744,12 +2743,17 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt)
|
|||
}
|
||||
else if (evt.Leaving())
|
||||
{
|
||||
_deactivate_undo_redo_toolbar_items();
|
||||
|
||||
// to remove hover on objects when the mouse goes out of this canvas
|
||||
m_mouse.position = Vec2d(-1.0, -1.0);
|
||||
m_dirty = true;
|
||||
}
|
||||
else if (evt.LeftDown() || evt.RightDown())
|
||||
else if (evt.LeftDown() || evt.RightDown() || evt.MiddleDown())
|
||||
{
|
||||
if (_deactivate_undo_redo_toolbar_items())
|
||||
return;
|
||||
|
||||
// If user pressed left or right button we first check whether this happened
|
||||
// on a volume or not.
|
||||
m_layers_editing.state = LayersEditing::Unknown;
|
||||
|
@ -5866,6 +5870,22 @@ void GLCanvas3D::_update_selection_from_hover()
|
|||
m_dirty = true;
|
||||
}
|
||||
|
||||
bool GLCanvas3D::_deactivate_undo_redo_toolbar_items()
|
||||
{
|
||||
if (m_toolbar.is_item_pressed("undo"))
|
||||
{
|
||||
m_toolbar.force_action(m_toolbar.get_item_id("undo"), *this);
|
||||
return true;
|
||||
}
|
||||
else if (m_toolbar.is_item_pressed("redo"))
|
||||
{
|
||||
m_toolbar.force_action(m_toolbar.get_item_id("redo"), *this);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
const Print* GLCanvas3D::fff_print() const
|
||||
{
|
||||
return (m_process == nullptr) ? nullptr : m_process->fff_print();
|
||||
|
|
|
@ -742,6 +742,8 @@ private:
|
|||
// updates the selection from the content of m_hover_volume_idxs
|
||||
void _update_selection_from_hover();
|
||||
|
||||
bool _deactivate_undo_redo_toolbar_items();
|
||||
|
||||
static std::vector<float> _parse_colors(const std::vector<std::string>& colors);
|
||||
|
||||
public:
|
||||
|
|
|
@ -389,6 +389,22 @@ bool GLToolbar::is_any_item_pressed() const
|
|||
return false;
|
||||
}
|
||||
|
||||
unsigned int GLToolbar::get_item_id(const std::string& name) const
|
||||
{
|
||||
for (unsigned int i = 0; i < (unsigned int)m_items.size(); ++i)
|
||||
{
|
||||
if (m_items[i]->get_name() == name)
|
||||
return i;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
void GLToolbar::force_action(unsigned int item_id, GLCanvas3D& parent)
|
||||
{
|
||||
do_action(item_id, parent, false);
|
||||
}
|
||||
|
||||
bool GLToolbar::update_items_state()
|
||||
{
|
||||
bool ret = false;
|
||||
|
@ -461,10 +477,8 @@ bool GLToolbar::on_mouse(wxMouseEvent& evt, GLCanvas3D& parent)
|
|||
m_mouse_capture.parent = &parent;
|
||||
processed = true;
|
||||
if ((item_id != -2) && !m_items[item_id]->is_separator())
|
||||
{
|
||||
// mouse is inside an icon
|
||||
do_action((unsigned int)item_id, parent);
|
||||
}
|
||||
do_action((unsigned int)item_id, parent, true);
|
||||
}
|
||||
else if (evt.MiddleDown())
|
||||
{
|
||||
|
@ -572,14 +586,14 @@ float GLToolbar::get_main_size() const
|
|||
return size;
|
||||
}
|
||||
|
||||
void GLToolbar::do_action(unsigned int item_id, GLCanvas3D& parent)
|
||||
void GLToolbar::do_action(unsigned int item_id, GLCanvas3D& parent, bool check_hover)
|
||||
{
|
||||
if ((m_pressed_toggable_id == -1) || (m_pressed_toggable_id == item_id))
|
||||
{
|
||||
if (item_id < (unsigned int)m_items.size())
|
||||
{
|
||||
GLToolbarItem* item = m_items[item_id];
|
||||
if ((item != nullptr) && !item->is_separator() && item->is_hovered())
|
||||
if ((item != nullptr) && !item->is_separator() && (!check_hover || item->is_hovered()))
|
||||
{
|
||||
if (item->is_toggable())
|
||||
{
|
||||
|
@ -588,6 +602,10 @@ void GLToolbar::do_action(unsigned int item_id, GLCanvas3D& parent)
|
|||
item->set_state(GLToolbarItem::HoverPressed);
|
||||
else if (state == GLToolbarItem::HoverPressed)
|
||||
item->set_state(GLToolbarItem::Hover);
|
||||
else if (state == GLToolbarItem::Pressed)
|
||||
item->set_state(GLToolbarItem::Normal);
|
||||
else if (state == GLToolbarItem::Normal)
|
||||
item->set_state(GLToolbarItem::Pressed);
|
||||
|
||||
m_pressed_toggable_id = item->is_pressed() ? item_id : -1;
|
||||
|
||||
|
@ -599,7 +617,7 @@ void GLToolbar::do_action(unsigned int item_id, GLCanvas3D& parent)
|
|||
if (m_type == Radio)
|
||||
select_item(item->get_name());
|
||||
else
|
||||
item->set_state(GLToolbarItem::HoverPressed);
|
||||
item->set_state(item->is_hovered() ? GLToolbarItem::HoverPressed : GLToolbarItem::Pressed);
|
||||
|
||||
parent.render();
|
||||
item->do_action();
|
||||
|
|
|
@ -301,8 +301,11 @@ public:
|
|||
|
||||
bool is_any_item_pressed() const;
|
||||
|
||||
const std::string& get_tooltip() const { return m_tooltip; }
|
||||
unsigned int get_item_id(const std::string& name) const;
|
||||
|
||||
void force_action(unsigned int item_id, GLCanvas3D& parent);
|
||||
|
||||
const std::string& get_tooltip() const { return m_tooltip; }
|
||||
|
||||
// returns true if any item changed its state
|
||||
bool update_items_state();
|
||||
|
@ -318,7 +321,7 @@ private:
|
|||
float get_height_horizontal() const;
|
||||
float get_height_vertical() const;
|
||||
float get_main_size() const;
|
||||
void do_action(unsigned int item_id, GLCanvas3D& parent);
|
||||
void do_action(unsigned int item_id, GLCanvas3D& parent, bool check_hover);
|
||||
std::string update_hover_state(const Vec2d& mouse_pos, GLCanvas3D& parent);
|
||||
std::string update_hover_state_horizontal(const Vec2d& mouse_pos, GLCanvas3D& parent);
|
||||
std::string update_hover_state_vertical(const Vec2d& mouse_pos, GLCanvas3D& parent);
|
||||
|
|
Loading…
Reference in a new issue