48 #define USE_MOUSE_CAPTURE
53const wxEventType WX_VIEW_CONTROLS::EVT_REFRESH_MOUSE = wxNewEventType();
62 return std::make_unique<CONSTANT_ZOOM_CONTROLLER>( CONSTANT_ZOOM_CONTROLLER::MAC_SCALE );
65 return std::make_unique<CONSTANT_ZOOM_CONTROLLER>( CONSTANT_ZOOM_CONTROLLER::GTK3_SCALE );
68 return std::make_unique<ACCELERATING_ZOOM_CONTROLLER>();
70 return std::make_unique<CONSTANT_ZOOM_CONTROLLER>( CONSTANT_ZOOM_CONTROLLER::MSW_SCALE );
78 m_parentPanel( aParentPanel ),
79 m_scrollScale( 1.0, 1.0 ),
84 m_updateCursor( true )
92#if wxCHECK_VERSION( 3, 1, 0 ) || defined( USE_OSX_MAGNIFY_EVENT )
94 wxMouseEventHandler( WX_VIEW_CONTROLS::onMagnify ),
nullptr,
this );
131#if defined USE_MOUSE_CAPTURE
149#if defined USE_MOUSE_CAPTURE
200 ( *m_MotionEventCounter )++;
202 bool isAutoPanning =
false;
203 int x = aEvent.GetX();
204 int y = aEvent.GetY();
237 if( !isAutoPanning && aEvent.Dragging() )
241 static bool justWarped =
false;
248 warpX = parentSize.x;
250 else if(x >= parentSize.x )
252 warpX = -parentSize.x;
257 warpY = parentSize.y;
259 else if( y >= parentSize.y )
261 warpY = -parentSize.y;
270 aEvent.StopPropagation();
289 static bool justWarped =
false;
295 warpY = parentSize.y;
297 else if( y >= parentSize.y )
299 warpY = -parentSize.y;
312 aEvent.StopPropagation();
343 if( aEvent.GetTimestamp() == m_lastTimestamp )
345 aEvent.Skip(
false );
349 m_lastTimestamp = aEvent.GetTimestamp();
352 const double wheelPanSpeed = 0.001;
353 const int axis = aEvent.GetWheelAxis();
360 aEvent.ShiftDown() ? WXK_SHIFT :
361 ( aEvent.ControlDown() ? WXK_CONTROL : ( aEvent.AltDown() ? WXK_ALT : 0 ) );
368 const int rotation = aEvent.GetWheelRotation();
390 ( (double) aEvent.GetWheelRotation() * wheelPanSpeed );
391 double scrollX = 0.0;
392 double scrollY = 0.0;
395 scrollX = scrollVec.
x;
397 scrollY = -scrollVec.
y;
412#if wxCHECK_VERSION( 3, 1, 0 ) || defined( USE_OSX_MAGNIFY_EVENT )
413void WX_VIEW_CONTROLS::onMagnify( wxMouseEvent& aEvent )
441#if defined USE_MOUSE_CAPTURE
453#if defined USE_MOUSE_CAPTURE
459 if( aEvent.LeftUp() )
466 if( aEvent.MiddleUp() || aEvent.LeftUp() || aEvent.RightUp() )
470#if defined USE_MOUSE_CAPTURE
493#if defined( _WIN32 ) || defined( __WXGTK__ )
513#if !defined USE_MOUSE_CAPTURE
575 dir = dir.
Resize( borderSize * accel );
577 dir = dir.
Resize( borderSize );
598 const double linePanDelta = 0.05;
599 const double pagePanDelta = 0.5;
601 int type = aEvent.GetEventType();
602 int dir = aEvent.GetOrientation();
604 if( type == wxEVT_SCROLLWIN_THUMBTRACK )
611 boundary.GetRight() : boundary.GetLeft() );
614 if( dir == wxHORIZONTAL )
615 center.x = xstart + xdelta * ( aEvent.GetPosition() /
m_scrollScale.
x );
625 if( type == wxEVT_SCROLLWIN_PAGEUP )
627 else if( type == wxEVT_SCROLLWIN_PAGEDOWN )
628 dist = -pagePanDelta;
629 else if( type == wxEVT_SCROLLWIN_LINEUP )
631 else if( type == wxEVT_SCROLLWIN_LINEDOWN )
632 dist = -linePanDelta;
634 wxCHECK_MSG(
false, , wxT(
"Unhandled event type" ) );
638 double scrollX = 0.0;
639 double scrollY = 0.0;
641 if ( dir == wxHORIZONTAL )
657#if defined USE_MOUSE_CAPTURE
687#if defined USE_MOUSE_CAPTURE
733 bool aTriggeredByArrows,
long aArrowCommand )
739 if( aTriggeredByArrows )
760 bool aWarpView =
true )
770 if( aWarpView && !screen.
Contains( screenPos ) )
780 if( aWorldCoordinates )
814 VECTOR2I screenCenter( screenSize / 2 );
840 if( pos.
x < topLeft.
x )
842 else if( pos.
x > botRight.
x )
845 if( pos.
y < topLeft.
y )
847 else if( pos.
y > botRight.
y )
852 if( aWarpMouseCursor )
859 VECTOR2I p( aEvent.GetX(), aEvent.GetY() );
878 borderStart = std::max( borderStart, 2 );
882 if( p.
x < borderStart )
884 else if( p.
x > borderEndX )
889 if( p.
y < borderStart )
891 else if( p.
y > borderEndY )
915 m_panTimer.Start( (
int) ( 250.0 / 60.0 ),
true );
927 wxCHECK_MSG(
false,
false, wxT(
"This line should never be reached" ) );
945 else if( x >= parentSize.x )
947 x = parentSize.x - 1;
956 else if( y >= parentSize.y )
958 y = parentSize.y - 1;
973 moveEvent.SetX( msp.x );
974 moveEvent.SetY( msp.y );
979 moveEvent.SetControlDown( wxGetKeyState( WXK_CONTROL ) );
980 moveEvent.SetShiftDown( wxGetKeyState( WXK_SHIFT ) );
981 moveEvent.SetAltDown( wxGetKeyState( WXK_ALT ) );
991 wxPoint msp = wxGetMousePosition();
1021 || newRange.
y !=
m_parentPanel->GetScrollRange( wxSB_VERTICAL ) )
1023 m_parentPanel->SetScrollbars( 1, 1, newRange.
x, newRange.
y, newScroll.
x, newScroll.
y,
1027#if !defined( __APPLE__ ) && !defined( WIN32 )
coord_type GetTop() const
coord_type GetHeight() const
coord_type GetWidth() const
bool Contains(const Vec &aPoint) const
coord_type GetRight() const
coord_type GetLeft() const
The base class for create windows for drawing purpose.
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 m_MouseCapturedLost
used on wxMSW: true after a wxEVT_MOUSE_CAPTURE_LOST was received false after the mouse is recaptured...
bool StatusPopupHasFocus()
EDA_DRAW_FRAME * GetParentEDAFrame() const
Returns parent EDA_DRAW_FRAME, if available or NULL otherwise.
static constexpr double MANUAL_SCALE_FACTOR
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
const VECTOR2I & GetScreenPixelSize() const
Return GAL canvas size in pixels.
An interface for classes handling user events controlling the view behavior such as zooming,...
virtual void CaptureCursor(bool aEnabled)
Force the cursor to stay within the drawing panel area.
bool m_cursorWarped
Current VIEW_CONTROLS settings.
bool IsCursorWarpingEnabled() const
VIEW * m_view
< Pointer to controlled VIEW.
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
BOX2D GetViewport() const
Return the current viewport visible area rectangle.
const VECTOR2D & GetCenter() const
Return the center point of this VIEW (in world space coordinates).
virtual void SetScale(double aScale, VECTOR2D aAnchor={ 0, 0 })
Set the scaling factor, zooming around a given anchor point.
VECTOR2D ToScreen(const VECTOR2D &aCoord, bool aAbsolute=true) const
Convert a world space point/vector to a point/vector in screen space coordinates.
const VECTOR2I & GetScreenPixelSize() const
Return the size of the our rendering area in pixels.
GAL * GetGAL() const
Return the #GAL this view is using to draw graphical primitives.
VECTOR2D ToWorld(const VECTOR2D &aCoord, bool aAbsolute=true) const
Converts a screen space point/vector to a point/vector in world space coordinates.
bool IsMirroredX() const
Return true if view is flipped across the X axis.
const BOX2D & GetBoundary() const
void SetCenter(const VECTOR2D &aCenter)
Set the center point of the VIEW (i.e.
bool m_updateCursor
A #ZOOM_CONTROLLER that determines zoom steps. This is platform-specific.
void SetCrossHairCursorPosition(const VECTOR2D &aPosition, bool aWarpView) override
void LoadSettings() override
Event that forces mouse move event in the dispatcher (eg.
void setState(STATE aNewState)
Sets the interaction state, simply a internal setter to make it easier to debug changes.
STATE m_state
Panel that is affected by VIEW_CONTROLS.
void CaptureCursor(bool aEnabled) override
Force the cursor to stay within the drawing panel area.
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.
VECTOR2I m_scrollPos
The mouse position when a drag zoom started.
void refreshMouse(bool aSetModifiers)
Send an event to refresh mouse position.
void PinCursorInsideNonAutoscrollArea(bool aWarpMouseCursor) override
Return the current mouse pointer position.
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.
VECTOR2D GetMousePosition(bool aWorldCoordinates=true) const override
Return the current mouse pointer position.
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.
VECTOR2D GetRawCursorPosition(bool aSnappingEnabled=true) const override
Return the current cursor position in world coordinates ignoring the cursorUp position force mode.
VECTOR2D m_scrollScale
Current scrollbar position.
bool handleAutoPanning(const wxMouseEvent &aEvent)
Compute new viewport settings while in autopanning mode.
wxPoint getMouseScreenPosition() const
Get the cursor position in the screen coordinates.
void onTimer(wxTimerEvent &WXUNUSED(aEvent))
std::unique_ptr< ZOOM_CONTROLLER > m_zoomController
STATE
< Possible states for WX_VIEW_CONTROLS.
@ 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.
VECTOR2D GetCursorPosition() const
Return the current cursor position in world coordinates.
void CenterOnCursor() override
Adjusts the scrollbars position to match the current viewport.
virtual ~WX_VIEW_CONTROLS()
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 UpdateScrollbars()
End any mouse drag action still in progress.
void ForceCursorPosition(bool aEnabled, const VECTOR2D &aPosition=VECTOR2D(0, 0)) override
Applies VIEW_CONTROLS settings from the program COMMON_SETTINGS.
void handleCursorCapture(int x, int y)
Limit the cursor position to within the canvas by warping it.
void onLeave(wxMouseEvent &WXUNUSED(aEvent))
VECTOR2D m_zoomStartPoint
Current cursor position (world coordinates).
static const wxEventType EVT_REFRESH_MOUSE
VECTOR2D m_panDirection
Timer responsible for handling autopanning.
VECTOR2D m_dragStartPoint
Current direction of panning (only autopanning mode).
KIWAY & Kiway() const
Return a reference to the KIWAY that this object has an opportunity to participate in.
A wxFrame capable of the OpenProjectFiles function, meaning it can load a portion of a KiCad project.
virtual KIWAY_PLAYER * Player(FRAME_T aFrameType, bool doCreate=true, wxTopLevelWindow *aParent=nullptr)
Return the KIWAY_PLAYER* given a FRAME_T.
T EuclideanNorm() const
Compute the Euclidean norm of the vector, which is defined as sqrt(x ** 2 + y ** 2).
VECTOR2< T > Resize(T aNewLength) const
Return a vector of the same direction, but length specified in aNewLength.
a few functions useful in geometry calculations.
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...
const wxChar *const traceZoomScroll
Flag to enable debug output of zoom-scrolling calculations in KIGFX::ZOOM_CONTROLLER and derivatives.
The Cairo implementation of the graphics abstraction layer.
bool IsInputControlFocused(wxWindow *aFocus=nullptr)
Check if a input control has focus.
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
float m_autoPanMargin
How fast is panning when in auto mode.
VECTOR2D m_forcedPosition
Is the forced cursor position enabled.
MOUSE_DRAG_ACTION m_dragLeft
bool m_horizontalPan
Enable the accelerating zoom controller.
bool m_autoPanSettingEnabled
Distance from cursor to VIEW edge when panning is active.
bool m_focusFollowSchPcb
Flag for turning on autopanning.
float m_autoPanAcceleration
If the cursor is allowed to be warped.
MOUSE_DRAG_ACTION m_dragMiddle
bool m_cursorCaptured
Should the cursor snap to grid or move freely.
int m_zoomSpeed
When true, ignore zoom_speed and pick a platform-specific default.
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.
VECTOR2D m_lastKeyboardCursorPosition
bool m_warpCursor
Enable horizontal panning with the horizontal scroll/trackpad input.
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.
bool m_lastKeyboardCursorPositionValid
ACTIONS::CURSOR_UP, ACTIONS::CURSOR_DOWN, etc.
bool m_zoomSpeedAuto
What modifier key to enable zoom with the (vertical) scroll wheel.
bool m_autoPanEnabled
Flag for turning on autopanning.
long m_lastKeyboardCursorCommand
Position of the above event.
bool m_forceCursorPosition
Should the cursor be locked within the parent window area.
wxLogTrace helper definitions.
Functions to provide common constants and other functions to assist in making a consistent UI.
VECTOR2< double > VECTOR2D
static std::unique_ptr< ZOOM_CONTROLLER > GetZoomControllerForPlatform(bool aAcceleration)
WX_VIEW_CONTROLS class definition.