From 365ab99a6aeac7edbd3e7d76e8a44268959511f2 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Tue, 13 Feb 2018 09:45:03 +0100 Subject: [PATCH] GAL: update cursor position on panning and scrolling Fixes: lp:1749082 * https://bugs.launchpad.net/kicad/+bug/1749082 --- common/view/wx_view_controls.cpp | 24 +++++++++++++++++++----- include/view/view_controls.h | 2 +- include/view/wx_view_controls.h | 9 +++++++-- 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/common/view/wx_view_controls.cpp b/common/view/wx_view_controls.cpp index 5099ea036d..27ee89bc97 100644 --- a/common/view/wx_view_controls.cpp +++ b/common/view/wx_view_controls.cpp @@ -153,6 +153,7 @@ void WX_VIEW_CONTROLS::onWheel( wxMouseEvent& aEvent ) VECTOR2D delta( scrollX, scrollY ); m_view->SetCenter( m_view->GetCenter() + delta ); + refreshMouse(); } else { @@ -413,13 +414,13 @@ void WX_VIEW_CONTROLS::SetGrabMouse( bool aEnabled ) VECTOR2D WX_VIEW_CONTROLS::GetMousePosition( bool aWorldCoordinates ) const { - wxPoint msp = wxGetMousePosition(); - m_parentPanel->ScreenToClient( &msp.x, &msp.y ); + wxPoint msp = getMouseScreenPosition(); VECTOR2D screenPos( msp.x, msp.y ); return aWorldCoordinates ? m_view->ToWorld( screenPos ) : screenPos; } + VECTOR2D WX_VIEW_CONTROLS::GetRawCursorPosition( bool aEnableSnapping ) const { if( aEnableSnapping ) @@ -432,6 +433,7 @@ VECTOR2D WX_VIEW_CONTROLS::GetRawCursorPosition( bool aEnableSnapping ) const } } + VECTOR2D WX_VIEW_CONTROLS::GetCursorPosition( bool aEnableSnapping ) const { if( m_settings.m_forceCursorPosition ) @@ -463,7 +465,7 @@ void WX_VIEW_CONTROLS::SetCrossHairCursorPosition( const VECTOR2D& aPosition, bo if( !screen.Contains( screenPos ) ) { - m_view->SetCenter( aPosition ); + m_view->SetCenter( aPosition ); } m_cursorPos = aPosition; @@ -471,7 +473,7 @@ void WX_VIEW_CONTROLS::SetCrossHairCursorPosition( const VECTOR2D& aPosition, bo void WX_VIEW_CONTROLS::WarpCursor( const VECTOR2D& aPosition, bool aWorldCoordinates, - bool aWarpView ) const + bool aWarpView ) { if( aWorldCoordinates ) { @@ -575,10 +577,13 @@ bool WX_VIEW_CONTROLS::handleAutoPanning( const wxMouseEvent& aEvent ) } -void WX_VIEW_CONTROLS::refreshMouse() const +void WX_VIEW_CONTROLS::refreshMouse() { // Notify tools that the cursor position has changed in the world coordinates wxMouseEvent moveEvent( EVT_REFRESH_MOUSE ); + wxPoint msp = getMouseScreenPosition(); + moveEvent.SetX( msp.x ); + moveEvent.SetY( msp.y ); // Set the modifiers state #if wxCHECK_VERSION( 3, 0, 0 ) @@ -593,6 +598,15 @@ void WX_VIEW_CONTROLS::refreshMouse() const #endif wxPostEvent( m_parentPanel, moveEvent ); + onMotion( moveEvent ); +} + + +wxPoint WX_VIEW_CONTROLS::getMouseScreenPosition() const +{ + wxPoint msp = wxGetMousePosition(); + m_parentPanel->ScreenToClient( &msp.x, &msp.y ); + return msp; } diff --git a/include/view/view_controls.h b/include/view/view_controls.h index de60839ca5..c8f5b6a078 100644 --- a/include/view/view_controls.h +++ b/include/view/view_controls.h @@ -299,7 +299,7 @@ public: * specified in the world coordinates and its not visible in the current viewport). */ virtual void WarpCursor( const VECTOR2D& aPosition, bool aWorldCoordinates = false, - bool aWarpView = false ) const = 0; + bool aWarpView = false ) = 0; /** * Function EnableCursorWarping() diff --git a/include/view/wx_view_controls.h b/include/view/wx_view_controls.h index 588ac4ae43..b71d4b1ea5 100644 --- a/include/view/wx_view_controls.h +++ b/include/view/wx_view_controls.h @@ -88,7 +88,7 @@ public: /// @copydoc VIEW_CONTROLS::CursorWarp() void WarpCursor( const VECTOR2D& aPosition, bool aWorldCoordinates = false, - bool aWarpView = false ) const override; + bool aWarpView = false ) override; /// @copydoc VIEW_CONTROLS::CenterOnCursor() void CenterOnCursor() const override; @@ -124,7 +124,12 @@ private: * that the cursor position in the world coordinates has changed, whereas the screen coordinates * remained the same (e.g. frame edge autopanning). */ - void refreshMouse() const; + void refreshMouse(); + + /** + * Gets the cursor position in the screen coordinates. + */ + wxPoint getMouseScreenPosition() const; /// Current state of VIEW_CONTROLS STATE m_state;