From 8e88a621bad9bd9eb7fc386a5a261db845cab8d9 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Mon, 2 Sep 2013 16:26:42 +0200 Subject: [PATCH] Corrected behaviour of drag panning while autopanning is enabled. --- common/view/wx_view_controls.cpp | 33 ++++++++++++++++++++++++-------- include/view/wx_view_controls.h | 13 +++++++++++-- 2 files changed, 36 insertions(+), 10 deletions(-) diff --git a/common/view/wx_view_controls.cpp b/common/view/wx_view_controls.cpp index 465b94f8ae..22a0af5b0e 100644 --- a/common/view/wx_view_controls.cpp +++ b/common/view/wx_view_controls.cpp @@ -64,8 +64,14 @@ void WX_VIEW_CONTROLS::onMotion( wxMouseEvent& aEvent ) { m_mousePosition.x = aEvent.GetX(); m_mousePosition.y = aEvent.GetY(); + bool isAutoPanning = false; - if( aEvent.Dragging() ) + if( m_autoPanEnabled ) + { + isAutoPanning = handleAutoPanning( aEvent ); + } + + if( !isAutoPanning && aEvent.Dragging() ) { if( m_state == DRAG_PANNING ) { @@ -80,11 +86,6 @@ void WX_VIEW_CONTROLS::onMotion( wxMouseEvent& aEvent ) aEvent.Skip(); } } - else - { - if( m_autoPanEnabled ) - handleAutoPanning( aEvent ); - } } @@ -157,7 +158,7 @@ void WX_VIEW_CONTROLS::onButton( wxMouseEvent& aEvent ) m_state = IDLE; } break; - }; + } aEvent.Skip(); } @@ -190,6 +191,10 @@ void WX_VIEW_CONTROLS::onTimer( wxTimerEvent& aEvent ) wxPostEvent( m_parentPanel, redrawEvent ); } break; + + case IDLE: // Just remove unnecessary warnings + case DRAG_PANNING: + break; } } @@ -214,7 +219,7 @@ VECTOR2D WX_VIEW_CONTROLS::GetCursorPosition() const } -void WX_VIEW_CONTROLS::handleAutoPanning( const wxMouseEvent& aEvent ) +bool WX_VIEW_CONTROLS::handleAutoPanning( const wxMouseEvent& aEvent ) { VECTOR2D p( aEvent.GetX(), aEvent.GetY() ); @@ -245,7 +250,10 @@ void WX_VIEW_CONTROLS::handleAutoPanning( const wxMouseEvent& aEvent ) { m_panTimer.Stop(); m_state = IDLE; + + return false; } + return true; break; case IDLE: @@ -253,7 +261,16 @@ void WX_VIEW_CONTROLS::handleAutoPanning( const wxMouseEvent& aEvent ) { m_state = AUTO_PANNING; m_panTimer.Start( (int) ( 1000.0 / 60.0 ) ); + + return true; } + return false; break; + + case DRAG_PANNING: + return false; } + + wxASSERT_MSG( false, wxT( "This line should never be reached" ) ); + return false; // Should not be reached, just avoid the compiler warnings.. } diff --git a/include/view/wx_view_controls.h b/include/view/wx_view_controls.h index 81c3ed1d83..556338bd9e 100644 --- a/include/view/wx_view_controls.h +++ b/include/view/wx_view_controls.h @@ -85,6 +85,8 @@ public: void SetAutoPan( bool aEnabled ) { m_autoPanEnabled = aEnabled; + if( m_state == AUTO_PANNING ) + m_state = IDLE; } /** @@ -116,8 +118,15 @@ private: AUTO_PANNING, }; - /// Computes new viewport settings while in autopanning mode - void handleAutoPanning( const wxMouseEvent& aEvent ); + /** + * Function handleAutoPanning() + * Computes new viewport settings while in autopanning mode. + * + * @param aEvent is an event to be processed and decide if autopanning should happen. + * @return true if it is currently autopanning (ie. autopanning is active and mouse cursor + * is in the area that causes autopanning to happen). + */ + bool handleAutoPanning( const wxMouseEvent& aEvent ); /// Current state of VIEW_CONTROLS State m_state;