From 65c88ba2c3fdbf57e7cd8fe3b2c59aea4c65c71e Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Tue, 7 Jan 2020 19:35:45 +0000 Subject: [PATCH] Reduce the auto-panning margin and implement acceleration. --- common/view/view_controls.cpp | 4 +++- common/view/wx_view_controls.cpp | 7 +++++-- include/view/view_controls.h | 13 +++++++++++++ 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/common/view/view_controls.cpp b/common/view/view_controls.cpp index 5a022ba007..bce53e3ecb 100644 --- a/common/view/view_controls.cpp +++ b/common/view/view_controls.cpp @@ -63,8 +63,9 @@ void VC_SETTINGS::Reset() m_grabMouse = false; m_autoPanEnabled = false; m_autoPanSettingEnabled = false; - m_autoPanMargin = 0.1f; + m_autoPanMargin = 0.02f; m_autoPanSpeed = 0.15f; + m_autoPanAcceleration = 1.5f; m_warpCursor = false; m_enableMousewheelPan = false; m_panWithRightButton = false; @@ -82,5 +83,6 @@ void VIEW_CONTROLS::ApplySettings( const VC_SETTINGS& aSettings ) SetAutoPan( aSettings.m_autoPanEnabled ); SetAutoPanMargin( aSettings.m_autoPanMargin ); SetAutoPanSpeed( aSettings.m_autoPanSpeed ); + SetAutoPanAcceleration( aSettings.m_autoPanAcceleration ); ForceCursorPosition( aSettings.m_forceCursorPosition, aSettings.m_forcedPosition ); } diff --git a/common/view/wx_view_controls.cpp b/common/view/wx_view_controls.cpp index 7d7a690302..5e13c0e44f 100644 --- a/common/view/wx_view_controls.cpp +++ b/common/view/wx_view_controls.cpp @@ -363,11 +363,13 @@ void WX_VIEW_CONTROLS::onTimer( wxTimerEvent& aEvent ) VECTOR2D dir( m_panDirection ); - if( dir.EuclideanNorm() > borderSize ) + if( dir.EuclideanNorm() > borderSize / 2 ) + dir = dir.Resize( pow( borderSize, m_settings.m_autoPanAcceleration ) ); + else if( dir.EuclideanNorm() > borderSize ) dir = dir.Resize( borderSize ); dir = m_view->ToWorld( dir, false ); - m_view->SetCenter( m_view->GetCenter() + dir * m_settings.m_autoPanSpeed ); + m_view->SetCenter( m_view->GetCenter() + dir ); refreshMouse(); } @@ -591,6 +593,7 @@ bool WX_VIEW_CONTROLS::handleAutoPanning( const wxMouseEvent& aEvent ) // Compute areas where autopanning is active int borderStart = std::min( m_settings.m_autoPanMargin * m_view->GetScreenPixelSize().x, m_settings.m_autoPanMargin * m_view->GetScreenPixelSize().y ); + borderStart = std::max( borderStart, 2 ); int borderEndX = m_view->GetScreenPixelSize().x - borderStart; int borderEndY = m_view->GetScreenPixelSize().y - borderStart; diff --git a/include/view/view_controls.h b/include/view/view_controls.h index 2844b99c90..1e16ae6cf9 100644 --- a/include/view/view_controls.h +++ b/include/view/view_controls.h @@ -81,6 +81,9 @@ struct VC_SETTINGS ///> How fast is panning when in auto mode float m_autoPanSpeed; + ///> How fast does panning accelerate when approaching the window boundary + float m_autoPanAcceleration; + ///> If the cursor is allowed to be warped bool m_warpCursor; @@ -181,6 +184,16 @@ public: m_settings.m_autoPanSpeed = aSpeed; } + /** + * Function SetAutoPanSpeed() + * Sets speed of autopanning. + * @param aSpeed is a new speed for autopanning. + */ + virtual void SetAutoPanAcceleration( float aAcceleration ) + { + m_settings.m_autoPanAcceleration = aAcceleration; + } + /** * Function SetAutoPanMArgin() * Sets margin for autopanning (ie. the area when autopanning becomes active).