Modified interfaces for [WX_]VIEW_CONTROLS.
This commit is contained in:
parent
d2c47a74f2
commit
dbbe628b8c
|
@ -34,11 +34,6 @@ using namespace KiGfx;
|
||||||
WX_VIEW_CONTROLS::WX_VIEW_CONTROLS( VIEW* aView, wxWindow* aParentPanel ) :
|
WX_VIEW_CONTROLS::WX_VIEW_CONTROLS( VIEW* aView, wxWindow* aParentPanel ) :
|
||||||
VIEW_CONTROLS( aView ),
|
VIEW_CONTROLS( aView ),
|
||||||
m_state( IDLE ),
|
m_state( IDLE ),
|
||||||
m_grabMouse( false ),
|
|
||||||
m_snappingEnabled( true ),
|
|
||||||
m_autoPanEnabled( false ),
|
|
||||||
m_autoPanMargin( 0.1 ),
|
|
||||||
m_autoPanSpeed( 0.15 ),
|
|
||||||
m_parentPanel( aParentPanel )
|
m_parentPanel( aParentPanel )
|
||||||
{
|
{
|
||||||
m_parentPanel->Connect( wxEVT_MOTION, wxMouseEventHandler(
|
m_parentPanel->Connect( wxEVT_MOTION, wxMouseEventHandler(
|
||||||
|
@ -64,6 +59,12 @@ void WX_VIEW_CONTROLS::onMotion( wxMouseEvent& aEvent )
|
||||||
{
|
{
|
||||||
m_mousePosition.x = aEvent.GetX();
|
m_mousePosition.x = aEvent.GetX();
|
||||||
m_mousePosition.y = aEvent.GetY();
|
m_mousePosition.y = aEvent.GetY();
|
||||||
|
|
||||||
|
if( m_snappingEnabled )
|
||||||
|
m_cursorPosition = m_view->GetGAL()->GetGridPoint( m_mousePosition );
|
||||||
|
else
|
||||||
|
m_cursorPosition = m_mousePosition;
|
||||||
|
|
||||||
bool isAutoPanning = false;
|
bool isAutoPanning = false;
|
||||||
|
|
||||||
if( m_autoPanEnabled )
|
if( m_autoPanEnabled )
|
||||||
|
@ -210,15 +211,6 @@ void WX_VIEW_CONTROLS::SetGrabMouse( bool aEnabled )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
VECTOR2D WX_VIEW_CONTROLS::GetCursorPosition() const
|
|
||||||
{
|
|
||||||
if( m_snappingEnabled )
|
|
||||||
return m_view->GetGAL()->GetGridPoint( m_mousePosition );
|
|
||||||
|
|
||||||
return m_mousePosition;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool WX_VIEW_CONTROLS::handleAutoPanning( const wxMouseEvent& aEvent )
|
bool WX_VIEW_CONTROLS::handleAutoPanning( const wxMouseEvent& aEvent )
|
||||||
{
|
{
|
||||||
VECTOR2D p( aEvent.GetX(), aEvent.GetY() );
|
VECTOR2D p( aEvent.GetX(), aEvent.GetY() );
|
||||||
|
|
|
@ -46,23 +46,31 @@ class VIEW;
|
||||||
class VIEW_CONTROLS
|
class VIEW_CONTROLS
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
VIEW_CONTROLS( VIEW* aView ) : m_view( aView ) {};
|
VIEW_CONTROLS( VIEW* aView ) : m_view( aView ), m_snappingEnabled( false ),
|
||||||
|
m_grabMouse( false ), m_autoPanEnabled( false ), m_autoPanMargin( 0.1 ),
|
||||||
|
m_autoPanSpeed( 0.15 ) {};
|
||||||
virtual ~VIEW_CONTROLS() {};
|
virtual ~VIEW_CONTROLS() {};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function Activate
|
* Function SetSnapping()
|
||||||
* Determines if all view related events (mouse wheel, right click panning, etc.), should be
|
* Enables/disables snapping cursor to grid.
|
||||||
* handled or not. If not - they can be processed by the legacy view.
|
*
|
||||||
* @param aEnabled tells if events should be handled.
|
* @param aEnabled says whether the opion should be enabled or disabled.
|
||||||
*/
|
*/
|
||||||
virtual void Activate( bool aEnabled ) {};
|
void SetSnapping( bool aEnabled )
|
||||||
|
{
|
||||||
|
m_snappingEnabled = aEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function SetGrabMouse
|
* Function SetGrabMouse
|
||||||
* Turns on/off mouse grabbing. When the mouse is grabbed, it cannot go outside the VIEW.
|
* Turns on/off mouse grabbing. When the mouse is grabbed, it cannot go outside the VIEW.
|
||||||
* @param aEnabled tells if mouse should be grabbed or not.
|
* @param aEnabled tells if mouse should be grabbed or not.
|
||||||
*/
|
*/
|
||||||
virtual void SetGrabMouse( bool aEnabled ) {};
|
virtual void SetGrabMouse( bool aEnabled )
|
||||||
|
{
|
||||||
|
m_grabMouse = aEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function SetAutoPan
|
* Function SetAutoPan
|
||||||
|
@ -70,36 +78,90 @@ public:
|
||||||
* track) and user moves mouse to the VIEW edge - then the view can be translated or not).
|
* track) and user moves mouse to the VIEW edge - then the view can be translated or not).
|
||||||
* @param aEnabled tells if the autopanning should be active.
|
* @param aEnabled tells if the autopanning should be active.
|
||||||
*/
|
*/
|
||||||
virtual void SetAutoPan( bool aEnabled ) {}
|
virtual void SetAutoPan( bool aEnabled )
|
||||||
|
{
|
||||||
|
m_autoPanEnabled = aEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function SetPanSpeed
|
* Function SetAutoPanSpeed()
|
||||||
* Sets speed of panning.
|
* Sets speed of autopanning.
|
||||||
* @param aSpeed is a new speed for panning.
|
* @param aSpeed is a new speed for autopanning.
|
||||||
*/
|
*/
|
||||||
virtual void SetPanSpeed( float aSpeed ) {};
|
virtual void SetAutoPanSpeed( float aSpeed )
|
||||||
|
{
|
||||||
|
m_autoPanSpeed = aSpeed;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function SetZoomSpeed
|
* Function SetAutoPanMArgin()
|
||||||
* Determines how much zoom factor should be affected on one zoom event (eg. mouse wheel).
|
* Sets margin for autopanning (ie. the area when autopanning becomes active).
|
||||||
* @param aSpeed is a new zooming speed.
|
* @param aSpeed is a new margin for autopanning.
|
||||||
*/
|
*/
|
||||||
virtual void SetZoomSpeed( float aSpeed ) {};
|
virtual void SetAutoPanMargin( float aMargin )
|
||||||
|
{
|
||||||
|
m_autoPanMargin = aMargin;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function AnimatedZoom
|
* Function GetMousePosition()
|
||||||
* // TODO
|
* Returns the current mouse pointer position in the screen coordinates. Note, that it may be
|
||||||
|
* different from the cursor position if snapping is enabled (@see GetCursorPosition()).
|
||||||
|
*
|
||||||
|
* @return The current mouse pointer position.
|
||||||
*/
|
*/
|
||||||
virtual void AnimatedZoom( const BOX2I& aExtents ) {};
|
virtual const VECTOR2D& GetMousePosition() const
|
||||||
|
{
|
||||||
|
return m_mousePosition;
|
||||||
|
}
|
||||||
|
|
||||||
virtual void WarpCursor (const VECTOR2D& aPosition ) {};
|
/**
|
||||||
|
* Function GetCursorPosition()
|
||||||
virtual void ShowCursor (bool aEnabled ) {};
|
* Returns the current cursor position in the screen coordinates. Note, that it may be
|
||||||
|
* different from the mouse pointer position if snapping is enabled (@see GetMousePosition()).
|
||||||
|
*
|
||||||
|
* @return The current cursor position in screen coordinates.
|
||||||
|
*/
|
||||||
|
virtual const VECTOR2D& GetCursorPosition() const
|
||||||
|
{
|
||||||
|
return m_cursorPosition;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Function SetCursorPosition()
|
||||||
|
* Allows to move the cursor to a different location.
|
||||||
|
*
|
||||||
|
* @param aPosition is the new location expressed in screen coordinates.
|
||||||
|
*/
|
||||||
|
virtual void SetCursorPosition( const VECTOR2D& aPosition )
|
||||||
|
{
|
||||||
|
m_cursorPosition = aPosition;
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/// Pointer to controlled VIEW.
|
/// Pointer to controlled VIEW.
|
||||||
VIEW* m_view;
|
VIEW* m_view;
|
||||||
|
|
||||||
|
/// Current mouse position
|
||||||
|
VECTOR2D m_mousePosition;
|
||||||
|
|
||||||
|
/// Current cursor position
|
||||||
|
VECTOR2D m_cursorPosition;
|
||||||
|
|
||||||
|
/// Should the cursor snap to grid or move freely
|
||||||
|
bool m_snappingEnabled;
|
||||||
|
|
||||||
|
/// Flag for grabbing the mouse cursor
|
||||||
|
bool m_grabMouse;
|
||||||
|
|
||||||
|
/// Flag for turning on autopanning
|
||||||
|
bool m_autoPanEnabled;
|
||||||
|
|
||||||
|
/// Distance from cursor to VIEW edge when panning is active
|
||||||
|
float m_autoPanMargin;
|
||||||
|
|
||||||
|
/// How fast is panning when in auto mode
|
||||||
|
float m_autoPanSpeed;
|
||||||
};
|
};
|
||||||
} // namespace KiGfx
|
} // namespace KiGfx
|
||||||
|
|
||||||
|
|
|
@ -65,17 +65,6 @@ public:
|
||||||
*/
|
*/
|
||||||
void SetGrabMouse( bool aEnabled );
|
void SetGrabMouse( bool aEnabled );
|
||||||
|
|
||||||
/**
|
|
||||||
* Function SetSnapping()
|
|
||||||
* Enables/disables snapping cursor to grid.
|
|
||||||
*
|
|
||||||
* @param aEnabled says whether the opion should be enabled or disabled.
|
|
||||||
*/
|
|
||||||
void SetSnapping( bool aEnabled )
|
|
||||||
{
|
|
||||||
m_snappingEnabled = aEnabled;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function SetAutoPan()
|
* Function SetAutoPan()
|
||||||
* Enables/disables autopanning (panning when mouse cursor reaches the panel border).
|
* Enables/disables autopanning (panning when mouse cursor reaches the panel border).
|
||||||
|
@ -89,29 +78,8 @@ public:
|
||||||
m_state = IDLE;
|
m_state = IDLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Function GetMousePosition()
|
|
||||||
* Returns the current mouse pointer position in the screen coordinates. Note, that it may be
|
|
||||||
* different from the cursor position if snapping is enabled (@see GetCursorPosition()).
|
|
||||||
*
|
|
||||||
* @return The current mouse pointer position.
|
|
||||||
*/
|
|
||||||
const VECTOR2D& GetMousePosition() const
|
|
||||||
{
|
|
||||||
return m_mousePosition;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Function GetCursorPosition()
|
|
||||||
* Returns the current cursor position in the screen coordinates. Note, that it may be
|
|
||||||
* different from the mouse pointer position if snapping is enabled (@see GetMousePosition()).
|
|
||||||
*
|
|
||||||
* @return The current cursor position.
|
|
||||||
*/
|
|
||||||
VECTOR2D GetCursorPosition() const;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
/// Possible states for WX_VIEW_CONTROLS
|
||||||
enum State {
|
enum State {
|
||||||
IDLE = 1,
|
IDLE = 1,
|
||||||
DRAG_PANNING,
|
DRAG_PANNING,
|
||||||
|
@ -131,24 +99,6 @@ private:
|
||||||
/// Current state of VIEW_CONTROLS
|
/// Current state of VIEW_CONTROLS
|
||||||
State m_state;
|
State m_state;
|
||||||
|
|
||||||
/// Current mouse position
|
|
||||||
VECTOR2D m_mousePosition;
|
|
||||||
|
|
||||||
/// Flag for grabbing the mouse cursor
|
|
||||||
bool m_grabMouse;
|
|
||||||
|
|
||||||
/// Should the cursor snap to grid or move freely
|
|
||||||
bool m_snappingEnabled;
|
|
||||||
|
|
||||||
/// Flag for turning on autopanning
|
|
||||||
bool m_autoPanEnabled;
|
|
||||||
|
|
||||||
/// Distance from cursor to VIEW edge when panning is active
|
|
||||||
float m_autoPanMargin;
|
|
||||||
|
|
||||||
/// How fast is panning when in auto mode
|
|
||||||
float m_autoPanSpeed;
|
|
||||||
|
|
||||||
/// Panel that is affected by VIEW_CONTROLS
|
/// Panel that is affected by VIEW_CONTROLS
|
||||||
wxWindow* m_parentPanel;
|
wxWindow* m_parentPanel;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue