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, bool aTriggeredByArrows) 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...
 
void ForceCursorPosition (bool aEnabled, const VECTOR2D &aPosition=VECTOR2D(0, 0)) override
 Function ForceCursorPosition() Places the cursor immediately at a given point. More...
 
VECTOR2D GetCursorPosition () const
 Returns the current cursor position in world coordinates. More...
 
virtual VECTOR2D GetCursorPosition (bool aEnableSnapping) const=0
 Returns the current cursor position in world coordinates. More...
 
virtual void SetSnapping (bool aEnabled)
 Function SetSnapping() Enables/disables snapping cursor to grid. More...
 
virtual bool GetSnappingState ()
 
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...
 
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...
 
bool m_cursorWarped
 

Application warped the cursor, not the user (keyboard)

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

◆ STATE

Possible states for WX_VIEW_CONTROLS.

Enumerator
IDLE 
DRAG_PANNING 

Nothing is happening.

AUTO_PANNING 

Panning with mouse button pressed.

Definition at line 111 of file wx_view_controls.h.

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

Constructor & Destructor Documentation

◆ WX_VIEW_CONTROLS()

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

Definition at line 56 of file wx_view_controls.cpp.

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 
93  m_parentPanel->Connect( wxEVT_SCROLLWIN_BOTTOM,
94  wxScrollWinEventHandler( WX_VIEW_CONTROLS::onScroll ), NULL, this );
95  m_parentPanel->Connect( wxEVT_SCROLLWIN_TOP,
96  wxScrollWinEventHandler( WX_VIEW_CONTROLS::onScroll ), NULL, this );
97  m_parentPanel->Connect( wxEVT_SCROLLWIN_LINEUP,
98  wxScrollWinEventHandler( WX_VIEW_CONTROLS::onScroll ), NULL, this );
99  m_parentPanel->Connect( wxEVT_SCROLLWIN_LINEDOWN,
100  wxScrollWinEventHandler( WX_VIEW_CONTROLS::onScroll ), NULL, this );
101 
103 
104  m_cursorWarped = false;
105 
106  m_panTimer.SetOwner( this );
107  this->Connect( wxEVT_TIMER,
108  wxTimerEventHandler( WX_VIEW_CONTROLS::onTimer ), NULL, this );
109 
111 }
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.
VC_SETTINGS m_settings
Current VIEW_CONTROLS settings
VECTOR2D m_scrollScale
Ratio used for scaling world coordinates to scrollbar position.
void onWheel(wxMouseEvent &aEvent)
Handler functions.
bool m_cursorWarped
Application warped the cursor, not the user (keyboard)
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.
bool m_lastKeyboardCursorPositionValid
Is last cursor motion event coming from keyboard arrow cursor motion action
Definition: view_controls.h:97
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.

References GetZoomControllerForPlatform(), KIGFX::VIEW_CONTROLS::m_cursorWarped, KIGFX::VC_SETTINGS::m_lastKeyboardCursorPositionValid, m_panTimer, m_parentPanel, KIGFX::VIEW_CONTROLS::m_settings, m_zoomController, onButton(), onEnter(), onLeave(), onMotion(), onScroll(), onTimer(), and onWheel().

◆ ~WX_VIEW_CONTROLS()

WX_VIEW_CONTROLS::~WX_VIEW_CONTROLS ( )
virtual

Definition at line 114 of file wx_view_controls.cpp.

115 {
116 }

Member Function Documentation

◆ ApplySettings()

void VIEW_CONTROLS::ApplySettings ( const VC_SETTINGS aSettings)
inherited

Applies VIEW_CONTROLS settings from an object

Definition at line 76 of file view_controls.cpp.

77 {
78  ShowCursor( aSettings.m_showCursor );
79  CaptureCursor( aSettings.m_cursorCaptured );
80  SetSnapping( aSettings.m_snappingEnabled );
81  SetGrabMouse( aSettings.m_grabMouse );
82  SetAutoPan( aSettings.m_autoPanEnabled );
83  SetAutoPanMargin( aSettings.m_autoPanMargin );
84  SetAutoPanSpeed( aSettings.m_autoPanSpeed );
86 }
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

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().

◆ CaptureCursor()

◆ CenterOnCursor()

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

533 {
534  const VECTOR2I& screenSize = m_view->GetGAL()->GetScreenPixelSize();
535  VECTOR2I screenCenter( screenSize / 2 );
536 
537  if( GetMousePosition( false ) != screenCenter )
538  {
540  m_parentPanel->WarpPointer( KiROUND( screenSize.x / 2 ), KiROUND( screenSize.y / 2 ) );
541  }
542 }
static int KiROUND(double v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: common.h:118
VECTOR2D GetMousePosition(bool aWorldCoordinates=true) const override
Function GetMousePosition() Returns the current mouse pointer position.
GAL * GetGAL() const
Function GetGAL() Returns the GAL this view is using to draw graphical primitives.
Definition: view.h:180
VIEW * m_view
Pointer to controlled VIEW.
const VECTOR2I & GetScreenPixelSize() const
Returns GAL canvas size in pixels.
void SetCenter(const VECTOR2D &aCenter)
Function SetCenter() Sets the center point of the VIEW (i.e.
Definition: view.cpp:601
wxScrolledCanvas * m_parentPanel
Panel that is affected by VIEW_CONTROLS.
VECTOR2D GetCursorPosition() const
Returns the current cursor position in world coordinates.

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().

◆ EnableAutoPan()

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

167  {
169  }
VC_SETTINGS m_settings
Current VIEW_CONTROLS settings
bool m_autoPanSettingEnabled
Flag for turning on autopanning
Definition: view_controls.h:76

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

Referenced by EDA_DRAW_FRAME::UseGalCanvas().

◆ EnableCursorWarping()

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

325  {
326  m_settings.m_warpCursor = aEnable;
327  }
VC_SETTINGS m_settings
Current VIEW_CONTROLS settings
bool m_warpCursor
If the cursor is allowed to be warped
Definition: view_controls.h:85

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

Referenced by EDA_DRAW_FRAME::UseGalCanvas().

◆ EnableMousewheelPan()

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

344  {
346  }
bool m_enableMousewheelPan
Mousewheel (2-finger touchpad) panning
Definition: view_controls.h:88
VC_SETTINGS m_settings
Current VIEW_CONTROLS settings

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

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

◆ ForceCursorPosition()

void WX_VIEW_CONTROLS::ForceCursorPosition ( bool  aEnabled,
const VECTOR2D aPosition = VECTOR2D( 0, 0 ) 
)
overridevirtual

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

Mouse movement is ignored.

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

Reimplemented from KIGFX::VIEW_CONTROLS.

Definition at line 690 of file wx_view_controls.cpp.

691 {
693  m_settings.m_forcedPosition = aPosition;
694 }
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

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

◆ ForcedCursorPosition()

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

268  {
270  }
VC_SETTINGS m_settings
Current VIEW_CONTROLS settings
bool m_forceCursorPosition
Is the forced cursor position enabled
Definition: view_controls.h:61

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

◆ GetCursorPosition() [1/4]

VECTOR2D KIGFX::VIEW_CONTROLS::GetCursorPosition
inline

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

210  {
212  }
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.

◆ GetCursorPosition() [2/4]

virtual VECTOR2D KIGFX::VIEW_CONTROLS::GetCursorPosition

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.

Parameters
aEnableSnappingselects whether cursor position should be snapped to the grid.
Returns
The current cursor position in world coordinates.

◆ GetCursorPosition() [3/4]

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

452 {
454  {
456  }
457  else
458  {
459  return GetRawCursorPosition( aEnableSnapping );
460  }
461 }
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

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().

◆ GetCursorPosition() [4/4]

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

210  {
212  }
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.

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

Referenced by EE_POINT_EDITOR::addCorner(), POINT_EDITOR::addCorner(), EE_POINT_EDITOR::addCornerCondition(), SCH_EDIT_TOOL::BreakWire(), CenterOnCursor(), TOOL_MANAGER::dispatchContextMenu(), SCH_WIRE_BUS_TOOL::doDrawSegments(), PCB_TOOL_BASE::doInteractiveItemPlacement(), SCH_DRAWING_TOOLS::doPlaceComponent(), SCH_DRAWING_TOOLS::doSingleClickPlace(), LIB_DRAWING_TOOLS::doTwoClickPlace(), SCH_DRAWING_TOOLS::doTwoClickPlace(), MICROWAVE_TOOL::drawMicrowaveInductor(), LIB_DRAWING_TOOLS::DrawShape(), SCH_DRAWING_TOOLS::DrawSheet(), MODULE_EDITOR_TOOLS::EnumeratePads(), SELECTION_TOOL::findMove(), EDA_DRAW_FRAME::GetCrossHairPosition(), SCH_EDITOR_CONTROL::HighlightNet(), ROUTER_TOOL::InlineDrag(), SCH_MOVE_TOOL::Main(), EE_POINT_EDITOR::Main(), LIB_MOVE_TOOL::Main(), EE_PICKER_TOOL::Main(), EDIT_TOOL::Main(), ROUTER_TOOL::mainLoop(), LIB_DRAWING_TOOLS::PlaceAnchor(), SCH_DRAWING_TOOLS::PlaceImage(), DRAWING_TOOL::PlaceImportedGraphics(), PCB_EDITOR_CONTROL::PlaceModule(), PCB_EDITOR_CONTROL::PlaceTarget(), DRAWING_TOOL::PlaceText(), SCH_EDIT_TOOL::RepeatDrawItem(), EE_SELECTION_TOOL::RequestSelection(), CVPCB_CONTROL::ResetCoords(), GERBVIEW_CONTROL::ResetCoords(), PCBNEW_CONTROL::ResetCoords(), EE_SELECTION_TOOL::SelectNode(), DRAWING_TOOL::SetAnchor(), LIB_MOVE_TOOL::updateModificationPoint(), SCH_MOVE_TOOL::updateModificationPoint(), EDIT_TOOL::updateModificationPoint(), and PNS::TOOL_BASE::updateStartItem().

◆ GetMousePosition()

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

430 {
431  wxPoint msp = getMouseScreenPosition();
432  VECTOR2D screenPos( msp.x, msp.y );
433 
434  return aWorldCoordinates ? m_view->ToWorld( screenPos ) : screenPos;
435 }
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:475
wxPoint getMouseScreenPosition() const
Gets the cursor position in the screen coordinates.
VIEW * m_view
Pointer to controlled VIEW.

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

Referenced by CenterOnCursor().

◆ getMouseScreenPosition()

wxPoint WX_VIEW_CONTROLS::getMouseScreenPosition ( ) const
private

Gets the cursor position in the screen coordinates.

Definition at line 645 of file wx_view_controls.cpp.

646 {
647  wxPoint msp = wxGetMousePosition();
648  m_parentPanel->ScreenToClient( &msp.x, &msp.y );
649  return msp;
650 }
wxScrolledCanvas * m_parentPanel
Panel that is affected by VIEW_CONTROLS.

References m_parentPanel.

Referenced by GetMousePosition(), and refreshMouse().

◆ GetRawCursorPosition()

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

439 {
440  if( aEnableSnapping )
441  {
442  return m_view->GetGAL()->GetGridPoint( m_cursorPos );
443  }
444  else
445  {
446  return m_cursorPos;
447  }
448 }
GAL * GetGAL() const
Function GetGAL() Returns the GAL this view is using to draw graphical primitives.
Definition: view.h:180
VIEW * m_view
Pointer to controlled VIEW.
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)

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

Referenced by GetCursorPosition().

◆ GetSettings()

const VC_SETTINGS& KIGFX::VIEW_CONTROLS::GetSettings ( ) const
inlineinherited

Returns the current VIEW_CONTROLS settings

Definition at line 377 of file view_controls.h.

378  {
379  return m_settings;
380  }
VC_SETTINGS m_settings
Current VIEW_CONTROLS settings

References KIGFX::VIEW_CONTROLS::m_settings.

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

◆ GetSnappingState()

virtual bool KIGFX::VIEW_CONTROLS::GetSnappingState ( )
inlinevirtualinherited
Returns
the current state of the snapping cursor to grid.

Definition at line 135 of file view_controls.h.

136  {
138  }
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

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

◆ handleAutoPanning()

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

546 {
547  VECTOR2I p( aEvent.GetX(), aEvent.GetY() );
549 
551  {
552  // last cursor move event came from keyboard cursor control. If auto-panning is enabled and
553  // the next position is inside the autopan zone, check if it really came from a mouse event, otherwise
554  // disable autopan temporarily. Also temporaly disable autopan if the cursor is in the autopan zone
555  // because the application warped the cursor.
556 
557  m_cursorWarped = false;
558  return true;
559  }
560 
561  m_cursorWarped = false;
562 
563  // Compute areas where autopanning is active
566  int borderEndX = m_view->GetScreenPixelSize().x - borderStart;
567  int borderEndY = m_view->GetScreenPixelSize().y - borderStart;
568 
569  if( p.x < borderStart )
570  m_panDirection.x = -( borderStart - p.x );
571  else if( p.x > borderEndX )
572  m_panDirection.x = ( p.x - borderEndX );
573  else
574  m_panDirection.x = 0;
575 
576  if( p.y < borderStart )
577  m_panDirection.y = -( borderStart - p.y );
578  else if( p.y > borderEndY )
579  m_panDirection.y = ( p.y - borderEndY );
580  else
581  m_panDirection.y = 0;
582 
583  bool borderHit = ( m_panDirection.x != 0 || m_panDirection.y != 0 );
584 
585  switch( m_state )
586  {
587  case AUTO_PANNING:
588  if( !borderHit )
589  {
590  m_panTimer.Stop();
591  m_state = IDLE;
592 
593  return false;
594  }
595 
596  return true;
597  break;
598 
599  case IDLE:
600  if( borderHit )
601  {
603  m_panTimer.Start( (int) ( 250.0 / 60.0 ) );
604 
605  return true;
606  }
607 
608  return false;
609  break;
610 
611  case DRAG_PANNING:
612  return false;
613  }
614 
615  wxASSERT_MSG( false, wxT( "This line should never be reached" ) );
616  return false; // Should not be reached, just avoid the compiler warnings..
617 }
VC_SETTINGS m_settings
Current VIEW_CONTROLS settings
VIEW * m_view
Pointer to controlled VIEW.
VECTOR2D m_lastKeyboardCursorPosition
Position of the above event
Panning with mouse button pressed.
const VECTOR2I & GetScreenPixelSize() const
Function GetScreenPixelSize() Returns the size of the our rendering area, in pixels.
Definition: view.cpp:1176
float m_autoPanMargin
Distance from cursor to VIEW edge when panning is active
Definition: view_controls.h:79
bool m_cursorWarped
Application warped the cursor, not the user (keyboard)
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:494
VECTOR2D m_panDirection
Current direction of panning (only autopanning mode)
bool m_lastKeyboardCursorPositionValid
Is last cursor motion event coming from keyboard arrow cursor motion action
Definition: view_controls.h:97
STATE m_state
Current state of VIEW_CONTROLS.
#define min(a, b)
Definition: auxiliary.h:85
wxTimer m_panTimer
Timer repsonsible for handling autopanning.

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

Referenced by onMotion().

◆ IsCursorPositionForced()

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

302  {
304  }
VC_SETTINGS m_settings
Current VIEW_CONTROLS settings
bool m_forceCursorPosition
Is the forced cursor position enabled
Definition: view_controls.h:61

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

◆ IsCursorShown()

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.

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

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

◆ IsCursorWarpingEnabled()

bool KIGFX::VIEW_CONTROLS::IsCursorWarpingEnabled ( ) const
inlineinherited

Function IsCursorWarpingEnabled()

Returns
the current setting for cursor warping.

Definition at line 333 of file view_controls.h.

334  {
335  return m_settings.m_warpCursor;
336  }
VC_SETTINGS m_settings
Current VIEW_CONTROLS settings
bool m_warpCursor
If the cursor is allowed to be warped
Definition: view_controls.h:85

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

Referenced by onWheel().

◆ IsMousewheelPanEnabled()

virtual bool KIGFX::VIEW_CONTROLS::IsMousewheelPanEnabled ( ) const
inlinevirtualinherited

Function IsMousewheelPanEnabled()

Returns
the current setting for mousewheel panning

Definition at line 352 of file view_controls.h.

353  {
355  }
bool m_enableMousewheelPan
Mousewheel (2-finger touchpad) panning
Definition: view_controls.h:88
VC_SETTINGS m_settings
Current VIEW_CONTROLS settings

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

◆ onButton()

void WX_VIEW_CONTROLS::onButton ( wxMouseEvent &  aEvent)

Definition at line 243 of file wx_view_controls.cpp.

244 {
245  switch( m_state )
246  {
247  case IDLE:
248  case AUTO_PANNING:
249  if( aEvent.MiddleDown() ||
250  ( aEvent.LeftDown() && m_settings.m_panWithLeftButton ) ||
251  ( aEvent.RightDown() && m_settings.m_panWithRightButton ) )
252  {
253  m_dragStartPoint = VECTOR2D( aEvent.GetX(), aEvent.GetY() );
256  }
257 
258  if( aEvent.LeftUp() )
259  m_state = IDLE; // Stop autopanning when user release left mouse button
260 
261  break;
262 
263  case DRAG_PANNING:
264  if( aEvent.MiddleUp() || aEvent.LeftUp() || aEvent.RightUp() )
265  m_state = IDLE;
266 
267  break;
268  }
269 
270  aEvent.Skip();
271 }
VECTOR2D m_lookStartPoint
Stores information about the center of viewport when dragging has started.
const VECTOR2D & GetCenter() const
Function GetCenter() Returns the center point of this VIEW (in world space coordinates)
Definition: view.h:339
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

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().

◆ onEnter()

void WX_VIEW_CONTROLS::onEnter ( wxMouseEvent &  WXUNUSEDaEvent)

Definition at line 274 of file wx_view_controls.cpp.

275 {
276  m_parentPanel->SetFocus();
277 }
wxScrolledCanvas * m_parentPanel
Panel that is affected by VIEW_CONTROLS.

References m_parentPanel.

Referenced by WX_VIEW_CONTROLS().

◆ onLeave()

void WX_VIEW_CONTROLS::onLeave ( wxMouseEvent &  WXUNUSEDaEvent)

Definition at line 280 of file wx_view_controls.cpp.

281 {
283  {
284  bool warp = false;
285  int x = aEvent.GetX();
286  int y = aEvent.GetY();
287  wxSize parentSize = m_parentPanel->GetClientSize();
288 
289  if( x < 0 )
290  {
291  x = 0;
292  warp = true;
293  }
294  else if( x >= parentSize.x )
295  {
296  x = parentSize.x - 1;
297  warp = true;
298  }
299 
300  if( y < 0 )
301  {
302  y = 0;
303  warp = true;
304  }
305  else if( y >= parentSize.y )
306  {
307  y = parentSize.y - 1;
308  warp = true;
309  }
310 
311  if( warp )
312  m_parentPanel->WarpPointer( x, y );
313  }
314 }
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

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

Referenced by WX_VIEW_CONTROLS().

◆ onMotion()

void WX_VIEW_CONTROLS::onMotion ( wxMouseEvent &  aEvent)

Definition at line 119 of file wx_view_controls.cpp.

120 {
121  bool isAutoPanning = false;
122  VECTOR2D mousePos( aEvent.GetX(), aEvent.GetY() );
123 
125  isAutoPanning = handleAutoPanning( aEvent );
126 
127  if( !isAutoPanning && aEvent.Dragging() )
128  {
129  if( m_state == DRAG_PANNING )
130  {
131  VECTOR2D d = m_dragStartPoint - mousePos;
132  VECTOR2D delta = m_view->ToWorld( d, false );
133 
135  aEvent.StopPropagation();
136  }
137  }
138 
139  if( m_updateCursor ) // do not update the cursor position if it was explicitly set
140  m_cursorPos = m_view->ToWorld( mousePos );
141  else
142  m_updateCursor = true;
143 
144  aEvent.Skip();
145 }
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:475
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:601
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)

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().

◆ onScroll()

void WX_VIEW_CONTROLS::onScroll ( wxScrollWinEvent &  aEvent)

Definition at line 356 of file wx_view_controls.cpp.

357 {
358  const double linePanDelta = 0.05;
359  const double pagePanDelta = 0.5;
360 
361  int type = aEvent.GetEventType();
362  int dir = aEvent.GetOrientation();
363 
364  if( type == wxEVT_SCROLLWIN_THUMBTRACK )
365  {
366  auto center = m_view->GetCenter();
367  const auto& boundary = m_view->GetBoundary();
368 
369  // Flip scroll direction in flipped view
370  const double xstart = ( m_view->IsMirroredX() ?
371  boundary.GetRight() : boundary.GetLeft() );
372  const double xdelta = ( m_view->IsMirroredX() ? -1 : 1 );
373 
374  if( dir == wxHORIZONTAL )
375  center.x = xstart + xdelta * ( aEvent.GetPosition() / m_scrollScale.x );
376  else
377  center.y = boundary.GetTop() + aEvent.GetPosition() / m_scrollScale.y;
378 
379  m_view->SetCenter( center );
380  }
381  else
382  {
383  double dist = 0;
384 
385  if( type == wxEVT_SCROLLWIN_PAGEUP )
386  dist = pagePanDelta;
387  else if( type == wxEVT_SCROLLWIN_PAGEDOWN )
388  dist = -pagePanDelta;
389  else if( type == wxEVT_SCROLLWIN_LINEUP )
390  dist = linePanDelta;
391  else if( type == wxEVT_SCROLLWIN_LINEDOWN )
392  dist = -linePanDelta;
393  else
394  {
395  wxASSERT( "Unhandled event type" );
396  return;
397  }
398 
399  VECTOR2D scroll = m_view->ToWorld( m_view->GetScreenPixelSize(), false ) * dist;
400 
401  double scrollX = 0.0;
402  double scrollY = 0.0;
403 
404  if ( dir == wxHORIZONTAL )
405  scrollX = -scroll.x;
406  else
407  scrollY = -scroll.y;
408 
409  VECTOR2D delta( scrollX, scrollY );
410 
412  }
413 
414  m_parentPanel->Refresh();
415 }
static const int dist[10][10]
Definition: ar_matrix.cpp:320
const BOX2D & GetBoundary() const
Function GetBoundary()
Definition: view.h:298
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:475
coord_type GetTop() const
Definition: box2.h:202
const VECTOR2D & GetCenter() const
Function GetCenter() Returns the center point of this VIEW (in world space coordinates)
Definition: view.h:339
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
void SetCenter(const VECTOR2D &aCenter)
Function SetCenter() Sets the center point of the VIEW (i.e.
Definition: view.cpp:601
const VECTOR2I & GetScreenPixelSize() const
Function GetScreenPixelSize() Returns the size of the our rendering area, in pixels.
Definition: view.cpp:1176
bool IsMirroredX() const
Function IsMirroredX() Returns true if view is flipped across the X axis.
Definition: view.h:230
wxScrolledCanvas * m_parentPanel
Panel that is affected by VIEW_CONTROLS.

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().

◆ onTimer()

void WX_VIEW_CONTROLS::onTimer ( wxTimerEvent &  WXUNUSEDaEvent)

Definition at line 317 of file wx_view_controls.cpp.

318 {
319  switch( m_state )
320  {
321  case AUTO_PANNING:
322  {
324  {
325  m_state = IDLE;
326  return;
327  }
328 
329 #if wxCHECK_VERSION( 3, 0, 0 )
330  if( !m_parentPanel->HasFocus() )
331  break;
332 #endif
333 
334  double borderSize = std::min( m_settings.m_autoPanMargin * m_view->GetScreenPixelSize().x,
336 
337  VECTOR2D dir( m_panDirection );
338 
339  if( dir.EuclideanNorm() > borderSize )
340  dir = dir.Resize( borderSize );
341 
342  dir = m_view->ToWorld( dir, false );
344 
345  refreshMouse();
346  }
347  break;
348 
349  case IDLE: // Just remove unnecessary warnings
350  case DRAG_PANNING:
351  break;
352  }
353 }
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:475
const VECTOR2D & GetCenter() const
Function GetCenter() Returns the center point of this VIEW (in world space coordinates)
Definition: view.h:339
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:601
Panning with mouse button pressed.
const VECTOR2I & GetScreenPixelSize() const
Function GetScreenPixelSize() Returns the size of the our rendering area, in pixels.
Definition: view.cpp:1176
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)
STATE m_state
Current state of VIEW_CONTROLS.
#define min(a, b)
Definition: auxiliary.h:85

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().

◆ onWheel()

void WX_VIEW_CONTROLS::onWheel ( wxMouseEvent &  aEvent)

Handler functions.

Definition at line 148 of file wx_view_controls.cpp.

149 {
150 #ifdef __WXGTK3__
151  if( aEvent.GetTimestamp() == m_lastTimestamp )
152  {
153  aEvent.Skip( false );
154  return;
155  }
156 
157  m_lastTimestamp = aEvent.GetTimestamp();
158 #endif
159 
160  const double wheelPanSpeed = 0.001;
161  const int axis = aEvent.GetWheelAxis();
162 
163  // mousewheelpan disabled:
164  // wheel + ctrl -> horizontal scrolling;
165  // wheel + shift -> vertical scrolling;
166  // wheel -> zooming;
167  // mousewheelpan enabled:
168  // wheel -> pan;
169  // wheel + ctrl -> zooming;
170  // wheel + shift -> horizontal scrolling.
171 
172  if( ( !m_settings.m_enableMousewheelPan && ( aEvent.ControlDown() || aEvent.ShiftDown() ) ) ||
173  ( m_settings.m_enableMousewheelPan && !aEvent.ControlDown() ) )
174  {
175  // Scrolling
176  VECTOR2D scrollVec = m_view->ToWorld( m_view->GetScreenPixelSize(), false ) *
177  ( (double) aEvent.GetWheelRotation() * wheelPanSpeed );
178  double scrollX = 0.0;
179  double scrollY = 0.0;
180 
182  {
183  if ( axis == wxMOUSE_WHEEL_HORIZONTAL || aEvent.ShiftDown() )
184  scrollX = scrollVec.x;
185  else
186  scrollY = -scrollVec.y;
187  }
188  else
189  {
190  if( aEvent.ControlDown() )
191  scrollX = -scrollVec.x;
192  else
193  scrollY = -scrollVec.y;
194  }
195 
196  VECTOR2D delta( scrollX, scrollY );
197 
199  refreshMouse();
200  }
201  else
202  {
203  // Restrict zoom handling to the vertical axis, otherwise horizontal
204  // scrolling events (e.g. touchpads and some mice) end up interpreted
205  // as vertical scroll events and confuse the user.
206  if( axis == wxMOUSE_WHEEL_VERTICAL )
207  {
208  const int rotation = aEvent.GetWheelRotation();
209  const double zoomScale = m_zoomController->GetScaleForRotation( rotation );
210 
211  if( IsCursorWarpingEnabled() )
212  {
213  CenterOnCursor();
214  m_view->SetScale( m_view->GetScale() * zoomScale );
215  }
216  else
217  {
218  const VECTOR2D anchor = m_view->ToWorld( VECTOR2D( aEvent.GetX(), aEvent.GetY() ) );
219  m_view->SetScale( m_view->GetScale() * zoomScale, anchor );
220  }
221  }
222  }
223 
224  // Do not skip this event, otherwise wxWidgets will fire
225  // 3 wxEVT_SCROLLWIN_LINEUP or wxEVT_SCROLLWIN_LINEDOWN (normal wxWidgets behavior)
226  // and we do not want that.
227  m_parentPanel->Refresh();
228 }
bool m_enableMousewheelPan
Mousewheel (2-finger touchpad) panning
Definition: view_controls.h:88
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:475
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.
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:601
VECTOR2< double > VECTOR2D
Definition: vector2d.h:586
const VECTOR2I & GetScreenPixelSize() const
Function GetScreenPixelSize() Returns the size of the our rendering area, in pixels.
Definition: view.cpp:1176
bool IsCursorWarpingEnabled() const
Function IsCursorWarpingEnabled()
void refreshMouse()
Sends an event to refresh mouse position.
wxScrolledCanvas * m_parentPanel
Panel that is affected by VIEW_CONTROLS.
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...

References CenterOnCursor(), delta, KIGFX::VIEW::GetCenter(), KIGFX::VIEW::GetScale(), KIGFX::VIEW::GetScreenPixelSize(), KIGFX::VIEW_CONTROLS::IsCursorWarpingEnabled(), KIGFX::VC_SETTINGS::m_enableMousewheelPan, m_lastTimestamp, m_parentPanel, 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().

◆ refreshMouse()

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

621 {
622  // Notify tools that the cursor position has changed in the world coordinates
623  wxMouseEvent moveEvent( EVT_REFRESH_MOUSE );
624  wxPoint msp = getMouseScreenPosition();
625  moveEvent.SetX( msp.x );
626  moveEvent.SetY( msp.y );
627 
628  // Set the modifiers state
629 #if wxCHECK_VERSION( 3, 0, 0 )
630  moveEvent.SetControlDown( wxGetKeyState( WXK_CONTROL ) );
631  moveEvent.SetShiftDown( wxGetKeyState( WXK_SHIFT ) );
632  moveEvent.SetAltDown( wxGetKeyState( WXK_ALT ) );
633 #else
634  // wx <3.0 do not have accessors, but the fields are exposed
635  moveEvent.m_controlDown = wxGetKeyState( WXK_CONTROL );
636  moveEvent.m_shiftDown = wxGetKeyState( WXK_SHIFT );
637  moveEvent.m_altDown = wxGetKeyState( WXK_ALT );
638 #endif
639 
640  m_cursorPos = m_view->ToWorld( VECTOR2D( msp.x, msp.y ) );
641  wxPostEvent( m_parentPanel, moveEvent );
642 }
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:475
wxPoint getMouseScreenPosition() const
Gets the cursor position in the screen coordinates.
VIEW * m_view
Pointer to controlled VIEW.
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)

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

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

◆ Reset()

void VIEW_CONTROLS::Reset ( )
virtualinherited

Function Reset() Restores the default VIEW_CONTROLS settings.

Definition at line 49 of file view_controls.cpp.

50 {
51  // Get the default settings from the default constructor
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

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

◆ SetAdditionalPanButtons()

void KIGFX::VIEW_CONTROLS::SetAdditionalPanButtons ( bool  aLeft = false,
bool  aRight = false 
)
inlineinherited

Definition at line 364 of file view_controls.h.

365  {
368  }
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

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

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

◆ SetAutoPan()

virtual void KIGFX::VIEW_CONTROLS::SetAutoPan ( bool  aEnabled)
inlinevirtualinherited

Function SetAutoPan Turns on/off auto panning (this feature is used when there is a tool active (eg.

drawing a track) and user moves mouse to the VIEW edge - then the view can be translated or not).

Parameters
aEnabledtells if the autopanning should be active.

Definition at line 156 of file view_controls.h.

157  {
158  m_settings.m_autoPanEnabled = aEnabled;
159  }
VC_SETTINGS m_settings
Current VIEW_CONTROLS settings
bool m_autoPanEnabled
Flag for turning on autopanning
Definition: view_controls.h:73

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

Referenced by KIGFX::VIEW_CONTROLS::ApplySettings(), SCH_WIRE_BUS_TOOL::doDrawSegments(), PCB_TOOL_BASE::doInteractiveItemPlacement(), SCH_DRAWING_TOOLS::doPlaceComponent(), LIB_DRAWING_TOOLS::doTwoClickPlace(), SCH_DRAWING_TOOLS::doTwoClickPlace(), DRAWING_TOOL::drawArc(), DRAWING_TOOL::DrawDimension(), MICROWAVE_TOOL::drawMicrowaveInductor(), DRAWING_TOOL::drawSegment(), LIB_DRAWING_TOOLS::DrawShape(), SCH_DRAWING_TOOLS::DrawSheet(), DRAWING_TOOL::drawZone(), ROUTER_TOOL::finishInteractive(), SCH_WIRE_BUS_TOOL::finishSegments(), ROUTER_TOOL::InlineDrag(), SCH_MOVE_TOOL::Main(), EE_POINT_EDITOR::Main(), LIB_MOVE_TOOL::Main(), EDIT_TOOL::Main(), EDIT_TOOL::MeasureTool(), POINT_EDITOR::OnSelectionChange(), ROUTER_TOOL::performDragging(), LENGTH_TUNER_TOOL::performTuning(), SCH_DRAWING_TOOLS::PlaceImage(), PCB_EDITOR_CONTROL::PlaceModule(), DRAWING_TOOL::PlaceText(), ROUTER_TOOL::prepareInteractive(), POINT_EDITOR::Reset(), GERBVIEW_SELECTION_TOOL::selectMultiple(), EE_SELECTION_TOOL::selectMultiple(), SELECTION_TOOL::selectMultiple(), ZOOM_TOOL::selectRegion(), DRAWING_TOOL::SetAnchor(), EE_PICKER_TOOL::setControls(), and PICKER_TOOL::setControls().

◆ SetAutoPanMargin()

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

187  {
188  m_settings.m_autoPanMargin = aMargin;
189  }
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

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

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

◆ SetAutoPanSpeed()

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

177  {
178  m_settings.m_autoPanSpeed = aSpeed;
179  }
float m_autoPanSpeed
How fast is panning when in auto mode
Definition: view_controls.h:82
VC_SETTINGS m_settings
Current VIEW_CONTROLS settings

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

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

◆ SetCrossHairCursorPosition()

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

487 {
488  m_updateCursor = false;
489 
490  const VECTOR2I& screenSize = m_view->GetGAL()->GetScreenPixelSize();
491  BOX2I screen( VECTOR2I( 0, 0 ), screenSize );
492  VECTOR2D screenPos = m_view->ToScreen( aPosition );
493 
494  if( aWarpView && !screen.Contains( screenPos ) )
495  m_view->SetCenter( aPosition );
496 
497  m_cursorPos = aPosition;
498 }
GAL * GetGAL() const
Function GetGAL() Returns the GAL this view is using to draw graphical primitives.
Definition: view.h:180
VIEW * m_view
Pointer to controlled VIEW.
VECTOR2< int > VECTOR2I
Definition: vector2d.h:587
const VECTOR2I & GetScreenPixelSize() const
Returns GAL canvas size in pixels.
void SetCenter(const VECTOR2D &aCenter)
Function SetCenter() Sets the center point of the VIEW (i.e.
Definition: view.cpp:601
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:494
bool m_updateCursor
Flag deciding whether the cursor position should be calculated using the mouse position.
VECTOR2D m_cursorPos
Current cursor position (world coordinates)

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().

◆ SetCursorPosition()

void WX_VIEW_CONTROLS::SetCursorPosition ( const VECTOR2D aPosition,
bool  aWarpView,
bool  aTriggeredByArrows 
)
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 464 of file wx_view_controls.cpp.

466 {
467  m_updateCursor = false;
468 
469  if( aTriggeredByArrows )
470  {
473  m_cursorWarped = false;
474  }
475  else
476  {
478  m_cursorWarped = true;
479  }
480 
481  WarpCursor( aPosition, true, aWarpView );
482  m_cursorPos = aPosition;
483 }
VC_SETTINGS m_settings
Current VIEW_CONTROLS settings
VECTOR2D m_lastKeyboardCursorPosition
Position of the above event
bool m_cursorWarped
Application warped the cursor, not the user (keyboard)
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.
bool m_lastKeyboardCursorPositionValid
Is last cursor motion event coming from keyboard arrow cursor motion action
Definition: view_controls.h:97
VECTOR2D m_cursorPos
Current cursor position (world coordinates)

References m_cursorPos, KIGFX::VIEW_CONTROLS::m_cursorWarped, KIGFX::VC_SETTINGS::m_lastKeyboardCursorPosition, KIGFX::VC_SETTINGS::m_lastKeyboardCursorPositionValid, KIGFX::VIEW_CONTROLS::m_settings, m_updateCursor, and WarpCursor().

◆ SetGrabMouse()

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

419 {
420  if( aEnabled && !m_settings.m_grabMouse )
421  m_parentPanel->CaptureMouse();
422  else if( !aEnabled && m_settings.m_grabMouse )
423  m_parentPanel->ReleaseMouse();
424 
425  VIEW_CONTROLS::SetGrabMouse( aEnabled );
426 }
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.

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

◆ SetSnapping()

◆ ShowCursor()

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.

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
GAL * GetGAL() const
Function GetGAL() Returns the GAL this view is using to draw graphical primitives.
Definition: view.h:180
VIEW * m_view
Pointer to controlled VIEW.
bool m_showCursor
Flag determining the cursor visibility
Definition: view_controls.h:55

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(), SCH_WIRE_BUS_TOOL::doDrawSegments(), PCB_TOOL_BASE::doInteractiveItemPlacement(), SCH_DRAWING_TOOLS::doPlaceComponent(), SCH_DRAWING_TOOLS::doSingleClickPlace(), LIB_DRAWING_TOOLS::doTwoClickPlace(), SCH_DRAWING_TOOLS::doTwoClickPlace(), DRAWING_TOOL::drawArc(), DRAWING_TOOL::DrawDimension(), MICROWAVE_TOOL::drawMicrowaveInductor(), DRAWING_TOOL::drawSegment(), LIB_DRAWING_TOOLS::DrawShape(), SCH_DRAWING_TOOLS::DrawSheet(), DRAWING_TOOL::drawZone(), MODULE_EDITOR_TOOLS::EnumeratePads(), ROUTER_TOOL::InlineDrag(), SCH_MOVE_TOOL::Main(), EE_POINT_EDITOR::Main(), LIB_MOVE_TOOL::Main(), EDIT_TOOL::Main(), LENGTH_TUNER_TOOL::mainLoop(), ROUTER_TOOL::mainLoop(), EDIT_TOOL::MeasureTool(), POINT_EDITOR::OnSelectionChange(), LIB_DRAWING_TOOLS::PlaceAnchor(), SCH_DRAWING_TOOLS::PlaceImage(), DRAWING_TOOL::PlaceImportedGraphics(), PCB_EDITOR_CONTROL::PlaceModule(), DRAWING_TOOL::PlaceText(), DRAWING_TOOL::SetAnchor(), EE_POINT_EDITOR::setEditedPoint(), and POINT_EDITOR::setEditedPoint().

◆ UpdateScrollbars()

void WX_VIEW_CONTROLS::UpdateScrollbars ( )

Adjusts the scrollbars position to match the current viewport.

Definition at line 653 of file wx_view_controls.cpp.

654 {
655  const BOX2D viewport = m_view->GetViewport();
656  const BOX2D& boundary = m_view->GetBoundary();
657 
658  m_scrollScale.x = 2e3 / viewport.GetWidth(); // TODO it does not have to be updated so often
659  m_scrollScale.y = 2e3 / viewport.GetHeight();
660  VECTOR2I newScroll( ( viewport.Centre().x - boundary.GetLeft() ) * m_scrollScale.x,
661  ( viewport.Centre().y - boundary.GetTop() ) * m_scrollScale.y );
662 
663  // Flip scroll direction in flipped view
664  if( m_view->IsMirroredX() )
665  newScroll.x = ( boundary.GetRight() - viewport.Centre().x ) * m_scrollScale.x;
666 
667  // Adjust scrollbars only if it is needed. Otherwise there are cases when canvas is continuosly
668  // refreshed (Windows)
669  if( m_scrollPos != newScroll )
670  {
671  // Another example of wxWidgets being broken by design: scroll position is determined by the
672  // left (or top, if vertical) edge of the slider. Fortunately, slider size seems to be constant
673  // (at least for wxGTK and wxMSW), so we have to add its size to allow user to scroll the workspace
674  // till the end.
675 
676  m_parentPanel->SetScrollbars( 1, 1,
677 #if defined(__LINUX__)
678  m_scrollScale.x * boundary.GetWidth() + 1623, m_scrollScale.y * boundary.GetHeight() + 1623,
679 #elif defined(__WIN32__) || defined(__WIN64__)
680  m_scrollScale.x * boundary.GetWidth() + 1377, m_scrollScale.y * boundary.GetHeight() + 741,
681 #else
682  m_scrollScale.x * boundary.GetWidth(), m_scrollScale.y * boundary.GetHeight(),
683 #endif
684  newScroll.x, newScroll.y, false );
685 
686  m_scrollPos = newScroll;
687  }
688 }
BOX2D GetViewport() const
Function GetViewport() Returns the current viewport visible area rectangle.
Definition: view.cpp:538
const BOX2D & GetBoundary() const
Function GetBoundary()
Definition: view.h:298
coord_type GetTop() const
Definition: box2.h:202
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 GetWidth() const
Definition: box2.h:195
bool IsMirroredX() const
Function IsMirroredX() Returns true if view is flipped across the X axis.
Definition: view.h:230
wxScrolledCanvas * m_parentPanel
Panel that is affected by VIEW_CONTROLS.
Vec Centre() const
Definition: box2.h:77
VECTOR2I m_scrollPos
Current scrollbar position.
coord_type GetHeight() const
Definition: box2.h:196
coord_type GetLeft() const
Definition: box2.h:201

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().

◆ WarpCursor()

void WX_VIEW_CONTROLS::WarpCursor ( const VECTOR2D aPosition,
bool  aWorldCoordinates = false,
bool  aWarpView = false 
)
overridevirtual

Implements KIGFX::VIEW_CONTROLS.

Definition at line 501 of file wx_view_controls.cpp.

503 {
504  if( aWorldCoordinates )
505  {
506  const VECTOR2I& screenSize = m_view->GetGAL()->GetScreenPixelSize();
507  BOX2I screen( VECTOR2I( 0, 0 ), screenSize );
508  VECTOR2D screenPos = m_view->ToScreen( aPosition );
509 
510  if( !screen.Contains( screenPos ) )
511  {
512  if( aWarpView )
513  {
514  m_view->SetCenter( aPosition );
515  m_parentPanel->WarpPointer( screenSize.x / 2, screenSize.y / 2 );
516  }
517  }
518  else
519  {
520  m_parentPanel->WarpPointer( screenPos.x, screenPos.y );
521  }
522  }
523  else
524  {
525  m_parentPanel->WarpPointer( aPosition.x, aPosition.y );
526  }
527 
528  refreshMouse();
529 }
GAL * GetGAL() const
Function GetGAL() Returns the GAL this view is using to draw graphical primitives.
Definition: view.h:180
VIEW * m_view
Pointer to controlled VIEW.
VECTOR2< int > VECTOR2I
Definition: vector2d.h:587
const VECTOR2I & GetScreenPixelSize() const
Returns GAL canvas size in pixels.
void SetCenter(const VECTOR2D &aCenter)
Function SetCenter() Sets the center point of the VIEW (i.e.
Definition: view.cpp:601
void refreshMouse()
Sends an event to refresh 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:494
wxScrolledCanvas * m_parentPanel
Panel that is affected by VIEW_CONTROLS.

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().

Member Data Documentation

◆ EVT_REFRESH_MOUSE

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

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

◆ m_cursorPos

VECTOR2D KIGFX::WX_VIEW_CONTROLS::m_cursorPos
private

Current cursor position (world coordinates)

Definition at line 168 of file wx_view_controls.h.

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

◆ m_cursorWarped

bool KIGFX::VIEW_CONTROLS::m_cursorWarped
protectedinherited

Application warped the cursor, not the user (keyboard)

Definition at line 390 of file view_controls.h.

Referenced by handleAutoPanning(), SetCursorPosition(), and WX_VIEW_CONTROLS().

◆ m_dragStartPoint

VECTOR2D KIGFX::WX_VIEW_CONTROLS::m_dragStartPoint
private

Stores information about point where dragging has started.

Definition at line 147 of file wx_view_controls.h.

Referenced by onButton(), and onMotion().

◆ m_lastTimestamp

long int KIGFX::WX_VIEW_CONTROLS::m_lastTimestamp
private

Last event timestamp to remove duplicates.

Definition at line 165 of file wx_view_controls.h.

Referenced by onWheel().

◆ m_lookStartPoint

VECTOR2D KIGFX::WX_VIEW_CONTROLS::m_lookStartPoint
private

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

Definition at line 150 of file wx_view_controls.h.

Referenced by onButton(), and onMotion().

◆ m_panDirection

VECTOR2D KIGFX::WX_VIEW_CONTROLS::m_panDirection
private

Current direction of panning (only autopanning mode)

Definition at line 153 of file wx_view_controls.h.

Referenced by handleAutoPanning(), and onTimer().

◆ m_panTimer

wxTimer KIGFX::WX_VIEW_CONTROLS::m_panTimer
private

Timer repsonsible for handling autopanning.

Definition at line 156 of file wx_view_controls.h.

Referenced by handleAutoPanning(), and WX_VIEW_CONTROLS().

◆ m_parentPanel

wxScrolledCanvas* KIGFX::WX_VIEW_CONTROLS::m_parentPanel
private

◆ m_scrollPos

VECTOR2I KIGFX::WX_VIEW_CONTROLS::m_scrollPos
private

Current scrollbar position.

Definition at line 162 of file wx_view_controls.h.

Referenced by UpdateScrollbars().

◆ m_scrollScale

VECTOR2D KIGFX::WX_VIEW_CONTROLS::m_scrollScale
private

Ratio used for scaling world coordinates to scrollbar position.

Definition at line 159 of file wx_view_controls.h.

Referenced by onScroll(), and UpdateScrollbars().

◆ m_settings

◆ m_state

STATE KIGFX::WX_VIEW_CONTROLS::m_state
private

Current state of VIEW_CONTROLS.

Definition at line 141 of file wx_view_controls.h.

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

◆ m_updateCursor

bool KIGFX::WX_VIEW_CONTROLS::m_updateCursor
private

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

Definition at line 171 of file wx_view_controls.h.

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

◆ m_view

◆ m_zoomController

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

Referenced by onWheel(), and WX_VIEW_CONTROLS().


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