From 39be962a69a4b2c14ff4c00ec796cf8dad4c2a18 Mon Sep 17 00:00:00 2001 From: mitxela Date: Wed, 20 Jan 2021 02:05:42 +0000 Subject: [PATCH] Restructure mouse capture to avoid recapture asserts --- common/view/wx_view_controls.cpp | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/common/view/wx_view_controls.cpp b/common/view/wx_view_controls.cpp index a37e6b296b..aba7976ca5 100644 --- a/common/view/wx_view_controls.cpp +++ b/common/view/wx_view_controls.cpp @@ -180,8 +180,7 @@ void WX_VIEW_CONTROLS::onMotion( wxMouseEvent& aEvent ) int y = aEvent.GetY(); VECTOR2D mousePos( x, y ); - if( !aEvent.Dragging() && - ( m_settings.m_cursorCaptured || m_settings.m_grabMouse || m_settings.m_autoPanEnabled ) ) + if( !aEvent.Dragging() && m_settings.m_grabMouse ) { bool warp = false; wxSize parentSize = m_parentPanel->GetClientSize(); @@ -411,7 +410,8 @@ void WX_VIEW_CONTROLS::onButton( wxMouseEvent& aEvent ) m_dragStartPoint = VECTOR2D( aEvent.GetX(), aEvent.GetY() ); m_lookStartPoint = m_view->GetCenter(); m_state = DRAG_PANNING; - m_parentPanel->CaptureMouse(); + if( !m_parentPanel->HasCapture() ) + m_parentPanel->CaptureMouse(); } else if( ( aEvent.MiddleDown() && m_settings.m_dragMiddle == MOUSE_DRAG_ACTION::ZOOM ) || ( aEvent.RightDown() && m_settings.m_dragRight == MOUSE_DRAG_ACTION::ZOOM ) ) @@ -420,7 +420,8 @@ void WX_VIEW_CONTROLS::onButton( wxMouseEvent& aEvent ) m_zoomStartPoint = m_dragStartPoint; m_initialZoomScale = m_view->GetScale(); m_state = DRAG_ZOOMING; - m_parentPanel->CaptureMouse(); + if( !m_parentPanel->HasCapture() ) + m_parentPanel->CaptureMouse(); } if( aEvent.LeftUp() ) @@ -433,7 +434,8 @@ void WX_VIEW_CONTROLS::onButton( wxMouseEvent& aEvent ) if( aEvent.MiddleUp() || aEvent.LeftUp() || aEvent.RightUp() ) { m_state = IDLE; - m_parentPanel->ReleaseMouse(); + if( !m_settings.m_grabMouse && m_parentPanel->HasCapture() ) + m_parentPanel->ReleaseMouse(); } break; @@ -590,9 +592,9 @@ void WX_VIEW_CONTROLS::onScroll( wxScrollWinEvent& aEvent ) void WX_VIEW_CONTROLS::SetGrabMouse( bool aEnabled ) { - if( aEnabled && !m_settings.m_grabMouse ) + if( aEnabled && !m_parentPanel->HasCapture() ) m_parentPanel->CaptureMouse(); - else if( !aEnabled && m_settings.m_grabMouse ) + else if( !aEnabled && m_parentPanel->HasCapture() && m_state == IDLE ) m_parentPanel->ReleaseMouse(); VIEW_CONTROLS::SetGrabMouse( aEnabled ); @@ -601,22 +603,14 @@ void WX_VIEW_CONTROLS::SetGrabMouse( bool aEnabled ) void WX_VIEW_CONTROLS::CaptureCursor( bool aEnabled ) { - if( aEnabled && !m_settings.m_cursorCaptured ) - m_parentPanel->CaptureMouse(); - else if( !aEnabled && m_settings.m_cursorCaptured ) - m_parentPanel->ReleaseMouse(); - + SetGrabMouse( aEnabled ); VIEW_CONTROLS::CaptureCursor( aEnabled ); } void WX_VIEW_CONTROLS::SetAutoPan( bool aEnabled ) { - if( aEnabled && !m_settings.m_autoPanEnabled ) - m_parentPanel->CaptureMouse(); - else if( !aEnabled && m_settings.m_autoPanEnabled ) - m_parentPanel->ReleaseMouse(); - + SetGrabMouse( aEnabled ); VIEW_CONTROLS::SetAutoPan( aEnabled ); }