41 #define USE_MOUSE_CAPTURE 44 using namespace KIGFX;
60 return std::make_unique<ACCELERATING_ZOOM_CONTROLLER>();
68 m_parentPanel( aParentPanel ),
69 m_scrollScale( 1.0, 1.0 ),
70 m_initialZoomScale( 0.0 ),
75 m_updateCursor( true )
81 #if wxCHECK_VERSION( 3, 1, 0 ) || defined( USE_OSX_MAGNIFY_EVENT ) 83 wxMouseEventHandler( WX_VIEW_CONTROLS::onMagnify ),
NULL,
this );
120 #if defined USE_MOUSE_CAPTURE 138 #if defined USE_MOUSE_CAPTURE 189 bool isAutoPanning =
false;
190 int x = aEvent.GetX();
191 int y = aEvent.GetY();
200 if( !isAutoPanning && aEvent.Dragging() )
204 static bool justWarped =
false;
211 warpX = parentSize.x;
213 else if(x >= parentSize.x )
215 warpX = -parentSize.x;
220 warpY = parentSize.y;
222 else if( y >= parentSize.y )
224 warpY = -parentSize.y;
232 aEvent.StopPropagation();
251 static bool justWarped =
false;
257 warpY = parentSize.y;
259 else if( y >= parentSize.y )
261 warpY = -parentSize.y;
272 aEvent.StopPropagation();
303 if( aEvent.GetTimestamp() == m_lastTimestamp )
305 aEvent.Skip(
false );
309 m_lastTimestamp = aEvent.GetTimestamp();
312 const double wheelPanSpeed = 0.001;
313 const int axis = aEvent.GetWheelAxis();
320 aEvent.ShiftDown() ? WXK_SHIFT :
321 ( aEvent.ControlDown() ? WXK_CONTROL : ( aEvent.AltDown() ? WXK_ALT : 0 ) );
328 const int rotation = aEvent.GetWheelRotation();
350 ( (
double) aEvent.GetWheelRotation() * wheelPanSpeed );
351 double scrollX = 0.0;
352 double scrollY = 0.0;
355 scrollX = scrollVec.
x;
357 scrollY = -scrollVec.
y;
372 #if wxCHECK_VERSION( 3, 1, 0 ) || defined( USE_OSX_MAGNIFY_EVENT ) 373 void WX_VIEW_CONTROLS::onMagnify( wxMouseEvent& aEvent )
396 #if defined USE_MOUSE_CAPTURE 408 #if defined USE_MOUSE_CAPTURE 414 if( aEvent.LeftUp() )
421 if( aEvent.MiddleUp() || aEvent.LeftUp() || aEvent.RightUp() )
424 #if defined USE_MOUSE_CAPTURE 447 #if defined( _WIN32 ) 453 if( GetForegroundWindow() ==
m_parentPanel->GetParent()->GetHWND() )
466 #if !defined USE_MOUSE_CAPTURE 506 if( dir.EuclideanNorm() >= borderSize )
507 dir = dir.Resize( borderSize * accel );
508 else if( dir.EuclideanNorm() > borderSize / 2 )
509 dir = dir.Resize( borderSize );
528 const double linePanDelta = 0.05;
529 const double pagePanDelta = 0.5;
531 int type = aEvent.GetEventType();
532 int dir = aEvent.GetOrientation();
534 if( type == wxEVT_SCROLLWIN_THUMBTRACK )
541 boundary.GetRight() : boundary.GetLeft() );
544 if( dir == wxHORIZONTAL )
545 center.x = xstart + xdelta * ( aEvent.GetPosition() /
m_scrollScale.
x );
555 if( type == wxEVT_SCROLLWIN_PAGEUP )
557 else if( type == wxEVT_SCROLLWIN_PAGEDOWN )
558 dist = -pagePanDelta;
559 else if( type == wxEVT_SCROLLWIN_LINEUP )
561 else if( type == wxEVT_SCROLLWIN_LINEDOWN )
562 dist = -linePanDelta;
565 wxASSERT(
"Unhandled event type" );
571 double scrollX = 0.0;
572 double scrollY = 0.0;
574 if ( dir == wxHORIZONTAL )
590 #if defined USE_MOUSE_CAPTURE 606 #if defined USE_MOUSE_CAPTURE 619 return aWorldCoordinates ?
m_view->
ToWorld( screenPos ) : screenPos;
652 bool aTriggeredByArrows,
long aArrowCommand )
656 if( aTriggeredByArrows )
684 if( aWarpView && !screen.
Contains( screenPos ) )
694 if( aWorldCoordinates )
725 VECTOR2I screenCenter( screenSize / 2 );
737 VECTOR2I p( aEvent.GetX(), aEvent.GetY() );
756 borderStart = std::max( borderStart, 2 );
760 if( p.x < borderStart )
762 else if( p.x > borderEndX )
767 if( p.y < borderStart )
769 else if( p.y > borderEndY )
807 wxASSERT_MSG(
false, wxT(
"This line should never be reached" ) );
824 else if( x >= parentSize.x )
826 x = parentSize.x - 1;
835 else if( y >= parentSize.y )
837 y = parentSize.y - 1;
852 moveEvent.SetX( msp.x );
853 moveEvent.SetY( msp.y );
856 moveEvent.SetControlDown( wxGetKeyState( WXK_CONTROL ) );
857 moveEvent.SetShiftDown( wxGetKeyState( WXK_SHIFT ) );
858 moveEvent.SetAltDown( wxGetKeyState( WXK_ALT ) );
867 wxPoint msp = wxGetMousePosition();
895 || newRange.y !=
m_parentPanel->GetScrollRange( wxSB_VERTICAL ) )
897 m_parentPanel->SetScrollbars( 1, 1, newRange.x, newRange.y, newScroll.
x, newScroll.
y,
true );
900 #if !defined( __APPLE__ ) && !defined( WIN32 )
VECTOR2D m_lookStartPoint
Current direction of panning (only autopanning mode).
virtual ~WX_VIEW_CONTROLS()
BOX2D GetViewport() const
Return the current viewport visible area rectangle.
const wxChar *const traceZoomScroll
Flag to enable debug output of zoom-scrolling calculations in KIGFX::ZOOM_CONTROLLER and derivatives.
void LoadSettings() override
Event that forces mouse move event in the dispatcher (eg.
MOUSE_DRAG_ACTION m_dragRight
Is last cursor motion event coming from keyboard arrow cursor motion action.
The Cairo implementation of the graphics abstraction layer.
const BOX2D & GetBoundary() const
Panning with mouse button pressed.
static std::unique_ptr< ZOOM_CONTROLLER > GetZoomControllerForPlatform()
static const wxEventType EVT_REFRESH_MOUSE
VECTOR2D ToWorld(const VECTOR2D &aCoord, bool aAbsolute=true) const
Converts a screen space point/vector to a point/vector in world space coordinates.
coord_type GetTop() const
const VECTOR2D & GetCenter() const
Return the center point of this VIEW (in world space coordinates).
wxPoint getMouseScreenPosition() const
Get the cursor position in the screen coordinates.
VECTOR2D GetMousePosition(bool aWorldCoordinates=true) const override
Return the current mouse pointer position.
std::unique_ptr< ZOOM_CONTROLLER > m_zoomController
void onButton(wxMouseEvent &aEvent)
VECTOR2D m_forcedPosition
Is the forced cursor position enabled.
coord_type GetRight() const
GAL * GetGAL() const
Return the #GAL this view is using to draw graphical primitives.
VIEW * m_view
< Pointer to controlled VIEW.
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
VECTOR2D m_scrollScale
Current scrollbar position.
WX_VIEW_CONTROLS class definition.
static constexpr double GTK3_SCALE
A suitable (magic) scale factor for Mac systems.
bool IsInputControlFocused()
Checks if a input control has focus.
void UpdateScrollbars()
End any mouse drag action still in progress.
void onCaptureLost(wxMouseEvent &WXUNUSED(aEvent))
VECTOR2D GetGridPoint(const VECTOR2D &aPoint) const
For a given point it returns the nearest point belonging to the grid in world coordinates.
Zooming with mouse button pressed.
const VECTOR2I & GetScreenPixelSize() const
Return GAL canvas size in pixels.
int m_scrollModifierPanH
What modifier key to enable vertical with the (vertical) scroll wheel.
VECTOR2D m_lastKeyboardCursorPosition
bool GetGridSnapping() const
VECTOR2D GetRawCursorPosition(bool aSnappingEnabled=true) const override
Return the current cursor position in world coordinates ignoring the cursorUp position force mode.
bool m_autoPanSettingEnabled
Distance from cursor to VIEW edge when panning is active.
void onWheel(wxMouseEvent &aEvent)
Handler functions.
MOUSE_DRAG_ACTION m_dragLeft
void SetCenter(const VECTOR2D &aCenter)
Set the center point of the VIEW (i.e.
Panning on approaching borders of the frame.
bool m_forceCursorPosition
Should the cursor be locked within the parent window area.
VECTOR2< double > VECTOR2D
MOUSE_DRAG_ACTION m_dragMiddle
bool m_zoomSpeedAuto
What modifier key to enable zoom with the (vertical) scroll wheel.
virtual void CaptureCursor(bool aEnabled)
Force the cursor to stay within the drawing panel area.
coord_type GetWidth() const
int m_scrollModifierZoom
What modifier key to enable horizontal pan with the (vertical) scroll wheel.
bool Contains(const Vec &aPoint) const
Function Contains.
void SetCrossHairCursorPosition(const VECTOR2D &aPosition, bool aWarpView) override
void CaptureCursor(bool aEnabled) override
Force the cursor to stay within the drawing panel area.
float m_autoPanAcceleration
If the cursor is allowed to be warped.
int m_zoomSpeed
When true, ignore zoom_speed and pick a platform-specific default.
const VECTOR2I & GetScreenPixelSize() const
Return the size of the our rendering area in pixels.
Functions to provide common constants and other functions to assist in making a consistent UI.
bool IsCursorWarpingEnabled() const
An interface for classes handling user events controlling the view behavior such as zooming,...
bool m_warpCursor
Enable horizontal panning with the horizontal scroll/trackpad input.
static constexpr double MAC_SCALE
Multiplier for manual scale ssetting.
wxLogTrace helper definitions.
float m_autoPanMargin
How fast is panning when in auto mode.
bool m_horizontalPan
Enable the accelerating zoom controller.
bool m_cursorWarped
Current VIEW_CONTROLS settings.
void refreshMouse()
Send an event to refresh mouse position.
VECTOR2D ToScreen(const VECTOR2D &aCoord, bool aAbsolute=true) const
Convert a world space point/vector to a point/vector in screen space coordinates.
bool m_autoPanEnabled
Flag for turning on autopanning.
void handleCursorCapture(int x, int y)
Limit the cursor position to within the canvas by warping it.
bool m_zoomAcceleration
Zoom speed for the non-accelerating zoom controller.
void onMotion(wxMouseEvent &aEvent)
void WarpCursor(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.
bool IsMirroredX() const
Return true if view is flipped across the X axis.
void ForceCursorPosition(bool aEnabled, const VECTOR2D &aPosition=VECTOR2D(0, 0)) override
Applies VIEW_CONTROLS settings from the program COMMON_SETTINGS.
virtual void SetScale(double aScale, VECTOR2D aAnchor={ 0, 0 })
Set the scaling factor, zooming around a given anchor point.
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
VECTOR2D m_zoomStartPoint
Current cursor position (world coordinates).
wxScrolledCanvas * m_parentPanel
Store information about point where dragging has started.
void onTimer(wxTimerEvent &WXUNUSED(aEvent))
VECTOR2D m_panDirection
Timer responsible for handling autopanning.
long m_lastKeyboardCursorCommand
Position of the above event.
static constexpr double MANUAL_SCALE_FACTOR
bool m_updateCursor
A #ZOOM_CONTROLLER that determines zoom steps. This is platform-specific.
bool m_lastKeyboardCursorPositionValid
ACTIONS::CURSOR_UP, ACTIONS::CURSOR_DOWN, etc.
double m_initialZoomScale
The mouse position when a drag zoom started.
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
VECTOR2I m_scrollPos
The zoom scale when a drag zoom started.
coord_type GetHeight() const
WX_VIEW_CONTROLS(VIEW *aView, wxScrolledCanvas *aParentPanel)
bool handleAutoPanning(const wxMouseEvent &aEvent)
Compute new viewport settings while in autopanning mode.
void onEnter(wxMouseEvent &WXUNUSED(aEvent))
VECTOR2D m_dragStartPoint
Stores information about the center of viewport when dragging has started.
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.
STATE m_state
Panel that is affected by VIEW_CONTROLS.
coord_type GetLeft() const
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
void CenterOnCursor() const override
Adjusts the scrollbars position to match the current viewport.
bool m_cursorCaptured
Should the cursor snap to grid or move freely.
void onScroll(wxScrollWinEvent &aEvent)
VECTOR2D GetCursorPosition() const
Return the current cursor position in world coordinates.
Abstract interface for drawing on a 2D-surface.
void onLeave(wxMouseEvent &WXUNUSED(aEvent))
VECTOR2D m_cursorPos
Flag deciding whether the cursor position should be calculated using the mouse position.
wxTimer m_panTimer
Ratio used for scaling world coordinates to scrollbar position.