From bebbe6ed227f22ac274ba865828ee9e7bdd62fb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20W=C5=82ostowski?= Date: Sun, 23 Dec 2018 18:57:40 +0100 Subject: [PATCH] pcbnew: disable autopanning when cursor entered auto-pan margin following a keyboard cursor move command Fixes: lp:1803523 * https://bugs.launchpad.net/kicad/+bug/1803523 --- common/tool/common_tools.cpp | 2 +- common/view/wx_view_controls.cpp | 35 ++++++++++++++++++++++++----- include/view/view_controls.h | 8 ++++++- include/view/wx_view_controls.h | 4 +++- pcbnew/router/length_tuner_tool.cpp | 1 + 5 files changed, 42 insertions(+), 8 deletions(-) diff --git a/common/tool/common_tools.cpp b/common/tool/common_tools.cpp index 0a4eb49522..d550e7365b 100644 --- a/common/tool/common_tools.cpp +++ b/common/tool/common_tools.cpp @@ -116,7 +116,7 @@ int COMMON_TOOLS::CursorControl( const TOOL_EVENT& aEvent ) break; } - getViewControls()->SetCursorPosition( cursor ); + getViewControls()->SetCursorPosition( cursor, true, true ); return 0; } diff --git a/common/view/wx_view_controls.cpp b/common/view/wx_view_controls.cpp index 180232b3b2..e354dc302a 100644 --- a/common/view/wx_view_controls.cpp +++ b/common/view/wx_view_controls.cpp @@ -95,6 +95,8 @@ WX_VIEW_CONTROLS::WX_VIEW_CONTROLS( VIEW* aView, wxScrolledCanvas* aParentPanel m_panTimer.SetOwner( this ); this->Connect( wxEVT_TIMER, wxTimerEventHandler( WX_VIEW_CONTROLS::onTimer ), NULL, this ); + + m_settings.m_lastKeyboardCursorPositionValid = false; } @@ -439,9 +441,16 @@ VECTOR2D WX_VIEW_CONTROLS::GetCursorPosition( bool aEnableSnapping ) const } -void WX_VIEW_CONTROLS::SetCursorPosition( const VECTOR2D& aPosition, bool aWarpView ) +void WX_VIEW_CONTROLS::SetCursorPosition( const VECTOR2D& aPosition, bool aWarpView, bool aTriggeredByArrows ) { m_updateCursor = false; + if( aTriggeredByArrows ) + { + m_settings.m_lastKeyboardCursorPositionValid = true; + m_settings.m_lastKeyboardCursorPosition = aPosition; + } else { + m_settings.m_lastKeyboardCursorPositionValid = false; + } WarpCursor( aPosition, true, aWarpView ); m_cursorPos = aPosition; } @@ -508,13 +517,23 @@ void WX_VIEW_CONTROLS::CenterOnCursor() const bool WX_VIEW_CONTROLS::handleAutoPanning( const wxMouseEvent& aEvent ) { - VECTOR2D p( aEvent.GetX(), aEvent.GetY() ); + VECTOR2I p( aEvent.GetX(), aEvent.GetY() ); + VECTOR2I pKey( m_view->ToScreen(m_settings.m_lastKeyboardCursorPosition ) ); + + if( m_settings.m_lastKeyboardCursorPositionValid && (p == pKey) ) + { + // last cursor move event came from keyboard cursor control. If auto-panning is enabled and + // the next position is inside the autopan zone, check if it really came from a mouse event, otherwise + // disable autopan temporarily. + + return true; + } // Compute areas where autopanning is active - double borderStart = std::min( m_settings.m_autoPanMargin * m_view->GetScreenPixelSize().x, + int borderStart = std::min( m_settings.m_autoPanMargin * m_view->GetScreenPixelSize().x, m_settings.m_autoPanMargin * m_view->GetScreenPixelSize().y ); - double borderEndX = m_view->GetScreenPixelSize().x - borderStart; - double borderEndY = m_view->GetScreenPixelSize().y - borderStart; + int borderEndX = m_view->GetScreenPixelSize().x - borderStart; + int borderEndY = m_view->GetScreenPixelSize().y - borderStart; if( p.x < borderStart ) m_panDirection.x = -( borderStart - p.x ); @@ -642,3 +661,9 @@ void WX_VIEW_CONTROLS::UpdateScrollbars() m_scrollPos = newScroll; } } + +void WX_VIEW_CONTROLS::ForceCursorPosition( bool aEnabled, const VECTOR2D& aPosition ) +{ + m_settings.m_forceCursorPosition = aEnabled; + m_settings.m_forcedPosition = aPosition; +} diff --git a/include/view/view_controls.h b/include/view/view_controls.h index c8f5b6a078..4ac038e924 100644 --- a/include/view/view_controls.h +++ b/include/view/view_controls.h @@ -92,6 +92,12 @@ struct VC_SETTINGS ///> Allow panning with the left button in addition to middle bool m_panWithLeftButton; + + ///> Is last cursor motion event coming from keyboard arrow cursor motion action + bool m_lastKeyboardCursorPositionValid; + + ///> Position of the above event + VECTOR2D m_lastKeyboardCursorPosition; }; @@ -233,7 +239,7 @@ public: * @param aPosition is the requested cursor position in the world coordinates. * @param aWarpView enables/disables view warp if the cursor is outside the current viewport. */ - virtual void SetCursorPosition( const VECTOR2D& aPosition, bool aWarpView = true ) = 0; + virtual void SetCursorPosition( const VECTOR2D& aPosition, bool aWarpView = true, bool aTriggeredByArrows = false ) = 0; /** diff --git a/include/view/wx_view_controls.h b/include/view/wx_view_controls.h index 755e69dee1..2809ee2651 100644 --- a/include/view/wx_view_controls.h +++ b/include/view/wx_view_controls.h @@ -85,7 +85,7 @@ public: /// @copydoc VIEW_CONTROLS::GetRawCursorPosition() VECTOR2D GetRawCursorPosition( bool aSnappingEnabled = true ) const override; - void SetCursorPosition( const VECTOR2D& aPosition, bool warpView ) override; + void SetCursorPosition( const VECTOR2D& aPosition, bool warpView, bool aTriggeredByArrows ) override; /// @copydoc VIEW_CONTROLS::SetCrossHairCursorPosition() void SetCrossHairCursorPosition( const VECTOR2D& aPosition, bool aWarpView ) override; @@ -100,6 +100,8 @@ public: /// Adjusts the scrollbars position to match the current viewport. void UpdateScrollbars(); + void ForceCursorPosition( bool aEnabled, const VECTOR2D& aPosition = VECTOR2D( 0, 0 ) ) override; + /// Event that forces mouse move event in the dispatcher (eg. used in autopanning, when mouse /// cursor does not move in screen coordinates, but does in world coordinates) static const wxEventType EVT_REFRESH_MOUSE; diff --git a/pcbnew/router/length_tuner_tool.cpp b/pcbnew/router/length_tuner_tool.cpp index d76195349d..207fa2b590 100644 --- a/pcbnew/router/length_tuner_tool.cpp +++ b/pcbnew/router/length_tuner_tool.cpp @@ -128,6 +128,7 @@ void LENGTH_TUNER_TOOL::Reset( RESET_REASON aReason ) void LENGTH_TUNER_TOOL::updateStatusPopup( PNS_TUNE_STATUS_POPUP& aPopup ) { + // fixme: wx code not allowed inside tools! wxPoint p = wxGetMousePosition(); p.x += 20;