Fix into GLToolbar::on_mouse()

This commit is contained in:
Enrico Turri 2019-03-20 15:30:03 +01:00
parent 9f06dbd615
commit 42c5d624cb
2 changed files with 22 additions and 4 deletions

View file

@ -157,7 +157,7 @@ GLToolbar::GLToolbar(GLToolbar::EType type)
#if ENABLE_SVG_ICONS #if ENABLE_SVG_ICONS
, m_icons_texture_dirty(true) , m_icons_texture_dirty(true)
#endif // ENABLE_SVG_ICONS #endif // ENABLE_SVG_ICONS
, m_mouse_capture({false, false, false}) , m_mouse_capture({ false, false, false, nullptr })
, m_tooltip("") , m_tooltip("")
{ {
} }
@ -418,8 +418,17 @@ bool GLToolbar::on_mouse(wxMouseEvent& evt, GLCanvas3D& parent)
m_mouse_capture.middle = false; m_mouse_capture.middle = false;
else if (evt.RightUp()) else if (evt.RightUp())
m_mouse_capture.right = false; m_mouse_capture.right = false;
else if (m_mouse_capture.any() && evt.Dragging()) else if (m_mouse_capture.any())
processed = true; {
if (evt.Dragging())
processed = true;
else if (evt.Entering() && (m_mouse_capture.parent == &parent))
// Resets the mouse capture state to avoid setting the dragging event as processed when, for example,
// the item action opens a modal dialog
// Keeps the mouse capture state if the entering event happens on different parent from the one
// who received the button down event, to prevent, for example, dragging when switching between scene views
m_mouse_capture.reset();
}
int item_id = contains_mouse(mouse_pos, parent); int item_id = contains_mouse(mouse_pos, parent);
if (item_id == -1) if (item_id == -1)
@ -429,10 +438,11 @@ bool GLToolbar::on_mouse(wxMouseEvent& evt, GLCanvas3D& parent)
} }
else else
{ {
// mouse inside toolbar only // mouse inside toolbar
if (evt.LeftDown() || evt.LeftDClick()) if (evt.LeftDown() || evt.LeftDClick())
{ {
m_mouse_capture.left = true; m_mouse_capture.left = true;
m_mouse_capture.parent = &parent;
if ((item_id != -2) && !m_items[item_id]->is_separator()) if ((item_id != -2) && !m_items[item_id]->is_separator())
{ {
// mouse is inside an icon // mouse is inside an icon
@ -441,9 +451,15 @@ bool GLToolbar::on_mouse(wxMouseEvent& evt, GLCanvas3D& parent)
} }
} }
else if (evt.MiddleDown()) else if (evt.MiddleDown())
{
m_mouse_capture.middle = true; m_mouse_capture.middle = true;
m_mouse_capture.parent = &parent;
}
else if (evt.RightDown()) else if (evt.RightDown())
{
m_mouse_capture.right = true; m_mouse_capture.right = true;
m_mouse_capture.parent = &parent;
}
else if (evt.LeftUp()) else if (evt.LeftUp())
processed = true; processed = true;
} }

View file

@ -236,8 +236,10 @@ private:
bool left; bool left;
bool middle; bool middle;
bool right; bool right;
GLCanvas3D* parent;
bool any() const { return left || middle || right; } bool any() const { return left || middle || right; }
void reset() { left = middle = right = false; parent = nullptr; }
}; };
MouseCapture m_mouse_capture; MouseCapture m_mouse_capture;