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 WarpCursor (const VECTOR2D &aPosition, bool aWorldCoordinates=false, bool aWarpView=false) const 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 () const
 Sends an event to refresh mouse position. 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...
 
wxLongLong m_timeStamp
 Used for determining time intervals between scroll & zoom events. 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...
 
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...
 

Detailed Description

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

Definition at line 46 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 102 of file wx_view_controls.h.

103  {
104  IDLE = 1,
105  DRAG_PANNING,
106  AUTO_PANNING,
107  };
Panning with mouse button pressed.

Constructor & Destructor Documentation

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

Definition at line 38 of file wx_view_controls.cpp.

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

38  :
39  VIEW_CONTROLS( aView ), m_state( IDLE ), m_parentPanel( aParentPanel ),
40  m_scrollScale( 1.0, 1.0 ), m_cursorPos( 0, 0 ), m_updateCursor( true )
41 {
42  m_parentPanel->Connect( wxEVT_MOTION,
43  wxMouseEventHandler( WX_VIEW_CONTROLS::onMotion ), NULL, this );
44 #if wxCHECK_VERSION( 3, 1, 0 ) || defined( USE_OSX_MAGNIFY_EVENT )
45  m_parentPanel->Connect( wxEVT_MAGNIFY,
46  wxMouseEventHandler( WX_VIEW_CONTROLS::onMagnify ), NULL, this );
47 #endif
48  m_parentPanel->Connect( wxEVT_MOUSEWHEEL,
49  wxMouseEventHandler( WX_VIEW_CONTROLS::onWheel ), NULL, this );
50  m_parentPanel->Connect( wxEVT_MIDDLE_UP,
51  wxMouseEventHandler( WX_VIEW_CONTROLS::onButton ), NULL, this );
52  m_parentPanel->Connect( wxEVT_MIDDLE_DOWN,
53  wxMouseEventHandler( WX_VIEW_CONTROLS::onButton ), NULL, this );
54  m_parentPanel->Connect( wxEVT_LEFT_UP,
55  wxMouseEventHandler( WX_VIEW_CONTROLS::onButton ), NULL, this );
56  m_parentPanel->Connect( wxEVT_LEFT_DOWN,
57  wxMouseEventHandler( WX_VIEW_CONTROLS::onButton ), NULL, this );
58  m_parentPanel->Connect( wxEVT_RIGHT_UP,
59  wxMouseEventHandler( WX_VIEW_CONTROLS::onButton ), NULL, this );
60  m_parentPanel->Connect( wxEVT_RIGHT_DOWN,
61  wxMouseEventHandler( WX_VIEW_CONTROLS::onButton ), NULL, this );
62 #if defined _WIN32 || defined _WIN64
63  m_parentPanel->Connect( wxEVT_ENTER_WINDOW,
64  wxMouseEventHandler( WX_VIEW_CONTROLS::onEnter ), NULL, this );
65 #endif
66  m_parentPanel->Connect( wxEVT_LEAVE_WINDOW,
67  wxMouseEventHandler( WX_VIEW_CONTROLS::onLeave ), NULL, this );
68  m_parentPanel->Connect( wxEVT_SCROLLWIN_THUMBTRACK,
69  wxScrollWinEventHandler( WX_VIEW_CONTROLS::onScroll ), NULL, this );
70  m_parentPanel->Connect( wxEVT_SCROLLWIN_LINEUP,
71  wxScrollWinEventHandler( WX_VIEW_CONTROLS::onScroll ), NULL, this );
72  m_parentPanel->Connect( wxEVT_SCROLLWIN_LINEDOWN,
73  wxScrollWinEventHandler( WX_VIEW_CONTROLS::onScroll ), NULL, this );
74  m_parentPanel->Connect( wxEVT_SCROLLWIN_PAGEUP,
75  wxScrollWinEventHandler( WX_VIEW_CONTROLS::onScroll ), NULL, this );
76  m_parentPanel->Connect( wxEVT_SCROLLWIN_PAGEDOWN,
77  wxScrollWinEventHandler( WX_VIEW_CONTROLS::onScroll ), NULL, this );
78 
79  m_panTimer.SetOwner( this );
80  this->Connect( wxEVT_TIMER,
81  wxTimerEventHandler( WX_VIEW_CONTROLS::onTimer ), NULL, this );
82 }
VIEW_CONTROLS(VIEW *aView)
void onButton(wxMouseEvent &aEvent)
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.
virtual KIGFX::WX_VIEW_CONTROLS::~WX_VIEW_CONTROLS ( )
inlinevirtual

Definition at line 50 of file wx_view_controls.h.

51  {}

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 267 of file view_controls.h.

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

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

268  {
269  m_settings.m_cursorCaptured = aEnabled;
270  }
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 478 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().

479 {
480  const VECTOR2I& screenSize = m_view->GetGAL()->GetScreenPixelSize();
481  VECTOR2I screenCenter( screenSize / 2 );
482 
483  if( GetMousePosition( false ) != screenCenter )
484  {
486  m_parentPanel->WarpPointer( KiROUND( screenSize.x / 2 ), KiROUND( screenSize.y / 2 ) );
487  }
488 }
static int KiROUND(double v)
KiROUND rounds a floating point number to an int using "round halfway cases away from zero"...
Definition: common.h:107
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:565
GAL * GetGAL() const
Function GetGAL() Returns the GAL this view is using to draw graphical primitives.
Definition: view.h:177
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.

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

Referenced by EDA_DRAW_PANEL::SetEnableAutoPan(), 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 300 of file view_controls.h.

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

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

301  {
302  m_settings.m_warpCursor = aEnable;
303  }
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 319 of file view_controls.h.

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

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

320  {
322  }
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

Function ForceCursorPosition() Places the cursor immediately at a given point.

Mouse movement is ignored.

Parameters
aEnabledenable forced cursor position
aPositionthe position (world coordinates).

Definition at line 223 of file view_controls.h.

References KIGFX::VC_SETTINGS::m_forceCursorPosition, KIGFX::VC_SETTINGS::m_forcedPosition, and KIGFX::VIEW_CONTROLS::m_settings.

Referenced by KIGFX::VIEW_CONTROLS::ApplySettings(), TOOL_MANAGER::dispatchContextMenu(), SELECTION_TOOL::findMove(), ROUTER_TOOL::finishInteractive(), ROUTER_TOOL::InlineDrag(), PICKER_TOOL::Main(), EDIT_TOOL::Main(), POINT_EDITOR::OnSelectionChange(), ROUTER_TOOL::performDragging(), LENGTH_TUNER_TOOL::performTuning(), ROUTER_TOOL::prepareInteractive(), POINT_EDITOR::setEditedPoint(), PNS::TOOL_BASE::updateEndItem(), and PNS::TOOL_BASE::updateStartItem().

224  {
226  m_settings.m_forcedPosition = aPosition;
227  }
VC_SETTINGS m_settings
Current VIEW_CONTROLS settings
VECTOR2D m_forcedPosition
Forced cursor position (world coordinates)
Definition: view_controls.h:58
bool m_forceCursorPosition
Is the forced cursor position enabled
Definition: view_controls.h:61
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 243 of file view_controls.h.

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

Referenced by TOOL_MANAGER::dispatchContextMenu().

244  {
246  }
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 426 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().

427 {
429  {
431  }
432  else
433  {
434  return GetRawCursorPosition( aEnableSnapping );
435  }
436 }
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.

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

Referenced by POINT_EDITOR::addCorner(), CenterOnCursor(), TOOL_MANAGER::dispatchContextMenu(), PCB_TOOL::doInteractiveItemPlacement(), DRAWING_TOOL::drawArc(), DRAWING_TOOL::DrawDimension(), MICROWAVE_TOOL::drawMicrowaveInductor(), DRAWING_TOOL::drawSegment(), MODULE_EDITOR_TOOLS::EnumeratePads(), SELECTION_TOOL::findMove(), EDA_DRAW_FRAME::GetCrossHairPosition(), ROUTER_TOOL::InlineDrag(), EDIT_TOOL::Main(), ROUTER_TOOL::mainLoop(), DRAWING_TOOL::make45DegLine(), EDIT_TOOL::MeasureTool(), POINT_EDITOR::OnSelectionChange(), DRAWING_TOOL::PlaceDXF(), PCB_EDITOR_CONTROL::PlaceModule(), PCB_EDITOR_CONTROL::PlaceTarget(), DRAWING_TOOL::PlaceText(), PCBNEW_CONTROL::ResetCoords(), DRAWING_TOOL::runPolygonEventLoop(), DRAWING_TOOL::SetAnchor(), PNS::TOOL_BASE::updateEndItem(), EDIT_TOOL::updateModificationPoint(), PNS::TOOL_BASE::updateStartItem(), and COMMON_TOOLS::ZoomInOut().

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 405 of file wx_view_controls.cpp.

References m_parentPanel, KIGFX::VIEW_CONTROLS::m_view, KIGFX::VIEW::ToWorld(), wxPoint::x, and wxPoint::y.

Referenced by CenterOnCursor().

406 {
407  wxPoint msp = wxGetMousePosition();
408  m_parentPanel->ScreenToClient( &msp.x, &msp.y );
409  VECTOR2D screenPos( msp.x, msp.y );
410 
411  return aWorldCoordinates ? m_view->ToWorld( screenPos ) : screenPos;
412 }
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:441
VIEW * m_view
Pointer to controlled VIEW.
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 414 of file wx_view_controls.cpp.

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

Referenced by GetCursorPosition().

415 {
416  if( aEnableSnapping )
417  {
418  return m_view->GetGAL()->GetGridPoint( m_cursorPos );
419  }
420  else
421  {
422  return m_cursorPos;
423  }
424 }
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:177
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 353 of file view_controls.h.

References KIGFX::VIEW_CONTROLS::m_settings.

Referenced by TOOL_MANAGER::saveViewControls().

354  {
355  return m_settings;
356  }
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 491 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().

492 {
493  VECTOR2D p( aEvent.GetX(), aEvent.GetY() );
494 
495  // Compute areas where autopanning is active
496  double borderStart = std::min( m_settings.m_autoPanMargin * m_view->GetScreenPixelSize().x,
498  double borderEndX = m_view->GetScreenPixelSize().x - borderStart;
499  double borderEndY = m_view->GetScreenPixelSize().y - borderStart;
500 
501  if( p.x < borderStart )
502  m_panDirection.x = -( borderStart - p.x );
503  else if( p.x > borderEndX )
504  m_panDirection.x = ( p.x - borderEndX );
505  else
506  m_panDirection.x = 0;
507 
508  if( p.y < borderStart )
509  m_panDirection.y = -( borderStart - p.y );
510  else if( p.y > borderEndY )
511  m_panDirection.y = ( p.y - borderEndY );
512  else
513  m_panDirection.y = 0;
514 
515  bool borderHit = ( m_panDirection.x != 0 || m_panDirection.y != 0 );
516 
517  switch( m_state )
518  {
519  case AUTO_PANNING:
520  if( !borderHit )
521  {
522  m_panTimer.Stop();
523  m_state = IDLE;
524 
525  return false;
526  }
527 
528  return true;
529  break;
530 
531  case IDLE:
532  if( borderHit )
533  {
535  m_panTimer.Start( (int) ( 250.0 / 60.0 ) );
536 
537  return true;
538  }
539 
540  return false;
541  break;
542 
543  case DRAG_PANNING:
544  return false;
545  }
546 
547  wxASSERT_MSG( false, wxT( "This line should never be reached" ) );
548  return false; // Should not be reached, just avoid the compiler warnings..
549 }
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:1028
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 277 of file view_controls.h.

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

278  {
280  }
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 309 of file view_controls.h.

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

Referenced by onWheel(), and COMMON_TOOLS::ZoomInOut().

310  {
311  return m_settings.m_warpCursor;
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 bool KIGFX::VIEW_CONTROLS::IsMousewheelPanEnabled ( ) const
inlinevirtualinherited

Function IsMousewheelPanEnabled()

Returns
the current setting for mousewheel panning

Definition at line 328 of file view_controls.h.

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

329  {
331  }
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 224 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().

225 {
226  switch( m_state )
227  {
228  case IDLE:
229  case AUTO_PANNING:
230  if( aEvent.MiddleDown() ||
231  ( aEvent.LeftDown() && m_settings.m_panWithLeftButton ) ||
232  ( aEvent.RightDown() && m_settings.m_panWithRightButton ) )
233  {
234  m_dragStartPoint = VECTOR2D( aEvent.GetX(), aEvent.GetY() );
237  }
238 
239  if( aEvent.LeftUp() )
240  m_state = IDLE; // Stop autopanning when user release left mouse button
241 
242  break;
243 
244  case DRAG_PANNING:
245  if( aEvent.MiddleUp() || aEvent.LeftUp() || aEvent.RightUp() )
246  m_state = IDLE;
247 
248  break;
249  }
250 
251  aEvent.Skip();
252 }
const VECTOR2D & GetCenter() const
Function GetCenter() Returns the center point of this VIEW (in world space coordinates) ...
Definition: view.h:316
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:588
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 255 of file wx_view_controls.cpp.

References m_parentPanel.

Referenced by WX_VIEW_CONTROLS().

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

Definition at line 261 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().

262 {
264  {
265  bool warp = false;
266  int x = aEvent.GetX();
267  int y = aEvent.GetY();
268  wxSize parentSize = m_parentPanel->GetClientSize();
269 
270  if( x < 0 )
271  {
272  x = 0;
273  warp = true;
274  }
275  else if( x >= parentSize.x )
276  {
277  x = parentSize.x - 1;
278  warp = true;
279  }
280 
281  if( y < 0 )
282  {
283  y = 0;
284  warp = true;
285  }
286  else if( y >= parentSize.y )
287  {
288  y = parentSize.y - 1;
289  warp = true;
290  }
291 
292  if( warp )
293  m_parentPanel->WarpPointer( x, y );
294  }
295 }
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 85 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().

86 {
87  bool isAutoPanning = false;
88  VECTOR2D mousePos( aEvent.GetX(), aEvent.GetY() );
89 
91  isAutoPanning = handleAutoPanning( aEvent );
92 
93  if( !isAutoPanning && aEvent.Dragging() )
94  {
95  if( m_state == DRAG_PANNING )
96  {
97  VECTOR2D d = m_dragStartPoint - mousePos;
98  VECTOR2D delta = m_view->ToWorld( d, false );
99 
100  m_view->SetCenter( m_lookStartPoint + delta );
101  aEvent.StopPropagation();
102  }
103  }
104 
105  if( m_updateCursor ) // do not update the cursor position if it was explicitly set
106  m_cursorPos = m_view->ToWorld( mousePos );
107  else
108  m_updateCursor = true;
109 
110  aEvent.Skip();
111 }
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:441
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:565
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 337 of file wx_view_controls.cpp.

References delta, dist, KIGFX::VIEW::GetBoundary(), KIGFX::VIEW::GetCenter(), BOX2< Vec >::GetLeft(), KIGFX::VIEW::GetScreenPixelSize(), BOX2< Vec >::GetTop(), 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().

338 {
339  const double linePanDelta = 0.05;
340  const double pagePanDelta = 0.5;
341 
342  int type = aEvent.GetEventType();
343  int dir = aEvent.GetOrientation();
344 
345  if( type == wxEVT_SCROLLWIN_THUMBTRACK )
346  {
347  VECTOR2D center = m_view->GetCenter();
348  const BOX2I& boundary = m_view->GetBoundary();
349 
350  if( dir == wxHORIZONTAL )
351  center.x = boundary.GetLeft() + aEvent.GetPosition() / m_scrollScale.x;
352  else
353  center.y = boundary.GetTop() + aEvent.GetPosition() / m_scrollScale.y;
354 
355  m_view->SetCenter( center );
356  }
357  else
358  {
359  double dist = 0;
360 
361  if( type == wxEVT_SCROLLWIN_PAGEUP )
362  dist = pagePanDelta;
363  else if( type == wxEVT_SCROLLWIN_PAGEDOWN )
364  dist = -pagePanDelta;
365  else if( type == wxEVT_SCROLLWIN_LINEUP )
366  dist = linePanDelta;
367  else if( type == wxEVT_SCROLLWIN_LINEDOWN )
368  dist = -linePanDelta;
369  else
370  {
371  wxASSERT( "Unhandled event type" );
372  return;
373  }
374 
375  VECTOR2D scroll = m_view->ToWorld( m_view->GetScreenPixelSize(), false ) * dist;
376 
377  double scrollX = 0.0;
378  double scrollY = 0.0;
379 
380  if ( dir == wxHORIZONTAL )
381  scrollX = -scroll.x;
382  else
383  scrollY = -scroll.y;
384 
385  VECTOR2D delta( scrollX, scrollY );
386 
388  }
389 
390  m_parentPanel->Refresh();
391 }
const VECTOR2D & GetCenter() const
Function GetCenter() Returns the center point of this VIEW (in world space coordinates) ...
Definition: view.h:316
const BOX2I & GetBoundary() const
Function GetBoundary()
Definition: view.h:284
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:441
static const int dist[10][10]
Definition: dist.cpp:57
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:192
void SetCenter(const VECTOR2D &aCenter)
Function SetCenter() Sets the center point of the VIEW (i.e.
Definition: view.cpp:565
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:1028
coord_type GetLeft() const
Definition: box2.h:191
void WX_VIEW_CONTROLS::onTimer ( wxTimerEvent &  WXUNUSEDaEvent)

Definition at line 298 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().

299 {
300  switch( m_state )
301  {
302  case AUTO_PANNING:
303  {
305  {
306  m_state = IDLE;
307  return;
308  }
309 
310 #if wxCHECK_VERSION( 3, 0, 0 )
311  if( !m_parentPanel->HasFocus() )
312  break;
313 #endif
314 
315  double borderSize = std::min( m_settings.m_autoPanMargin * m_view->GetScreenPixelSize().x,
317 
318  VECTOR2D dir( m_panDirection );
319 
320  if( dir.EuclideanNorm() > borderSize )
321  dir = dir.Resize( borderSize );
322 
323  dir = m_view->ToWorld( dir, false );
325 
326  refreshMouse();
327  }
328  break;
329 
330  case IDLE: // Just remove unnecessary warnings
331  case DRAG_PANNING:
332  break;
333  }
334 }
const VECTOR2D & GetCenter() const
Function GetCenter() Returns the center point of this VIEW (in world space coordinates) ...
Definition: view.h:316
float m_autoPanSpeed
How fast is panning when in auto mode
Definition: view_controls.h:82
void refreshMouse() const
Sends an event to refresh mouse position.
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:441
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:565
Panning with mouse button pressed.
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
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:1028
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 114 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, KIGFX::VIEW_CONTROLS::m_settings, m_timeStamp, KIGFX::VIEW_CONTROLS::m_view, max, min, KIGFX::VIEW::SetCenter(), KIGFX::VIEW::SetScale(), KIGFX::VIEW::ToWorld(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by WX_VIEW_CONTROLS().

115 {
116  const double wheelPanSpeed = 0.001;
117 
118  // mousewheelpan disabled:
119  // wheel + ctrl -> horizontal scrolling;
120  // wheel + shift -> vertical scrolling;
121  // wheel -> zooming;
122  // mousewheelpan enabled:
123  // wheel -> pan;
124  // wheel + ctrl -> zooming;
125  // wheel + shift -> horizontal scrolling.
126 
127  if( ( !m_settings.m_enableMousewheelPan && ( aEvent.ControlDown() || aEvent.ShiftDown() ) ) ||
128  ( m_settings.m_enableMousewheelPan && !aEvent.ControlDown() ) )
129  {
130  // Scrolling
131  VECTOR2D scrollVec = m_view->ToWorld( m_view->GetScreenPixelSize(), false ) *
132  ( (double) aEvent.GetWheelRotation() * wheelPanSpeed );
133  int axis = aEvent.GetWheelAxis();
134  double scrollX = 0.0;
135  double scrollY = 0.0;
136 
138  {
139  if ( axis == wxMOUSE_WHEEL_HORIZONTAL || aEvent.ShiftDown() )
140  scrollX = scrollVec.x;
141  else
142  scrollY = -scrollVec.y;
143  }
144  else
145  {
146  if( aEvent.ControlDown() )
147  scrollX = -scrollVec.x;
148  else
149  scrollY = -scrollVec.y;
150  }
151 
152  VECTOR2D delta( scrollX, scrollY );
153 
155  }
156  else
157  {
158  // Zooming
159  wxLongLong timeStamp = wxGetLocalTimeMillis();
160  double timeDiff = timeStamp.ToDouble() - m_timeStamp.ToDouble();
161  int rotation = aEvent.GetWheelRotation();
162  double zoomScale = 1.0;
163 
164 #ifdef __WXMAC__
165  // On Apple pointer devices, wheel events occur frequently and with
166  // smaller rotation values. For those devices, let's handle zoom
167  // based on the rotation amount rather than the time difference.
168 
169  // Unused
170  ( void )timeDiff;
171 
172  rotation = ( rotation > 0 ) ? std::min( rotation , 100 )
173  : std::max( rotation , -100 );
174 
175  double dscale = rotation * 0.01;
176  zoomScale = ( rotation > 0 ) ? (1 + dscale) : 1/(1 - dscale);
177 
178 #else
179 
180  m_timeStamp = timeStamp;
181 
182  // Set scaling speed depending on scroll wheel event interval
183  if( timeDiff < 500 && timeDiff > 0 )
184  {
185  zoomScale = 2.05 - timeDiff / 500;
186 
187  if( rotation < 0 )
188  zoomScale = 1.0 / zoomScale;
189  }
190  else
191  {
192  zoomScale = ( rotation > 0 ) ? 1.05 : 1/1.05;
193  }
194 #endif
195 
196  if( IsCursorWarpingEnabled() )
197  {
198  CenterOnCursor();
199  m_view->SetScale( m_view->GetScale() * zoomScale );
200  }
201  else
202  {
203  VECTOR2D anchor = m_view->ToWorld( VECTOR2D( aEvent.GetX(), aEvent.GetY() ) );
204  m_view->SetScale( m_view->GetScale() * zoomScale, anchor );
205  }
206  }
207 
208  aEvent.Skip();
209 }
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:316
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:441
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:247
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:565
VECTOR2< double > VECTOR2D
Definition: vector2d.h:588
#define max(a, b)
Definition: auxiliary.h:86
bool IsCursorWarpingEnabled() const
Function IsCursorWarpingEnabled()
const VECTOR2I & GetScreenPixelSize() const
Function GetScreenPixelSize() Returns the size of the our rendering area, in pixels.
Definition: view.cpp:1028
double GetScale() const
Function GetScale()
Definition: view.h:265
wxLongLong m_timeStamp
Used for determining time intervals between scroll & zoom events.
void CenterOnCursor() const override
Function CenterOnCursor() Sets the viewport center to the current cursor position and warps the curso...
#define min(a, b)
Definition: auxiliary.h:85
void WX_VIEW_CONTROLS::refreshMouse ( ) const
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 552 of file wx_view_controls.cpp.

References EVT_REFRESH_MOUSE, and m_parentPanel.

Referenced by onTimer(), and WarpCursor().

553 {
554  // Notify tools that the cursor position has changed in the world coordinates
555  wxMouseEvent moveEvent( EVT_REFRESH_MOUSE );
556 
557  // Set the modifiers state
558 #if wxCHECK_VERSION( 3, 0, 0 )
559  moveEvent.SetControlDown( wxGetKeyState( WXK_CONTROL ) );
560  moveEvent.SetShiftDown( wxGetKeyState( WXK_SHIFT ) );
561  moveEvent.SetAltDown( wxGetKeyState( WXK_ALT ) );
562 #else
563  // wx <3.0 do not have accessors, but the fields are exposed
564  moveEvent.m_controlDown = wxGetKeyState( WXK_CONTROL );
565  moveEvent.m_shiftDown = wxGetKeyState( WXK_SHIFT );
566  moveEvent.m_altDown = wxGetKeyState( WXK_ALT );
567 #endif
568 
569  wxPostEvent( m_parentPanel, moveEvent );
570 }
static const wxEventType EVT_REFRESH_MOUSE
Event that forces mouse move event in the dispatcher (eg.
wxScrolledCanvas * m_parentPanel
Panel that is affected by VIEW_CONTROLS.
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 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
Structure to keep VIEW_CONTROLS settings for easy store/restore operations
Definition: view_controls.h:44
static LIB_PART * dummy()
Used when a LIB_PART is not found in library to draw a dummy shape This component is a 400 mils squar...
void KIGFX::VIEW_CONTROLS::SetAdditionalPanButtons ( bool  aLeft = false,
bool  aRight = false 
)
inlineinherited

Definition at line 340 of file view_controls.h.

References KIGFX::VC_SETTINGS::m_panWithLeftButton, KIGFX::VC_SETTINGS::m_panWithRightButton, and KIGFX::VIEW_CONTROLS::m_settings.

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

341  {
344  }
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.

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

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.

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

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::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 439 of file wx_view_controls.cpp.

References m_cursorPos, m_updateCursor, and WarpCursor().

440 {
441  m_updateCursor = false;
442  WarpCursor( aPosition, true, aWarpView );
443  m_cursorPos = aPosition;
444 }
bool m_updateCursor
Flag deciding whether the cursor position should be calculated using the mouse position.
void WarpCursor(const VECTOR2D &aPosition, bool aWorldCoordinates=false, bool aWarpView=false) const override
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 394 of file wx_view_controls.cpp.

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

395 {
396  if( aEnabled && !m_settings.m_grabMouse )
397  m_parentPanel->CaptureMouse();
398  else if( !aEnabled && m_settings.m_grabMouse )
399  m_parentPanel->ReleaseMouse();
400 
401  VIEW_CONTROLS::SetGrabMouse( aEnabled );
402 }
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(), DRAWING_TOOL::PlaceDXF(), PCB_EDITOR_CONTROL::PlaceModule(), 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:177
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 573 of file wx_view_controls.cpp.

References BOX2< Vec >::Centre(), KIGFX::VIEW::GetBoundary(), BOX2< Vec >::GetHeight(), BOX2< Vec >::GetLeft(), BOX2< Vec >::GetTop(), KIGFX::VIEW::GetViewport(), BOX2< Vec >::GetWidth(), 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().

574 {
575  const BOX2D viewport = m_view->GetViewport();
576  const BOX2I& boundary = m_view->GetBoundary();
577 
578  m_scrollScale.x = 2e3 / viewport.GetWidth(); // TODO it does not have to be updated so often
579  m_scrollScale.y = 2e3 / viewport.GetHeight();
580  VECTOR2I newScroll( ( viewport.Centre().x - boundary.GetLeft() ) * m_scrollScale.x,
581  ( viewport.Centre().y - boundary.GetTop() ) * m_scrollScale.y );
582 
583  // Adjust scrollbars only if it is needed. Otherwise there are cases when canvas is continuosly
584  // refreshed (Windows)
585  if( m_scrollPos != newScroll )
586  {
587  // Another example of wxWidgets being broken by design: scroll position is determined by the
588  // left (or top, if vertical) edge of the slider. Fortunately, slider size seems to be constant
589  // (at least for wxGTK and wxMSW), so we have to add its size to allow user to scroll the workspace
590  // till the end.
591 
592  m_parentPanel->SetScrollbars( 1, 1,
593 #if defined(__LINUX__)
594  m_scrollScale.x * boundary.GetWidth() + 1623, m_scrollScale.y * boundary.GetHeight() + 1623,
595 #elif defined(__WIN32__) || defined(__WIN64__)
596  m_scrollScale.x * boundary.GetWidth() + 1377, m_scrollScale.y * boundary.GetHeight() + 741,
597 #else
598  m_scrollScale.x * boundary.GetWidth(), m_scrollScale.y * boundary.GetHeight(),
599 #endif
600  newScroll.x, newScroll.y, false );
601 
602  m_scrollPos = newScroll;
603  }
604 }
const BOX2I & GetBoundary() const
Function GetBoundary()
Definition: view.h:284
VIEW * m_view
Pointer to controlled VIEW.
Class BOX2 handles a 2-D bounding box, built on top of an origin point and size vector, both of templated class Vec.
Definition: box2.h:41
VECTOR2D m_scrollScale
Ratio used for scaling world coordinates to scrollbar position.
coord_type GetTop() const
Definition: box2.h:192
coord_type GetWidth() const
Definition: box2.h:185
BOX2D GetViewport() const
Function GetViewport() Returns the current viewport visible area rectangle.
Definition: view.cpp:502
Vec Centre() const
Definition: box2.h:67
coord_type GetHeight() const
Definition: box2.h:186
wxScrolledCanvas * m_parentPanel
Panel that is affected by VIEW_CONTROLS.
VECTOR2I m_scrollPos
Current scrollbar position.
coord_type GetLeft() const
Definition: box2.h:191
void WX_VIEW_CONTROLS::WarpCursor ( const VECTOR2D aPosition,
bool  aWorldCoordinates = false,
bool  aWarpView = false 
) const
overridevirtual

Implements KIGFX::VIEW_CONTROLS.

Definition at line 447 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().

449 {
450  if( aWorldCoordinates )
451  {
452  const VECTOR2I& screenSize = m_view->GetGAL()->GetScreenPixelSize();
453  BOX2I screen( VECTOR2I( 0, 0 ), screenSize );
454  VECTOR2D screenPos = m_view->ToScreen( aPosition );
455 
456  if( !screen.Contains( screenPos ) )
457  {
458  if( aWarpView )
459  {
460  m_view->SetCenter( aPosition );
461  m_parentPanel->WarpPointer( screenSize.x / 2, screenSize.y / 2 );
462  }
463  }
464  else
465  {
466  m_parentPanel->WarpPointer( screenPos.x, screenPos.y );
467  }
468  }
469  else
470  {
471  m_parentPanel->WarpPointer( aPosition.x, aPosition.y );
472  }
473 
474  refreshMouse();
475 }
void refreshMouse() const
Sends an event to refresh mouse position.
VIEW * m_view
Pointer to controlled VIEW.
VECTOR2< int > VECTOR2I
Definition: vector2d.h:589
void SetCenter(const VECTOR2D &aCenter)
Function SetCenter() Sets the center point of the VIEW (i.e.
Definition: view.cpp:565
GAL * GetGAL() const
Function GetGAL() Returns the GAL this view is using to draw graphical primitives.
Definition: view.h:177
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:460

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 98 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 154 of file wx_view_controls.h.

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

VECTOR2D KIGFX::WX_VIEW_CONTROLS::m_dragStartPoint
private

Stores information about point where dragging has started.

Definition at line 133 of file wx_view_controls.h.

Referenced by onButton(), and onMotion().

VECTOR2D KIGFX::WX_VIEW_CONTROLS::m_lookStartPoint
private

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

Definition at line 136 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 139 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 145 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 151 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 148 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 127 of file wx_view_controls.h.

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

wxLongLong KIGFX::WX_VIEW_CONTROLS::m_timeStamp
private

Used for determining time intervals between scroll & zoom events.

Definition at line 142 of file wx_view_controls.h.

Referenced by onWheel().

bool KIGFX::WX_VIEW_CONTROLS::m_updateCursor
private

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

Definition at line 157 of file wx_view_controls.h.

Referenced by onMotion(), and SetCursorPosition().

VIEW* KIGFX::VIEW_CONTROLS::m_view
protectedinherited

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