KiCad PCB EDA Suite
KIGFX::WX_VIEW_CONTROLS Class Reference

Class WX_VIEW_CONTROLS is a specific implementation of class VIEW_CONTROLS for wxWidgets library. More...

#include <wx_view_controls.h>

Inheritance diagram for KIGFX::WX_VIEW_CONTROLS:
KIGFX::VIEW_CONTROLS

Public Member Functions

 WX_VIEW_CONTROLS (VIEW *aView, wxScrolledCanvas *aParentPanel)
 
virtual ~WX_VIEW_CONTROLS ()
 
void onWheel (wxMouseEvent &aEvent)
 Handler functions. More...
 
void onMotion (wxMouseEvent &aEvent)
 
void onButton (wxMouseEvent &aEvent)
 
void onEnter (wxMouseEvent &WXUNUSED(aEvent))
 
void onLeave (wxMouseEvent &WXUNUSED(aEvent))
 
void onTimer (wxTimerEvent &WXUNUSED(aEvent))
 
void onScroll (wxScrollWinEvent &aEvent)
 
void SetGrabMouse (bool aEnabled) override
 Function SetGrabMouse() Enables/disables mouse cursor grabbing (limits the movement field only to the panel area). More...
 
VECTOR2D GetMousePosition (bool aWorldCoordinates=true) const override
 Function GetMousePosition() Returns the current mouse pointer position. More...
 
VECTOR2D GetCursorPosition (bool aSnappingEnabled) const override
 Returns the current cursor position in world coordinates. More...
 
VECTOR2D GetRawCursorPosition (bool aSnappingEnabled=true) const override
 Returns the current cursor position in world coordinates - ingoring the cursorUp position force mode. More...
 
void SetCursorPosition (const VECTOR2D &aPosition, bool warpView) override
 Moves cursor to the requested position expressed in world coordinates. More...
 
void SetCrossHairCursorPosition (const VECTOR2D &aPosition, bool aWarpView) override
 Moves the graphic crosshair cursor to the requested position expressed in world coordinates. More...
 
void WarpCursor (const VECTOR2D &aPosition, bool aWorldCoordinates=false, bool aWarpView=false) override
 
void CenterOnCursor () const override
 Function CenterOnCursor() Sets the viewport center to the current cursor position and warps the cursor to the screen center. More...
 
void UpdateScrollbars ()
 Adjusts the scrollbars position to match the current viewport. More...
 
virtual void SetSnapping (bool aEnabled)
 Function SetSnapping() Enables/disables snapping cursor to grid. More...
 
virtual void SetAutoPan (bool aEnabled)
 Function SetAutoPan Turns on/off auto panning (this feature is used when there is a tool active (eg. More...
 
virtual void EnableAutoPan (bool aEnabled)
 Function EnableAutoPan Turns on/off auto panning (user setting to disable it entirely). More...
 
virtual void SetAutoPanSpeed (float aSpeed)
 Function SetAutoPanSpeed() Sets speed of autopanning. More...
 
virtual void SetAutoPanMargin (float aMargin)
 Function SetAutoPanMArgin() Sets margin for autopanning (ie. More...
 
VECTOR2D GetCursorPosition () const
 Returns the current cursor position in world coordinates. More...
 
virtual void ForceCursorPosition (bool aEnabled, const VECTOR2D &aPosition=VECTOR2D(0, 0))
 Function ForceCursorPosition() Places the cursor immediately at a given point. More...
 
bool ForcedCursorPosition () const
 Function ForcedCursorPosition() Returns true if the current cursor position is forced to a specific location, ignoring the mouse cursor position. More...
 
virtual void ShowCursor (bool aEnabled)
 Function ShowCursor() Enables or disables display of cursor. More...
 
bool IsCursorShown () const
 Function IsCursorShown() Returns true when cursor is visible. More...
 
virtual void CaptureCursor (bool aEnabled)
 Function CaptureCursor() Forces the cursor to stay within the drawing panel area. More...
 
bool IsCursorPositionForced () const
 Function IsCursorPositionForced() Returns true if the cursor position is set by one of the tools. More...
 
void EnableCursorWarping (bool aEnable)
 Function EnableCursorWarping() Enables or disables warping the cursor. More...
 
bool IsCursorWarpingEnabled () const
 Function IsCursorWarpingEnabled() More...
 
virtual void EnableMousewheelPan (bool aEnable)
 Function EnableMousewheelPan() Enables or disables mousewheel panning. More...
 
virtual bool IsMousewheelPanEnabled () const
 Function IsMousewheelPanEnabled() More...
 
void SetAdditionalPanButtons (bool aLeft=false, bool aRight=false)
 
virtual void Reset ()
 Function Reset() Restores the default VIEW_CONTROLS settings. More...
 
const VC_SETTINGSGetSettings () const
 

Returns the current VIEW_CONTROLS settings

More...
 
void ApplySettings (const VC_SETTINGS &aSettings)
 

Applies VIEW_CONTROLS settings from an object

More...
 

Static Public Attributes

static const wxEventType EVT_REFRESH_MOUSE = wxNewEventType()
 Event that forces mouse move event in the dispatcher (eg. More...
 

Protected Attributes

VIEWm_view
 

Pointer to controlled VIEW.

More...
 
VC_SETTINGS m_settings
 

Current VIEW_CONTROLS settings

More...
 

Private Types

enum  STATE { IDLE = 1, DRAG_PANNING, AUTO_PANNING }
 Possible states for WX_VIEW_CONTROLS. More...
 

Private Member Functions

bool handleAutoPanning (const wxMouseEvent &aEvent)
 Function handleAutoPanning() Computes new viewport settings while in autopanning mode. More...
 
void refreshMouse ()
 Sends an event to refresh mouse position. More...
 
wxPoint getMouseScreenPosition () const
 Gets the cursor position in the screen coordinates. More...
 

Private Attributes

STATE m_state
 Current state of VIEW_CONTROLS. More...
 
wxScrolledCanvas * m_parentPanel
 Panel that is affected by VIEW_CONTROLS. More...
 
VECTOR2D m_dragStartPoint
 Stores information about point where dragging has started. More...
 
VECTOR2D m_lookStartPoint
 Stores information about the center of viewport when dragging has started. More...
 
VECTOR2D m_panDirection
 Current direction of panning (only autopanning mode) More...
 
wxTimer m_panTimer
 Timer repsonsible for handling autopanning. More...
 
VECTOR2D m_scrollScale
 Ratio used for scaling world coordinates to scrollbar position. More...
 
VECTOR2I m_scrollPos
 Current scrollbar position. More...
 
long int m_lastTimestamp
 Last event timestamp to remove duplicates. More...
 
VECTOR2D m_cursorPos
 Current cursor position (world coordinates) More...
 
bool m_updateCursor
 Flag deciding whether the cursor position should be calculated using the mouse position. More...
 
std::unique_ptr< ZOOM_CONTROLLERm_zoomController
 a ZOOM_CONTROLLER that determines zoom steps. This is platform-specific. More...
 

Detailed Description

Class WX_VIEW_CONTROLS is a specific implementation of class VIEW_CONTROLS for wxWidgets library.

Definition at line 51 of file wx_view_controls.h.

Member Enumeration Documentation

Possible states for WX_VIEW_CONTROLS.

Enumerator
IDLE 
DRAG_PANNING 

Nothing is happening.

AUTO_PANNING 

Panning with mouse button pressed.

Definition at line 109 of file wx_view_controls.h.

110  {
111  IDLE = 1,
112  DRAG_PANNING,
113  AUTO_PANNING,
114  };
Panning with mouse button pressed.

Constructor & Destructor Documentation

WX_VIEW_CONTROLS::WX_VIEW_CONTROLS ( VIEW aView,
wxScrolledCanvas *  aParentPanel 
)

Definition at line 56 of file wx_view_controls.cpp.

References GetZoomControllerForPlatform(), m_panTimer, m_parentPanel, m_zoomController, onButton(), onEnter(), onLeave(), onMotion(), onScroll(), onTimer(), and onWheel().

56  :
57  VIEW_CONTROLS( aView ), m_state( IDLE ), m_parentPanel( aParentPanel ),
58  m_scrollScale( 1.0, 1.0 ), m_lastTimestamp( 0 ), m_cursorPos( 0, 0 ), m_updateCursor( true )
59 {
60  m_parentPanel->Connect( wxEVT_MOTION,
61  wxMouseEventHandler( WX_VIEW_CONTROLS::onMotion ), NULL, this );
62 #if wxCHECK_VERSION( 3, 1, 0 ) || defined( USE_OSX_MAGNIFY_EVENT )
63  m_parentPanel->Connect( wxEVT_MAGNIFY,
64  wxMouseEventHandler( WX_VIEW_CONTROLS::onMagnify ), NULL, this );
65 #endif
66  m_parentPanel->Connect( wxEVT_MOUSEWHEEL,
67  wxMouseEventHandler( WX_VIEW_CONTROLS::onWheel ), NULL, this );
68  m_parentPanel->Connect( wxEVT_MIDDLE_UP,
69  wxMouseEventHandler( WX_VIEW_CONTROLS::onButton ), NULL, this );
70  m_parentPanel->Connect( wxEVT_MIDDLE_DOWN,
71  wxMouseEventHandler( WX_VIEW_CONTROLS::onButton ), NULL, this );
72  m_parentPanel->Connect( wxEVT_LEFT_UP,
73  wxMouseEventHandler( WX_VIEW_CONTROLS::onButton ), NULL, this );
74  m_parentPanel->Connect( wxEVT_LEFT_DOWN,
75  wxMouseEventHandler( WX_VIEW_CONTROLS::onButton ), NULL, this );
76  m_parentPanel->Connect( wxEVT_RIGHT_UP,
77  wxMouseEventHandler( WX_VIEW_CONTROLS::onButton ), NULL, this );
78  m_parentPanel->Connect( wxEVT_RIGHT_DOWN,
79  wxMouseEventHandler( WX_VIEW_CONTROLS::onButton ), NULL, this );
80 #if defined _WIN32 || defined _WIN64
81  m_parentPanel->Connect( wxEVT_ENTER_WINDOW,
82  wxMouseEventHandler( WX_VIEW_CONTROLS::onEnter ), NULL, this );
83 #endif
84  m_parentPanel->Connect( wxEVT_LEAVE_WINDOW,
85  wxMouseEventHandler( WX_VIEW_CONTROLS::onLeave ), NULL, this );
86  m_parentPanel->Connect( wxEVT_SCROLLWIN_THUMBTRACK,
87  wxScrollWinEventHandler( WX_VIEW_CONTROLS::onScroll ), NULL, this );
88  m_parentPanel->Connect( wxEVT_SCROLLWIN_PAGEUP,
89  wxScrollWinEventHandler( WX_VIEW_CONTROLS::onScroll ), NULL, this );
90  m_parentPanel->Connect( wxEVT_SCROLLWIN_PAGEDOWN,
91  wxScrollWinEventHandler( WX_VIEW_CONTROLS::onScroll ), NULL, this );
92 
94 
95  m_panTimer.SetOwner( this );
96  this->Connect( wxEVT_TIMER,
97  wxTimerEventHandler( WX_VIEW_CONTROLS::onTimer ), NULL, this );
98 }
static std::unique_ptr< ZOOM_CONTROLLER > GetZoomControllerForPlatform()
VIEW_CONTROLS(VIEW *aView)
std::unique_ptr< ZOOM_CONTROLLER > m_zoomController
a ZOOM_CONTROLLER that determines zoom steps. This is platform-specific.
void onButton(wxMouseEvent &aEvent)
long int m_lastTimestamp
Last event timestamp to remove duplicates.
VECTOR2D m_scrollScale
Ratio used for scaling world coordinates to scrollbar position.
void onWheel(wxMouseEvent &aEvent)
Handler functions.
void onMotion(wxMouseEvent &aEvent)
wxScrolledCanvas * m_parentPanel
Panel that is affected by VIEW_CONTROLS.
void onTimer(wxTimerEvent &WXUNUSED(aEvent))
bool m_updateCursor
Flag deciding whether the cursor position should be calculated using the mouse position.
void onEnter(wxMouseEvent &WXUNUSED(aEvent))
STATE m_state
Current state of VIEW_CONTROLS.
void onScroll(wxScrollWinEvent &aEvent)
void onLeave(wxMouseEvent &WXUNUSED(aEvent))
VECTOR2D m_cursorPos
Current cursor position (world coordinates)
wxTimer m_panTimer
Timer repsonsible for handling autopanning.
WX_VIEW_CONTROLS::~WX_VIEW_CONTROLS ( )
virtual

Definition at line 101 of file wx_view_controls.cpp.

102 {
103 }

Member Function Documentation

void VIEW_CONTROLS::ApplySettings ( const VC_SETTINGS aSettings)
inherited

Applies VIEW_CONTROLS settings from an object

Definition at line 75 of file view_controls.cpp.

References KIGFX::VIEW_CONTROLS::CaptureCursor(), KIGFX::VIEW_CONTROLS::ForceCursorPosition(), KIGFX::VC_SETTINGS::m_autoPanEnabled, KIGFX::VC_SETTINGS::m_autoPanMargin, KIGFX::VC_SETTINGS::m_autoPanSpeed, KIGFX::VC_SETTINGS::m_cursorCaptured, KIGFX::VC_SETTINGS::m_forceCursorPosition, KIGFX::VC_SETTINGS::m_forcedPosition, KIGFX::VC_SETTINGS::m_grabMouse, KIGFX::VC_SETTINGS::m_showCursor, KIGFX::VC_SETTINGS::m_snappingEnabled, KIGFX::VIEW_CONTROLS::SetAutoPan(), KIGFX::VIEW_CONTROLS::SetAutoPanMargin(), KIGFX::VIEW_CONTROLS::SetAutoPanSpeed(), KIGFX::VIEW_CONTROLS::SetGrabMouse(), KIGFX::VIEW_CONTROLS::SetSnapping(), and KIGFX::VIEW_CONTROLS::ShowCursor().

Referenced by TOOL_MANAGER::applyViewControls(), and KIGFX::VIEW_CONTROLS::Reset().

76 {
77  ShowCursor( aSettings.m_showCursor );
78  CaptureCursor( aSettings.m_cursorCaptured );
79  SetSnapping( aSettings.m_snappingEnabled );
80  SetGrabMouse( aSettings.m_grabMouse );
81  SetAutoPan( aSettings.m_autoPanEnabled );
82  SetAutoPanMargin( aSettings.m_autoPanMargin );
83  SetAutoPanSpeed( aSettings.m_autoPanSpeed );
85 }
virtual void ShowCursor(bool aEnabled)
Function ShowCursor() Enables or disables display of cursor.
virtual void SetAutoPanSpeed(float aSpeed)
Function SetAutoPanSpeed() Sets speed of autopanning.
float m_autoPanSpeed
How fast is panning when in auto mode
Definition: view_controls.h:82
bool m_snappingEnabled
Should the cursor snap to grid or move freely
Definition: view_controls.h:67
bool m_grabMouse
Flag for grabbing the mouse cursor
Definition: view_controls.h:70
VECTOR2D m_forcedPosition
Forced cursor position (world coordinates)
Definition: view_controls.h:58
virtual void SetSnapping(bool aEnabled)
Function SetSnapping() Enables/disables snapping cursor to grid.
virtual void SetAutoPanMargin(float aMargin)
Function SetAutoPanMArgin() Sets margin for autopanning (ie.
bool m_forceCursorPosition
Is the forced cursor position enabled
Definition: view_controls.h:61
virtual void CaptureCursor(bool aEnabled)
Function CaptureCursor() Forces the cursor to stay within the drawing panel area. ...
virtual void ForceCursorPosition(bool aEnabled, const VECTOR2D &aPosition=VECTOR2D(0, 0))
Function ForceCursorPosition() Places the cursor immediately at a given point.
float m_autoPanMargin
Distance from cursor to VIEW edge when panning is active
Definition: view_controls.h:79
bool m_autoPanEnabled
Flag for turning on autopanning
Definition: view_controls.h:73
virtual void SetAutoPan(bool aEnabled)
Function SetAutoPan Turns on/off auto panning (this feature is used when there is a tool active (eg...
bool m_showCursor
Flag determining the cursor visibility
Definition: view_controls.h:55
virtual void SetGrabMouse(bool aEnabled)
Function SetGrabMouse Turns on/off mouse grabbing.
bool m_cursorCaptured
Should the cursor be locked within the parent window area
Definition: view_controls.h:64
virtual void KIGFX::VIEW_CONTROLS::CaptureCursor ( bool  aEnabled)
inlinevirtualinherited

Function CaptureCursor() Forces the cursor to stay within the drawing panel area.

Parameters
aEnableddetermines if the cursor should be captured.

Definition at line 276 of file view_controls.h.

Referenced by KIGFX::VIEW_CONTROLS::ApplySettings(), PCB_TOOL::doInteractiveItemPlacement(), DRAWING_TOOL::drawArc(), DRAWING_TOOL::DrawDimension(), MICROWAVE_TOOL::drawMicrowaveInductor(), DRAWING_TOOL::drawSegment(), DRAWING_TOOL::drawZone(), EDIT_TOOL::MeasureTool(), DRAWING_TOOL::PlaceText(), DRAWING_TOOL::SetAnchor(), and PICKER_TOOL::setControls().

277  {
278  m_settings.m_cursorCaptured = aEnabled;
279  }
VC_SETTINGS m_settings
Current VIEW_CONTROLS settings
bool m_cursorCaptured
Should the cursor be locked within the parent window area
Definition: view_controls.h:64
void WX_VIEW_CONTROLS::CenterOnCursor ( ) const
overridevirtual

Function CenterOnCursor() Sets the viewport center to the current cursor position and warps the cursor to the screen center.

Implements KIGFX::VIEW_CONTROLS.

Definition at line 496 of file wx_view_controls.cpp.

References KIGFX::VIEW_CONTROLS::GetCursorPosition(), KIGFX::VIEW::GetGAL(), GetMousePosition(), KIGFX::GAL::GetScreenPixelSize(), KiROUND(), m_parentPanel, KIGFX::VIEW_CONTROLS::m_view, KIGFX::VIEW::SetCenter(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by onWheel().

497 {
498  const VECTOR2I& screenSize = m_view->GetGAL()->GetScreenPixelSize();
499  VECTOR2I screenCenter( screenSize / 2 );
500 
501  if( GetMousePosition( false ) != screenCenter )
502  {
504  m_parentPanel->WarpPointer( KiROUND( screenSize.x / 2 ), KiROUND( screenSize.y / 2 ) );
505  }
506 }
static int KiROUND(double v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: common.h:120
VECTOR2D GetMousePosition(bool aWorldCoordinates=true) const override
Function GetMousePosition() Returns the current mouse pointer position.
VIEW * m_view
Pointer to controlled VIEW.
void SetCenter(const VECTOR2D &aCenter)
Function SetCenter() Sets the center point of the VIEW (i.e.
Definition: view.cpp:599
GAL * GetGAL() const
Function GetGAL() Returns the GAL this view is using to draw graphical primitives.
Definition: view.h:180
VECTOR2D GetCursorPosition() const
Returns the current cursor position in world coordinates.
const VECTOR2I & GetScreenPixelSize() const
Returns GAL canvas size in pixels.
wxScrolledCanvas * m_parentPanel
Panel that is affected by VIEW_CONTROLS.
virtual void KIGFX::VIEW_CONTROLS::EnableAutoPan ( bool  aEnabled)
inlinevirtualinherited

Function EnableAutoPan Turns on/off auto panning (user setting to disable it entirely).

Parameters
aEnabledtells if the autopanning should be enabled.

Definition at line 151 of file view_controls.h.

Referenced by EDA_DRAW_PANEL::OnPaint(), and EDA_DRAW_FRAME::UseGalCanvas().

152  {
154  }
VC_SETTINGS m_settings
Current VIEW_CONTROLS settings
bool m_autoPanSettingEnabled
Flag for turning on autopanning
Definition: view_controls.h:76
void KIGFX::VIEW_CONTROLS::EnableCursorWarping ( bool  aEnable)
inlineinherited

Function EnableCursorWarping() Enables or disables warping the cursor.

Parameters
aEnableis true if the cursor is allowed to be warped.

Definition at line 309 of file view_controls.h.

Referenced by EDA_DRAW_PANEL::OnPaint(), and EDA_DRAW_FRAME::UseGalCanvas().

310  {
311  m_settings.m_warpCursor = aEnable;
312  }
VC_SETTINGS m_settings
Current VIEW_CONTROLS settings
bool m_warpCursor
If the cursor is allowed to be warped
Definition: view_controls.h:85
virtual void KIGFX::VIEW_CONTROLS::EnableMousewheelPan ( bool  aEnable)
inlinevirtualinherited

Function EnableMousewheelPan() Enables or disables mousewheel panning.

Parameters
aEnableis true if mouse-wheel panning is enabled.

Definition at line 328 of file view_controls.h.

Referenced by EDA_DRAW_PANEL::OnPaint(), DIALOG_PAD_PROPERTIES::prepareCanvas(), and EDA_DRAW_FRAME::UseGalCanvas().

329  {
331  }
bool m_enableMousewheelPan
Mousewheel (2-finger touchpad) panning
Definition: view_controls.h:88
VC_SETTINGS m_settings
Current VIEW_CONTROLS settings
virtual void KIGFX::VIEW_CONTROLS::ForceCursorPosition ( bool  aEnabled,
const VECTOR2D aPosition = VECTOR2D( 0, 0 ) 
)
inlinevirtualinherited
bool KIGFX::VIEW_CONTROLS::ForcedCursorPosition ( ) const
inlineinherited

Function ForcedCursorPosition() Returns true if the current cursor position is forced to a specific location, ignoring the mouse cursor position.

Definition at line 252 of file view_controls.h.

253  {
255  }
VC_SETTINGS m_settings
Current VIEW_CONTROLS settings
bool m_forceCursorPosition
Is the forced cursor position enabled
Definition: view_controls.h:61
VECTOR2D WX_VIEW_CONTROLS::GetCursorPosition ( bool  aSnappingEnabled) const
overridevirtual

Returns the current cursor position in world coordinates.

Note, that it may be different from the mouse pointer position if snapping is enabled or cursor position is forced to a specific point.

Returns
The current cursor position in world coordinates.

Implements KIGFX::VIEW_CONTROLS.

Definition at line 429 of file wx_view_controls.cpp.

References GetRawCursorPosition(), KIGFX::VC_SETTINGS::m_forceCursorPosition, KIGFX::VC_SETTINGS::m_forcedPosition, and KIGFX::VIEW_CONTROLS::m_settings.

Referenced by EDA_DRAW_PANEL_GAL::onPaint().

430 {
432  {
434  }
435  else
436  {
437  return GetRawCursorPosition( aEnableSnapping );
438  }
439 }
VC_SETTINGS m_settings
Current VIEW_CONTROLS settings
VECTOR2D m_forcedPosition
Forced cursor position (world coordinates)
Definition: view_controls.h:58
VECTOR2D GetRawCursorPosition(bool aSnappingEnabled=true) const override
Returns the current cursor position in world coordinates - ingoring the cursorUp position force mode...
bool m_forceCursorPosition
Is the forced cursor position enabled
Definition: view_controls.h:61
VECTOR2D KIGFX::VIEW_CONTROLS::GetCursorPosition ( ) const
inlineinherited

Returns the current cursor position in world coordinates.

Note, that it may be different from the mouse pointer position if snapping is enabled or cursor position is forced to a specific point.

Returns
The current cursor position in world coordinates.

Definition at line 194 of file view_controls.h.

Referenced by POINT_EDITOR::addCorner(), CenterOnCursor(), TOOL_MANAGER::dispatchContextMenu(), PCB_TOOL::doInteractiveItemPlacement(), MICROWAVE_TOOL::drawMicrowaveInductor(), MODULE_EDITOR_TOOLS::EnumeratePads(), SELECTION_TOOL::findMove(), EDA_DRAW_FRAME::GetCrossHairPosition(), ROUTER_TOOL::InlineDrag(), EDIT_TOOL::Main(), ROUTER_TOOL::mainLoop(), DRAWING_TOOL::PlaceImportedGraphics(), PCB_EDITOR_CONTROL::PlaceTarget(), DRAWING_TOOL::PlaceText(), CVPCB_CONTROL::ResetCoords(), GERBVIEW_CONTROL::ResetCoords(), PCBNEW_CONTROL::ResetCoords(), DRAWING_TOOL::SetAnchor(), PNS::TOOL_BASE::updateEndItem(), EDIT_TOOL::updateModificationPoint(), and PNS::TOOL_BASE::updateStartItem().

195  {
197  }
bool m_snappingEnabled
Should the cursor snap to grid or move freely
Definition: view_controls.h:67
VC_SETTINGS m_settings
Current VIEW_CONTROLS settings
VECTOR2D GetCursorPosition() const
Returns the current cursor position in world coordinates.
VECTOR2D WX_VIEW_CONTROLS::GetMousePosition ( bool  aWorldCoordinates = true) const
overridevirtual

Function GetMousePosition() Returns the current mouse pointer position.

Note, that it may be different from the cursor position if snapping is enabled (

See also
GetCursorPosition()).
Parameters
aWorldCoordinatesif true, the result is given in world coordinates, otherwise it is given in screen coordinates.
Returns
The current mouse pointer position in either world or screen coordinates.

Implements KIGFX::VIEW_CONTROLS.

Definition at line 407 of file wx_view_controls.cpp.

References getMouseScreenPosition(), KIGFX::VIEW_CONTROLS::m_view, and KIGFX::VIEW::ToWorld().

Referenced by CenterOnCursor().

408 {
409  wxPoint msp = getMouseScreenPosition();
410  VECTOR2D screenPos( msp.x, msp.y );
411 
412  return aWorldCoordinates ? m_view->ToWorld( screenPos ) : screenPos;
413 }
VECTOR2D ToWorld(const VECTOR2D &aCoord, bool aAbsolute=true) const
Function ToWorld() Converts a screen space point/vector to a point/vector in world space coordinates...
Definition: view.cpp:473
VIEW * m_view
Pointer to controlled VIEW.
wxPoint getMouseScreenPosition() const
Gets the cursor position in the screen coordinates.
wxPoint WX_VIEW_CONTROLS::getMouseScreenPosition ( ) const
private

Gets the cursor position in the screen coordinates.

Definition at line 595 of file wx_view_controls.cpp.

References m_parentPanel.

Referenced by GetMousePosition(), and refreshMouse().

596 {
597  wxPoint msp = wxGetMousePosition();
598  m_parentPanel->ScreenToClient( &msp.x, &msp.y );
599  return msp;
600 }
wxScrolledCanvas * m_parentPanel
Panel that is affected by VIEW_CONTROLS.
VECTOR2D WX_VIEW_CONTROLS::GetRawCursorPosition ( bool  aSnappingEnabled = true) const
overridevirtual

Returns the current cursor position in world coordinates - ingoring the cursorUp position force mode.

Returns
The current cursor position in world coordinates.

Implements KIGFX::VIEW_CONTROLS.

Definition at line 416 of file wx_view_controls.cpp.

References KIGFX::VIEW::GetGAL(), KIGFX::GAL::GetGridPoint(), m_cursorPos, and KIGFX::VIEW_CONTROLS::m_view.

Referenced by GetCursorPosition().

417 {
418  if( aEnableSnapping )
419  {
420  return m_view->GetGAL()->GetGridPoint( m_cursorPos );
421  }
422  else
423  {
424  return m_cursorPos;
425  }
426 }
VIEW * m_view
Pointer to controlled VIEW.
GAL * GetGAL() const
Function GetGAL() Returns the GAL this view is using to draw graphical primitives.
Definition: view.h:180
VECTOR2D GetGridPoint(const VECTOR2D &aPoint) const
Function GetGridPoint() For a given point it returns the nearest point belonging to the grid in world...
VECTOR2D m_cursorPos
Current cursor position (world coordinates)
const VC_SETTINGS& KIGFX::VIEW_CONTROLS::GetSettings ( ) const
inlineinherited

Returns the current VIEW_CONTROLS settings

Definition at line 362 of file view_controls.h.

Referenced by TOOL_MANAGER::GetCurrentToolVC(), and TOOL_MANAGER::saveViewControls().

363  {
364  return m_settings;
365  }
VC_SETTINGS m_settings
Current VIEW_CONTROLS settings
bool WX_VIEW_CONTROLS::handleAutoPanning ( const wxMouseEvent &  aEvent)
private

Function handleAutoPanning() Computes new viewport settings while in autopanning mode.

Parameters
aEventis an event to be processed and decide if autopanning should happen.
Returns
true if it is currently autopanning (ie. autopanning is active and mouse cursor is in the area that causes autopanning to happen).

Definition at line 509 of file wx_view_controls.cpp.

References AUTO_PANNING, DRAG_PANNING, KIGFX::VIEW::GetScreenPixelSize(), IDLE, KIGFX::VC_SETTINGS::m_autoPanMargin, m_panDirection, m_panTimer, KIGFX::VIEW_CONTROLS::m_settings, m_state, KIGFX::VIEW_CONTROLS::m_view, min, VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by onMotion().

510 {
511  VECTOR2D p( aEvent.GetX(), aEvent.GetY() );
512 
513  // Compute areas where autopanning is active
514  double borderStart = std::min( m_settings.m_autoPanMargin * m_view->GetScreenPixelSize().x,
516  double borderEndX = m_view->GetScreenPixelSize().x - borderStart;
517  double borderEndY = m_view->GetScreenPixelSize().y - borderStart;
518 
519  if( p.x < borderStart )
520  m_panDirection.x = -( borderStart - p.x );
521  else if( p.x > borderEndX )
522  m_panDirection.x = ( p.x - borderEndX );
523  else
524  m_panDirection.x = 0;
525 
526  if( p.y < borderStart )
527  m_panDirection.y = -( borderStart - p.y );
528  else if( p.y > borderEndY )
529  m_panDirection.y = ( p.y - borderEndY );
530  else
531  m_panDirection.y = 0;
532 
533  bool borderHit = ( m_panDirection.x != 0 || m_panDirection.y != 0 );
534 
535  switch( m_state )
536  {
537  case AUTO_PANNING:
538  if( !borderHit )
539  {
540  m_panTimer.Stop();
541  m_state = IDLE;
542 
543  return false;
544  }
545 
546  return true;
547  break;
548 
549  case IDLE:
550  if( borderHit )
551  {
553  m_panTimer.Start( (int) ( 250.0 / 60.0 ) );
554 
555  return true;
556  }
557 
558  return false;
559  break;
560 
561  case DRAG_PANNING:
562  return false;
563  }
564 
565  wxASSERT_MSG( false, wxT( "This line should never be reached" ) );
566  return false; // Should not be reached, just avoid the compiler warnings..
567 }
VC_SETTINGS m_settings
Current VIEW_CONTROLS settings
VIEW * m_view
Pointer to controlled VIEW.
Panning with mouse button pressed.
float m_autoPanMargin
Distance from cursor to VIEW edge when panning is active
Definition: view_controls.h:79
VECTOR2D m_panDirection
Current direction of panning (only autopanning mode)
const VECTOR2I & GetScreenPixelSize() const
Function GetScreenPixelSize() Returns the size of the our rendering area, in pixels.
Definition: view.cpp:1167
STATE m_state
Current state of VIEW_CONTROLS.
#define min(a, b)
Definition: auxiliary.h:85
wxTimer m_panTimer
Timer repsonsible for handling autopanning.
bool KIGFX::VIEW_CONTROLS::IsCursorPositionForced ( ) const
inlineinherited

Function IsCursorPositionForced() Returns true if the cursor position is set by one of the tools.

Forced cursor position means it does not react to mouse movement.

Definition at line 286 of file view_controls.h.

287  {
289  }
VC_SETTINGS m_settings
Current VIEW_CONTROLS settings
bool m_forceCursorPosition
Is the forced cursor position enabled
Definition: view_controls.h:61
bool VIEW_CONTROLS::IsCursorShown ( ) const
inherited

Function IsCursorShown() Returns true when cursor is visible.

Returns
True if cursor is visible.

Definition at line 40 of file view_controls.cpp.

References KIGFX::VIEW_CONTROLS::m_settings, and KIGFX::VC_SETTINGS::m_showCursor.

41 {
42  // this only says if the VIEW_CONTROLS say the cursor should be
43  // shown: m_view->GetGAL()->IsCursorEnabled() will say if the GAL is
44  // actually going to do show the cursor or not
45  return m_settings.m_showCursor;
46 }
VC_SETTINGS m_settings
Current VIEW_CONTROLS settings
bool m_showCursor
Flag determining the cursor visibility
Definition: view_controls.h:55
bool KIGFX::VIEW_CONTROLS::IsCursorWarpingEnabled ( ) const
inlineinherited

Function IsCursorWarpingEnabled()

Returns
the current setting for cursor warping.

Definition at line 318 of file view_controls.h.

Referenced by onWheel().

319  {
320  return m_settings.m_warpCursor;
321  }
VC_SETTINGS m_settings
Current VIEW_CONTROLS settings
bool m_warpCursor
If the cursor is allowed to be warped
Definition: view_controls.h:85
virtual bool KIGFX::VIEW_CONTROLS::IsMousewheelPanEnabled ( ) const
inlinevirtualinherited

Function IsMousewheelPanEnabled()

Returns
the current setting for mousewheel panning

Definition at line 337 of file view_controls.h.

338  {
340  }
bool m_enableMousewheelPan
Mousewheel (2-finger touchpad) panning
Definition: view_controls.h:88
VC_SETTINGS m_settings
Current VIEW_CONTROLS settings
void WX_VIEW_CONTROLS::onButton ( wxMouseEvent &  aEvent)

Definition at line 221 of file wx_view_controls.cpp.

References AUTO_PANNING, DRAG_PANNING, KIGFX::VIEW::GetCenter(), IDLE, m_dragStartPoint, m_lookStartPoint, KIGFX::VC_SETTINGS::m_panWithLeftButton, KIGFX::VC_SETTINGS::m_panWithRightButton, KIGFX::VIEW_CONTROLS::m_settings, m_state, and KIGFX::VIEW_CONTROLS::m_view.

Referenced by WX_VIEW_CONTROLS().

222 {
223  switch( m_state )
224  {
225  case IDLE:
226  case AUTO_PANNING:
227  if( aEvent.MiddleDown() ||
228  ( aEvent.LeftDown() && m_settings.m_panWithLeftButton ) ||
229  ( aEvent.RightDown() && m_settings.m_panWithRightButton ) )
230  {
231  m_dragStartPoint = VECTOR2D( aEvent.GetX(), aEvent.GetY() );
234  }
235 
236  if( aEvent.LeftUp() )
237  m_state = IDLE; // Stop autopanning when user release left mouse button
238 
239  break;
240 
241  case DRAG_PANNING:
242  if( aEvent.MiddleUp() || aEvent.LeftUp() || aEvent.RightUp() )
243  m_state = IDLE;
244 
245  break;
246  }
247 
248  aEvent.Skip();
249 }
const VECTOR2D & GetCenter() const
Function GetCenter() Returns the center point of this VIEW (in world space coordinates) ...
Definition: view.h:339
VECTOR2D m_lookStartPoint
Stores information about the center of viewport when dragging has started.
VC_SETTINGS m_settings
Current VIEW_CONTROLS settings
bool m_panWithRightButton
Allow panning with the right button in addition to middle
Definition: view_controls.h:91
VIEW * m_view
Pointer to controlled VIEW.
Panning with mouse button pressed.
VECTOR2< double > VECTOR2D
Definition: vector2d.h:586
VECTOR2D m_dragStartPoint
Stores information about point where dragging has started.
STATE m_state
Current state of VIEW_CONTROLS.
bool m_panWithLeftButton
Allow panning with the left button in addition to middle
Definition: view_controls.h:94
void WX_VIEW_CONTROLS::onEnter ( wxMouseEvent &  WXUNUSEDaEvent)

Definition at line 252 of file wx_view_controls.cpp.

References m_parentPanel.

Referenced by WX_VIEW_CONTROLS().

253 {
254  m_parentPanel->SetFocus();
255 }
wxScrolledCanvas * m_parentPanel
Panel that is affected by VIEW_CONTROLS.
void WX_VIEW_CONTROLS::onLeave ( wxMouseEvent &  WXUNUSEDaEvent)

Definition at line 258 of file wx_view_controls.cpp.

References KIGFX::VC_SETTINGS::m_cursorCaptured, m_parentPanel, and KIGFX::VIEW_CONTROLS::m_settings.

Referenced by WX_VIEW_CONTROLS().

259 {
261  {
262  bool warp = false;
263  int x = aEvent.GetX();
264  int y = aEvent.GetY();
265  wxSize parentSize = m_parentPanel->GetClientSize();
266 
267  if( x < 0 )
268  {
269  x = 0;
270  warp = true;
271  }
272  else if( x >= parentSize.x )
273  {
274  x = parentSize.x - 1;
275  warp = true;
276  }
277 
278  if( y < 0 )
279  {
280  y = 0;
281  warp = true;
282  }
283  else if( y >= parentSize.y )
284  {
285  y = parentSize.y - 1;
286  warp = true;
287  }
288 
289  if( warp )
290  m_parentPanel->WarpPointer( x, y );
291  }
292 }
VC_SETTINGS m_settings
Current VIEW_CONTROLS settings
wxScrolledCanvas * m_parentPanel
Panel that is affected by VIEW_CONTROLS.
bool m_cursorCaptured
Should the cursor be locked within the parent window area
Definition: view_controls.h:64
void WX_VIEW_CONTROLS::onMotion ( wxMouseEvent &  aEvent)

Definition at line 106 of file wx_view_controls.cpp.

References delta, DRAG_PANNING, handleAutoPanning(), KIGFX::VC_SETTINGS::m_autoPanEnabled, KIGFX::VC_SETTINGS::m_autoPanSettingEnabled, m_cursorPos, m_dragStartPoint, m_lookStartPoint, KIGFX::VIEW_CONTROLS::m_settings, m_state, m_updateCursor, KIGFX::VIEW_CONTROLS::m_view, KIGFX::VIEW::SetCenter(), and KIGFX::VIEW::ToWorld().

Referenced by WX_VIEW_CONTROLS().

107 {
108  bool isAutoPanning = false;
109  VECTOR2D mousePos( aEvent.GetX(), aEvent.GetY() );
110 
112  isAutoPanning = handleAutoPanning( aEvent );
113 
114  if( !isAutoPanning && aEvent.Dragging() )
115  {
116  if( m_state == DRAG_PANNING )
117  {
118  VECTOR2D d = m_dragStartPoint - mousePos;
119  VECTOR2D delta = m_view->ToWorld( d, false );
120 
121  m_view->SetCenter( m_lookStartPoint + delta );
122  aEvent.StopPropagation();
123  }
124  }
125 
126  if( m_updateCursor ) // do not update the cursor position if it was explicitly set
127  m_cursorPos = m_view->ToWorld( mousePos );
128  else
129  m_updateCursor = true;
130 
131  aEvent.Skip();
132 }
VECTOR2D m_lookStartPoint
Stores information about the center of viewport when dragging has started.
VECTOR2D ToWorld(const VECTOR2D &aCoord, bool aAbsolute=true) const
Function ToWorld() Converts a screen space point/vector to a point/vector in world space coordinates...
Definition: view.cpp:473
VC_SETTINGS m_settings
Current VIEW_CONTROLS settings
VIEW * m_view
Pointer to controlled VIEW.
static const int delta[8][2]
Definition: solve.cpp:112
bool m_autoPanSettingEnabled
Flag for turning on autopanning
Definition: view_controls.h:76
void SetCenter(const VECTOR2D &aCenter)
Function SetCenter() Sets the center point of the VIEW (i.e.
Definition: view.cpp:599
bool m_autoPanEnabled
Flag for turning on autopanning
Definition: view_controls.h:73
bool m_updateCursor
Flag deciding whether the cursor position should be calculated using the mouse position.
bool handleAutoPanning(const wxMouseEvent &aEvent)
Function handleAutoPanning() Computes new viewport settings while in autopanning mode.
VECTOR2D m_dragStartPoint
Stores information about point where dragging has started.
STATE m_state
Current state of VIEW_CONTROLS.
VECTOR2D m_cursorPos
Current cursor position (world coordinates)
void WX_VIEW_CONTROLS::onScroll ( wxScrollWinEvent &  aEvent)

Definition at line 334 of file wx_view_controls.cpp.

References delta, dist, KIGFX::VIEW::GetBoundary(), KIGFX::VIEW::GetCenter(), KIGFX::VIEW::GetScreenPixelSize(), BOX2< Vec >::GetTop(), KIGFX::VIEW::IsMirroredX(), m_parentPanel, m_scrollScale, KIGFX::VIEW_CONTROLS::m_view, KIGFX::VIEW::SetCenter(), KIGFX::VIEW::ToWorld(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by WX_VIEW_CONTROLS().

335 {
336  const double linePanDelta = 0.05;
337  const double pagePanDelta = 0.5;
338 
339  int type = aEvent.GetEventType();
340  int dir = aEvent.GetOrientation();
341 
342  if( type == wxEVT_SCROLLWIN_THUMBTRACK )
343  {
344  auto center = m_view->GetCenter();
345  const auto& boundary = m_view->GetBoundary();
346 
347  // Flip scroll direction in flipped view
348  const double xstart = ( m_view->IsMirroredX() ?
349  boundary.GetRight() : boundary.GetLeft() );
350  const double xdelta = ( m_view->IsMirroredX() ? -1 : 1 );
351 
352  if( dir == wxHORIZONTAL )
353  center.x = xstart + xdelta * ( aEvent.GetPosition() / m_scrollScale.x );
354  else
355  center.y = boundary.GetTop() + aEvent.GetPosition() / m_scrollScale.y;
356 
357  m_view->SetCenter( center );
358  }
359  else
360  {
361  double dist = 0;
362 
363  if( type == wxEVT_SCROLLWIN_PAGEUP )
364  dist = pagePanDelta;
365  else if( type == wxEVT_SCROLLWIN_PAGEDOWN )
366  dist = -pagePanDelta;
367  else if( type == wxEVT_SCROLLWIN_LINEUP )
368  dist = linePanDelta;
369  else if( type == wxEVT_SCROLLWIN_LINEDOWN )
370  dist = -linePanDelta;
371  else
372  {
373  wxASSERT( "Unhandled event type" );
374  return;
375  }
376 
377  VECTOR2D scroll = m_view->ToWorld( m_view->GetScreenPixelSize(), false ) * dist;
378 
379  double scrollX = 0.0;
380  double scrollY = 0.0;
381 
382  if ( dir == wxHORIZONTAL )
383  scrollX = -scroll.x;
384  else
385  scrollY = -scroll.y;
386 
387  VECTOR2D delta( scrollX, scrollY );
388 
390  }
391 
392  m_parentPanel->Refresh();
393 }
const VECTOR2D & GetCenter() const
Function GetCenter() Returns the center point of this VIEW (in world space coordinates) ...
Definition: view.h:339
static const int dist[10][10]
Definition: ar_matrix.cpp:320
bool IsMirroredX() const
Function IsMirroredX() Returns true if view is flipped across the X axis.
Definition: view.h:230
VECTOR2D ToWorld(const VECTOR2D &aCoord, bool aAbsolute=true) const
Function ToWorld() Converts a screen space point/vector to a point/vector in world space coordinates...
Definition: view.cpp:473
VIEW * m_view
Pointer to controlled VIEW.
VECTOR2D m_scrollScale
Ratio used for scaling world coordinates to scrollbar position.
static const int delta[8][2]
Definition: solve.cpp:112
coord_type GetTop() const
Definition: box2.h:202
void SetCenter(const VECTOR2D &aCenter)
Function SetCenter() Sets the center point of the VIEW (i.e.
Definition: view.cpp:599
const BOX2D & GetBoundary() const
Function GetBoundary()
Definition: view.h:298
wxScrolledCanvas * m_parentPanel
Panel that is affected by VIEW_CONTROLS.
const VECTOR2I & GetScreenPixelSize() const
Function GetScreenPixelSize() Returns the size of the our rendering area, in pixels.
Definition: view.cpp:1167
void WX_VIEW_CONTROLS::onTimer ( wxTimerEvent &  WXUNUSEDaEvent)

Definition at line 295 of file wx_view_controls.cpp.

References AUTO_PANNING, DRAG_PANNING, KIGFX::VIEW::GetCenter(), KIGFX::VIEW::GetScreenPixelSize(), IDLE, KIGFX::VC_SETTINGS::m_autoPanEnabled, KIGFX::VC_SETTINGS::m_autoPanMargin, KIGFX::VC_SETTINGS::m_autoPanSpeed, m_panDirection, m_parentPanel, KIGFX::VIEW_CONTROLS::m_settings, m_state, KIGFX::VIEW_CONTROLS::m_view, min, refreshMouse(), KIGFX::VIEW::SetCenter(), KIGFX::VIEW::ToWorld(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by WX_VIEW_CONTROLS().

296 {
297  switch( m_state )
298  {
299  case AUTO_PANNING:
300  {
302  {
303  m_state = IDLE;
304  return;
305  }
306 
307 #if wxCHECK_VERSION( 3, 0, 0 )
308  if( !m_parentPanel->HasFocus() )
309  break;
310 #endif
311 
312  double borderSize = std::min( m_settings.m_autoPanMargin * m_view->GetScreenPixelSize().x,
314 
315  VECTOR2D dir( m_panDirection );
316 
317  if( dir.EuclideanNorm() > borderSize )
318  dir = dir.Resize( borderSize );
319 
320  dir = m_view->ToWorld( dir, false );
322 
323  refreshMouse();
324  }
325  break;
326 
327  case IDLE: // Just remove unnecessary warnings
328  case DRAG_PANNING:
329  break;
330  }
331 }
const VECTOR2D & GetCenter() const
Function GetCenter() Returns the center point of this VIEW (in world space coordinates) ...
Definition: view.h:339
float m_autoPanSpeed
How fast is panning when in auto mode
Definition: view_controls.h:82
VECTOR2D ToWorld(const VECTOR2D &aCoord, bool aAbsolute=true) const
Function ToWorld() Converts a screen space point/vector to a point/vector in world space coordinates...
Definition: view.cpp:473
VC_SETTINGS m_settings
Current VIEW_CONTROLS settings
VIEW * m_view
Pointer to controlled VIEW.
void SetCenter(const VECTOR2D &aCenter)
Function SetCenter() Sets the center point of the VIEW (i.e.
Definition: view.cpp:599
Panning with mouse button pressed.
float m_autoPanMargin
Distance from cursor to VIEW edge when panning is active
Definition: view_controls.h:79
void refreshMouse()
Sends an event to refresh mouse position.
bool m_autoPanEnabled
Flag for turning on autopanning
Definition: view_controls.h:73
wxScrolledCanvas * m_parentPanel
Panel that is affected by VIEW_CONTROLS.
VECTOR2D m_panDirection
Current direction of panning (only autopanning mode)
const VECTOR2I & GetScreenPixelSize() const
Function GetScreenPixelSize() Returns the size of the our rendering area, in pixels.
Definition: view.cpp:1167
STATE m_state
Current state of VIEW_CONTROLS.
#define min(a, b)
Definition: auxiliary.h:85
void WX_VIEW_CONTROLS::onWheel ( wxMouseEvent &  aEvent)

Handler functions.

Definition at line 135 of file wx_view_controls.cpp.

References CenterOnCursor(), delta, KIGFX::VIEW::GetCenter(), KIGFX::VIEW::GetScale(), KIGFX::VIEW::GetScreenPixelSize(), KIGFX::VIEW_CONTROLS::IsCursorWarpingEnabled(), KIGFX::VC_SETTINGS::m_enableMousewheelPan, m_lastTimestamp, KIGFX::VIEW_CONTROLS::m_settings, KIGFX::VIEW_CONTROLS::m_view, m_zoomController, refreshMouse(), KIGFX::VIEW::SetCenter(), KIGFX::VIEW::SetScale(), KIGFX::VIEW::ToWorld(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by WX_VIEW_CONTROLS().

136 {
137  const double wheelPanSpeed = 0.001;
138 
139 #ifdef __WXGTK3__
140  if( aEvent.GetTimestamp() == m_lastTimestamp )
141  {
142  aEvent.Skip( false );
143  return;
144  }
145 
146  m_lastTimestamp = aEvent.GetTimestamp();
147 #endif
148 
149  // mousewheelpan disabled:
150  // wheel + ctrl -> horizontal scrolling;
151  // wheel + shift -> vertical scrolling;
152  // wheel -> zooming;
153  // mousewheelpan enabled:
154  // wheel -> pan;
155  // wheel + ctrl -> zooming;
156  // wheel + shift -> horizontal scrolling.
157 
158  if( ( !m_settings.m_enableMousewheelPan && ( aEvent.ControlDown() || aEvent.ShiftDown() ) ) ||
159  ( m_settings.m_enableMousewheelPan && !aEvent.ControlDown() ) )
160  {
161  // Scrolling
162  VECTOR2D scrollVec = m_view->ToWorld( m_view->GetScreenPixelSize(), false ) *
163  ( (double) aEvent.GetWheelRotation() * wheelPanSpeed );
164  int axis = aEvent.GetWheelAxis();
165  double scrollX = 0.0;
166  double scrollY = 0.0;
167 
169  {
170  if ( axis == wxMOUSE_WHEEL_HORIZONTAL || aEvent.ShiftDown() )
171  scrollX = scrollVec.x;
172  else
173  scrollY = -scrollVec.y;
174  }
175  else
176  {
177  if( aEvent.ControlDown() )
178  scrollX = -scrollVec.x;
179  else
180  scrollY = -scrollVec.y;
181  }
182 
183  VECTOR2D delta( scrollX, scrollY );
184 
186  refreshMouse();
187  }
188  else
189  {
190  int rotation = aEvent.GetWheelRotation();
191  double zoomScale = m_zoomController->GetScaleForRotation( rotation );
192 
193  if( IsCursorWarpingEnabled() )
194  {
195  CenterOnCursor();
196  m_view->SetScale( m_view->GetScale() * zoomScale );
197  }
198  else
199  {
200  VECTOR2D anchor = m_view->ToWorld( VECTOR2D( aEvent.GetX(), aEvent.GetY() ) );
201  m_view->SetScale( m_view->GetScale() * zoomScale, anchor );
202  }
203  }
204 
205  aEvent.Skip();
206 }
bool m_enableMousewheelPan
Mousewheel (2-finger touchpad) panning
Definition: view_controls.h:88
const VECTOR2D & GetCenter() const
Function GetCenter() Returns the center point of this VIEW (in world space coordinates) ...
Definition: view.h:339
std::unique_ptr< ZOOM_CONTROLLER > m_zoomController
a ZOOM_CONTROLLER that determines zoom steps. This is platform-specific.
VECTOR2D ToWorld(const VECTOR2D &aCoord, bool aAbsolute=true) const
Function ToWorld() Converts a screen space point/vector to a point/vector in world space coordinates...
Definition: view.cpp:473
long int m_lastTimestamp
Last event timestamp to remove duplicates.
VC_SETTINGS m_settings
Current VIEW_CONTROLS settings
VIEW * m_view
Pointer to controlled VIEW.
void SetScale(double aScale)
Function SetScale() Sets the scaling factor.
Definition: view.h:250
static const int delta[8][2]
Definition: solve.cpp:112
void SetCenter(const VECTOR2D &aCenter)
Function SetCenter() Sets the center point of the VIEW (i.e.
Definition: view.cpp:599
VECTOR2< double > VECTOR2D
Definition: vector2d.h:586
void refreshMouse()
Sends an event to refresh mouse position.
bool IsCursorWarpingEnabled() const
Function IsCursorWarpingEnabled()
const VECTOR2I & GetScreenPixelSize() const
Function GetScreenPixelSize() Returns the size of the our rendering area, in pixels.
Definition: view.cpp:1167
double GetScale() const
Function GetScale()
Definition: view.h:268
void CenterOnCursor() const override
Function CenterOnCursor() Sets the viewport center to the current cursor position and warps the curso...
void WX_VIEW_CONTROLS::refreshMouse ( )
private

Sends an event to refresh mouse position.

It is mostly used for notifying the tools that the cursor position in the world coordinates has changed, whereas the screen coordinates remained the same (e.g. frame edge autopanning).

Definition at line 570 of file wx_view_controls.cpp.

References EVT_REFRESH_MOUSE, getMouseScreenPosition(), m_cursorPos, m_parentPanel, KIGFX::VIEW_CONTROLS::m_view, and KIGFX::VIEW::ToWorld().

Referenced by onTimer(), onWheel(), and WarpCursor().

571 {
572  // Notify tools that the cursor position has changed in the world coordinates
573  wxMouseEvent moveEvent( EVT_REFRESH_MOUSE );
574  wxPoint msp = getMouseScreenPosition();
575  moveEvent.SetX( msp.x );
576  moveEvent.SetY( msp.y );
577 
578  // Set the modifiers state
579 #if wxCHECK_VERSION( 3, 0, 0 )
580  moveEvent.SetControlDown( wxGetKeyState( WXK_CONTROL ) );
581  moveEvent.SetShiftDown( wxGetKeyState( WXK_SHIFT ) );
582  moveEvent.SetAltDown( wxGetKeyState( WXK_ALT ) );
583 #else
584  // wx <3.0 do not have accessors, but the fields are exposed
585  moveEvent.m_controlDown = wxGetKeyState( WXK_CONTROL );
586  moveEvent.m_shiftDown = wxGetKeyState( WXK_SHIFT );
587  moveEvent.m_altDown = wxGetKeyState( WXK_ALT );
588 #endif
589 
590  m_cursorPos = m_view->ToWorld( VECTOR2D( msp.x, msp.y ) );
591  wxPostEvent( m_parentPanel, moveEvent );
592 }
static const wxEventType EVT_REFRESH_MOUSE
Event that forces mouse move event in the dispatcher (eg.
VECTOR2D ToWorld(const VECTOR2D &aCoord, bool aAbsolute=true) const
Function ToWorld() Converts a screen space point/vector to a point/vector in world space coordinates...
Definition: view.cpp:473
VIEW * m_view
Pointer to controlled VIEW.
wxPoint getMouseScreenPosition() const
Gets the cursor position in the screen coordinates.
VECTOR2< double > VECTOR2D
Definition: vector2d.h:586
wxScrolledCanvas * m_parentPanel
Panel that is affected by VIEW_CONTROLS.
VECTOR2D m_cursorPos
Current cursor position (world coordinates)
void VIEW_CONTROLS::Reset ( )
virtualinherited

Function Reset() Restores the default VIEW_CONTROLS settings.

Definition at line 49 of file view_controls.cpp.

References KIGFX::VIEW_CONTROLS::ApplySettings(), and KIGFX::dummy().

50 {
51  // Get the default settings from the default constructor
53  ApplySettings( dummy );
54 }
void ApplySettings(const VC_SETTINGS &aSettings)
Applies VIEW_CONTROLS settings from an object
static LIB_PART * dummy()
Used when a LIB_PART is not found in library to draw a dummy shape.
Structure to keep VIEW_CONTROLS settings for easy store/restore operations
Definition: view_controls.h:44
void KIGFX::VIEW_CONTROLS::SetAdditionalPanButtons ( bool  aLeft = false,
bool  aRight = false 
)
inlineinherited

Definition at line 349 of file view_controls.h.

References KIGFX::VC_SETTINGS::Reset().

Referenced by CVPCB_SELECTION_TOOL::Main(), and GERBVIEW_SELECTION_TOOL::Main().

350  {
353  }
VC_SETTINGS m_settings
Current VIEW_CONTROLS settings
bool m_panWithRightButton
Allow panning with the right button in addition to middle
Definition: view_controls.h:91
bool m_panWithLeftButton
Allow panning with the left button in addition to middle
Definition: view_controls.h:94
virtual void KIGFX::VIEW_CONTROLS::SetAutoPan ( bool  aEnabled)
inlinevirtualinherited
virtual void KIGFX::VIEW_CONTROLS::SetAutoPanMargin ( float  aMargin)
inlinevirtualinherited

Function SetAutoPanMArgin() Sets margin for autopanning (ie.

the area when autopanning becomes active).

Parameters
aMarginis a new margin for autopanning.

Definition at line 171 of file view_controls.h.

Referenced by KIGFX::VIEW_CONTROLS::ApplySettings().

172  {
173  m_settings.m_autoPanMargin = aMargin;
174  }
VC_SETTINGS m_settings
Current VIEW_CONTROLS settings
float m_autoPanMargin
Distance from cursor to VIEW edge when panning is active
Definition: view_controls.h:79
virtual void KIGFX::VIEW_CONTROLS::SetAutoPanSpeed ( float  aSpeed)
inlinevirtualinherited

Function SetAutoPanSpeed() Sets speed of autopanning.

Parameters
aSpeedis a new speed for autopanning.

Definition at line 161 of file view_controls.h.

Referenced by KIGFX::VIEW_CONTROLS::ApplySettings().

162  {
163  m_settings.m_autoPanSpeed = aSpeed;
164  }
float m_autoPanSpeed
How fast is panning when in auto mode
Definition: view_controls.h:82
VC_SETTINGS m_settings
Current VIEW_CONTROLS settings
void WX_VIEW_CONTROLS::SetCrossHairCursorPosition ( const VECTOR2D aPosition,
bool  aWarpView = true 
)
overridevirtual

Moves the graphic crosshair cursor to the requested position expressed in world coordinates.

Parameters
aPositionis the requested cursor position in the world coordinates.
aWarpViewenables/disables view warp if the cursor is outside the current viewport.

Implements KIGFX::VIEW_CONTROLS.

Definition at line 450 of file wx_view_controls.cpp.

References BOX2< Vec >::Contains(), KIGFX::VIEW::GetGAL(), KIGFX::GAL::GetScreenPixelSize(), m_cursorPos, m_updateCursor, KIGFX::VIEW_CONTROLS::m_view, KIGFX::VIEW::SetCenter(), and KIGFX::VIEW::ToScreen().

451 {
452  m_updateCursor = false;
453 
454  const VECTOR2I& screenSize = m_view->GetGAL()->GetScreenPixelSize();
455  BOX2I screen( VECTOR2I( 0, 0 ), screenSize );
456  VECTOR2D screenPos = m_view->ToScreen( aPosition );
457 
458  if( aWarpView && !screen.Contains( screenPos ) )
459  m_view->SetCenter( aPosition );
460 
461  m_cursorPos = aPosition;
462 }
VIEW * m_view
Pointer to controlled VIEW.
VECTOR2< int > VECTOR2I
Definition: vector2d.h:587
void SetCenter(const VECTOR2D &aCenter)
Function SetCenter() Sets the center point of the VIEW (i.e.
Definition: view.cpp:599
GAL * GetGAL() const
Function GetGAL() Returns the GAL this view is using to draw graphical primitives.
Definition: view.h:180
const VECTOR2I & GetScreenPixelSize() const
Returns GAL canvas size in pixels.
bool m_updateCursor
Flag deciding whether the cursor position should be calculated using the mouse position.
VECTOR2D ToScreen(const VECTOR2D &aCoord, bool aAbsolute=true) const
Function ToScreen() Converts a world space point/vector to a point/vector in screen space coordinates...
Definition: view.cpp:492
VECTOR2D m_cursorPos
Current cursor position (world coordinates)
void WX_VIEW_CONTROLS::SetCursorPosition ( const VECTOR2D aPosition,
bool  aWarpView 
)
overridevirtual

Moves cursor to the requested position expressed in world coordinates.

The position is not forced and will be overridden with the next mouse motion event. Mouse cursor follows the world cursor.

Parameters
aPositionis the requested cursor position in the world coordinates.
aWarpViewenables/disables view warp if the cursor is outside the current viewport.

Implements KIGFX::VIEW_CONTROLS.

Definition at line 442 of file wx_view_controls.cpp.

References m_cursorPos, m_updateCursor, and WarpCursor().

443 {
444  m_updateCursor = false;
445  WarpCursor( aPosition, true, aWarpView );
446  m_cursorPos = aPosition;
447 }
void WarpCursor(const VECTOR2D &aPosition, bool aWorldCoordinates=false, bool aWarpView=false) override
bool m_updateCursor
Flag deciding whether the cursor position should be calculated using the mouse position.
VECTOR2D m_cursorPos
Current cursor position (world coordinates)
void WX_VIEW_CONTROLS::SetGrabMouse ( bool  aEnabled)
overridevirtual

Function SetGrabMouse() Enables/disables mouse cursor grabbing (limits the movement field only to the panel area).

Parameters
aEnabledsays whether the option should be enabled or disabled.

Reimplemented from KIGFX::VIEW_CONTROLS.

Definition at line 396 of file wx_view_controls.cpp.

References KIGFX::VC_SETTINGS::m_grabMouse, m_parentPanel, KIGFX::VIEW_CONTROLS::m_settings, and KIGFX::VIEW_CONTROLS::SetGrabMouse().

397 {
398  if( aEnabled && !m_settings.m_grabMouse )
399  m_parentPanel->CaptureMouse();
400  else if( !aEnabled && m_settings.m_grabMouse )
401  m_parentPanel->ReleaseMouse();
402 
403  VIEW_CONTROLS::SetGrabMouse( aEnabled );
404 }
bool m_grabMouse
Flag for grabbing the mouse cursor
Definition: view_controls.h:70
VC_SETTINGS m_settings
Current VIEW_CONTROLS settings
wxScrolledCanvas * m_parentPanel
Panel that is affected by VIEW_CONTROLS.
virtual void SetGrabMouse(bool aEnabled)
Function SetGrabMouse Turns on/off mouse grabbing.
virtual void KIGFX::VIEW_CONTROLS::SetSnapping ( bool  aEnabled)
inlinevirtualinherited
void VIEW_CONTROLS::ShowCursor ( bool  aEnabled)
virtualinherited

Function ShowCursor() Enables or disables display of cursor.

Parameters
aEnableddecides if the cursor should be shown.

Definition at line 33 of file view_controls.cpp.

References KIGFX::VIEW::GetGAL(), KIGFX::VIEW_CONTROLS::m_settings, KIGFX::VC_SETTINGS::m_showCursor, KIGFX::VIEW_CONTROLS::m_view, and KIGFX::GAL::SetCursorEnabled().

Referenced by KIGFX::VIEW_CONTROLS::ApplySettings(), PCB_TOOL::doInteractiveItemPlacement(), DRAWING_TOOL::drawArc(), DRAWING_TOOL::DrawDimension(), MICROWAVE_TOOL::drawMicrowaveInductor(), DRAWING_TOOL::drawSegment(), DRAWING_TOOL::drawZone(), MODULE_EDITOR_TOOLS::EnumeratePads(), ROUTER_TOOL::InlineDrag(), EDIT_TOOL::Main(), LENGTH_TUNER_TOOL::mainLoop(), ROUTER_TOOL::mainLoop(), EDIT_TOOL::MeasureTool(), POINT_EDITOR::OnSelectionChange(), DRAWING_TOOL::PlaceImportedGraphics(), DRAWING_TOOL::PlaceText(), DRAWING_TOOL::SetAnchor(), PICKER_TOOL::setControls(), and POINT_EDITOR::setEditedPoint().

34 {
35  m_settings.m_showCursor = aEnabled;
36  m_view->GetGAL()->SetCursorEnabled( aEnabled );
37 }
void SetCursorEnabled(bool aCursorEnabled)
Enable/disable cursor.
VC_SETTINGS m_settings
Current VIEW_CONTROLS settings
VIEW * m_view
Pointer to controlled VIEW.
GAL * GetGAL() const
Function GetGAL() Returns the GAL this view is using to draw graphical primitives.
Definition: view.h:180
bool m_showCursor
Flag determining the cursor visibility
Definition: view_controls.h:55
void WX_VIEW_CONTROLS::UpdateScrollbars ( )

Adjusts the scrollbars position to match the current viewport.

Definition at line 603 of file wx_view_controls.cpp.

References BOX2< Vec >::Centre(), KIGFX::VIEW::GetBoundary(), BOX2< Vec >::GetHeight(), BOX2< Vec >::GetLeft(), BOX2< Vec >::GetRight(), BOX2< Vec >::GetTop(), KIGFX::VIEW::GetViewport(), BOX2< Vec >::GetWidth(), KIGFX::VIEW::IsMirroredX(), m_parentPanel, m_scrollPos, m_scrollScale, KIGFX::VIEW_CONTROLS::m_view, VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by EDA_DRAW_PANEL_GAL::onPaint().

604 {
605 #ifdef __WXGTK3__
606  // Until we can handle the repaint events from scroll bar hide/show
607  // todo: Implement area mapping for re-painting scrollbars
608  return;
609 #endif
610 
611  const BOX2D viewport = m_view->GetViewport();
612  const BOX2D& boundary = m_view->GetBoundary();
613 
614  m_scrollScale.x = 2e3 / viewport.GetWidth(); // TODO it does not have to be updated so often
615  m_scrollScale.y = 2e3 / viewport.GetHeight();
616  VECTOR2I newScroll( ( viewport.Centre().x - boundary.GetLeft() ) * m_scrollScale.x,
617  ( viewport.Centre().y - boundary.GetTop() ) * m_scrollScale.y );
618 
619  // Flip scroll direction in flipped view
620  if( m_view->IsMirroredX() )
621  newScroll.x = ( boundary.GetRight() - viewport.Centre().x ) * m_scrollScale.x;
622 
623  // Adjust scrollbars only if it is needed. Otherwise there are cases when canvas is continuosly
624  // refreshed (Windows)
625  if( m_scrollPos != newScroll )
626  {
627  // Another example of wxWidgets being broken by design: scroll position is determined by the
628  // left (or top, if vertical) edge of the slider. Fortunately, slider size seems to be constant
629  // (at least for wxGTK and wxMSW), so we have to add its size to allow user to scroll the workspace
630  // till the end.
631 
632  m_parentPanel->SetScrollbars( 1, 1,
633 #if defined(__LINUX__)
634  m_scrollScale.x * boundary.GetWidth() + 1623, m_scrollScale.y * boundary.GetHeight() + 1623,
635 #elif defined(__WIN32__) || defined(__WIN64__)
636  m_scrollScale.x * boundary.GetWidth() + 1377, m_scrollScale.y * boundary.GetHeight() + 741,
637 #else
638  m_scrollScale.x * boundary.GetWidth(), m_scrollScale.y * boundary.GetHeight(),
639 #endif
640  newScroll.x, newScroll.y, false );
641 
642  m_scrollPos = newScroll;
643  }
644 }
bool IsMirroredX() const
Function IsMirroredX() Returns true if view is flipped across the X axis.
Definition: view.h:230
coord_type GetRight() const
Definition: box2.h:197
VIEW * m_view
Pointer to controlled VIEW.
VECTOR2D m_scrollScale
Ratio used for scaling world coordinates to scrollbar position.
coord_type GetTop() const
Definition: box2.h:202
coord_type GetWidth() const
Definition: box2.h:195
BOX2D GetViewport() const
Function GetViewport() Returns the current viewport visible area rectangle.
Definition: view.cpp:536
const BOX2D & GetBoundary() const
Function GetBoundary()
Definition: view.h:298
Vec Centre() const
Definition: box2.h:77
coord_type GetHeight() const
Definition: box2.h:196
wxScrolledCanvas * m_parentPanel
Panel that is affected by VIEW_CONTROLS.
VECTOR2I m_scrollPos
Current scrollbar position.
coord_type GetLeft() const
Definition: box2.h:201
void WX_VIEW_CONTROLS::WarpCursor ( const VECTOR2D aPosition,
bool  aWorldCoordinates = false,
bool  aWarpView = false 
)
overridevirtual

Implements KIGFX::VIEW_CONTROLS.

Definition at line 465 of file wx_view_controls.cpp.

References BOX2< Vec >::Contains(), KIGFX::VIEW::GetGAL(), KIGFX::GAL::GetScreenPixelSize(), m_parentPanel, KIGFX::VIEW_CONTROLS::m_view, refreshMouse(), KIGFX::VIEW::SetCenter(), KIGFX::VIEW::ToScreen(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by SetCursorPosition().

467 {
468  if( aWorldCoordinates )
469  {
470  const VECTOR2I& screenSize = m_view->GetGAL()->GetScreenPixelSize();
471  BOX2I screen( VECTOR2I( 0, 0 ), screenSize );
472  VECTOR2D screenPos = m_view->ToScreen( aPosition );
473 
474  if( !screen.Contains( screenPos ) )
475  {
476  if( aWarpView )
477  {
478  m_view->SetCenter( aPosition );
479  m_parentPanel->WarpPointer( screenSize.x / 2, screenSize.y / 2 );
480  }
481  }
482  else
483  {
484  m_parentPanel->WarpPointer( screenPos.x, screenPos.y );
485  }
486  }
487  else
488  {
489  m_parentPanel->WarpPointer( aPosition.x, aPosition.y );
490  }
491 
492  refreshMouse();
493 }
VIEW * m_view
Pointer to controlled VIEW.
VECTOR2< int > VECTOR2I
Definition: vector2d.h:587
void SetCenter(const VECTOR2D &aCenter)
Function SetCenter() Sets the center point of the VIEW (i.e.
Definition: view.cpp:599
GAL * GetGAL() const
Function GetGAL() Returns the GAL this view is using to draw graphical primitives.
Definition: view.h:180
void refreshMouse()
Sends an event to refresh mouse position.
const VECTOR2I & GetScreenPixelSize() const
Returns GAL canvas size in pixels.
wxScrolledCanvas * m_parentPanel
Panel that is affected by VIEW_CONTROLS.
VECTOR2D ToScreen(const VECTOR2D &aCoord, bool aAbsolute=true) const
Function ToScreen() Converts a world space point/vector to a point/vector in screen space coordinates...
Definition: view.cpp:492

Member Data Documentation

const wxEventType WX_VIEW_CONTROLS::EVT_REFRESH_MOUSE = wxNewEventType()
static

Event that forces mouse move event in the dispatcher (eg.

used in autopanning, when mouse cursor does not move in screen coordinates, but does in world coordinates)

Definition at line 105 of file wx_view_controls.h.

Referenced by TOOL_DISPATCHER::DispatchWxEvent(), EDA_DRAW_PANEL_GAL::EDA_DRAW_PANEL_GAL(), and refreshMouse().

VECTOR2D KIGFX::WX_VIEW_CONTROLS::m_cursorPos
private

Current cursor position (world coordinates)

Definition at line 166 of file wx_view_controls.h.

Referenced by GetRawCursorPosition(), onMotion(), refreshMouse(), SetCrossHairCursorPosition(), and SetCursorPosition().

VECTOR2D KIGFX::WX_VIEW_CONTROLS::m_dragStartPoint
private

Stores information about point where dragging has started.

Definition at line 145 of file wx_view_controls.h.

Referenced by onButton(), and onMotion().

long int KIGFX::WX_VIEW_CONTROLS::m_lastTimestamp
private

Last event timestamp to remove duplicates.

Definition at line 163 of file wx_view_controls.h.

Referenced by onWheel().

VECTOR2D KIGFX::WX_VIEW_CONTROLS::m_lookStartPoint
private

Stores information about the center of viewport when dragging has started.

Definition at line 148 of file wx_view_controls.h.

Referenced by onButton(), and onMotion().

VECTOR2D KIGFX::WX_VIEW_CONTROLS::m_panDirection
private

Current direction of panning (only autopanning mode)

Definition at line 151 of file wx_view_controls.h.

Referenced by handleAutoPanning(), and onTimer().

wxTimer KIGFX::WX_VIEW_CONTROLS::m_panTimer
private

Timer repsonsible for handling autopanning.

Definition at line 154 of file wx_view_controls.h.

Referenced by handleAutoPanning(), and WX_VIEW_CONTROLS().

wxScrolledCanvas* KIGFX::WX_VIEW_CONTROLS::m_parentPanel
private
VECTOR2I KIGFX::WX_VIEW_CONTROLS::m_scrollPos
private

Current scrollbar position.

Definition at line 160 of file wx_view_controls.h.

Referenced by UpdateScrollbars().

VECTOR2D KIGFX::WX_VIEW_CONTROLS::m_scrollScale
private

Ratio used for scaling world coordinates to scrollbar position.

Definition at line 157 of file wx_view_controls.h.

Referenced by onScroll(), and UpdateScrollbars().

STATE KIGFX::WX_VIEW_CONTROLS::m_state
private

Current state of VIEW_CONTROLS.

Definition at line 139 of file wx_view_controls.h.

Referenced by handleAutoPanning(), onButton(), onMotion(), and onTimer().

bool KIGFX::WX_VIEW_CONTROLS::m_updateCursor
private

Flag deciding whether the cursor position should be calculated using the mouse position.

Definition at line 169 of file wx_view_controls.h.

Referenced by onMotion(), SetCrossHairCursorPosition(), and SetCursorPosition().

std::unique_ptr<ZOOM_CONTROLLER> KIGFX::WX_VIEW_CONTROLS::m_zoomController
private

a ZOOM_CONTROLLER that determines zoom steps. This is platform-specific.

Definition at line 172 of file wx_view_controls.h.

Referenced by onWheel(), and WX_VIEW_CONTROLS().


The documentation for this class was generated from the following files: