KiCad PCB EDA Suite
KIGFX::WX_VIEW_CONTROLS Class Reference

An 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, EDA_DRAW_PANEL_GAL *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 onCaptureLost (wxMouseEvent &WXUNUSED(aEvent))
 
void CaptureCursor (bool aEnabled) override
 Force the cursor to stay within the drawing panel area. More...
 
void PinCursorInsideNonAutoscrollArea (bool aWarpMouseCursor) override
 Return the current mouse pointer position. More...
 
VECTOR2D GetMousePosition (bool aWorldCoordinates=true) const override
 Return the current mouse pointer position. More...
 
VECTOR2D GetCursorPosition (bool aSnappingEnabled) const override
 < More...
 
VECTOR2D GetRawCursorPosition (bool aSnappingEnabled=true) const override
 Return the current cursor position in world coordinates ignoring the cursorUp position force mode. More...
 
void SetCursorPosition (const VECTOR2D &aPosition, bool warpView, bool aTriggeredByArrows, long aArrowCommand) override
 Move the graphic crosshair cursor to the requested position expressed in world coordinates. More...
 
void SetCrossHairCursorPosition (const VECTOR2D &aPosition, bool aWarpView) override
 
void WarpMouseCursor (const VECTOR2D &aPosition, bool aWorldCoordinates=false, bool aWarpView=false) override
 Set the viewport center to the current cursor position and warps the cursor to the screen center. More...
 
void CenterOnCursor () override
 Adjusts the scrollbars position to match the current viewport. More...
 
void UpdateScrollbars ()
 End any mouse drag action still in progress. More...
 
void CancelDrag ()
 
void ForceCursorPosition (bool aEnabled, const VECTOR2D &aPosition=VECTOR2D(0, 0)) override
 Applies VIEW_CONTROLS settings from the program COMMON_SETTINGS. More...
 
void LoadSettings () override
 Event that forces mouse move event in the dispatcher (eg. More...
 
VECTOR2D GetCursorPosition () const
 Return the current cursor position in world coordinates. More...
 
virtual VECTOR2D GetCursorPosition (bool aEnableSnapping) const=0
 Return the current cursor position in world coordinates. More...
 
virtual void SetGrabMouse (bool aEnabled)
 Turn on/off mouse grabbing. More...
 
virtual void SetAutoPan (bool aEnabled)
 Turn on/off auto panning (this feature is used when there is a tool active (eg. More...
 
virtual void EnableAutoPan (bool aEnabled)
 Turn on/off auto panning (user setting to disable it entirely). More...
 
virtual void SetAutoPanSpeed (float aSpeed)
 Set the speed of autopanning. More...
 
virtual void SetAutoPanAcceleration (float aAcceleration)
 Set the speed of autopanning. More...
 
virtual void SetAutoPanMargin (float aMargin)
 Set the margin for autopanning (ie. More...
 
virtual void ShowCursor (bool aEnabled)
 Enable or disables display of cursor. More...
 
bool IsCursorShown () const
 Return true when cursor is visible. More...
 
void EnableCursorWarping (bool aEnable)
 Enable or disable warping the cursor. More...
 
bool IsCursorWarpingEnabled () const
 
virtual void Reset ()
 Restore the default VIEW_CONTROLS settings. More...
 
const VC_SETTINGSGetSettings () const
 Apply VIEW_CONTROLS settings from an object. More...
 
void ApplySettings (const VC_SETTINGS &aSettings)
 Load new settings from program common settings. More...
 

Public Attributes

std::unique_ptr< PROF_COUNTERm_MotionEventCounter
 

Static Public Attributes

static const wxEventType EVT_REFRESH_MOUSE = wxNewEventType()
 

Protected Attributes

VIEWm_view
 < Pointer to controlled VIEW. More...
 
bool m_cursorWarped
 Current VIEW_CONTROLS settings. More...
 
VC_SETTINGS m_settings
 

Private Types

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

Private Member Functions

void setState (STATE aNewState)
 Sets the interaction state, simply a internal setter to make it easier to debug changes. More...
 
bool handleAutoPanning (const wxMouseEvent &aEvent)
 Compute new viewport settings while in autopanning mode. More...
 
void handleCursorCapture (int x, int y)
 Limit the cursor position to within the canvas by warping it. More...
 
void refreshMouse (bool aSetModifiers)
 Send an event to refresh mouse position. More...
 
wxPoint getMouseScreenPosition () const
 Get the cursor position in the screen coordinates. More...
 

Private Attributes

STATE m_state
 Panel that is affected by VIEW_CONTROLS. More...
 
EDA_DRAW_PANEL_GALm_parentPanel
 Store information about point where dragging has started. More...
 
VECTOR2D m_dragStartPoint
 Current direction of panning (only autopanning mode). More...
 
VECTOR2D m_panDirection
 Timer responsible for handling autopanning. More...
 
wxTimer m_panTimer
 Ratio used for scaling world coordinates to scrollbar position. More...
 
VECTOR2D m_scrollScale
 Current scrollbar position. More...
 
VECTOR2I m_scrollPos
 The mouse position when a drag zoom started. More...
 
VECTOR2D m_zoomStartPoint
 Current cursor position (world coordinates). More...
 
VECTOR2D m_cursorPos
 Flag deciding whether the cursor position should be calculated using the mouse position. More...
 
bool m_updateCursor
 A #ZOOM_CONTROLLER that determines zoom steps. This is platform-specific. More...
 
std::unique_ptr< ZOOM_CONTROLLERm_zoomController
 

Detailed Description

An 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 

Nothing is happening.

DRAG_PANNING 

Panning with mouse button pressed.

AUTO_PANNING 

Panning on approaching borders of the frame.

DRAG_ZOOMING 

Zooming with mouse button pressed.

Definition at line 125 of file wx_view_controls.h.

126 {
127 IDLE = 1,
131 };
@ DRAG_PANNING
Panning with mouse button pressed.
@ AUTO_PANNING
Panning on approaching borders of the frame.
@ DRAG_ZOOMING
Zooming with mouse button pressed.
@ IDLE
Nothing is happening.

Constructor & Destructor Documentation

◆ WX_VIEW_CONTROLS()

WX_VIEW_CONTROLS::WX_VIEW_CONTROLS ( VIEW aView,
EDA_DRAW_PANEL_GAL aParentPanel 
)

Definition at line 75 of file wx_view_controls.cpp.

75 :
76 VIEW_CONTROLS( aView ),
77 m_state( IDLE ),
78 m_parentPanel( aParentPanel ),
79 m_scrollScale( 1.0, 1.0 ),
80#ifdef __WXGTK3__
81 m_lastTimestamp( 0 ),
82#endif
83 m_cursorPos( 0, 0 ),
84 m_updateCursor( true )
85{
87
88 m_MotionEventCounter = std::make_unique<PROF_COUNTER>( "Mouse motion events" );
89
90 m_parentPanel->Connect( wxEVT_MOTION,
91 wxMouseEventHandler( WX_VIEW_CONTROLS::onMotion ), nullptr, this );
92#if wxCHECK_VERSION( 3, 1, 0 ) || defined( USE_OSX_MAGNIFY_EVENT )
93 m_parentPanel->Connect( wxEVT_MAGNIFY,
94 wxMouseEventHandler( WX_VIEW_CONTROLS::onMagnify ), nullptr, this );
95#endif
96 m_parentPanel->Connect( wxEVT_MOUSEWHEEL,
97 wxMouseEventHandler( WX_VIEW_CONTROLS::onWheel ), nullptr, this );
98 m_parentPanel->Connect( wxEVT_MIDDLE_UP,
99 wxMouseEventHandler( WX_VIEW_CONTROLS::onButton ), nullptr, this );
100 m_parentPanel->Connect( wxEVT_MIDDLE_DOWN,
101 wxMouseEventHandler( WX_VIEW_CONTROLS::onButton ), nullptr, this );
102 m_parentPanel->Connect( wxEVT_LEFT_UP,
103 wxMouseEventHandler( WX_VIEW_CONTROLS::onButton ), nullptr, this );
104 m_parentPanel->Connect( wxEVT_LEFT_DOWN,
105 wxMouseEventHandler( WX_VIEW_CONTROLS::onButton ), nullptr, this );
106 m_parentPanel->Connect( wxEVT_RIGHT_UP,
107 wxMouseEventHandler( WX_VIEW_CONTROLS::onButton ), nullptr, this );
108 m_parentPanel->Connect( wxEVT_RIGHT_DOWN,
109 wxMouseEventHandler( WX_VIEW_CONTROLS::onButton ), nullptr, this );
110#if defined __WXMSW__
111 m_parentPanel->Connect( wxEVT_ENTER_WINDOW,
112 wxMouseEventHandler( WX_VIEW_CONTROLS::onEnter ), nullptr, this );
113#endif
114 m_parentPanel->Connect( wxEVT_LEAVE_WINDOW,
115 wxMouseEventHandler( WX_VIEW_CONTROLS::onLeave ), nullptr, this );
116 m_parentPanel->Connect( wxEVT_SCROLLWIN_THUMBTRACK,
117 wxScrollWinEventHandler( WX_VIEW_CONTROLS::onScroll ), nullptr, this );
118 m_parentPanel->Connect( wxEVT_SCROLLWIN_PAGEUP,
119 wxScrollWinEventHandler( WX_VIEW_CONTROLS::onScroll ), nullptr, this );
120 m_parentPanel->Connect( wxEVT_SCROLLWIN_PAGEDOWN,
121 wxScrollWinEventHandler( WX_VIEW_CONTROLS::onScroll ), nullptr, this );
122
123 m_parentPanel->Connect( wxEVT_SCROLLWIN_BOTTOM,
124 wxScrollWinEventHandler( WX_VIEW_CONTROLS::onScroll ), nullptr, this );
125 m_parentPanel->Connect( wxEVT_SCROLLWIN_TOP,
126 wxScrollWinEventHandler( WX_VIEW_CONTROLS::onScroll ), nullptr, this );
127 m_parentPanel->Connect( wxEVT_SCROLLWIN_LINEUP,
128 wxScrollWinEventHandler( WX_VIEW_CONTROLS::onScroll ), nullptr, this );
129 m_parentPanel->Connect( wxEVT_SCROLLWIN_LINEDOWN,
130 wxScrollWinEventHandler( WX_VIEW_CONTROLS::onScroll ), nullptr, this );
131#if defined USE_MOUSE_CAPTURE
132 m_parentPanel->Connect( wxEVT_MOUSE_CAPTURE_LOST,
133 wxMouseEventHandler( WX_VIEW_CONTROLS::onCaptureLost ), nullptr, this );
134#endif
135
136 m_cursorWarped = false;
137
138 m_panTimer.SetOwner( this );
139 this->Connect( wxEVT_TIMER, wxTimerEventHandler( WX_VIEW_CONTROLS::onTimer ), nullptr, this );
140
144}
bool m_cursorWarped
Current VIEW_CONTROLS settings.
VC_SETTINGS m_settings
VIEW_CONTROLS(VIEW *aView)
bool m_updateCursor
A #ZOOM_CONTROLLER that determines zoom steps. This is platform-specific.
void LoadSettings() override
Event that forces mouse move event in the dispatcher (eg.
STATE m_state
Panel that is affected by VIEW_CONTROLS.
void onScroll(wxScrollWinEvent &aEvent)
wxTimer m_panTimer
Ratio used for scaling world coordinates to scrollbar position.
void onButton(wxMouseEvent &aEvent)
void onEnter(wxMouseEvent &WXUNUSED(aEvent))
void onWheel(wxMouseEvent &aEvent)
Handler functions.
VECTOR2D m_scrollScale
Current scrollbar position.
void onTimer(wxTimerEvent &WXUNUSED(aEvent))
VECTOR2D m_cursorPos
Flag deciding whether the cursor position should be calculated using the mouse position.
void onCaptureLost(wxMouseEvent &WXUNUSED(aEvent))
void onMotion(wxMouseEvent &aEvent)
std::unique_ptr< PROF_COUNTER > m_MotionEventCounter
EDA_DRAW_PANEL_GAL * m_parentPanel
Store information about point where dragging has started.
void onLeave(wxMouseEvent &WXUNUSED(aEvent))
VECTOR2D m_lastKeyboardCursorPosition
bool m_lastKeyboardCursorPositionValid
ACTIONS::CURSOR_UP, ACTIONS::CURSOR_DOWN, etc.
long m_lastKeyboardCursorCommand
Position of the above event.

References LoadSettings(), KIGFX::VIEW_CONTROLS::m_cursorWarped, KIGFX::VC_SETTINGS::m_lastKeyboardCursorCommand, KIGFX::VC_SETTINGS::m_lastKeyboardCursorPosition, KIGFX::VC_SETTINGS::m_lastKeyboardCursorPositionValid, m_MotionEventCounter, m_panTimer, m_parentPanel, KIGFX::VIEW_CONTROLS::m_settings, onButton(), onCaptureLost(), onEnter(), onLeave(), onMotion(), onScroll(), onTimer(), and onWheel().

◆ ~WX_VIEW_CONTROLS()

WX_VIEW_CONTROLS::~WX_VIEW_CONTROLS ( )
virtual

Definition at line 147 of file wx_view_controls.cpp.

148{
149#if defined USE_MOUSE_CAPTURE
150 if( m_parentPanel->HasCapture() )
151 m_parentPanel->ReleaseMouse();
152#endif
153}

References m_parentPanel.

Member Function Documentation

◆ ApplySettings()

void VIEW_CONTROLS::ApplySettings ( const VC_SETTINGS aSettings)
inherited

Load new settings from program common settings.

Definition at line 87 of file view_controls.cpp.

88{
89 ShowCursor( aSettings.m_showCursor );
91 SetGrabMouse( aSettings.m_grabMouse );
92 SetAutoPan( aSettings.m_autoPanEnabled );
96}
virtual void CaptureCursor(bool aEnabled)
Force the cursor to stay within the drawing panel area.
virtual void ForceCursorPosition(bool aEnabled, const VECTOR2D &aPosition=VECTOR2D(0, 0))
Place the cursor immediately at a given point.
virtual void ShowCursor(bool aEnabled)
Enable or disables display of cursor.
virtual void SetAutoPanMargin(float aMargin)
Set the margin for autopanning (ie.
virtual void SetGrabMouse(bool aEnabled)
Turn on/off mouse grabbing.
virtual void SetAutoPanSpeed(float aSpeed)
Set the speed of autopanning.
virtual void SetAutoPan(bool aEnabled)
Turn on/off auto panning (this feature is used when there is a tool active (eg.
float m_autoPanMargin
How fast is panning when in auto mode.
Definition: view_controls.h:79
VECTOR2D m_forcedPosition
Is the forced cursor position enabled.
Definition: view_controls.h:55
bool m_cursorCaptured
Should the cursor snap to grid or move freely.
Definition: view_controls.h:61
float m_autoPanSpeed
How fast does panning accelerate when approaching the window boundary.
Definition: view_controls.h:82
bool m_grabMouse
Flag for automatic focus switching between Schematic and PCB editors.
Definition: view_controls.h:67
bool m_autoPanEnabled
Flag for turning on autopanning.
Definition: view_controls.h:73
bool m_showCursor
Forced cursor position (world coordinates).
Definition: view_controls.h:52
bool m_forceCursorPosition
Should the cursor be locked within the parent window area.
Definition: view_controls.h:58

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::VIEW_CONTROLS::SetAutoPan(), KIGFX::VIEW_CONTROLS::SetAutoPanMargin(), KIGFX::VIEW_CONTROLS::SetAutoPanSpeed(), KIGFX::VIEW_CONTROLS::SetGrabMouse(), and KIGFX::VIEW_CONTROLS::ShowCursor().

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

◆ CancelDrag()

void WX_VIEW_CONTROLS::CancelDrag ( )

Definition at line 682 of file wx_view_controls.cpp.

683{
685 {
686 setState( IDLE );
687#if defined USE_MOUSE_CAPTURE
688 if( !m_settings.m_cursorCaptured && m_parentPanel->HasCapture() )
689 m_parentPanel->ReleaseMouse();
690#endif
691 }
692}
void setState(STATE aNewState)
Sets the interaction state, simply a internal setter to make it easier to debug changes.

References DRAG_PANNING, DRAG_ZOOMING, IDLE, KIGFX::VC_SETTINGS::m_cursorCaptured, m_parentPanel, KIGFX::VIEW_CONTROLS::m_settings, m_state, and setState().

Referenced by EDA_DRAW_PANEL_GAL::onLostFocus().

◆ CaptureCursor()

void WX_VIEW_CONTROLS::CaptureCursor ( bool  aEnabled)
overridevirtual

Force the cursor to stay within the drawing panel area.

Parameters
aEnableddetermines if the cursor should be captured.

Reimplemented from KIGFX::VIEW_CONTROLS.

Definition at line 655 of file wx_view_controls.cpp.

656{
657#if defined USE_MOUSE_CAPTURE
658 // Note: for some reason, m_parentPanel->HasCapture() can be false even if CaptureMouse()
659 // was called (i.e. mouse was captured, so when need to test m_MouseCapturedLost to be
660 // sure a wxEVT_MOUSE_CAPTURE_LOST event was fired before. Otherwise wxMSW complains
661 if( aEnabled && !m_parentPanel->HasCapture() && m_parentPanel->m_MouseCapturedLost )
662 {
663 m_parentPanel->CaptureMouse();
664
665 // Clear the flag to allow calling m_parentPanel->CaptureMouse()
666 // Calling it without calling ReleaseMouse() is not accepted by wxWidgets (MSW specific)
668 }
669 else if( !aEnabled && m_parentPanel->HasCapture()
671 {
672 m_parentPanel->ReleaseMouse();
673
674 // Mouse is released, calling CaptureMouse() is allowed now:
676 }
677#endif
679}
bool m_MouseCapturedLost
used on wxMSW: true after a wxEVT_MOUSE_CAPTURE_LOST was received false after the mouse is recaptured...

References KIGFX::VIEW_CONTROLS::CaptureCursor(), DRAG_PANNING, DRAG_ZOOMING, EDA_DRAW_PANEL_GAL::m_MouseCapturedLost, m_parentPanel, and m_state.

◆ CenterOnCursor()

void WX_VIEW_CONTROLS::CenterOnCursor ( )
overridevirtual

Adjusts the scrollbars position to match the current viewport.

Implements KIGFX::VIEW_CONTROLS.

Definition at line 811 of file wx_view_controls.cpp.

812{
813 const VECTOR2I& screenSize = m_view->GetGAL()->GetScreenPixelSize();
814 VECTOR2I screenCenter( screenSize / 2 );
815
816 if( GetMousePosition( false ) != screenCenter )
817 {
819 m_dragStartPoint = screenCenter;
820 KIPLATFORM::UI::WarpPointer( m_parentPanel, screenCenter.x, screenCenter.y );
821 }
822}
const VECTOR2I & GetScreenPixelSize() const
Return GAL canvas size in pixels.
VIEW * m_view
< Pointer to controlled VIEW.
GAL * GetGAL() const
Return the #GAL this view is using to draw graphical primitives.
Definition: view.h:195
void SetCenter(const VECTOR2D &aCenter)
Set the center point of the VIEW (i.e.
Definition: view.cpp:577
VECTOR2D GetMousePosition(bool aWorldCoordinates=true) const override
Return the current mouse pointer position.
VECTOR2D GetCursorPosition() const
Return the current cursor position in world coordinates.
VECTOR2D m_dragStartPoint
Current direction of panning (only autopanning mode).
void WarpPointer(wxWindow *aWindow, int aX, int aY)
Move the mouse cursor to a specific position relative to the window.
Definition: gtk/ui.cpp:150

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

Referenced by onWheel().

◆ EnableAutoPan()

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

Turn on/off auto panning (user setting to disable it entirely).

Parameters
aEnabledtells if the autopanning should be enabled.

Definition at line 169 of file view_controls.h.

170 {
172 }
bool m_autoPanSettingEnabled
Distance from cursor to VIEW edge when panning is active.
Definition: view_controls.h:76

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

◆ EnableCursorWarping()

void KIGFX::VIEW_CONTROLS::EnableCursorWarping ( bool  aEnable)
inlineinherited

Enable or disable warping the cursor.

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

Definition at line 340 of file view_controls.h.

341 {
342 m_settings.m_warpCursor = aEnable;
343 }
bool m_warpCursor
Enable horizontal panning with the horizontal scroll/trackpad input.
Definition: view_controls.h:88

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

◆ ForceCursorPosition()

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

Applies VIEW_CONTROLS settings from the program COMMON_SETTINGS.

Reimplemented from KIGFX::VIEW_CONTROLS.

Definition at line 1036 of file wx_view_controls.cpp.

1037{
1038 VECTOR2D clampedPosition = GetClampedCoords( aPosition );
1039
1041 m_settings.m_forcedPosition = clampedPosition;
1042}
VECTOR2< ret_type > GetClampedCoords(const VECTOR2< in_type > &aCoords, pad_type aPadding=1u)
Clamps a vector to values that can be negated, respecting numeric limits of coordinates data type wit...

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

◆ GetCursorPosition() [1/3]

VECTOR2D KIGFX::VIEW_CONTROLS::GetCursorPosition ( ) const
inline

Return the current cursor position in world coordinates.

Note
The position may be different from the mouse pointer position if snapping is enabled or cursor position is forced to a specific point.
The position is clamped if outside of coordinates representation limits.
Returns
The current cursor position in world coordinates.

Definition at line 230 of file view_controls.h.

231 {
233 }
bool m_snappingEnabled
Flag for grabbing the mouse cursor.
Definition: view_controls.h:64

Referenced by CenterOnCursor().

◆ GetCursorPosition() [2/3]

virtual VECTOR2D KIGFX::VIEW_CONTROLS::GetCursorPosition ( bool  aEnableSnapping) const
virtual

Return the current cursor position in world coordinates.

Note
The position may be different from the mouse pointer position if snapping is enabled or cursor position is forced to a specific point.
The position is clamped if outside of coordinates representation limits.
Parameters
aEnableSnappingselects whether cursor position should be snapped to the grid.
Returns
The current cursor position in world coordinates.

Implements KIGFX::VIEW_CONTROLS.

◆ GetCursorPosition() [3/3]

VECTOR2D WX_VIEW_CONTROLS::GetCursorPosition ( bool  aSnappingEnabled) const
overridevirtual

<

Return the current cursor position in world coordinates.

Note
The position may be different from the mouse pointer position if snapping is enabled or cursor position is forced to a specific point.
The position is clamped if outside of coordinates representation limits.
Returns
The current cursor position in world coordinates. Return the current cursor position in world coordinates ignoring the cursorUp position force mode.
The current cursor position in world coordinates.

Implements KIGFX::VIEW_CONTROLS.

Definition at line 719 of file wx_view_controls.cpp.

720{
722 {
724 }
725 else
726 {
727 return GetClampedCoords( GetRawCursorPosition( aEnableSnapping ) );
728 }
729}
VECTOR2D GetRawCursorPosition(bool aSnappingEnabled=true) const override
Return the current cursor position in world coordinates ignoring the cursorUp position force mode.

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

Referenced by EDA_DRAW_PANEL_GAL::DoRePaint().

◆ GetMousePosition()

VECTOR2D WX_VIEW_CONTROLS::GetMousePosition ( bool  aWorldCoordinates = true) const
overridevirtual

Return the current mouse pointer position.

Note
The position may be different from the cursor position if snapping is enabled (
See also
GetCursorPosition()).
Note
The position is clamped if outside of coordinates representation limits.
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 695 of file wx_view_controls.cpp.

696{
697 wxPoint msp = getMouseScreenPosition();
698 VECTOR2D screenPos( msp.x, msp.y );
699
700 return aWorldCoordinates ? GetClampedCoords( m_view->ToWorld( screenPos ) ) : screenPos;
701}
VECTOR2D ToWorld(const VECTOR2D &aCoord, bool aAbsolute=true) const
Converts a screen space point/vector to a point/vector in world space coordinates.
Definition: view.cpp:448
wxPoint getMouseScreenPosition() const
Get the cursor position in the screen coordinates.

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

Referenced by CenterOnCursor(), and PinCursorInsideNonAutoscrollArea().

◆ getMouseScreenPosition()

wxPoint WX_VIEW_CONTROLS::getMouseScreenPosition ( ) const
private

Get the cursor position in the screen coordinates.

Current state of VIEW_CONTROLS.

Definition at line 989 of file wx_view_controls.cpp.

990{
991 wxPoint msp = wxGetMousePosition();
992 m_parentPanel->ScreenToClient( &msp.x, &msp.y );
993 return msp;
994}

References m_parentPanel.

Referenced by GetMousePosition(), and refreshMouse().

◆ GetRawCursorPosition()

VECTOR2D WX_VIEW_CONTROLS::GetRawCursorPosition ( bool  aSnappingEnabled = true) const
overridevirtual

Return the current cursor position in world coordinates ignoring the cursorUp position force mode.

Returns
The current cursor position in world coordinates.

Implements KIGFX::VIEW_CONTROLS.

Definition at line 704 of file wx_view_controls.cpp.

705{
706 GAL* gal = m_view->GetGAL();
707
708 if( aEnableSnapping && gal->GetGridSnapping() )
709 {
710 return gal->GetGridPoint( m_cursorPos );
711 }
712 else
713 {
714 return m_cursorPos;
715 }
716}
Abstract interface for drawing on a 2D-surface.
VECTOR2D GetGridPoint(const VECTOR2D &aPoint) const
For a given point it returns the nearest point belonging to the grid in world coordinates.
bool GetGridSnapping() const

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

Referenced by GetCursorPosition().

◆ GetSettings()

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

◆ handleAutoPanning()

bool WX_VIEW_CONTROLS::handleAutoPanning ( const wxMouseEvent &  aEvent)
private

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

858{
859 VECTOR2I p( aEvent.GetX(), aEvent.GetY() );
861
863 {
864 // last cursor move event came from keyboard cursor control. If auto-panning is enabled
865 // and the next position is inside the autopan zone, check if it really came from a mouse
866 // event, otherwise disable autopan temporarily. Also temporarily disable autopan if the
867 // cursor is in the autopan zone because the application warped the cursor.
868
869 m_cursorWarped = false;
870 return true;
871 }
872
873 m_cursorWarped = false;
874
875 // Compute areas where autopanning is active
876 int borderStart = std::min( m_settings.m_autoPanMargin * m_view->GetScreenPixelSize().x,
878 borderStart = std::max( borderStart, 2 );
879 int borderEndX = m_view->GetScreenPixelSize().x - borderStart;
880 int borderEndY = m_view->GetScreenPixelSize().y - borderStart;
881
882 if( p.x < borderStart )
883 m_panDirection.x = -( borderStart - p.x );
884 else if( p.x > borderEndX )
885 m_panDirection.x = ( p.x - borderEndX );
886 else
887 m_panDirection.x = 0;
888
889 if( p.y < borderStart )
890 m_panDirection.y = -( borderStart - p.y );
891 else if( p.y > borderEndY )
892 m_panDirection.y = ( p.y - borderEndY );
893 else
894 m_panDirection.y = 0;
895
896 bool borderHit = ( m_panDirection.x != 0 || m_panDirection.y != 0 );
897
898 switch( m_state )
899 {
900 case AUTO_PANNING:
901 if( !borderHit )
902 {
903 m_panTimer.Stop();
904 setState( IDLE );
905
906 return false;
907 }
908
909 return true;
910
911 case IDLE:
912 if( borderHit )
913 {
915 m_panTimer.Start( (int) ( 250.0 / 60.0 ), true );
916
917 return true;
918 }
919
920 return false;
921
922 case DRAG_PANNING:
923 case DRAG_ZOOMING:
924 return false;
925 }
926
927 wxCHECK_MSG( false, false, wxT( "This line should never be reached" ) );
928
929 return false;
930}
VECTOR2D ToScreen(const VECTOR2D &aCoord, bool aAbsolute=true) const
Convert a world space point/vector to a point/vector in screen space coordinates.
Definition: view.cpp:467
const VECTOR2I & GetScreenPixelSize() const
Return the size of the our rendering area in pixels.
Definition: view.cpp:1166
VECTOR2D m_panDirection
Timer responsible for handling autopanning.

References AUTO_PANNING, DRAG_PANNING, DRAG_ZOOMING, 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, setState(), KIGFX::VIEW::ToScreen(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by onMotion().

◆ handleCursorCapture()

void WX_VIEW_CONTROLS::handleCursorCapture ( int  x,
int  y 
)
private

Limit the cursor position to within the canvas by warping it.

Parameters
xMouse position
yMouse position

Definition at line 933 of file wx_view_controls.cpp.

934{
936 {
937 bool warp = false;
938 wxSize parentSize = m_parentPanel->GetClientSize();
939
940 if( x < 0 )
941 {
942 x = 0;
943 warp = true;
944 }
945 else if( x >= parentSize.x )
946 {
947 x = parentSize.x - 1;
948 warp = true;
949 }
950
951 if( y < 0 )
952 {
953 y = 0;
954 warp = true;
955 }
956 else if( y >= parentSize.y )
957 {
958 y = parentSize.y - 1;
959 warp = true;
960 }
961
962 if( warp )
964 }
965}

References KIGFX::VC_SETTINGS::m_cursorCaptured, m_parentPanel, KIGFX::VIEW_CONTROLS::m_settings, and KIPLATFORM::UI::WarpPointer().

Referenced by onMotion().

◆ IsCursorShown()

bool VIEW_CONTROLS::IsCursorShown ( ) const
inherited

Return true when cursor is visible.

Returns
True if cursor is visible.

Definition at line 41 of file view_controls.cpp.

42{
43 // this only says if the VIEW_CONTROLS say the cursor should be
44 // shown: m_view->GetGAL()->IsCursorEnabled() will say if the GAL is
45 // actually going to do show the cursor or not
47}

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

◆ IsCursorWarpingEnabled()

bool KIGFX::VIEW_CONTROLS::IsCursorWarpingEnabled ( ) const
inlineinherited
Returns
the current setting for cursor warping.

Definition at line 348 of file view_controls.h.

349 {
351 }

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

Referenced by onWheel().

◆ LoadSettings()

void WX_VIEW_CONTROLS::LoadSettings ( )
overridevirtual

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)

Reimplemented from KIGFX::VIEW_CONTROLS.

Definition at line 156 of file wx_view_controls.cpp.

157{
158 COMMON_SETTINGS* cfg = Pgm().GetCommonSettings();
159
174
175 m_zoomController.reset();
176
177 if( cfg->m_Input.zoom_speed_auto )
178 {
180 }
181 else
182 {
183 if( cfg->m_Input.zoom_acceleration )
184 {
186 std::make_unique<ACCELERATING_ZOOM_CONTROLLER>( cfg->m_Input.zoom_speed );
187 }
188 else
189 {
191
192 m_zoomController = std::make_unique<CONSTANT_ZOOM_CONTROLLER>( scale );
193 }
194 }
195}
static constexpr double MANUAL_SCALE_FACTOR
std::unique_ptr< ZOOM_CONTROLLER > m_zoomController
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:111
const int scale
MOUSE_DRAG_ACTION drag_right
MOUSE_DRAG_ACTION drag_middle
MOUSE_DRAG_ACTION drag_left
MOUSE_DRAG_ACTION m_dragLeft
bool m_horizontalPan
Enable the accelerating zoom controller.
Definition: view_controls.h:91
bool m_focusFollowSchPcb
Flag for turning on autopanning.
Definition: view_controls.h:70
float m_autoPanAcceleration
If the cursor is allowed to be warped.
Definition: view_controls.h:85
MOUSE_DRAG_ACTION m_dragMiddle
int m_zoomSpeed
When true, ignore zoom_speed and pick a platform-specific default.
Definition: view_controls.h:97
int m_scrollModifierZoom
What modifier key to enable horizontal pan with the (vertical) scroll wheel.
int m_scrollModifierPanH
What modifier key to enable vertical with the (vertical) scroll wheel.
MOUSE_DRAG_ACTION m_dragRight
Is last cursor motion event coming from keyboard arrow cursor motion action.
bool m_zoomAcceleration
Zoom speed for the non-accelerating zoom controller.
Definition: view_controls.h:94
bool m_zoomSpeedAuto
What modifier key to enable zoom with the (vertical) scroll wheel.
static std::unique_ptr< ZOOM_CONTROLLER > GetZoomControllerForPlatform(bool aAcceleration)

References COMMON_SETTINGS::INPUT::auto_pan, COMMON_SETTINGS::INPUT::auto_pan_acceleration, COMMON_SETTINGS::INPUT::center_on_zoom, COMMON_SETTINGS::INPUT::drag_left, COMMON_SETTINGS::INPUT::drag_middle, COMMON_SETTINGS::INPUT::drag_right, COMMON_SETTINGS::INPUT::focus_follow_sch_pcb, GetZoomControllerForPlatform(), COMMON_SETTINGS::INPUT::horizontal_pan, KIGFX::VC_SETTINGS::m_autoPanAcceleration, KIGFX::VC_SETTINGS::m_autoPanSettingEnabled, KIGFX::VC_SETTINGS::m_dragLeft, KIGFX::VC_SETTINGS::m_dragMiddle, KIGFX::VC_SETTINGS::m_dragRight, KIGFX::VC_SETTINGS::m_focusFollowSchPcb, KIGFX::VC_SETTINGS::m_horizontalPan, COMMON_SETTINGS::m_Input, KIGFX::VC_SETTINGS::m_scrollModifierPanH, KIGFX::VC_SETTINGS::m_scrollModifierPanV, KIGFX::VC_SETTINGS::m_scrollModifierZoom, KIGFX::VIEW_CONTROLS::m_settings, KIGFX::VC_SETTINGS::m_warpCursor, KIGFX::VC_SETTINGS::m_zoomAcceleration, m_zoomController, KIGFX::VC_SETTINGS::m_zoomSpeed, KIGFX::VC_SETTINGS::m_zoomSpeedAuto, KIGFX::CONSTANT_ZOOM_CONTROLLER::MANUAL_SCALE_FACTOR, Pgm(), scale, COMMON_SETTINGS::INPUT::scroll_modifier_pan_h, COMMON_SETTINGS::INPUT::scroll_modifier_pan_v, COMMON_SETTINGS::INPUT::scroll_modifier_zoom, COMMON_SETTINGS::INPUT::zoom_acceleration, COMMON_SETTINGS::INPUT::zoom_speed, and COMMON_SETTINGS::INPUT::zoom_speed_auto.

Referenced by WX_VIEW_CONTROLS().

◆ onButton()

void WX_VIEW_CONTROLS::onButton ( wxMouseEvent &  aEvent)

Definition at line 429 of file wx_view_controls.cpp.

430{
431 switch( m_state )
432 {
433 case IDLE:
434 case AUTO_PANNING:
435 if( ( aEvent.MiddleDown() && m_settings.m_dragMiddle == MOUSE_DRAG_ACTION::PAN ) ||
436 ( aEvent.RightDown() && m_settings.m_dragRight == MOUSE_DRAG_ACTION::PAN ) )
437 {
438 m_dragStartPoint = VECTOR2D( aEvent.GetX(), aEvent.GetY() );
440
441#if defined USE_MOUSE_CAPTURE
442 if( !m_parentPanel->HasCapture() )
443 m_parentPanel->CaptureMouse();
444#endif
445 }
446 else if( ( aEvent.MiddleDown() && m_settings.m_dragMiddle == MOUSE_DRAG_ACTION::ZOOM ) ||
447 ( aEvent.RightDown() && m_settings.m_dragRight == MOUSE_DRAG_ACTION::ZOOM ) )
448 {
449 m_dragStartPoint = VECTOR2D( aEvent.GetX(), aEvent.GetY() );
452
453#if defined USE_MOUSE_CAPTURE
454 if( !m_parentPanel->HasCapture() )
455 m_parentPanel->CaptureMouse();
456#endif
457 }
458
459 if( aEvent.LeftUp() )
460 setState( IDLE ); // Stop autopanning when user release left mouse button
461
462 break;
463
464 case DRAG_ZOOMING:
465 case DRAG_PANNING:
466 if( aEvent.MiddleUp() || aEvent.LeftUp() || aEvent.RightUp() )
467 {
468 setState( IDLE );
469
470#if defined USE_MOUSE_CAPTURE
471 if( !m_settings.m_cursorCaptured && m_parentPanel->HasCapture() )
472 m_parentPanel->ReleaseMouse();
473#endif
474 }
475
476 break;
477 }
478
479 aEvent.Skip();
480}
VECTOR2D m_zoomStartPoint
Current cursor position (world coordinates).
VECTOR2< double > VECTOR2D
Definition: vector2d.h:617

References AUTO_PANNING, DRAG_PANNING, DRAG_ZOOMING, IDLE, KIGFX::VC_SETTINGS::m_cursorCaptured, KIGFX::VC_SETTINGS::m_dragMiddle, KIGFX::VC_SETTINGS::m_dragRight, m_dragStartPoint, m_parentPanel, KIGFX::VIEW_CONTROLS::m_settings, m_state, m_zoomStartPoint, PAN, setState(), and ZOOM.

Referenced by WX_VIEW_CONTROLS().

◆ onCaptureLost()

void WX_VIEW_CONTROLS::onCaptureLost ( wxMouseEvent &  WXUNUSEDaEvent)

Definition at line 518 of file wx_view_controls.cpp.

519{
520 // This method must be present to suppress the capture-lost assertion
521
522 // Set the flag to allow calling m_parentPanel->CaptureMouse()
523 // Note: One cannot call m_parentPanel->CaptureMouse() twice, this is not accepted
524 // by wxWidgets (MSW specific) so we need this guard
526}

References EDA_DRAW_PANEL_GAL::m_MouseCapturedLost, and m_parentPanel.

Referenced by WX_VIEW_CONTROLS().

◆ onEnter()

void WX_VIEW_CONTROLS::onEnter ( wxMouseEvent &  WXUNUSEDaEvent)

Definition at line 483 of file wx_view_controls.cpp.

484{
485 // Avoid stealing focus from text controls
486 // This is particularly important for users using On-Screen-Keyboards
487 // They may move the mouse over the canvas to reach the keyboard
489 {
490 return;
491 }
492
493#if defined( _WIN32 ) || defined( __WXGTK__ )
494 // Win32 and some *nix WMs transmit mouse move and wheel events to all controls below the mouse regardless
495 // of focus. Forcing the focus here will cause the EDA FRAMES to immediately become the
496 // top level active window.
497 if( m_parentPanel->GetParent() != nullptr )
498 {
499 // this assumes the parent panel's parent is the eda window
501 {
503 }
504 }
505#else
507#endif
508}
void SetFocus() override
bool IsWindowActive(wxWindow *aWindow)
Check to see if the given window is the currently active window (e.g.
Definition: gtk/ui.cpp:50
bool IsInputControlFocused(wxWindow *aFocus=nullptr)
Check if a input control has focus.
Definition: ui_common.cpp:265

References KIUI::IsInputControlFocused(), KIPLATFORM::UI::IsWindowActive(), m_parentPanel, and EDA_DRAW_PANEL_GAL::SetFocus().

Referenced by WX_VIEW_CONTROLS().

◆ onLeave()

void WX_VIEW_CONTROLS::onLeave ( wxMouseEvent &  WXUNUSEDaEvent)

Definition at line 511 of file wx_view_controls.cpp.

512{
513#if !defined USE_MOUSE_CAPTURE
514 onMotion( aEvent );
515#endif
516}

References onMotion().

Referenced by WX_VIEW_CONTROLS().

◆ onMotion()

void WX_VIEW_CONTROLS::onMotion ( wxMouseEvent &  aEvent)

Definition at line 198 of file wx_view_controls.cpp.

199{
200 ( *m_MotionEventCounter )++;
201
202 bool isAutoPanning = false;
203 int x = aEvent.GetX();
204 int y = aEvent.GetY();
205 VECTOR2D mousePos( x, y );
206
207 // Automatic focus switching between SCH and PCB windows on canvas mouse motion
209 {
211 {
212 KIWAY_PLAYER* otherFrame = nullptr;
213
214 if( frame->IsType( FRAME_PCB_EDITOR ) )
215 {
216 otherFrame = frame->Kiway().Player( FRAME_SCH, false );
217 }
218 else if( frame->IsType( FRAME_SCH ) )
219 {
220 otherFrame = frame->Kiway().Player( FRAME_PCB_EDITOR, false );
221 }
222
223 if( otherFrame && KIPLATFORM::UI::IsWindowActive( otherFrame )
224 && !KIPLATFORM::UI::IsWindowActive( frame ) )
225 {
226 frame->Raise();
227 }
228 }
229 }
230
232 handleCursorCapture( x, y );
233
235 isAutoPanning = handleAutoPanning( aEvent );
236
237 if( !isAutoPanning && aEvent.Dragging() )
238 {
239 if( m_state == DRAG_PANNING )
240 {
241 static bool justWarped = false;
242 int warpX = 0;
243 int warpY = 0;
244 wxSize parentSize = m_parentPanel->GetClientSize();
245
246 if( x < 0 )
247 {
248 warpX = parentSize.x;
249 }
250 else if(x >= parentSize.x )
251 {
252 warpX = -parentSize.x;
253 }
254
255 if( y < 0 )
256 {
257 warpY = parentSize.y;
258 }
259 else if( y >= parentSize.y )
260 {
261 warpY = -parentSize.y;
262 }
263
264 if( !justWarped )
265 {
266 VECTOR2D d = m_dragStartPoint - mousePos;
267 m_dragStartPoint = mousePos;
268 VECTOR2D delta = m_view->ToWorld( d, false );
270 aEvent.StopPropagation();
271 }
272
273 if( warpX || warpY )
274 {
275 if( !justWarped )
276 {
277 KIPLATFORM::UI::WarpPointer( m_parentPanel, x + warpX, y + warpY );
278 m_dragStartPoint += VECTOR2D( warpX, warpY );
279 justWarped = true;
280 }
281 else
282 justWarped = false;
283 }
284 else
285 justWarped = false;
286 }
287 else if( m_state == DRAG_ZOOMING )
288 {
289 static bool justWarped = false;
290 int warpY = 0;
291 wxSize parentSize = m_parentPanel->GetClientSize();
292
293 if( y < 0 )
294 {
295 warpY = parentSize.y;
296 }
297 else if( y >= parentSize.y )
298 {
299 warpY = -parentSize.y;
300 }
301
302 if( !justWarped )
303 {
304 VECTOR2D d = m_dragStartPoint - mousePos;
305 m_dragStartPoint = mousePos;
306
307 double scale = exp( d.y * m_settings.m_zoomSpeed * 0.001 );
308
309 wxLogTrace( traceZoomScroll, wxString::Format( "dy: %f scale: %f", d.y, scale ) );
310
312 aEvent.StopPropagation();
313 }
314
315 if( warpY )
316 {
317 if( !justWarped )
318 {
320 m_dragStartPoint += VECTOR2D( 0, warpY );
321 justWarped = true;
322 }
323 else
324 justWarped = false;
325 }
326 else
327 justWarped = false;
328 }
329 }
330
331 if( m_updateCursor ) // do not update the cursor position if it was explicitly set
332 m_cursorPos = GetClampedCoords( m_view->ToWorld( mousePos ) );
333 else
334 m_updateCursor = true;
335
336 aEvent.Skip();
337}
The base class for create windows for drawing purpose.
EDA_DRAW_FRAME * GetParentEDAFrame() const
Returns parent EDA_DRAW_FRAME, if available or NULL otherwise.
double GetScale() const
Definition: view.h:269
const VECTOR2D & GetCenter() const
Return the center point of this VIEW (in world space coordinates).
Definition: view.h:339
virtual void SetScale(double aScale, VECTOR2D aAnchor={ 0, 0 })
Set the scaling factor, zooming around a given anchor point.
Definition: view.cpp:551
bool handleAutoPanning(const wxMouseEvent &aEvent)
Compute new viewport settings while in autopanning mode.
void handleCursorCapture(int x, int y)
Limit the cursor position to within the canvas by warping it.
KIWAY & Kiway() const
Return a reference to the KIWAY that this object has an opportunity to participate in.
Definition: kiway_holder.h:53
A wxFrame capable of the OpenProjectFiles function, meaning it can load a portion of a KiCad project.
Definition: kiway_player.h:66
virtual KIWAY_PLAYER * Player(FRAME_T aFrameType, bool doCreate=true, wxTopLevelWindow *aParent=nullptr)
Return the KIWAY_PLAYER* given a FRAME_T.
Definition: kiway.cpp:394
@ FRAME_PCB_EDITOR
Definition: frame_type.h:40
@ FRAME_SCH
Definition: frame_type.h:34
const wxChar *const traceZoomScroll
Flag to enable debug output of zoom-scrolling calculations in KIGFX::ZOOM_CONTROLLER and derivatives.
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
constexpr int delta

References delta, DRAG_PANNING, DRAG_ZOOMING, Format(), FRAME_PCB_EDITOR, FRAME_SCH, KIGFX::VIEW::GetCenter(), GetClampedCoords(), EDA_DRAW_PANEL_GAL::GetParentEDAFrame(), KIGFX::VIEW::GetScale(), handleAutoPanning(), handleCursorCapture(), KIPLATFORM::UI::IsWindowActive(), KIWAY_HOLDER::Kiway(), KIGFX::VC_SETTINGS::m_autoPanEnabled, KIGFX::VC_SETTINGS::m_autoPanSettingEnabled, m_cursorPos, m_dragStartPoint, KIGFX::VC_SETTINGS::m_focusFollowSchPcb, m_parentPanel, KIGFX::VIEW_CONTROLS::m_settings, m_state, m_updateCursor, KIGFX::VIEW_CONTROLS::m_view, KIGFX::VC_SETTINGS::m_zoomSpeed, m_zoomStartPoint, KIWAY::Player(), scale, KIGFX::VIEW::SetCenter(), KIGFX::VIEW::SetScale(), KIGFX::VIEW::ToWorld(), traceZoomScroll, KIPLATFORM::UI::WarpPointer(), and VECTOR2< T >::y.

Referenced by onLeave(), and WX_VIEW_CONTROLS().

◆ onScroll()

void WX_VIEW_CONTROLS::onScroll ( wxScrollWinEvent &  aEvent)

Definition at line 596 of file wx_view_controls.cpp.

597{
598 const double linePanDelta = 0.05;
599 const double pagePanDelta = 0.5;
600
601 int type = aEvent.GetEventType();
602 int dir = aEvent.GetOrientation();
603
604 if( type == wxEVT_SCROLLWIN_THUMBTRACK )
605 {
606 auto center = m_view->GetCenter();
607 const auto& boundary = m_view->GetBoundary();
608
609 // Flip scroll direction in flipped view
610 const double xstart = ( m_view->IsMirroredX() ?
611 boundary.GetRight() : boundary.GetLeft() );
612 const double xdelta = ( m_view->IsMirroredX() ? -1 : 1 );
613
614 if( dir == wxHORIZONTAL )
615 center.x = xstart + xdelta * ( aEvent.GetPosition() / m_scrollScale.x );
616 else
617 center.y = boundary.GetTop() + aEvent.GetPosition() / m_scrollScale.y;
618
619 m_view->SetCenter( center );
620 }
621 else
622 {
623 double dist = 0;
624
625 if( type == wxEVT_SCROLLWIN_PAGEUP )
626 dist = pagePanDelta;
627 else if( type == wxEVT_SCROLLWIN_PAGEDOWN )
628 dist = -pagePanDelta;
629 else if( type == wxEVT_SCROLLWIN_LINEUP )
630 dist = linePanDelta;
631 else if( type == wxEVT_SCROLLWIN_LINEDOWN )
632 dist = -linePanDelta;
633 else
634 wxCHECK_MSG( false, /* void */, wxT( "Unhandled event type" ) );
635
636 VECTOR2D scroll = m_view->ToWorld( m_view->GetScreenPixelSize(), false ) * dist;
637
638 double scrollX = 0.0;
639 double scrollY = 0.0;
640
641 if ( dir == wxHORIZONTAL )
642 scrollX = -scroll.x;
643 else
644 scrollY = -scroll.y;
645
646 VECTOR2D delta( scrollX, scrollY );
647
649 }
650
652}
coord_type GetTop() const
Definition: box2.h:194
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=nullptr) override
Update the board display after modifying it by a python script (note: it is automatically called by a...
bool IsMirroredX() const
Return true if view is flipped across the X axis.
Definition: view.h:243
const BOX2D & GetBoundary() const
Definition: view.h:298

References delta, KIGFX::VIEW::GetBoundary(), KIGFX::VIEW::GetCenter(), KIGFX::VIEW::GetScreenPixelSize(), BOX2< Vec >::GetTop(), KIGFX::VIEW::IsMirroredX(), m_parentPanel, m_scrollScale, KIGFX::VIEW_CONTROLS::m_view, EDA_DRAW_PANEL_GAL::Refresh(), 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 529 of file wx_view_controls.cpp.

530{
531 switch( m_state )
532 {
533 case AUTO_PANNING:
534 {
536 {
537 setState( IDLE );
538 return;
539 }
540
541 #ifdef __WXMSW__
542 // Hackfix: It's possible for the mouse to leave the canvas
543 // without triggering any leave events on windows
544 // Use a MSW only wx function
545 if( !m_parentPanel->IsMouseInWindow() )
546 {
547 m_panTimer.Stop();
548 setState( IDLE );
549 return;
550 }
551 #endif
552
553 if( !m_parentPanel->HasFocus() && !m_parentPanel->StatusPopupHasFocus() )
554 {
555 setState( IDLE );
556 return;
557 }
558
559 double borderSize = std::min( m_settings.m_autoPanMargin * m_view->GetScreenPixelSize().x,
561
562 // When the mouse cursor is outside the area with no pan,
563 // m_panDirection is the dist to this area limit ( in pixels )
564 // It will be used also as pan value (the pan speed depends on this dist).
566
567 // When the mouse cursor is outside the area with no pan, the pan value
568 // is accelerated depending on the dist between the area and the cursor
569 float accel = 0.5f + ( m_settings.m_autoPanAcceleration / 5.0f );
570
571 // For a small mouse cursor dist to area, just use the distance.
572 // But for a dist > borderSize / 2, use an accelerated pan value
573
574 if( dir.EuclideanNorm() >= borderSize ) // far from area limits
575 dir = dir.Resize( borderSize * accel );
576 else if( dir.EuclideanNorm() > borderSize / 2 ) // Near from area limits
577 dir = dir.Resize( borderSize );
578
579 dir = m_view->ToWorld( dir, false );
580 m_view->SetCenter( m_view->GetCenter() + dir );
581
582 refreshMouse( true );
583
584 m_panTimer.Start();
585 }
586 break;
587
588 case IDLE: // Just remove unnecessary warnings
589 case DRAG_PANNING:
590 case DRAG_ZOOMING:
591 break;
592 }
593}
void refreshMouse(bool aSetModifiers)
Send an event to refresh mouse position.

References AUTO_PANNING, DRAG_PANNING, DRAG_ZOOMING, VECTOR2< T >::EuclideanNorm(), KIGFX::VIEW::GetCenter(), KIGFX::VIEW::GetScreenPixelSize(), IDLE, KIGFX::VC_SETTINGS::m_autoPanAcceleration, KIGFX::VC_SETTINGS::m_autoPanEnabled, KIGFX::VC_SETTINGS::m_autoPanMargin, m_panDirection, m_panTimer, m_parentPanel, KIGFX::VIEW_CONTROLS::m_settings, m_state, KIGFX::VIEW_CONTROLS::m_view, refreshMouse(), VECTOR2< T >::Resize(), KIGFX::VIEW::SetCenter(), setState(), EDA_DRAW_PANEL_GAL::StatusPopupHasFocus(), 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 340 of file wx_view_controls.cpp.

341{
342#ifdef __WXGTK3__
343 if( aEvent.GetTimestamp() == m_lastTimestamp )
344 {
345 aEvent.Skip( false );
346 return;
347 }
348
349 m_lastTimestamp = aEvent.GetTimestamp();
350#endif
351
352 const double wheelPanSpeed = 0.001;
353 const int axis = aEvent.GetWheelAxis();
354
355 if( axis == wxMOUSE_WHEEL_HORIZONTAL && !m_settings.m_horizontalPan )
356 return;
357
358 // Pick the modifier, if any. Shift beats control beats alt, we don't support more than one.
359 int modifiers =
360 aEvent.ShiftDown() ? WXK_SHIFT :
361 ( aEvent.ControlDown() ? WXK_CONTROL : ( aEvent.AltDown() ? WXK_ALT : 0 ) );
362
363 // Restrict zoom handling to the vertical axis, otherwise horizontal
364 // scrolling events (e.g. touchpads and some mice) end up interpreted
365 // as vertical scroll events and confuse the user.
366 if( axis == wxMOUSE_WHEEL_VERTICAL && modifiers == m_settings.m_scrollModifierZoom )
367 {
368 const int rotation = aEvent.GetWheelRotation();
369 const double zoomScale = m_zoomController->GetScaleForRotation( rotation );
370
372 {
374 m_view->SetScale( m_view->GetScale() * zoomScale );
375 }
376 else
377 {
378 const VECTOR2D anchor = m_view->ToWorld( VECTOR2D( aEvent.GetX(), aEvent.GetY() ) );
379 m_view->SetScale( m_view->GetScale() * zoomScale, anchor );
380 }
381
382 // Refresh the zoom level and mouse position on message panel
383 // (mouse position has not changed, only the zoom level has changed):
384 refreshMouse( true );
385 }
386 else
387 {
388 // Scrolling
389 VECTOR2D scrollVec = m_view->ToWorld( m_view->GetScreenPixelSize(), false ) *
390 ( (double) aEvent.GetWheelRotation() * wheelPanSpeed );
391 double scrollX = 0.0;
392 double scrollY = 0.0;
393
394 if( axis == wxMOUSE_WHEEL_HORIZONTAL || modifiers == m_settings.m_scrollModifierPanH )
395 scrollX = scrollVec.x;
396 else
397 scrollY = -scrollVec.y;
398
399 VECTOR2D delta( scrollX, scrollY );
400
402 refreshMouse( true );
403 }
404
405 // Do not skip this event, otherwise wxWidgets will fire
406 // 3 wxEVT_SCROLLWIN_LINEUP or wxEVT_SCROLLWIN_LINEDOWN (normal wxWidgets behavior)
407 // and we do not want that.
409}
bool IsCursorWarpingEnabled() const
void CenterOnCursor() override
Adjusts the scrollbars position to match the current viewport.

References anchor, CenterOnCursor(), delta, KIGFX::VIEW::GetCenter(), KIGFX::VIEW::GetScale(), KIGFX::VIEW::GetScreenPixelSize(), KIGFX::VIEW_CONTROLS::IsCursorWarpingEnabled(), KIGFX::VC_SETTINGS::m_horizontalPan, m_parentPanel, KIGFX::VC_SETTINGS::m_scrollModifierPanH, KIGFX::VC_SETTINGS::m_scrollModifierZoom, KIGFX::VIEW_CONTROLS::m_settings, KIGFX::VIEW_CONTROLS::m_view, m_zoomController, EDA_DRAW_PANEL_GAL::Refresh(), refreshMouse(), KIGFX::VIEW::SetCenter(), KIGFX::VIEW::SetScale(), KIGFX::VIEW::ToWorld(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by WX_VIEW_CONTROLS().

◆ PinCursorInsideNonAutoscrollArea()

void WX_VIEW_CONTROLS::PinCursorInsideNonAutoscrollArea ( bool  aWarpMouseCursor)
overridevirtual

Return the current mouse pointer position.

Note
The position may be different from the cursor position if snapping is enabled (
See also
GetCursorPosition()).
Note
The position is clamped if outside of coordinates representation limits.
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 825 of file wx_view_controls.cpp.

826{
827 int border = std::min( m_settings.m_autoPanMargin * m_view->GetScreenPixelSize().x,
829 border += 2;
830
831 VECTOR2D topLeft( border, border );
832 VECTOR2D botRight( m_view->GetScreenPixelSize().x - border,
833 m_view->GetScreenPixelSize().y - border );
834
835 topLeft = m_view->ToWorld( topLeft );
836 botRight = m_view->ToWorld( botRight );
837
838 VECTOR2D pos = GetMousePosition( true );
839
840 if( pos.x < topLeft.x )
841 pos.x = topLeft.x;
842 else if( pos.x > botRight.x )
843 pos.x = botRight.x;
844
845 if( pos.y < topLeft.y )
846 pos.y = topLeft.y;
847 else if( pos.y > botRight.y )
848 pos.y = botRight.y;
849
850 SetCursorPosition( pos, false, false, 0 );
851
852 if( aWarpMouseCursor )
853 WarpMouseCursor( pos, true );
854}
void SetCursorPosition(const VECTOR2D &aPosition, bool warpView, bool aTriggeredByArrows, long aArrowCommand) override
Move the graphic crosshair cursor to the requested position expressed in world coordinates.
void WarpMouseCursor(const VECTOR2D &aPosition, bool aWorldCoordinates=false, bool aWarpView=false) override
Set the viewport center to the current cursor position and warps the cursor to the screen center.

References GetMousePosition(), KIGFX::VIEW::GetScreenPixelSize(), KIGFX::VC_SETTINGS::m_autoPanMargin, KIGFX::VIEW_CONTROLS::m_settings, KIGFX::VIEW_CONTROLS::m_view, SetCursorPosition(), KIGFX::VIEW::ToWorld(), WarpMouseCursor(), VECTOR2< T >::x, and VECTOR2< T >::y.

◆ refreshMouse()

void WX_VIEW_CONTROLS::refreshMouse ( bool  aSetModifiers)
private

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

Parameters
aSetModifiersIf false, don't change the modifiers (they were set using the keyboard motion)

Definition at line 968 of file wx_view_controls.cpp.

969{
970 // Notify tools that the cursor position has changed in the world coordinates
971 wxMouseEvent moveEvent( EVT_REFRESH_MOUSE );
972 wxPoint msp = getMouseScreenPosition();
973 moveEvent.SetX( msp.x );
974 moveEvent.SetY( msp.y );
975
976 if( aSetModifiers )
977 {
978 // Set the modifiers state
979 moveEvent.SetControlDown( wxGetKeyState( WXK_CONTROL ) );
980 moveEvent.SetShiftDown( wxGetKeyState( WXK_SHIFT ) );
981 moveEvent.SetAltDown( wxGetKeyState( WXK_ALT ) );
982 }
983
984 m_cursorPos = GetClampedCoords( m_view->ToWorld( VECTOR2D( msp.x, msp.y ) ) );
985 wxPostEvent( m_parentPanel, moveEvent );
986}
static const wxEventType EVT_REFRESH_MOUSE

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

Referenced by onTimer(), onWheel(), UpdateScrollbars(), and WarpMouseCursor().

◆ Reset()

void VIEW_CONTROLS::Reset ( )
virtualinherited

Restore the default VIEW_CONTROLS settings.

Return the current VIEW_CONTROLS settings.

Definition at line 50 of file view_controls.cpp.

51{
52 // Get the default settings from the default constructor
55}
void ApplySettings(const VC_SETTINGS &aSettings)
Load new settings from program common settings.
static LIB_SYMBOL * dummy()
Used when a LIB_SYMBOL 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:42

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

◆ SetAutoPan()

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

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

160 {
161 m_settings.m_autoPanEnabled = aEnabled;
162 }

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

Referenced by KIGFX::VIEW_CONTROLS::ApplySettings(), SCH_LINE_WIRE_BUS_TOOL::doDrawSegments(), PCB_TOOL_BASE::doInteractiveItemPlacement(), EDIT_TOOL::doMoveSelection(), EDIT_TOOL::DragArcTrack(), DRAWING_TOOL::drawArc(), DRAWING_TOOL::DrawDimension(), MICROWAVE_TOOL::drawMicrowaveInductor(), SCH_DRAWING_TOOLS::DrawShape(), SYMBOL_EDITOR_DRAWING_TOOLS::DrawShape(), PL_DRAWING_TOOLS::DrawShape(), DRAWING_TOOL::drawShape(), SCH_DRAWING_TOOLS::DrawSheet(), DRAWING_TOOL::DrawZone(), ROUTER_TOOL::finishInteractive(), SCH_LINE_WIRE_BUS_TOOL::finishSegments(), ROUTER_TOOL::InlineDrag(), EE_POINT_EDITOR::Main(), SYMBOL_EDITOR_MOVE_TOOL::Main(), PL_EDIT_TOOL::Main(), PL_POINT_EDITOR::Main(), GERBVIEW_INSPECTION_TOOL::MeasureTool(), PCB_POINT_EDITOR::OnSelectionChange(), ROUTER_TOOL::performDragging(), ROUTER_TOOL::performRouting(), LENGTH_TUNER_TOOL::performTuning(), BOARD_EDITOR_CONTROL::PlaceFootprint(), SCH_DRAWING_TOOLS::PlaceImage(), DRAWING_TOOL::PlaceImage(), PL_DRAWING_TOOLS::PlaceItem(), SCH_DRAWING_TOOLS::PlaceSymbol(), DRAWING_TOOL::PlaceText(), ROUTER_TOOL::prepareInteractive(), PCB_POINT_EDITOR::Reset(), EE_SELECTION_TOOL::selectMultiple(), PL_SELECTION_TOOL::selectMultiple(), PCB_SELECTION_TOOL::selectMultiple(), ZOOM_TOOL::selectRegion(), DRAWING_TOOL::SetAnchor(), PICKER_TOOL::setControls(), PCB_PICKER_TOOL::setControls(), SCH_DRAWING_TOOLS::TwoClickPlace(), and SYMBOL_EDITOR_DRAWING_TOOLS::TwoClickPlace().

◆ SetAutoPanAcceleration()

virtual void KIGFX::VIEW_CONTROLS::SetAutoPanAcceleration ( float  aAcceleration)
inlinevirtualinherited

Set the speed of autopanning.

Parameters
aSpeedis a new speed for autopanning.

Definition at line 189 of file view_controls.h.

190 {
191 m_settings.m_autoPanAcceleration = aAcceleration;
192 }

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

◆ SetAutoPanMargin()

virtual void KIGFX::VIEW_CONTROLS::SetAutoPanMargin ( float  aMargin)
inlinevirtualinherited

Set the margin for autopanning (ie.

the area when autopanning becomes active).

Parameters
aMarginis a new margin for autopanning.

Definition at line 199 of file view_controls.h.

200 {
201 m_settings.m_autoPanMargin = aMargin;
202 }

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

Set the speed of autopanning.

Parameters
aSpeedis a new speed for autopanning.

Definition at line 179 of file view_controls.h.

180 {
181 m_settings.m_autoPanSpeed = aSpeed;
182 }

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

Implements KIGFX::VIEW_CONTROLS.

Definition at line 759 of file wx_view_controls.cpp.

761{
762 m_updateCursor = false;
763
764 VECTOR2D clampedPosition = GetClampedCoords( aPosition );
765
766 const VECTOR2I& screenSize = m_view->GetGAL()->GetScreenPixelSize();
767 BOX2I screen( VECTOR2I( 0, 0 ), screenSize );
768 VECTOR2D screenPos = m_view->ToScreen( clampedPosition );
769
770 if( aWarpView && !screen.Contains( screenPos ) )
771 m_view->SetCenter( clampedPosition );
772
773 m_cursorPos = clampedPosition;
774}
VECTOR2< int > VECTOR2I
Definition: vector2d.h:618

References BOX2< Vec >::Contains(), GetClampedCoords(), 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  warpView,
bool  aTriggeredByArrows,
long  aArrowCommand 
)
overridevirtual

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

Note
The position is clamped if outside of coordinates representation limits.
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 732 of file wx_view_controls.cpp.

734{
735 m_updateCursor = false;
736
737 VECTOR2D clampedPosition = GetClampedCoords( aPosition );
738
739 if( aTriggeredByArrows )
740 {
744 m_cursorWarped = false;
745 }
746 else
747 {
751 m_cursorWarped = true;
752 }
753
754 WarpMouseCursor( clampedPosition, true, aWarpView );
755 m_cursorPos = clampedPosition;
756}

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

Referenced by PinCursorInsideNonAutoscrollArea().

◆ SetGrabMouse()

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

Turn on/off mouse grabbing.

When the mouse is grabbed, it cannot go outside the VIEW.

Parameters
aEnabledtells if mouse should be grabbed or not.

Definition at line 148 of file view_controls.h.

149 {
150 m_settings.m_grabMouse = aEnabled;
151 }

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

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

◆ setState()

void WX_VIEW_CONTROLS::setState ( STATE  aNewState)
private

Sets the interaction state, simply a internal setter to make it easier to debug changes.

Definition at line 424 of file wx_view_controls.cpp.

425{
426 m_state = aNewState;
427}

References m_state.

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

◆ ShowCursor()

void VIEW_CONTROLS::ShowCursor ( bool  aEnabled)
virtualinherited

Enable or disables display of cursor.

Parameters
aEnableddecides if the cursor should be shown.

Definition at line 34 of file view_controls.cpp.

35{
36 m_settings.m_showCursor = aEnabled;
37 m_view->GetGAL()->SetCursorEnabled( aEnabled );
38}
void SetCursorEnabled(bool aCursorEnabled)
Enable/disable cursor.

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_LINE_WIRE_BUS_TOOL::doDrawSegments(), PCB_TOOL_BASE::doInteractiveItemPlacement(), EDIT_TOOL::doMoveSelection(), EDIT_TOOL::DragArcTrack(), DRAWING_TOOL::drawArc(), DRAWING_TOOL::DrawDimension(), MICROWAVE_TOOL::drawMicrowaveInductor(), SCH_DRAWING_TOOLS::DrawShape(), SYMBOL_EDITOR_DRAWING_TOOLS::DrawShape(), PL_DRAWING_TOOLS::DrawShape(), DRAWING_TOOL::drawShape(), SCH_DRAWING_TOOLS::DrawSheet(), DRAWING_TOOL::DrawZone(), PAD_TOOL::EnumeratePads(), ROUTER_TOOL::InlineDrag(), DRAWING_TOOL::InteractivePlaceWithPreview(), EE_POINT_EDITOR::Main(), SYMBOL_EDITOR_MOVE_TOOL::Main(), PL_EDIT_TOOL::Main(), PL_POINT_EDITOR::Main(), PCB_PICKER_TOOL::Main(), LENGTH_TUNER_TOOL::MainLoop(), ROUTER_TOOL::MainLoop(), GERBVIEW_INSPECTION_TOOL::MeasureTool(), PCB_POINT_EDITOR::OnSelectionChange(), SYMBOL_EDITOR_DRAWING_TOOLS::PlaceAnchor(), BOARD_EDITOR_CONTROL::PlaceFootprint(), SCH_DRAWING_TOOLS::PlaceImage(), DRAWING_TOOL::PlaceImage(), DRAWING_TOOL::PlaceImportedGraphics(), PL_DRAWING_TOOLS::PlaceItem(), SCH_DRAWING_TOOLS::PlaceSymbol(), DRAWING_TOOL::PlaceText(), ROUTER_TOOL::RouteSelected(), DRAWING_TOOL::SetAnchor(), EE_POINT_EDITOR::setEditedPoint(), PL_POINT_EDITOR::setEditedPoint(), PCB_POINT_EDITOR::setEditedPoint(), SCH_DRAWING_TOOLS::SingleClickPlace(), SCH_DRAWING_TOOLS::TwoClickPlace(), and SYMBOL_EDITOR_DRAWING_TOOLS::TwoClickPlace().

◆ UpdateScrollbars()

void WX_VIEW_CONTROLS::UpdateScrollbars ( )

End any mouse drag action still in progress.

Definition at line 997 of file wx_view_controls.cpp.

998{
999 const BOX2D viewport = m_view->GetViewport();
1000 const BOX2D& boundary = m_view->GetBoundary();
1001
1002 m_scrollScale.x = 2e3 / viewport.GetWidth(); // TODO it does not have to be updated so often
1003 m_scrollScale.y = 2e3 / viewport.GetHeight();
1004 VECTOR2I newScroll( ( viewport.Centre().x - boundary.GetLeft() ) * m_scrollScale.x,
1005 ( viewport.Centre().y - boundary.GetTop() ) * m_scrollScale.y );
1006
1007 // We add the width of the scroll bar thumb to the range because the scroll range is given by
1008 // the full bar while the position is given by the left/top position of the thumb
1009 VECTOR2I newRange( m_scrollScale.x * boundary.GetWidth() +
1010 m_parentPanel->GetScrollThumb( wxSB_HORIZONTAL ),
1011 m_scrollScale.y * boundary.GetHeight() +
1012 m_parentPanel->GetScrollThumb( wxSB_VERTICAL ) );
1013
1014 // Flip scroll direction in flipped view
1015 if( m_view->IsMirroredX() )
1016 newScroll.x = ( boundary.GetRight() - viewport.Centre().x ) * m_scrollScale.x;
1017
1018 // Adjust scrollbars only if it is needed. Otherwise there are cases when canvas is continuously
1019 // refreshed (Windows)
1020 if( m_scrollPos != newScroll || newRange.x != m_parentPanel->GetScrollRange( wxSB_HORIZONTAL )
1021 || newRange.y != m_parentPanel->GetScrollRange( wxSB_VERTICAL ) )
1022 {
1023 m_parentPanel->SetScrollbars( 1, 1, newRange.x, newRange.y, newScroll.x, newScroll.y,
1024 true );
1025 m_scrollPos = newScroll;
1026
1027#if !defined( __APPLE__ ) && !defined( WIN32 )
1028 // Trigger a mouse refresh to get the canvas update in GTK (re-draws the scrollbars).
1029 // Note that this causes an infinite loop on OSX and Windows (in certain cases) as it
1030 // generates a paint event.
1031 refreshMouse( false );
1032#endif
1033 }
1034}
coord_type GetHeight() const
Definition: box2.h:188
coord_type GetWidth() const
Definition: box2.h:187
Vec Centre() const
Definition: box2.h:70
coord_type GetRight() const
Definition: box2.h:189
coord_type GetLeft() const
Definition: box2.h:193
BOX2D GetViewport() const
Return the current viewport visible area rectangle.
Definition: view.cpp:511
VECTOR2I m_scrollPos
The mouse position when a drag zoom started.

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, refreshMouse(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by EDA_DRAW_PANEL_GAL::DoRePaint().

◆ WarpMouseCursor()

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

Set the viewport center to the current cursor position and warps the cursor to the screen center.

Implements KIGFX::VIEW_CONTROLS.

Definition at line 777 of file wx_view_controls.cpp.

779{
780 if( aWorldCoordinates )
781 {
782 const VECTOR2I& screenSize = m_view->GetGAL()->GetScreenPixelSize();
783 BOX2I screen( VECTOR2I( 0, 0 ), screenSize );
784 VECTOR2D clampedPosition = GetClampedCoords( aPosition );
785 VECTOR2D screenPos = m_view->ToScreen( clampedPosition );
786
787 if( !screen.Contains( screenPos ) )
788 {
789 if( aWarpView )
790 {
791 m_view->SetCenter( clampedPosition );
792 KIPLATFORM::UI::WarpPointer( m_parentPanel, screenSize.x / 2, screenSize.y / 2 );
793 }
794 }
795 else
796 {
797 KIPLATFORM::UI::WarpPointer( m_parentPanel, screenPos.x, screenPos.y );
798 }
799 }
800 else
801 {
802 KIPLATFORM::UI::WarpPointer( m_parentPanel, aPosition.x, aPosition.y );
803 }
804
805 // If we are not refreshing because of mouse movement, don't set the modifiers
806 // because we are refreshing for keyboard movement, which uses the same modifiers for other actions
808}

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

Referenced by PinCursorInsideNonAutoscrollArea(), and SetCursorPosition().

Member Data Documentation

◆ EVT_REFRESH_MOUSE

const wxEventType WX_VIEW_CONTROLS::EVT_REFRESH_MOUSE = wxNewEventType()
static

◆ m_cursorPos

VECTOR2D KIGFX::WX_VIEW_CONTROLS::m_cursorPos
private

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

Definition at line 200 of file wx_view_controls.h.

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

◆ m_cursorWarped

bool KIGFX::VIEW_CONTROLS::m_cursorWarped
protectedinherited

Current VIEW_CONTROLS settings.

Definition at line 381 of file view_controls.h.

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

◆ m_dragStartPoint

VECTOR2D KIGFX::WX_VIEW_CONTROLS::m_dragStartPoint
private

Current direction of panning (only autopanning mode).

Definition at line 177 of file wx_view_controls.h.

Referenced by CenterOnCursor(), onButton(), and onMotion().

◆ m_MotionEventCounter

std::unique_ptr<PROF_COUNTER> KIGFX::WX_VIEW_CONTROLS::m_MotionEventCounter

Definition at line 121 of file wx_view_controls.h.

Referenced by EVT_UPDATE_UI_RANGE(), and WX_VIEW_CONTROLS().

◆ m_panDirection

VECTOR2D KIGFX::WX_VIEW_CONTROLS::m_panDirection
private

Timer responsible for handling autopanning.

Definition at line 180 of file wx_view_controls.h.

Referenced by handleAutoPanning(), and onTimer().

◆ m_panTimer

wxTimer KIGFX::WX_VIEW_CONTROLS::m_panTimer
private

Ratio used for scaling world coordinates to scrollbar position.

Definition at line 183 of file wx_view_controls.h.

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

◆ m_parentPanel

EDA_DRAW_PANEL_GAL* KIGFX::WX_VIEW_CONTROLS::m_parentPanel
private

◆ m_scrollPos

VECTOR2I KIGFX::WX_VIEW_CONTROLS::m_scrollPos
private

The mouse position when a drag zoom started.

Definition at line 189 of file wx_view_controls.h.

Referenced by UpdateScrollbars().

◆ m_scrollScale

VECTOR2D KIGFX::WX_VIEW_CONTROLS::m_scrollScale
private

Current scrollbar position.

Definition at line 186 of file wx_view_controls.h.

Referenced by onScroll(), and UpdateScrollbars().

◆ m_settings

◆ m_state

STATE KIGFX::WX_VIEW_CONTROLS::m_state
private

Panel that is affected by VIEW_CONTROLS.

Definition at line 171 of file wx_view_controls.h.

Referenced by CancelDrag(), CaptureCursor(), handleAutoPanning(), onButton(), onMotion(), onTimer(), and setState().

◆ m_updateCursor

bool KIGFX::WX_VIEW_CONTROLS::m_updateCursor
private

A #ZOOM_CONTROLLER that determines zoom steps. This is platform-specific.

Definition at line 203 of file wx_view_controls.h.

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

◆ m_view

VIEW* KIGFX::VIEW_CONTROLS::m_view
protectedinherited

◆ m_zoomController

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

Definition at line 206 of file wx_view_controls.h.

Referenced by LoadSettings(), and onWheel().

◆ m_zoomStartPoint

VECTOR2D KIGFX::WX_VIEW_CONTROLS::m_zoomStartPoint
private

Current cursor position (world coordinates).

Definition at line 192 of file wx_view_controls.h.

Referenced by onButton(), and onMotion().


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