48 #define USE_MOUSE_CAPTURE
68 return std::make_unique<ACCELERATING_ZOOM_CONTROLLER>();
76 VIEW_CONTROLS( aView ), m_state( IDLE ), m_parentPanel( aParentPanel ),
77 m_scrollScale( 1.0, 1.0 ), m_cursorPos( 0, 0 ), m_updateCursor( true ),
78 m_infinitePanWorks( false ), m_gestureLastZoomFactor( 1.0 )
123#if defined USE_MOUSE_CAPTURE
129 if(
m_parentPanel->EnableTouchEvents( wxTOUCH_ZOOM_GESTURE | wxTOUCH_PAN_GESTURES ) )
154#if defined USE_MOUSE_CAPTURE
207 ( *m_MotionEventCounter )++;
212 bool isAutoPanning =
false;
247 if( !isAutoPanning && aEvent.Dragging() )
251 static bool justWarped =
false;
258 warpX = parentSize.x;
260 else if(x >= parentSize.x )
262 warpX = -parentSize.x;
267 warpY = parentSize.y;
269 else if( y >= parentSize.y )
271 warpY = -parentSize.y;
280 aEvent.StopPropagation();
306 static bool justWarped =
false;
312 warpY = parentSize.y;
314 else if( y >= parentSize.y )
316 warpY = -parentSize.y;
329 aEvent.StopPropagation();
361 const double wheelPanSpeed = 0.001;
362 const int axis = aEvent.GetWheelAxis();
371 if( aEvent.ShiftDown() )
374 modifiers = WXK_SHIFT;
377 if( aEvent.ControlDown() )
380 modifiers = modifiers == 0 ? WXK_CONTROL : modifiers;
383 if( aEvent.AltDown() )
386 modifiers = modifiers == 0 ? WXK_ALT : modifiers;
420 * ( (double) aEvent.GetWheelRotation() * wheelPanSpeed );
421 double scrollX = 0.0;
422 double scrollY = 0.0;
423 bool hReverse =
false;
425 if( axis != wxMOUSE_WHEEL_HORIZONTAL )
431 scrollX = scrollVec.
x;
433 scrollX = ( axis == wxMOUSE_WHEEL_HORIZONTAL ) ? scrollVec.
x : -scrollVec.
x;
437 scrollY = -scrollVec.
y;
487#if defined USE_MOUSE_CAPTURE
499#if defined USE_MOUSE_CAPTURE
505 if( aEvent.LeftUp() )
512 if( aEvent.MiddleUp() || aEvent.LeftUp() || aEvent.RightUp() )
517#if defined USE_MOUSE_CAPTURE
540#if defined( _WIN32 ) || defined( __WXGTK__ )
560#if !defined USE_MOUSE_CAPTURE
623 dir = dir.
Resize( borderSize * accel );
625 dir = dir.
Resize( borderSize );
646 if( aEvent.IsGestureStart() )
652 VECTOR2D evtPos( aEvent.GetPosition().x, aEvent.GetPosition().y );
669 VECTOR2I screenDelta( aEvent.GetDelta().x, aEvent.GetDelta().y );
680 const double linePanDelta = 0.05;
681 const double pagePanDelta = 0.5;
683 int type = aEvent.GetEventType();
684 int dir = aEvent.GetOrientation();
686 if( type == wxEVT_SCROLLWIN_THUMBTRACK )
693 boundary.GetRight() : boundary.GetLeft() );
696 if( dir == wxHORIZONTAL )
697 center.x = xstart + xdelta * ( aEvent.GetPosition() /
m_scrollScale.
x );
703 else if( type == wxEVT_SCROLLWIN_THUMBRELEASE ||
704 type == wxEVT_SCROLLWIN_TOP ||
705 type == wxEVT_SCROLLWIN_BOTTOM )
714 if( type == wxEVT_SCROLLWIN_PAGEUP )
718 else if( type == wxEVT_SCROLLWIN_PAGEDOWN )
720 dist = -pagePanDelta;
722 else if( type == wxEVT_SCROLLWIN_LINEUP )
726 else if( type == wxEVT_SCROLLWIN_LINEDOWN )
728 dist = -linePanDelta;
732 wxCHECK_MSG(
false, , wxT(
"Unhandled event type" ) );
737 double scrollX = 0.0;
738 double scrollY = 0.0;
740 if ( dir == wxHORIZONTAL )
756#if defined USE_MOUSE_CAPTURE
791#if defined USE_MOUSE_CAPTURE
837 bool aTriggeredByArrows,
long aArrowCommand )
843 if( aTriggeredByArrows )
864 bool aWarpView =
true )
874 if( aWarpView && !screen.
Contains( screenPos ) )
884 if( aWorldCoordinates )
918 VECTOR2D screenCenter( screenSize / 2 );
948 if( pos.
x < topLeft.
x )
950 else if( pos.
x > botRight.
x )
953 if( pos.
y < topLeft.
y )
955 else if( pos.
y > botRight.
y )
960 if( aWarpMouseCursor )
967 VECTOR2I p( aEvent.GetX(), aEvent.GetY() );
986 borderStart = std::max( borderStart, 2 );
990 if( p.
x < borderStart )
992 else if( p.
x > borderEndX )
997 if( p.
y < borderStart )
999 else if( p.
y > borderEndY )
1023 m_panTimer.Start( (
int) ( 250.0 / 60.0 ),
true );
1035 wxCHECK_MSG(
false,
false, wxT(
"This line should never be reached" ) );
1053 else if( x >= parentSize.x )
1055 x = parentSize.x - 1;
1064 else if( y >= parentSize.y )
1066 y = parentSize.y - 1;
1081 moveEvent.SetX( msp.x );
1082 moveEvent.SetY( msp.y );
1087 moveEvent.SetControlDown( wxGetKeyState( WXK_CONTROL ) );
1088 moveEvent.SetShiftDown( wxGetKeyState( WXK_SHIFT ) );
1089 moveEvent.SetAltDown( wxGetKeyState( WXK_ALT ) );
1129 || newRange.
y !=
m_parentPanel->GetScrollRange( wxSB_VERTICAL ) )
1131 m_parentPanel->SetScrollbars( 1, 1, newRange.
x, newRange.
y, newScroll.
x, newScroll.
y,
1135#if !defined( __APPLE__ ) && !defined( WIN32 )
constexpr size_type GetWidth() const
constexpr Vec Centre() const
constexpr size_type GetHeight() const
constexpr coord_type GetLeft() const
constexpr bool Contains(const Vec &aPoint) const
constexpr coord_type GetRight() const
constexpr coord_type GetTop() const
The base class for create windows for drawing purpose.
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=nullptr) override
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 MAC_SCALE
A suitable (magic) scale factor for Mac systems.
static constexpr double MSW_SCALE
A suitable (magic) scale factor for Windows systems.
static constexpr double GTK3_SCALE
A suitable (magic) scale factor for GTK3 systems.
static constexpr double MANUAL_SCALE_FACTOR
Multiplier for manual scale ssetting.
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
Application warped the cursor, not the user (keyboard).
bool IsCursorWarpingEnabled() const
VC_SETTINGS m_settings
Current VIEW_CONTROLS settings.
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
Flag deciding whether the cursor position should be calculated using the mouse position.
bool m_infinitePanWorks
Flag to indicate if infinite panning works on this platform.
void SetCrossHairCursorPosition(const VECTOR2D &aPosition, bool aWarpView) override
Move the graphic crosshair cursor to the requested position expressed in world coordinates.
void LoadSettings() override
Applies VIEW_CONTROLS settings from the program COMMON_SETTINGS.
void setState(STATE aNewState)
Set the interaction state, simply a internal setter to make it easier to debug changes.
STATE m_state
Current state of VIEW_CONTROLS.
void CaptureCursor(bool aEnabled) override
Force the cursor to stay within the drawing panel area.
void onScroll(wxScrollWinEvent &aEvent)
wxTimer m_panTimer
Timer responsible for handling autopanning.
void CancelDrag()
End any mouse drag action still in progress.
VECTOR2D m_gestureLastPos
void onButton(wxMouseEvent &aEvent)
double m_gestureLastZoomFactor
Used to track gesture events.
void onEnter(wxMouseEvent &WXUNUSED(aEvent))
void onWheel(wxMouseEvent &aEvent)
Handler functions.
VECTOR2I m_scrollPos
Current scrollbar position.
void refreshMouse(bool aSetModifiers)
Send an event to refresh mouse position.
WX_VIEW_CONTROLS(VIEW *aView, EDA_DRAW_PANEL_GAL *aParentPanel)
void onZoomGesture(wxZoomGestureEvent &aEvent)
void PinCursorInsideNonAutoscrollArea(bool aWarpMouseCursor) override
void SetCursorPosition(const VECTOR2D &aPosition, bool warpView, bool aTriggeredByArrows, long aArrowCommand) override
Move 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
void onMagnify(wxMouseEvent &aEvent)
VECTOR2D GetRawCursorPosition(bool aSnappingEnabled=true) const override
Return the current cursor position in world coordinates ignoring the cursorUp position force mode.
VECTOR2D m_scrollScale
Ratio used for scaling world coordinates to 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 onPanGesture(wxPanGestureEvent &aEvent)
void onTimer(wxTimerEvent &WXUNUSED(aEvent))
std::unique_ptr< ZOOM_CONTROLLER > m_zoomController
A #ZOOM_CONTROLLER that determines zoom steps. This is platform-specific.
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
Set the viewport center to the current cursor position and warps the cursor to the screen center.
virtual ~WX_VIEW_CONTROLS()
VECTOR2D m_cursorPos
Current cursor position (world coordinates).
void onCaptureLost(wxMouseEvent &WXUNUSED(aEvent))
void onMotion(wxMouseEvent &aEvent)
std::unique_ptr< PROF_COUNTER > m_MotionEventCounter
EDA_DRAW_PANEL_GAL * m_parentPanel
Panel that is affected by VIEW_CONTROLS.
void UpdateScrollbars()
Adjusts the scrollbars position to match the current viewport.
void ForceCursorPosition(bool aEnabled, const VECTOR2D &aPosition=VECTOR2D(0, 0)) override
Place the cursor immediately at a given point.
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
The mouse position when a drag zoom started.
static const wxEventType EVT_REFRESH_MOUSE
Event that forces mouse move event in the dispatcher (eg.
VECTOR2D m_panDirection
Current direction of panning (only autopanning mode).
VECTOR2D m_dragStartPoint
Store information about point where dragging has started.
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.
virtual COMMON_SETTINGS * GetCommonSettings() const
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.
KICOMMON_API bool IsInputControlFocused(wxWindow *aFocus=nullptr)
Check if a input control has focus.
KICOMMON_API bool IsModalDialogFocused()
PGM_BASE & Pgm()
The global program "get" accessor.
float m_autoPanMargin
Distance from cursor to VIEW edge when panning is active.
VECTOR2D m_forcedPosition
Forced cursor position (world coordinates).
MOUSE_DRAG_ACTION m_dragLeft
bool m_horizontalPan
Enable horizontal panning with the horizontal scroll/trackpad input.
bool m_scrollReversePanH
Whether to invert the scroll wheel movement for horizontal pan.
bool m_autoPanSettingEnabled
Flag for turning on autopanning.
bool m_focusFollowSchPcb
Flag for automatic focus switching between Schematic and PCB editors.
float m_autoPanAcceleration
How fast does panning accelerate when approaching the window boundary.
MOUSE_DRAG_ACTION m_dragMiddle
bool m_cursorCaptured
Should the cursor be locked within the parent window area.
int m_zoomSpeed
Zoom speed for the non-accelerating zoom controller.
int m_scrollModifierZoom
What modifier key to enable zoom with the (vertical) scroll wheel.
int m_scrollModifierPanH
What modifier key to enable horizontal pan with the (vertical) scroll wheel.
VECTOR2D m_lastKeyboardCursorPosition
Position of the above event.
bool m_warpCursor
If the cursor is allowed to be warped.
MOUSE_DRAG_ACTION m_dragRight
bool m_scrollReverseZoom
Whether to invert the scroll wheel movement for zoom.
bool m_zoomAcceleration
Enable the accelerating zoom controller.
bool m_lastKeyboardCursorPositionValid
Is last cursor motion event coming from keyboard arrow cursor motion action.
bool m_zoomSpeedAuto
When true, ignore zoom_speed and pick a platform-specific default.
bool m_autoPanEnabled
Flag for turning on autopanning.
int m_scrollModifierPanV
What modifier key to enable vertical with the (vertical) scroll wheel.
long m_lastKeyboardCursorCommand
ACTIONS::CURSOR_UP, ACTIONS::CURSOR_DOWN, etc.
bool m_forceCursorPosition
Is the forced cursor position enabled.
wxLogTrace helper definitions.
Functions to provide common constants and other functions to assist in making a consistent UI.
VECTOR2< int32_t > VECTOR2I
VECTOR2< double > VECTOR2D
static std::unique_ptr< ZOOM_CONTROLLER > GetZoomControllerForPlatform(bool aAcceleration)
WX_VIEW_CONTROLS class definition.
ZOOM_CONTROLLER class definition.