Commit 143f52eb authored by Maciej Suminski's avatar Maciej Suminski

VIEW_CONTROLS::CaptureCursor()

parent a72a0465
...@@ -53,6 +53,8 @@ WX_VIEW_CONTROLS::WX_VIEW_CONTROLS( VIEW* aView, wxWindow* aParentPanel ) : ...@@ -53,6 +53,8 @@ WX_VIEW_CONTROLS::WX_VIEW_CONTROLS( VIEW* aView, wxWindow* aParentPanel ) :
m_parentPanel->Connect( wxEVT_ENTER_WINDOW, m_parentPanel->Connect( wxEVT_ENTER_WINDOW,
wxMouseEventHandler( WX_VIEW_CONTROLS::onEnter ), NULL, this ); wxMouseEventHandler( WX_VIEW_CONTROLS::onEnter ), NULL, this );
#endif #endif
m_parentPanel->Connect( wxEVT_LEAVE_WINDOW,
wxMouseEventHandler( WX_VIEW_CONTROLS::onLeave ), NULL, this );
m_panTimer.SetOwner( this ); m_panTimer.SetOwner( this );
this->Connect( wxEVT_TIMER, this->Connect( wxEVT_TIMER,
...@@ -211,6 +213,43 @@ void WX_VIEW_CONTROLS::onEnter( wxMouseEvent& aEvent ) ...@@ -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 ) void WX_VIEW_CONTROLS::onTimer( wxTimerEvent& aEvent )
{ {
switch( m_state ) switch( m_state )
......
...@@ -47,8 +47,9 @@ class VIEW_CONTROLS ...@@ -47,8 +47,9 @@ class VIEW_CONTROLS
{ {
public: public:
VIEW_CONTROLS( VIEW* aView ) : m_view( aView ), m_minScale( 4.0 ), m_maxScale( 15000 ), VIEW_CONTROLS( VIEW* aView ) : m_view( aView ), m_minScale( 4.0 ), m_maxScale( 15000 ),
m_forceCursorPosition( false ), m_snappingEnabled( false ), m_grabMouse( false ), m_forceCursorPosition( false ), m_cursorCaptured( false ), m_snappingEnabled( false ),
m_autoPanEnabled( false ), m_autoPanMargin( 0.1 ), m_autoPanSpeed( 0.15 ) m_grabMouse( false ), m_autoPanEnabled( false ), m_autoPanMargin( 0.1 ),
m_autoPanSpeed( 0.15 )
{ {
m_panBoundary.SetMaximum(); m_panBoundary.SetMaximum();
} }
...@@ -171,6 +172,16 @@ public: ...@@ -171,6 +172,16 @@ public:
*/ */
virtual void ShowCursor( bool aEnabled ); 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: protected:
/// Sets center for VIEW, takes into account panning boundaries. /// Sets center for VIEW, takes into account panning boundaries.
void setCenter( const VECTOR2D& aCenter ); void setCenter( const VECTOR2D& aCenter );
...@@ -199,6 +210,9 @@ protected: ...@@ -199,6 +210,9 @@ protected:
/// Is the forced cursor position enabled /// Is the forced cursor position enabled
bool m_forceCursorPosition; 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 /// Should the cursor snap to grid or move freely
bool m_snappingEnabled; bool m_snappingEnabled;
......
...@@ -56,6 +56,7 @@ public: ...@@ -56,6 +56,7 @@ public:
void onMotion( wxMouseEvent& aEvent ); void onMotion( wxMouseEvent& aEvent );
void onButton( wxMouseEvent& aEvent ); void onButton( wxMouseEvent& aEvent );
void onEnter( wxMouseEvent& WXUNUSED( aEvent ) ); void onEnter( wxMouseEvent& WXUNUSED( aEvent ) );
void onLeave( wxMouseEvent& WXUNUSED( aEvent ) );
void onTimer( wxTimerEvent& WXUNUSED( aEvent ) ); void onTimer( wxTimerEvent& WXUNUSED( aEvent ) );
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment