diff --git a/common/view/wx_view_controls.cpp b/common/view/wx_view_controls.cpp index e7bce79733..f1814af3d5 100644 --- a/common/view/wx_view_controls.cpp +++ b/common/view/wx_view_controls.cpp @@ -53,6 +53,8 @@ WX_VIEW_CONTROLS::WX_VIEW_CONTROLS( VIEW* aView, wxWindow* aParentPanel ) : m_parentPanel->Connect( wxEVT_ENTER_WINDOW, wxMouseEventHandler( WX_VIEW_CONTROLS::onEnter ), NULL, this ); #endif + m_parentPanel->Connect( wxEVT_LEAVE_WINDOW, + wxMouseEventHandler( WX_VIEW_CONTROLS::onLeave ), NULL, this ); m_panTimer.SetOwner( this ); this->Connect( wxEVT_TIMER, @@ -211,6 +213,43 @@ void WX_VIEW_CONTROLS::onEnter( wxMouseEvent& aEvent ) } +void WX_VIEW_CONTROLS::onLeave( wxMouseEvent& aEvent ) +{ + if( m_cursorCaptured ) + { + bool warp = false; + int x = aEvent.GetX(); + int y = aEvent.GetY(); + wxSize parentSize = m_parentPanel->GetClientSize(); + + if( x < 0 ) + { + x = 0; + warp = true; + } + else if( x >= parentSize.x ) + { + x = parentSize.x - 1; + warp = true; + } + + if( y < 0 ) + { + y = 0; + warp = true; + } + else if( y >= parentSize.y ) + { + y = parentSize.y - 1; + warp = true; + } + + if( warp ) + m_parentPanel->WarpPointer( x, y ); + } +} + + void WX_VIEW_CONTROLS::onTimer( wxTimerEvent& aEvent ) { switch( m_state ) diff --git a/include/view/view_controls.h b/include/view/view_controls.h index a2770df7e8..fddf6ad68f 100644 --- a/include/view/view_controls.h +++ b/include/view/view_controls.h @@ -47,8 +47,9 @@ class VIEW_CONTROLS { public: VIEW_CONTROLS( VIEW* aView ) : m_view( aView ), m_minScale( 4.0 ), m_maxScale( 15000 ), - m_forceCursorPosition( false ), m_snappingEnabled( false ), m_grabMouse( false ), - m_autoPanEnabled( false ), m_autoPanMargin( 0.1 ), m_autoPanSpeed( 0.15 ) + m_forceCursorPosition( false ), m_cursorCaptured( false ), m_snappingEnabled( false ), + m_grabMouse( false ), m_autoPanEnabled( false ), m_autoPanMargin( 0.1 ), + m_autoPanSpeed( 0.15 ) { m_panBoundary.SetMaximum(); } @@ -171,6 +172,16 @@ public: */ virtual void ShowCursor( bool aEnabled ); + /** + * Function CaptureCursor() + * Forces the cursor to stay within the drawing panel area. + * @param aEnabled determines if the cursor should be captured. + */ + virtual void CaptureCursor( bool aEnabled ) + { + m_cursorCaptured = aEnabled; + } + protected: /// Sets center for VIEW, takes into account panning boundaries. void setCenter( const VECTOR2D& aCenter ); @@ -199,6 +210,9 @@ protected: /// Is the forced cursor position enabled bool m_forceCursorPosition; + /// Should the cursor be locked within the parent window area + bool m_cursorCaptured; + /// Should the cursor snap to grid or move freely bool m_snappingEnabled; diff --git a/include/view/wx_view_controls.h b/include/view/wx_view_controls.h index d8722d5b78..323a9a1443 100644 --- a/include/view/wx_view_controls.h +++ b/include/view/wx_view_controls.h @@ -56,6 +56,7 @@ public: void onMotion( wxMouseEvent& aEvent ); void onButton( wxMouseEvent& aEvent ); void onEnter( wxMouseEvent& WXUNUSED( aEvent ) ); + void onLeave( wxMouseEvent& WXUNUSED( aEvent ) ); void onTimer( wxTimerEvent& WXUNUSED( aEvent ) ); /**