KiCad PCB EDA Suite
Loading...
Searching...
No Matches
wx_view_controls.h
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2012 Torsten Hueter, torstenhtr <at> gmx.de
5 * Copyright (C) 2013 CERN
6 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
7 *
8 * @author Tomasz Wlostowski <[email protected]>
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 */
23
28
29#ifndef __WX_VIEW_CONTROLS_H
30#define __WX_VIEW_CONTROLS_H
31
32#include <view/view_controls.h>
33#include <wx/timer.h>
34#include <memory>
35
37class PROF_COUNTER;
38
39namespace KIGFX
40{
41
42class ZOOM_CONTROLLER;
43
47class WX_VIEW_CONTROLS : public VIEW_CONTROLS, public wxEvtHandler
48{
49public:
50 WX_VIEW_CONTROLS( VIEW* aView, EDA_DRAW_PANEL_GAL* aParentPanel );
51 virtual ~WX_VIEW_CONTROLS();
52
54 void onWheel( wxMouseEvent& aEvent );
55 void onMotion( wxMouseEvent& aEvent );
56 void onMagnify( wxMouseEvent& aEvent );
57 void onButton( wxMouseEvent& aEvent );
58 void onEnter( wxMouseEvent& WXUNUSED( aEvent ) );
59 void onLeave( wxMouseEvent& WXUNUSED( aEvent ) );
60 void onTimer( wxTimerEvent& WXUNUSED( aEvent ) );
61 void onZoomGesture( wxZoomGestureEvent& aEvent );
62 void onPanGesture( wxPanGestureEvent& aEvent );
63 void onScroll( wxScrollWinEvent& aEvent );
64 void onCaptureLost( wxMouseEvent& WXUNUSED( aEvent ) );
65
66
72 void CaptureCursor( bool aEnabled ) override;
73
74
75 void PinCursorInsideNonAutoscrollArea( bool aWarpMouseCursor ) override;
76
78 VECTOR2D GetMousePosition( bool aWorldCoordinates = true ) const override;
79
81
83 VECTOR2D GetCursorPosition( bool aSnappingEnabled ) const override;
84
86 VECTOR2D GetRawCursorPosition( bool aSnappingEnabled = true ) const override;
87
88 void SetCursorPosition( const VECTOR2D& aPosition, bool warpView, bool aTriggeredByArrows,
89 long aArrowCommand ) override;
90
92 void SetCrossHairCursorPosition( const VECTOR2D& aPosition, bool aWarpView ) override;
93
95 void WarpMouseCursor( const VECTOR2D& aPosition, bool aWorldCoordinates = false, bool aWarpView = false ) override;
96
98 void CenterOnCursor() override;
99
101 void UpdateScrollbars();
102
104 void CancelDrag();
105
106 void ForceCursorPosition( bool aEnabled, const VECTOR2D& aPosition = VECTOR2D( 0, 0 ) ) override;
107
109 void LoadSettings() override;
110
113 static const wxEventType EVT_REFRESH_MOUSE;
114
115 std::unique_ptr<PROF_COUNTER> m_MotionEventCounter;
116
117private:
126
130 void setState( STATE aNewState );
131
139 bool handleAutoPanning( const wxMouseEvent& aEvent );
140
147 void handleCursorCapture( int x, int y );
148
159 void refreshMouse( bool aSetModifiers );
160
164 wxPoint getMouseScreenPosition() const;
165
168
171
174
177
179 wxTimer m_panTimer;
180
183
186
189
192
195
198
201
204
206 std::unique_ptr<ZOOM_CONTROLLER> m_zoomController;
207
211};
212} // namespace KIGFX
213
214#endif
VECTOR2D GetCursorPosition() const
Return the current cursor position in world coordinates.
VIEW_CONTROLS(VIEW *aView)
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition view.h:63
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.
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 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.
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.
Handle the response of the zoom scale to external inputs.
A thread-safe event counter.
Definition profile.h:255
The Cairo implementation of the graphics abstraction layer.
Definition eda_group.h:29
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683
VECTOR2< double > VECTOR2D
Definition vector2d.h:682