KiCad PCB EDA Suite
KIGFX::WX_VIEW_CONTROLS Class Reference

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, long aArrowCommand) 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...
 
void LoadSettings () override
 

Applies VIEW_CONTROLS settings from the program COMMON_SETTINGS

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 SetAutoPanAcceleration (float aAcceleration)
 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 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, DRAG_ZOOMING }
 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...
 
double m_initialZoomScale
 The zoom scale when a drag zoom started. 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

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.

DRAG_ZOOMING 

Panning on approaching borders of the frame.

Definition at line 115 of file wx_view_controls.h.

116  {
117  IDLE = 1,
118  DRAG_PANNING,
119  AUTO_PANNING,
120  DRAG_ZOOMING,
121  };
Panning on approaching borders of the frame.
Panning with mouse button pressed.

Constructor & Destructor Documentation

◆ WX_VIEW_CONTROLS()

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

Definition at line 61 of file wx_view_controls.cpp.

61  :
62  VIEW_CONTROLS( aView ),
63  m_state( IDLE ),
64  m_parentPanel( aParentPanel ),
65  m_scrollScale( 1.0, 1.0 ),
66  m_initialZoomScale( 0.0 ),
67 #ifdef __WXGTK3__
68  m_lastTimestamp( 0 ),
69 #endif
70  m_cursorPos( 0, 0 ),
71  m_updateCursor( true )
72 {
73  LoadSettings();
74 
75  m_parentPanel->Connect( wxEVT_MOTION,
76  wxMouseEventHandler( WX_VIEW_CONTROLS::onMotion ), NULL, this );
77 #if wxCHECK_VERSION( 3, 1, 0 ) || defined( USE_OSX_MAGNIFY_EVENT )
78  m_parentPanel->Connect( wxEVT_MAGNIFY,
79  wxMouseEventHandler( WX_VIEW_CONTROLS::onMagnify ), NULL, this );
80 #endif
81  m_parentPanel->Connect( wxEVT_MOUSEWHEEL,
82  wxMouseEventHandler( WX_VIEW_CONTROLS::onWheel ), NULL, this );
83  m_parentPanel->Connect( wxEVT_MIDDLE_UP,
84  wxMouseEventHandler( WX_VIEW_CONTROLS::onButton ), NULL, this );
85  m_parentPanel->Connect( wxEVT_MIDDLE_DOWN,
86  wxMouseEventHandler( WX_VIEW_CONTROLS::onButton ), NULL, this );
87  m_parentPanel->Connect( wxEVT_LEFT_UP,
88  wxMouseEventHandler( WX_VIEW_CONTROLS::onButton ), NULL, this );
89  m_parentPanel->Connect( wxEVT_LEFT_DOWN,
90  wxMouseEventHandler( WX_VIEW_CONTROLS::onButton ), NULL, this );
91  m_parentPanel->Connect( wxEVT_RIGHT_UP,
92  wxMouseEventHandler( WX_VIEW_CONTROLS::onButton ), NULL, this );
93  m_parentPanel->Connect( wxEVT_RIGHT_DOWN,
94  wxMouseEventHandler( WX_VIEW_CONTROLS::onButton ), NULL, this );
95 #if defined _WIN32 || defined _WIN64
96  m_parentPanel->Connect( wxEVT_ENTER_WINDOW,
97  wxMouseEventHandler( WX_VIEW_CONTROLS::onEnter ), NULL, this );
98 #endif
99  m_parentPanel->Connect( wxEVT_LEAVE_WINDOW,
100  wxMouseEventHandler( WX_VIEW_CONTROLS::onLeave ), NULL, this );
101  m_parentPanel->Connect( wxEVT_SCROLLWIN_THUMBTRACK,
102  wxScrollWinEventHandler( WX_VIEW_CONTROLS::onScroll ), NULL, this );
103  m_parentPanel->Connect( wxEVT_SCROLLWIN_PAGEUP,
104  wxScrollWinEventHandler( WX_VIEW_CONTROLS::onScroll ), NULL, this );
105  m_parentPanel->Connect( wxEVT_SCROLLWIN_PAGEDOWN,
106  wxScrollWinEventHandler( WX_VIEW_CONTROLS::onScroll ), NULL, this );
107 
108  m_parentPanel->Connect( wxEVT_SCROLLWIN_BOTTOM,
109  wxScrollWinEventHandler( WX_VIEW_CONTROLS::onScroll ), NULL, this );
110  m_parentPanel->Connect( wxEVT_SCROLLWIN_TOP,
111  wxScrollWinEventHandler( WX_VIEW_CONTROLS::onScroll ), NULL, this );
112  m_parentPanel->Connect( wxEVT_SCROLLWIN_LINEUP,
113  wxScrollWinEventHandler( WX_VIEW_CONTROLS::onScroll ), NULL, this );
114  m_parentPanel->Connect( wxEVT_SCROLLWIN_LINEDOWN,
115  wxScrollWinEventHandler( WX_VIEW_CONTROLS::onScroll ), NULL, this );
116 
117  m_cursorWarped = false;
118 
119  m_panTimer.SetOwner( this );
120  this->Connect( wxEVT_TIMER, wxTimerEventHandler( WX_VIEW_CONTROLS::onTimer ), NULL, this );
121 
125 }
void LoadSettings() override
Applies VIEW_CONTROLS settings from the program COMMON_SETTINGS
VIEW_CONTROLS(VIEW *aView)
void onButton(wxMouseEvent &aEvent)
VC_SETTINGS m_settings
Current VIEW_CONTROLS settings
VECTOR2D m_scrollScale
Ratio used for scaling world coordinates to scrollbar position.
VECTOR2D m_lastKeyboardCursorPosition
Position of the above event
void onWheel(wxMouseEvent &aEvent)
Handler functions.
#define NULL
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))
long m_lastKeyboardCursorCommand
ACTIONS::CURSOR_UP, ACTIONS::CURSOR_DOWN, etc.
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
double m_initialZoomScale
The zoom scale when a drag zoom started.
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 LoadSettings(), KIGFX::VIEW_CONTROLS::m_cursorWarped, KIGFX::VC_SETTINGS::m_lastKeyboardCursorCommand, KIGFX::VC_SETTINGS::m_lastKeyboardCursorPosition, KIGFX::VC_SETTINGS::m_lastKeyboardCursorPositionValid, m_panTimer, m_parentPanel, KIGFX::VIEW_CONTROLS::m_settings, NULL, onButton(), onEnter(), onLeave(), onMotion(), onScroll(), onTimer(), and onWheel().

◆ ~WX_VIEW_CONTROLS()

WX_VIEW_CONTROLS::~WX_VIEW_CONTROLS ( )
virtual

Definition at line 128 of file wx_view_controls.cpp.

129 {
130 }

Member Function Documentation

◆ ApplySettings()

void VIEW_CONTROLS::ApplySettings ( const VC_SETTINGS aSettings)
inherited

Applies VIEW_CONTROLS settings from an object

Definition at line 86 of file view_controls.cpp.

87 {
88  ShowCursor( aSettings.m_showCursor );
89  CaptureCursor( aSettings.m_cursorCaptured );
90  SetSnapping( aSettings.m_snappingEnabled );
91  SetGrabMouse( aSettings.m_grabMouse );
92  SetAutoPan( aSettings.m_autoPanEnabled );
93  SetAutoPanMargin( aSettings.m_autoPanMargin );
94  SetAutoPanSpeed( aSettings.m_autoPanSpeed );
96 }
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:93
bool m_snappingEnabled
Should the cursor snap to grid or move freely
Definition: view_controls.h:78
bool m_grabMouse
Flag for grabbing the mouse cursor
Definition: view_controls.h:81
VECTOR2D m_forcedPosition
Forced cursor position (world coordinates)
Definition: view_controls.h:69
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:72
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:90
bool m_autoPanEnabled
Flag for turning on autopanning
Definition: view_controls.h:84
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:66
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:75

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(), DIALOG_PAD_PROPERTIES::prepareCanvas(), and KIGFX::VIEW_CONTROLS::Reset().

◆ CaptureCursor()

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

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

597 {
598  const VECTOR2I& screenSize = m_view->GetGAL()->GetScreenPixelSize();
599  VECTOR2I screenCenter( screenSize / 2 );
600 
601  if( GetMousePosition( false ) != screenCenter )
602  {
604  m_parentPanel->WarpPointer( KiROUND( screenSize.x / 2 ), KiROUND( screenSize.y / 2 ) );
605  }
606 }
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:608
wxScrolledCanvas * m_parentPanel
Panel that is affected by VIEW_CONTROLS.
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: util.h:68
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 201 of file view_controls.h.

202  {
204  }
VC_SETTINGS m_settings
Current VIEW_CONTROLS settings
bool m_autoPanSettingEnabled
Flag for turning on autopanning
Definition: view_controls.h:87

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

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

371  {
372  m_settings.m_warpCursor = aEnable;
373  }
VC_SETTINGS m_settings
Current VIEW_CONTROLS settings
bool m_warpCursor
If the cursor is allowed to be warped
Definition: view_controls.h:99

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

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

748 {
750  m_settings.m_forcedPosition = aPosition;
751 }
VC_SETTINGS m_settings
Current VIEW_CONTROLS settings
VECTOR2D m_forcedPosition
Forced cursor position (world coordinates)
Definition: view_controls.h:69
bool m_forceCursorPosition
Is the forced cursor position enabled
Definition: view_controls.h:72

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

314  {
316  }
VC_SETTINGS m_settings
Current VIEW_CONTROLS settings
bool m_forceCursorPosition
Is the forced cursor position enabled
Definition: view_controls.h:72

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

255  {
257  }
bool m_snappingEnabled
Should the cursor snap to grid or move freely
Definition: view_controls.h:78
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 512 of file wx_view_controls.cpp.

513 {
515  {
517  }
518  else
519  {
520  return GetRawCursorPosition( aEnableSnapping );
521  }
522 }
VC_SETTINGS m_settings
Current VIEW_CONTROLS settings
VECTOR2D m_forcedPosition
Forced cursor position (world coordinates)
Definition: view_controls.h:69
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:72

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

Referenced by EDA_DRAW_PANEL_GAL::DoRePaint().

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

255  {
257  }
bool m_snappingEnabled
Should the cursor snap to grid or move freely
Definition: view_controls.h:78
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(), FOOTPRINT_VIEWER_FRAME::AddFootprintToPCB(), CenterOnCursor(), ZONE_CREATE_HELPER::createNewZone(), TOOL_MANAGER::DispatchContextMenu(), SCH_LINE_WIRE_BUS_TOOL::doDrawSegments(), PCB_TOOL_BASE::doInteractiveItemPlacement(), EDIT_TOOL::doMoveSelection(), SCH_LINE_WIRE_BUS_TOOL::doUnfoldBus(), DRAWING_TOOL::DrawCircle(), DRAWING_TOOL::DrawLine(), MICROWAVE_TOOL::drawMicrowaveInductor(), DRAWING_TOOL::DrawRectangle(), SCH_LINE_WIRE_BUS_TOOL::DrawSegments(), LIB_DRAWING_TOOLS::DrawShape(), PL_DRAWING_TOOLS::DrawShape(), SCH_DRAWING_TOOLS::DrawSheet(), PAD_TOOL::EnumeratePads(), TOOL_MANAGER::GetCursorPosition(), SCH_EDITOR_CONTROL::HighlightNet(), ROUTER_TOOL::InlineDrag(), PL_EDIT_TOOL::Main(), EE_POINT_EDITOR::Main(), PL_POINT_EDITOR::Main(), LIB_MOVE_TOOL::Main(), SCH_MOVE_TOOL::Main(), PICKER_TOOL::Main(), ROUTER_TOOL::MainLoop(), COMMON_TOOLS::OnGridChanged(), LIB_DRAWING_TOOLS::PlaceAnchor(), SCH_DRAWING_TOOLS::PlaceComponent(), SCH_DRAWING_TOOLS::PlaceImage(), DRAWING_TOOL::PlaceImportedGraphics(), PL_DRAWING_TOOLS::PlaceItem(), PCB_EDITOR_CONTROL::PlaceModule(), PCB_EDITOR_CONTROL::PlaceTarget(), DRAWING_TOOL::PlaceText(), SCH_EDIT_TOOL::Properties(), EDIT_TOOL::Properties(), EDIT_TOOL::Remove(), SCH_EDIT_TOOL::RepeatDrawItem(), PL_SELECTION_TOOL::RequestSelection(), EE_SELECTION_TOOL::RequestSelection(), COMMON_TOOLS::ResetLocalCoords(), FOOTPRINT_EDIT_FRAME::SaveFootprintToBoard(), EE_SELECTION_TOOL::SelectNode(), SCH_DRAWING_TOOLS::SingleClickPlace(), LIB_DRAWING_TOOLS::TwoClickPlace(), SCH_DRAWING_TOOLS::TwoClickPlace(), LIB_MOVE_TOOL::updateModificationPoint(), PL_EDIT_TOOL::updateModificationPoint(), EDIT_TOOL::updateModificationPoint(), PNS::TOOL_BASE::updateStartItem(), PL_EDITOR_FRAME::UpdateStatusBar(), SCH_BASE_FRAME::UpdateStatusBar(), PCB_BASE_FRAME::UpdateStatusBar(), and GERBVIEW_FRAME::UpdateStatusBar().

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

491 {
493  VECTOR2D screenPos( msp.x, msp.y );
494 
495  return aWorldCoordinates ? m_view->ToWorld( screenPos ) : screenPos;
496 }
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:479
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, KIGFX::VIEW::ToWorld(), wxPoint::x, and wxPoint::y.

Referenced by CenterOnCursor().

◆ getMouseScreenPosition()

wxPoint WX_VIEW_CONTROLS::getMouseScreenPosition ( ) const
private

Gets the cursor position in the screen coordinates.

Definition at line 704 of file wx_view_controls.cpp.

705 {
706  wxPoint msp = wxGetMousePosition();
707  m_parentPanel->ScreenToClient( &msp.x, &msp.y );
708  return msp;
709 }
wxScrolledCanvas * m_parentPanel
Panel that is affected by VIEW_CONTROLS.

References m_parentPanel, wxPoint::x, and wxPoint::y.

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

500 {
501  if( aEnableSnapping )
502  {
503  return m_view->GetGAL()->GetGridPoint( m_cursorPos );
504  }
505  else
506  {
507  return m_cursorPos;
508  }
509 }
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 398 of file view_controls.h.

399  {
400  return m_settings;
401  }
VC_SETTINGS m_settings
Current VIEW_CONTROLS settings

References KIGFX::VIEW_CONTROLS::m_settings.

Referenced by EDIT_TOOL::doMoveSelection(), TOOL_MANAGER::GetCurrentToolVC(), DIALOG_PAD_PROPERTIES::prepareCanvas(), 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 170 of file view_controls.h.

171  {
173  }
bool m_snappingEnabled
Should the cursor snap to grid or move freely
Definition: view_controls.h:78
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 609 of file wx_view_controls.cpp.

610 {
611  VECTOR2I p( aEvent.GetX(), aEvent.GetY() );
613 
615  {
616  // last cursor move event came from keyboard cursor control. If auto-panning is enabled and
617  // the next position is inside the autopan zone, check if it really came from a mouse event, otherwise
618  // disable autopan temporarily. Also temporaly disable autopan if the cursor is in the autopan zone
619  // because the application warped the cursor.
620 
621  m_cursorWarped = false;
622  return true;
623  }
624 
625  m_cursorWarped = false;
626 
627  // Compute areas where autopanning is active
628  int borderStart = std::min( m_settings.m_autoPanMargin * m_view->GetScreenPixelSize().x,
630  borderStart = std::max( borderStart, 2 );
631  int borderEndX = m_view->GetScreenPixelSize().x - borderStart;
632  int borderEndY = m_view->GetScreenPixelSize().y - borderStart;
633 
634  if( p.x < borderStart )
635  m_panDirection.x = -( borderStart - p.x );
636  else if( p.x > borderEndX )
637  m_panDirection.x = ( p.x - borderEndX );
638  else
639  m_panDirection.x = 0;
640 
641  if( p.y < borderStart )
642  m_panDirection.y = -( borderStart - p.y );
643  else if( p.y > borderEndY )
644  m_panDirection.y = ( p.y - borderEndY );
645  else
646  m_panDirection.y = 0;
647 
648  bool borderHit = ( m_panDirection.x != 0 || m_panDirection.y != 0 );
649 
650  switch( m_state )
651  {
652  case AUTO_PANNING:
653  if( !borderHit )
654  {
655  m_panTimer.Stop();
656  m_state = IDLE;
657 
658  return false;
659  }
660 
661  return true;
662  break;
663 
664  case IDLE:
665  if( borderHit )
666  {
668  m_panTimer.Start( (int) ( 250.0 / 60.0 ) );
669 
670  return true;
671  }
672 
673  return false;
674  break;
675 
676  case DRAG_PANNING:
677  case DRAG_ZOOMING:
678  return false;
679  }
680 
681  wxASSERT_MSG( false, wxT( "This line should never be reached" ) );
682  return false; // Should not be reached, just avoid the compiler warnings..
683 }
VC_SETTINGS m_settings
Current VIEW_CONTROLS settings
VIEW * m_view
Pointer to controlled VIEW.
Panning on approaching borders of the frame.
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:1181
float m_autoPanMargin
Distance from cursor to VIEW edge when panning is active
Definition: view_controls.h:90
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:498
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
STATE m_state
Current state of VIEW_CONTROLS.
wxTimer m_panTimer
Timer repsonsible 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, 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 347 of file view_controls.h.

348  {
350  }
VC_SETTINGS m_settings
Current VIEW_CONTROLS settings
bool m_forceCursorPosition
Is the forced cursor position enabled
Definition: view_controls.h:72

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 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
46  return m_settings.m_showCursor;
47 }
VC_SETTINGS m_settings
Current VIEW_CONTROLS settings
bool m_showCursor
Flag determining the cursor visibility
Definition: view_controls.h:66

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

380  {
381  return m_settings.m_warpCursor;
382  }
VC_SETTINGS m_settings
Current VIEW_CONTROLS settings
bool m_warpCursor
If the cursor is allowed to be warped
Definition: view_controls.h:99

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

Referenced by onWheel().

◆ LoadSettings()

void WX_VIEW_CONTROLS::LoadSettings ( )
overridevirtual

Applies VIEW_CONTROLS settings from the program COMMON_SETTINGS

Reimplemented from KIGFX::VIEW_CONTROLS.

Definition at line 133 of file wx_view_controls.cpp.

134 {
135  COMMON_SETTINGS* cfg = Pgm().GetCommonSettings();
136 
147  m_settings.m_dragMiddle = static_cast<MOUSE_DRAG_ACTION>( cfg->m_Input.drag_middle );
148  m_settings.m_dragRight = static_cast<MOUSE_DRAG_ACTION>( cfg->m_Input.drag_right );
149 
150  m_zoomController.reset();
151 
152  if( cfg->m_Input.zoom_speed_auto )
153  {
154  // TODO(JE) this ignores the acceleration option
156  }
157  else
158  {
159  if( cfg->m_Input.zoom_acceleration )
160  {
162  std::make_unique<ACCELERATING_ZOOM_CONTROLLER>( cfg->m_Input.zoom_speed );
163  }
164  else
165  {
167 
168  m_zoomController = std::make_unique<CONSTANT_ZOOM_CONTROLLER>( scale );
169  }
170  }
171 }
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:104
MOUSE_DRAG_ACTION m_dragRight
What drag action to perform when the right button is pressed
static std::unique_ptr< ZOOM_CONTROLLER > GetZoomControllerForPlatform()
std::unique_ptr< ZOOM_CONTROLLER > m_zoomController
a ZOOM_CONTROLLER that determines zoom steps. This is platform-specific.
VC_SETTINGS m_settings
Current VIEW_CONTROLS settings
int m_scrollModifierPanH
What modifier key to enable horizontal pan with the (vertical) scroll wheel
bool m_autoPanSettingEnabled
Flag for turning on autopanning
Definition: view_controls.h:87
MOUSE_DRAG_ACTION m_dragMiddle
What drag action to perform when the middle button is pressed
bool m_zoomSpeedAuto
When true, ignore zoom_speed and pick a platform-specific default
int m_scrollModifierZoom
What modifier key to enable zoom with the (vertical) scroll wheel
float m_autoPanAcceleration
How fast does panning accelerate when approaching the window boundary
Definition: view_controls.h:96
int m_zoomSpeed
Zoom speed for the non-accelerating zoom controller
bool m_warpCursor
If the cursor is allowed to be warped
Definition: view_controls.h:99
bool m_horizontalPan
Enable horizontal panning with the horizontal scroll/trackpad input
bool m_zoomAcceleration
Enable the accelerating zoom controller
int m_scrollModifierPanV
What modifier key to enable vertical with the (vertical) scroll wheel
const int scale
static constexpr double MANUAL_SCALE_FACTOR
Multipler for manual scale ssetting.

References COMMON_SETTINGS::INPUT::auto_pan, COMMON_SETTINGS::INPUT::auto_pan_acceleration, COMMON_SETTINGS::INPUT::center_on_zoom, COMMON_SETTINGS::INPUT::drag_middle, COMMON_SETTINGS::INPUT::drag_right, GetZoomControllerForPlatform(), COMMON_SETTINGS::INPUT::horizontal_pan, KIGFX::VC_SETTINGS::m_autoPanAcceleration, KIGFX::VC_SETTINGS::m_autoPanSettingEnabled, KIGFX::VC_SETTINGS::m_dragMiddle, KIGFX::VC_SETTINGS::m_dragRight, 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 294 of file wx_view_controls.cpp.

295 {
296  switch( m_state )
297  {
298  case IDLE:
299  case AUTO_PANNING:
300  if( ( aEvent.MiddleDown() && m_settings.m_dragMiddle == MOUSE_DRAG_ACTION::PAN ) ||
301  ( aEvent.RightDown() && m_settings.m_dragRight == MOUSE_DRAG_ACTION::PAN ) )
302  {
303  m_dragStartPoint = VECTOR2D( aEvent.GetX(), aEvent.GetY() );
306  }
307  else if( ( aEvent.MiddleDown() && m_settings.m_dragMiddle == MOUSE_DRAG_ACTION::ZOOM ) ||
308  ( aEvent.RightDown() && m_settings.m_dragRight == MOUSE_DRAG_ACTION::ZOOM ) )
309  {
310  m_dragStartPoint = VECTOR2D( aEvent.GetX(), aEvent.GetY() );
313  }
314 
315  if( aEvent.LeftUp() )
316  m_state = IDLE; // Stop autopanning when user release left mouse button
317 
318  break;
319 
320  case DRAG_ZOOMING:
321  case DRAG_PANNING:
322  if( aEvent.MiddleUp() || aEvent.LeftUp() || aEvent.RightUp() )
323  m_state = IDLE;
324 
325  break;
326  }
327 
328  aEvent.Skip();
329 }
VECTOR2D m_lookStartPoint
Stores information about the center of viewport when dragging has started.
MOUSE_DRAG_ACTION m_dragRight
What drag action to perform when the right button is pressed
const VECTOR2D & GetCenter() const
Function GetCenter() Returns the center point of this VIEW (in world space coordinates)
Definition: view.h:328
VC_SETTINGS m_settings
Current VIEW_CONTROLS settings
VIEW * m_view
Pointer to controlled VIEW.
Panning on approaching borders of the frame.
Panning with mouse button pressed.
VECTOR2< double > VECTOR2D
Definition: vector2d.h:593
MOUSE_DRAG_ACTION m_dragMiddle
What drag action to perform when the middle button is pressed
double m_initialZoomScale
The zoom scale when a drag zoom started.
VECTOR2D m_dragStartPoint
Stores information about point where dragging has started.
STATE m_state
Current state of VIEW_CONTROLS.
double GetScale() const
Function GetScale()
Definition: view.h:257

References AUTO_PANNING, DRAG_PANNING, DRAG_ZOOMING, KIGFX::VIEW::GetCenter(), KIGFX::VIEW::GetScale(), IDLE, KIGFX::VC_SETTINGS::m_dragMiddle, KIGFX::VC_SETTINGS::m_dragRight, m_dragStartPoint, m_initialZoomScale, m_lookStartPoint, KIGFX::VIEW_CONTROLS::m_settings, m_state, KIGFX::VIEW_CONTROLS::m_view, KIGFX::PAN, and KIGFX::ZOOM.

Referenced by WX_VIEW_CONTROLS().

◆ onEnter()

void WX_VIEW_CONTROLS::onEnter ( wxMouseEvent &  WXUNUSEDaEvent)

Definition at line 332 of file wx_view_controls.cpp.

333 {
334  m_parentPanel->SetFocus();
335 }
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 338 of file wx_view_controls.cpp.

339 {
341  {
342  bool warp = false;
343  int x = aEvent.GetX();
344  int y = aEvent.GetY();
345  wxSize parentSize = m_parentPanel->GetClientSize();
346 
347  if( x < 0 )
348  {
349  x = 0;
350  warp = true;
351  }
352  else if( x >= parentSize.x )
353  {
354  x = parentSize.x - 1;
355  warp = true;
356  }
357 
358  if( y < 0 )
359  {
360  y = 0;
361  warp = true;
362  }
363  else if( y >= parentSize.y )
364  {
365  y = parentSize.y - 1;
366  warp = true;
367  }
368 
369  if( warp )
370  m_parentPanel->WarpPointer( x, y );
371  }
372 }
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:75

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

175 {
176  bool isAutoPanning = false;
177  VECTOR2D mousePos( aEvent.GetX(), aEvent.GetY() );
178 
180  isAutoPanning = handleAutoPanning( aEvent );
181 
182  if( !isAutoPanning && aEvent.Dragging() )
183  {
184  if( m_state == DRAG_PANNING )
185  {
186  VECTOR2D d = m_dragStartPoint - mousePos;
187  VECTOR2D delta = m_view->ToWorld( d, false );
188 
189  m_view->SetCenter( m_lookStartPoint + delta );
190  aEvent.StopPropagation();
191  }
192  else if( m_state == DRAG_ZOOMING )
193  {
194  VECTOR2D d = m_dragStartPoint - mousePos;
195 
196  double scale = 1 + ( d.y * m_settings.m_zoomSpeed * 0.001 );
197 
198  wxLogTrace( traceZoomScroll, wxString::Format( "dy: %f scale: %f", d.y, scale ) );
199 
201  aEvent.StopPropagation();
202  }
203  }
204 
205  if( m_updateCursor ) // do not update the cursor position if it was explicitly set
206  m_cursorPos = m_view->ToWorld( mousePos );
207  else
208  m_updateCursor = true;
209 
210  aEvent.Skip();
211 }
VECTOR2D m_lookStartPoint
Stores information about the center of viewport when dragging has started.
const wxChar *const traceZoomScroll
Flag to enable debug output of zoom-scrolling calculations in KIGFX::ZOOM_CONTROLLER and derivatives.
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:479
VC_SETTINGS m_settings
Current VIEW_CONTROLS settings
VIEW * m_view
Pointer to controlled VIEW.
Panning on approaching borders of the frame.
bool m_autoPanSettingEnabled
Flag for turning on autopanning
Definition: view_controls.h:87
void SetCenter(const VECTOR2D &aCenter)
Function SetCenter() Sets the center point of the VIEW (i.e.
Definition: view.cpp:608
int m_zoomSpeed
Zoom speed for the non-accelerating zoom controller
bool m_autoPanEnabled
Flag for turning on autopanning
Definition: view_controls.h:84
virtual void SetScale(double aScale, VECTOR2D aAnchor={ 0, 0 })
Function SetScale() Sets the scaling factor, zooming around a given anchor point.
Definition: view.cpp:582
const int scale
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
bool m_updateCursor
Flag deciding whether the cursor position should be calculated using the mouse position.
double m_initialZoomScale
The zoom scale when a drag zoom started.
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 DRAG_PANNING, DRAG_ZOOMING, Format(), handleAutoPanning(), KIGFX::VC_SETTINGS::m_autoPanEnabled, KIGFX::VC_SETTINGS::m_autoPanSettingEnabled, m_cursorPos, m_dragStartPoint, m_initialZoomScale, m_lookStartPoint, KIGFX::VIEW_CONTROLS::m_settings, m_state, m_updateCursor, KIGFX::VIEW_CONTROLS::m_view, KIGFX::VC_SETTINGS::m_zoomSpeed, scale, KIGFX::VIEW::SetCenter(), KIGFX::VIEW::SetScale(), KIGFX::VIEW::ToWorld(), traceZoomScroll, and VECTOR2< T >::y.

Referenced by WX_VIEW_CONTROLS().

◆ onScroll()

void WX_VIEW_CONTROLS::onScroll ( wxScrollWinEvent &  aEvent)

Definition at line 417 of file wx_view_controls.cpp.

418 {
419  const double linePanDelta = 0.05;
420  const double pagePanDelta = 0.5;
421 
422  int type = aEvent.GetEventType();
423  int dir = aEvent.GetOrientation();
424 
425  if( type == wxEVT_SCROLLWIN_THUMBTRACK )
426  {
427  auto center = m_view->GetCenter();
428  const auto& boundary = m_view->GetBoundary();
429 
430  // Flip scroll direction in flipped view
431  const double xstart = ( m_view->IsMirroredX() ?
432  boundary.GetRight() : boundary.GetLeft() );
433  const double xdelta = ( m_view->IsMirroredX() ? -1 : 1 );
434 
435  if( dir == wxHORIZONTAL )
436  center.x = xstart + xdelta * ( aEvent.GetPosition() / m_scrollScale.x );
437  else
438  center.y = boundary.GetTop() + aEvent.GetPosition() / m_scrollScale.y;
439 
440  m_view->SetCenter( center );
441  }
442  else
443  {
444  double dist = 0;
445 
446  if( type == wxEVT_SCROLLWIN_PAGEUP )
447  dist = pagePanDelta;
448  else if( type == wxEVT_SCROLLWIN_PAGEDOWN )
449  dist = -pagePanDelta;
450  else if( type == wxEVT_SCROLLWIN_LINEUP )
451  dist = linePanDelta;
452  else if( type == wxEVT_SCROLLWIN_LINEDOWN )
453  dist = -linePanDelta;
454  else
455  {
456  wxASSERT( "Unhandled event type" );
457  return;
458  }
459 
460  VECTOR2D scroll = m_view->ToWorld( m_view->GetScreenPixelSize(), false ) * dist;
461 
462  double scrollX = 0.0;
463  double scrollY = 0.0;
464 
465  if ( dir == wxHORIZONTAL )
466  scrollX = -scroll.x;
467  else
468  scrollY = -scroll.y;
469 
470  VECTOR2D delta( scrollX, scrollY );
471 
472  m_view->SetCenter( m_view->GetCenter() + delta );
473  }
474 
475  m_parentPanel->Refresh();
476 }
const BOX2D & GetBoundary() const
Function GetBoundary()
Definition: view.h:287
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:479
coord_type GetTop() const
Definition: box2.h:204
const VECTOR2D & GetCenter() const
Function GetCenter() Returns the center point of this VIEW (in world space coordinates)
Definition: view.h:328
VIEW * m_view
Pointer to controlled VIEW.
VECTOR2D m_scrollScale
Ratio used for scaling world coordinates to scrollbar position.
void SetCenter(const VECTOR2D &aCenter)
Function SetCenter() Sets the center point of the VIEW (i.e.
Definition: view.cpp:608
const VECTOR2I & GetScreenPixelSize() const
Function GetScreenPixelSize() Returns the size of the our rendering area, in pixels.
Definition: view.cpp:1181
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 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 375 of file wx_view_controls.cpp.

376 {
377  switch( m_state )
378  {
379  case AUTO_PANNING:
380  {
382  {
383  m_state = IDLE;
384  return;
385  }
386 
387  if( !m_parentPanel->HasFocus() )
388  break;
389 
390  double borderSize = std::min( m_settings.m_autoPanMargin * m_view->GetScreenPixelSize().x,
392 
393  VECTOR2D dir( m_panDirection );
394 
395  float accel = 0.5f + ( m_settings.m_autoPanAcceleration / 5.0f );
396 
397  if( dir.EuclideanNorm() > borderSize / 2 )
398  dir = dir.Resize( pow( borderSize, accel ) );
399  else if( dir.EuclideanNorm() > borderSize )
400  dir = dir.Resize( borderSize );
401 
402  dir = m_view->ToWorld( dir, false );
403  m_view->SetCenter( m_view->GetCenter() + dir );
404 
405  refreshMouse();
406  }
407  break;
408 
409  case IDLE: // Just remove unnecessary warnings
410  case DRAG_PANNING:
411  case DRAG_ZOOMING:
412  break;
413  }
414 }
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:479
const VECTOR2D & GetCenter() const
Function GetCenter() Returns the center point of this VIEW (in world space coordinates)
Definition: view.h:328
VC_SETTINGS m_settings
Current VIEW_CONTROLS settings
VIEW * m_view
Pointer to controlled VIEW.
Panning on approaching borders of the frame.
void SetCenter(const VECTOR2D &aCenter)
Function SetCenter() Sets the center point of the VIEW (i.e.
Definition: view.cpp:608
Panning with mouse button pressed.
float m_autoPanAcceleration
How fast does panning accelerate when approaching the window boundary
Definition: view_controls.h:96
const VECTOR2I & GetScreenPixelSize() const
Function GetScreenPixelSize() Returns the size of the our rendering area, in pixels.
Definition: view.cpp:1181
float m_autoPanMargin
Distance from cursor to VIEW edge when panning is active
Definition: view_controls.h:90
void refreshMouse()
Sends an event to refresh mouse position.
bool m_autoPanEnabled
Flag for turning on autopanning
Definition: view_controls.h:84
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.

References AUTO_PANNING, DRAG_PANNING, DRAG_ZOOMING, 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_parentPanel, KIGFX::VIEW_CONTROLS::m_settings, m_state, KIGFX::VIEW_CONTROLS::m_view, 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 214 of file wx_view_controls.cpp.

215 {
216 #ifdef __WXGTK3__
217  if( aEvent.GetTimestamp() == m_lastTimestamp )
218  {
219  aEvent.Skip( false );
220  return;
221  }
222 
223  m_lastTimestamp = aEvent.GetTimestamp();
224 #endif
225 
226  const double wheelPanSpeed = 0.001;
227  const int axis = aEvent.GetWheelAxis();
228 
229  if( axis == wxMOUSE_WHEEL_HORIZONTAL && !m_settings.m_horizontalPan )
230  return;
231 
232  // Pick the modifier, if any. Shift beats control beats alt, we don't support more than one.
233  int modifiers =
234  aEvent.ShiftDown() ? WXK_SHIFT :
235  ( aEvent.ControlDown() ? WXK_CONTROL : ( aEvent.AltDown() ? WXK_ALT : 0 ) );
236 
237  // Restrict zoom handling to the vertical axis, otherwise horizontal
238  // scrolling events (e.g. touchpads and some mice) end up interpreted
239  // as vertical scroll events and confuse the user.
240  if( axis == wxMOUSE_WHEEL_VERTICAL && modifiers == m_settings.m_scrollModifierZoom )
241  {
242  const int rotation = aEvent.GetWheelRotation();
243  const double zoomScale = m_zoomController->GetScaleForRotation( rotation );
244 
245  if( IsCursorWarpingEnabled() )
246  {
247  CenterOnCursor();
248  m_view->SetScale( m_view->GetScale() * zoomScale );
249  }
250  else
251  {
252  const VECTOR2D anchor = m_view->ToWorld( VECTOR2D( aEvent.GetX(), aEvent.GetY() ) );
253  m_view->SetScale( m_view->GetScale() * zoomScale, anchor );
254  }
255  }
256  else
257  {
258  // Scrolling
259  VECTOR2D scrollVec = m_view->ToWorld( m_view->GetScreenPixelSize(), false ) *
260  ( (double) aEvent.GetWheelRotation() * wheelPanSpeed );
261  double scrollX = 0.0;
262  double scrollY = 0.0;
263 
264  if( axis == wxMOUSE_WHEEL_HORIZONTAL || modifiers == m_settings.m_scrollModifierPanH )
265  scrollX = scrollVec.x;
266  else
267  scrollY = -scrollVec.y;
268 
269  VECTOR2D delta( scrollX, scrollY );
270 
271  m_view->SetCenter( m_view->GetCenter() + delta );
272  refreshMouse();
273  }
274 
275  // Do not skip this event, otherwise wxWidgets will fire
276  // 3 wxEVT_SCROLLWIN_LINEUP or wxEVT_SCROLLWIN_LINEDOWN (normal wxWidgets behavior)
277  // and we do not want that.
278  m_parentPanel->Refresh();
279 }
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:479
const VECTOR2D & GetCenter() const
Function GetCenter() Returns the center point of this VIEW (in world space coordinates)
Definition: view.h:328
std::unique_ptr< ZOOM_CONTROLLER > m_zoomController
a ZOOM_CONTROLLER that determines zoom steps. This is platform-specific.
VC_SETTINGS m_settings
Current VIEW_CONTROLS settings
VIEW * m_view
Pointer to controlled VIEW.
int m_scrollModifierPanH
What modifier key to enable horizontal pan with the (vertical) scroll wheel
void SetCenter(const VECTOR2D &aCenter)
Function SetCenter() Sets the center point of the VIEW (i.e.
Definition: view.cpp:608
VECTOR2< double > VECTOR2D
Definition: vector2d.h:593
int m_scrollModifierZoom
What modifier key to enable zoom with the (vertical) scroll wheel
const VECTOR2I & GetScreenPixelSize() const
Function GetScreenPixelSize() Returns the size of the our rendering area, in pixels.
Definition: view.cpp:1181
bool IsCursorWarpingEnabled() const
Function IsCursorWarpingEnabled()
bool m_horizontalPan
Enable horizontal panning with the horizontal scroll/trackpad input
void refreshMouse()
Sends an event to refresh mouse position.
virtual void SetScale(double aScale, VECTOR2D aAnchor={ 0, 0 })
Function SetScale() Sets the scaling factor, zooming around a given anchor point.
Definition: view.cpp:582
wxScrolledCanvas * m_parentPanel
Panel that is affected by VIEW_CONTROLS.
double GetScale() const
Function GetScale()
Definition: view.h:257
void CenterOnCursor() const override
Function CenterOnCursor() Sets the viewport center to the current cursor position and warps the curso...

References CenterOnCursor(), 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, 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 686 of file wx_view_controls.cpp.

687 {
688  // Notify tools that the cursor position has changed in the world coordinates
689  wxMouseEvent moveEvent( EVT_REFRESH_MOUSE );
691  moveEvent.SetX( msp.x );
692  moveEvent.SetY( msp.y );
693 
694  // Set the modifiers state
695  moveEvent.SetControlDown( wxGetKeyState( WXK_CONTROL ) );
696  moveEvent.SetShiftDown( wxGetKeyState( WXK_SHIFT ) );
697  moveEvent.SetAltDown( wxGetKeyState( WXK_ALT ) );
698 
699  m_cursorPos = m_view->ToWorld( VECTOR2D( msp.x, msp.y ) );
700  wxPostEvent( m_parentPanel, moveEvent );
701 }
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:479
wxPoint getMouseScreenPosition() const
Gets the cursor position in the screen coordinates.
VIEW * m_view
Pointer to controlled VIEW.
VECTOR2< double > VECTOR2D
Definition: vector2d.h:593
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, KIGFX::VIEW::ToWorld(), wxPoint::x, and wxPoint::y.

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

◆ Reset()

void VIEW_CONTROLS::Reset ( )
virtualinherited

Function Reset() Restores the default 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)
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:55

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

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

192  {
193  m_settings.m_autoPanEnabled = aEnabled;
194  }
VC_SETTINGS m_settings
Current VIEW_CONTROLS settings
bool m_autoPanEnabled
Flag for turning on autopanning
Definition: view_controls.h:84

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(), DRAWING_TOOL::drawArc(), DRAWING_TOOL::DrawDimension(), MICROWAVE_TOOL::drawMicrowaveInductor(), DRAWING_TOOL::drawSegment(), LIB_DRAWING_TOOLS::DrawShape(), PL_DRAWING_TOOLS::DrawShape(), SCH_DRAWING_TOOLS::DrawSheet(), DRAWING_TOOL::DrawZone(), ROUTER_TOOL::finishInteractive(), SCH_LINE_WIRE_BUS_TOOL::finishSegments(), ROUTER_TOOL::InlineDrag(), PL_EDIT_TOOL::Main(), EE_POINT_EDITOR::Main(), PL_POINT_EDITOR::Main(), LIB_MOVE_TOOL::Main(), POINT_EDITOR::OnSelectionChange(), ROUTER_TOOL::performDragging(), LENGTH_TUNER_TOOL::performTuning(), SCH_DRAWING_TOOLS::PlaceComponent(), SCH_DRAWING_TOOLS::PlaceImage(), PL_DRAWING_TOOLS::PlaceItem(), PCB_EDITOR_CONTROL::PlaceModule(), DRAWING_TOOL::PlaceText(), ROUTER_TOOL::prepareInteractive(), POINT_EDITOR::Reset(), PL_SELECTION_TOOL::selectMultiple(), EE_SELECTION_TOOL::selectMultiple(), SELECTION_TOOL::selectMultiple(), ZOOM_TOOL::selectRegion(), DRAWING_TOOL::SetAnchor(), PICKER_TOOL::setControls(), PCBNEW_PICKER_TOOL::setControls(), LIB_DRAWING_TOOLS::TwoClickPlace(), and SCH_DRAWING_TOOLS::TwoClickPlace().

◆ SetAutoPanAcceleration()

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

Function SetAutoPanSpeed() Sets speed of autopanning.

Parameters
aSpeedis a new speed for autopanning.

Definition at line 221 of file view_controls.h.

222  {
223  m_settings.m_autoPanAcceleration = aAcceleration;
224  }
VC_SETTINGS m_settings
Current VIEW_CONTROLS settings
float m_autoPanAcceleration
How fast does panning accelerate when approaching the window boundary
Definition: view_controls.h:96

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

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

232  {
233  m_settings.m_autoPanMargin = aMargin;
234  }
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:90

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

212  {
213  m_settings.m_autoPanSpeed = aSpeed;
214  }
float m_autoPanSpeed
How fast is panning when in auto mode
Definition: view_controls.h:93
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 550 of file wx_view_controls.cpp.

551 {
552  m_updateCursor = false;
553 
554  const VECTOR2I& screenSize = m_view->GetGAL()->GetScreenPixelSize();
555  BOX2I screen( VECTOR2I( 0, 0 ), screenSize );
556  VECTOR2D screenPos = m_view->ToScreen( aPosition );
557 
558  if( aWarpView && !screen.Contains( screenPos ) )
559  m_view->SetCenter( aPosition );
560 
561  m_cursorPos = aPosition;
562 }
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:594
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:608
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:498
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,
long  aArrowCommand 
)
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 525 of file wx_view_controls.cpp.

527 {
528  m_updateCursor = false;
529 
530  if( aTriggeredByArrows )
531  {
534  m_settings.m_lastKeyboardCursorCommand = aArrowCommand;
535  m_cursorWarped = false;
536  }
537  else
538  {
542  m_cursorWarped = true;
543  }
544 
545  WarpCursor( aPosition, true, aWarpView );
546  m_cursorPos = aPosition;
547 }
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
long m_lastKeyboardCursorCommand
ACTIONS::CURSOR_UP, ACTIONS::CURSOR_DOWN, etc.
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
VECTOR2D m_cursorPos
Current cursor position (world coordinates)

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

480 {
481  if( aEnabled && !m_settings.m_grabMouse )
482  m_parentPanel->CaptureMouse();
483  else if( !aEnabled && m_settings.m_grabMouse )
484  m_parentPanel->ReleaseMouse();
485 
486  VIEW_CONTROLS::SetGrabMouse( aEnabled );
487 }
bool m_grabMouse
Flag for grabbing the mouse cursor
Definition: view_controls.h:81
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 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.
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:66

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(), DRAWING_TOOL::drawArc(), DRAWING_TOOL::DrawDimension(), MICROWAVE_TOOL::drawMicrowaveInductor(), DRAWING_TOOL::drawSegment(), LIB_DRAWING_TOOLS::DrawShape(), PL_DRAWING_TOOLS::DrawShape(), SCH_DRAWING_TOOLS::DrawSheet(), DRAWING_TOOL::DrawZone(), PAD_TOOL::EnumeratePads(), ROUTER_TOOL::InlineDrag(), PL_EDIT_TOOL::Main(), EE_POINT_EDITOR::Main(), PL_POINT_EDITOR::Main(), LIB_MOVE_TOOL::Main(), ROUTER_TOOL::MainLoop(), LENGTH_TUNER_TOOL::MainLoop(), POINT_EDITOR::OnSelectionChange(), LIB_DRAWING_TOOLS::PlaceAnchor(), SCH_DRAWING_TOOLS::PlaceComponent(), SCH_DRAWING_TOOLS::PlaceImage(), DRAWING_TOOL::PlaceImportedGraphics(), PL_DRAWING_TOOLS::PlaceItem(), PCB_EDITOR_CONTROL::PlaceModule(), DRAWING_TOOL::PlaceText(), DRAWING_TOOL::SetAnchor(), EE_POINT_EDITOR::setEditedPoint(), PL_POINT_EDITOR::setEditedPoint(), POINT_EDITOR::setEditedPoint(), SCH_DRAWING_TOOLS::SingleClickPlace(), LIB_DRAWING_TOOLS::TwoClickPlace(), and SCH_DRAWING_TOOLS::TwoClickPlace().

◆ UpdateScrollbars()

void WX_VIEW_CONTROLS::UpdateScrollbars ( )

Adjusts the scrollbars position to match the current viewport.

Definition at line 712 of file wx_view_controls.cpp.

713 {
714  const BOX2D viewport = m_view->GetViewport();
715  const BOX2D& boundary = m_view->GetBoundary();
716 
717  m_scrollScale.x = 2e3 / viewport.GetWidth(); // TODO it does not have to be updated so often
718  m_scrollScale.y = 2e3 / viewport.GetHeight();
719  VECTOR2I newScroll( ( viewport.Centre().x - boundary.GetLeft() ) * m_scrollScale.x,
720  ( viewport.Centre().y - boundary.GetTop() ) * m_scrollScale.y );
721 
722  // We add the width of the scroll bar thumb to the range because the scroll range is given by
723  // the full bar while the position is given by the left/top position of the thumb
724  VECTOR2I newRange( m_scrollScale.x * boundary.GetWidth() + m_parentPanel->GetScrollThumb( wxSB_HORIZONTAL ),
725  m_scrollScale.y * boundary.GetHeight() + m_parentPanel->GetScrollThumb( wxSB_VERTICAL ) );
726 
727  // Flip scroll direction in flipped view
728  if( m_view->IsMirroredX() )
729  newScroll.x = ( boundary.GetRight() - viewport.Centre().x ) * m_scrollScale.x;
730 
731  // Adjust scrollbars only if it is needed. Otherwise there are cases when canvas is continuously
732  // refreshed (Windows)
733  if( m_scrollPos != newScroll || newRange.x != m_parentPanel->GetScrollRange( wxSB_HORIZONTAL )
734  || newRange.y != m_parentPanel->GetScrollRange( wxSB_VERTICAL ) )
735  {
736  m_parentPanel->SetScrollbars( 1, 1, newRange.x, newRange.y, newScroll.x, newScroll.y, true );
737  m_scrollPos = newScroll;
738 
739 #ifndef __APPLE__
740  // Trigger a mouse refresh to get the canvas update in GTK (re-draws the scrollbars).
741  // Note that this causes an infinite loop on OSX as it generates a paint event.
742  refreshMouse();
743 #endif
744  }
745 }
BOX2D GetViewport() const
Function GetViewport() Returns the current viewport visible area rectangle.
Definition: view.cpp:542
const BOX2D & GetBoundary() const
Function GetBoundary()
Definition: view.h:287
coord_type GetTop() const
Definition: box2.h:204
coord_type GetRight() const
Definition: box2.h:199
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:197
void refreshMouse()
Sends an event to refresh mouse position.
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:79
VECTOR2I m_scrollPos
Current scrollbar position.
coord_type GetHeight() const
Definition: box2.h:198
coord_type GetLeft() const
Definition: box2.h:203

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

◆ WarpCursor()

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

Implements KIGFX::VIEW_CONTROLS.

Definition at line 565 of file wx_view_controls.cpp.

567 {
568  if( aWorldCoordinates )
569  {
570  const VECTOR2I& screenSize = m_view->GetGAL()->GetScreenPixelSize();
571  BOX2I screen( VECTOR2I( 0, 0 ), screenSize );
572  VECTOR2D screenPos = m_view->ToScreen( aPosition );
573 
574  if( !screen.Contains( screenPos ) )
575  {
576  if( aWarpView )
577  {
578  m_view->SetCenter( aPosition );
579  m_parentPanel->WarpPointer( screenSize.x / 2, screenSize.y / 2 );
580  }
581  }
582  else
583  {
584  m_parentPanel->WarpPointer( screenPos.x, screenPos.y );
585  }
586  }
587  else
588  {
589  m_parentPanel->WarpPointer( aPosition.x, aPosition.y );
590  }
591 
592  refreshMouse();
593 }
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:594
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:608
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:498
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 111 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 178 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 414 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 152 of file wx_view_controls.h.

Referenced by onButton(), and onMotion().

◆ m_initialZoomScale

double KIGFX::WX_VIEW_CONTROLS::m_initialZoomScale
private

The zoom scale when a drag zoom started.

Definition at line 170 of file wx_view_controls.h.

Referenced by onButton(), and onMotion().

◆ m_lookStartPoint

VECTOR2D KIGFX::WX_VIEW_CONTROLS::m_lookStartPoint
private

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

Definition at line 155 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 158 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 161 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 167 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 164 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 146 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 181 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 184 of file wx_view_controls.h.

Referenced by LoadSettings(), and onWheel().


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