VIEW_CONTROLS::CaptureCursor()
This commit is contained in:
parent
a72a04654c
commit
143f52eb4d
|
@ -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 )
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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 ) );
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue