47#define USE_MOUSE_CAPTURE
50#ifdef KICAD_GAL_PROFILE
71 return std::make_unique<ACCELERATING_ZOOM_CONTROLLER>();
138#if defined USE_MOUSE_CAPTURE
144 if(
m_parentPanel->EnableTouchEvents( wxTOUCH_ZOOM_GESTURE | wxTOUCH_PAN_GESTURES ) )
161 m_settings.m_lastKeyboardCursorPositionValid =
false;
162 m_settings.m_lastKeyboardCursorPosition = { 0.0, 0.0 };
169#if defined USE_MOUSE_CAPTURE
225#ifdef KICAD_GAL_PROFILE
226 latencyProbeRepaintToMotion.Checkpoint(
"motion-event");
227 wxLogTrace(
traceGalProfile,
"%s", latencyProbeRepaintToMotion.to_string() );
228 latencyProbeZoomToRender.Reset();
231 ( *m_MotionEventCounter )++;
238 if( !aEvent.Leaving() &&
m_parentPanel->GetClientRect().Contains( mouseRel ) )
241 bool isAutoPanning =
false;
255 if( screenPos != keyboardScreenPos )
257 m_settings.m_lastKeyboardCursorPositionValid =
false;
258 m_settings.m_lastKeyboardCursorPosition = { 0.0, 0.0 };
286 if(
m_settings.m_motionPanModifier != WXK_NONE
287 && wxGetKeyState(
static_cast<wxKeyCode
>(
m_settings.m_motionPanModifier ) ) )
293 aEvent.StopPropagation();
301 aEvent.StopPropagation();
324 if( !isAutoPanning && aEvent.Dragging() )
328 static bool justWarped =
false;
335 warpX = parentSize.x;
337 else if( x >= parentSize.x )
339 warpX = -parentSize.x;
344 warpY = parentSize.y;
346 else if( y >= parentSize.y )
348 warpY = -parentSize.y;
356#ifdef KICAD_GAL_PROFILE
357 latencyProbeZoomToRender.Checkpoint(
"mouse-mb-pan");
360 aEvent.StopPropagation();
385 static bool justWarped =
false;
391 warpY = parentSize.y;
393 else if( y >= parentSize.y )
395 warpY = -parentSize.y;
408 aEvent.StopPropagation();
442 if(
m_view->GetGAL() &&
m_view->GetGAL()->HasRetainedScene() )
451 const double wheelPanSpeed = 0.001;
452 const int axis = aEvent.GetWheelAxis();
454#ifdef KICAD_GAL_PROFILE
455 latencyProbeZoomToRender.Reset();
460 if( axis == wxMOUSE_WHEEL_HORIZONTAL )
466 * ( (double) aEvent.GetWheelRotation() * wheelPanSpeed );
478 if( aEvent.ShiftDown() )
481 modifiers = WXK_SHIFT;
484 if( aEvent.ControlDown() )
487 modifiers = modifiers == 0 ? WXK_CONTROL : modifiers;
490 if( aEvent.AltDown() )
493 modifiers = modifiers == 0 ? WXK_ALT : modifiers;
502 if( modifiers ==
m_settings.m_scrollModifierZoom && axis == wxMOUSE_WHEEL_VERTICAL )
504 const int rotation = aEvent.GetWheelRotation() * (
m_settings.m_scrollReverseZoom ? -1 : 1 );
508 const int wheelDelta = 0;
510 const int wheelDelta = aEvent.GetWheelDelta();
513 const double zoomScale =
m_zoomController->GetScaleForRotation( rotation, wheelDelta );
516#ifdef KICAD_GAL_PROFILE
518 latencyProbeZoomToRender.Checkpoint(
"mouse-wheel-zoom");
541 * ( (double) aEvent.GetWheelRotation() * wheelPanSpeed );
542 double scrollX = 0.0;
543 double scrollY = 0.0;
544 bool hReverse =
m_settings.m_scrollReversePanH;
546 if( modifiers ==
m_settings.m_scrollModifierPanH )
548 scrollX = hReverse ? scrollVec.
x : -scrollVec.
x;
552 scrollY = -scrollVec.
y;
578 m_view->SetScale(
m_view->GetScale() * ( aEvent.GetMagnification() + 1.0f ),
anchor );
604#if defined USE_MOUSE_CAPTURE
616#if defined USE_MOUSE_CAPTURE
622 if( aEvent.LeftUp() )
629 if( aEvent.MiddleUp() || aEvent.LeftUp() || aEvent.RightUp() )
634#if defined USE_MOUSE_CAPTURE
661#if defined( _WIN32 ) || defined( __WXGTK__ )
688 if( !crossingIntoChild )
691#if !defined USE_MOUSE_CAPTURE
755 double borderSize = std::min(
m_settings.m_autoPanMargin *
m_view->GetScreenPixelSize().x,
765 float accel = 0.5f + (
m_settings.m_autoPanAcceleration / 5.0f );
771 dir = dir.
Resize( borderSize * accel );
773 dir = dir.
Resize( borderSize );
775 dir =
m_view->ToWorld( dir,
false );
794 if( aEvent.IsGestureStart() )
800 VECTOR2D evtPos( aEvent.GetPosition().x, aEvent.GetPosition().y );
813 if( wxGetMouseState().LeftIsDown() )
819 VECTOR2I screenDelta( aEvent.GetDelta().x, aEvent.GetDelta().y );
832 if( std::isfinite( aZoomFactor ) && aZoomFactor > 0.0 && aZoomFactor != 1.0 )
841 const double linePanDelta = 0.05;
842 const double pagePanDelta = 0.5;
844 int type = aEvent.GetEventType();
845 int dir = aEvent.GetOrientation();
847 if( type == wxEVT_SCROLLWIN_THUMBTRACK )
850 const auto& boundary =
m_view->GetBoundary();
853 const double xstart = (
m_view->IsMirroredX() ? boundary.GetRight() : boundary.GetLeft() );
854 const double xdelta = (
m_view->IsMirroredX() ? -1 : 1 );
856 if( dir == wxHORIZONTAL )
863 else if( type == wxEVT_SCROLLWIN_THUMBRELEASE || type == wxEVT_SCROLLWIN_TOP || type == wxEVT_SCROLLWIN_BOTTOM )
872 if( type == wxEVT_SCROLLWIN_PAGEUP )
876 else if( type == wxEVT_SCROLLWIN_PAGEDOWN )
878 dist = -pagePanDelta;
880 else if( type == wxEVT_SCROLLWIN_LINEUP )
884 else if( type == wxEVT_SCROLLWIN_LINEDOWN )
886 dist = -linePanDelta;
890 wxCHECK_MSG(
false, , wxT(
"Unhandled event type" ) );
895 double scrollX = 0.0;
896 double scrollY = 0.0;
898 if( dir == wxHORIZONTAL )
914#if defined USE_MOUSE_CAPTURE
950#if defined USE_MOUSE_CAPTURE
1000 long aArrowCommand )
1006 if( aTriggeredByArrows )
1008 m_settings.m_lastKeyboardCursorPositionValid =
true;
1009 m_settings.m_lastKeyboardCursorPosition = clampedPosition;
1010 m_settings.m_lastKeyboardCursorCommand = aArrowCommand;
1015 m_settings.m_lastKeyboardCursorPositionValid =
false;
1016 m_settings.m_lastKeyboardCursorPosition = { 0.0, 0.0 };
1032 const VECTOR2I& screenSize =
m_view->GetGAL()->GetScreenPixelSize();
1036 if( aWarpView && !screen.
Contains( screenPos ) )
1037 m_view->SetCenter( clampedPosition );
1045 if( aWorldCoordinates )
1047 const VECTOR2I& screenSize =
m_view->GetGAL()->GetScreenPixelSize();
1052 if( !screen.
Contains( screenPos ) )
1056 m_view->SetCenter( clampedPosition );
1078 const VECTOR2I& screenSize =
m_view->GetGAL()->GetScreenPixelSize();
1079 VECTOR2D screenCenter( screenSize / 2 );
1087 m_view->SetCenter( newCenter );
1096 int border = std::min(
m_settings.m_autoPanMargin *
m_view->GetScreenPixelSize().x,
1100 VECTOR2D topLeft( border, border );
1101 VECTOR2D botRight(
m_view->GetScreenPixelSize().x - border,
m_view->GetScreenPixelSize().y - border );
1103 topLeft =
m_view->ToWorld( topLeft );
1104 botRight =
m_view->ToWorld( botRight );
1108 if( pos.
x < topLeft.
x )
1110 else if( pos.
x > botRight.
x )
1113 if( pos.
y < topLeft.
y )
1115 else if( pos.
y > botRight.
y )
1120 if( aWarpMouseCursor )
1127 VECTOR2I p( aEvent.GetX(), aEvent.GetY() );
1144 int borderStart = std::min(
m_settings.m_autoPanMargin *
m_view->GetScreenPixelSize().x,
1146 borderStart = std::max( borderStart, 2 );
1147 int borderEndX =
m_view->GetScreenPixelSize().x - borderStart;
1148 int borderEndY =
m_view->GetScreenPixelSize().y - borderStart;
1150 if( p.
x < borderStart )
1152 else if( p.
x > borderEndX )
1157 if( p.
y < borderStart )
1159 else if( p.
y > borderEndY )
1183 m_panTimer.Start( (
int) ( 250.0 / 60.0 ),
true );
1194 wxCHECK_MSG(
false,
false, wxT(
"This line should never be reached" ) );
1212 else if( x >= parentSize.x )
1214 x = parentSize.x - 1;
1223 else if( y >= parentSize.y )
1225 y = parentSize.y - 1;
1240 moveEvent.SetX( msp.x );
1241 moveEvent.SetY( msp.y );
1246 moveEvent.SetControlDown( wxGetKeyState( WXK_CONTROL ) );
1247 moveEvent.SetShiftDown( wxGetKeyState( WXK_SHIFT ) );
1248 moveEvent.SetAltDown( wxGetKeyState( WXK_ALT ) );
1280 if(
m_view->IsMirroredX() )
1286 || newRange.
y !=
m_parentPanel->GetScrollRange( wxSB_VERTICAL ) )
1288 m_parentPanel->SetScrollbars( 1, 1, newRange.
x, newRange.
y, newScroll.
x, newScroll.
y,
true );
1291#if !defined( __APPLE__ ) && !defined( WIN32 )
1306 m_settings.m_forcedPosition = clampedPosition;
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.
static void NoteInput()
Count an input so the frame that answers it is never held back by the display-rate limit.
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
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.
VIEW_CONTROLS(VIEW *aView)
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
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 ApplyPanAndZoomGesture(const VECTOR2D &aPanDelta, double aZoomFactor, const VECTOR2D &aZoomAnchor)
Apply a platform gesture expressed in canvas pixel 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.
VECTOR2D m_metaPanStart
Last mouse position when panning via the meta key.
bool m_metaPanning
True if we are panning via the meta key.
void onScroll(wxScrollWinEvent &aEvent)
wxTimer m_panTimer
Timer responsible for handling autopanning.
void CancelDrag()
End any mouse drag action still in progress.
void repaintRetained()
Repaint only when the canvas keeps a retained scene.
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
If enabled (.
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 syncCursorInCanvas()
Set the panel's cursor-in-canvas state from the pointer position after a capture change.
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))
bool isPointerOverCanvas() const
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)
Clamp a vector to values that can be negated, respecting numeric limits of coordinates data type with...
const wxChar *const traceZoomScroll
Flag to enable debug output of zoom-scrolling calculations in KIGFX::ZOOM_CONTROLLER and derivatives.
const wxChar *const traceGalProfile
Flag to enable debug output of GAL performance profiling.
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.
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.