KiCad PCB EDA Suite
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 (C) 2021 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, you may find one here:
22 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
23 * or you may search the http://www.gnu.org website for the version 2 license,
24 * or you may write to the Free Software Foundation, Inc.,
25 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
26 */
27
33#ifndef __WX_VIEW_CONTROLS_H
34#define __WX_VIEW_CONTROLS_H
35
36#include <view/view_controls.h>
37#include <wx/timer.h>
38#include <memory>
39
41class PROF_COUNTER;
42
43namespace KIGFX
44{
45
46class ZOOM_CONTROLLER;
47
51class WX_VIEW_CONTROLS : public VIEW_CONTROLS, public wxEvtHandler
52{
53public:
54 WX_VIEW_CONTROLS( VIEW* aView, EDA_DRAW_PANEL_GAL* aParentPanel );
55 virtual ~WX_VIEW_CONTROLS();
56
58 void onWheel( wxMouseEvent& aEvent );
59 void onMotion( wxMouseEvent& aEvent );
60#if wxCHECK_VERSION( 3, 1, 0 ) || defined( USE_OSX_MAGNIFY_EVENT )
61 void onMagnify( wxMouseEvent& aEvent );
62#endif
63 void onButton( wxMouseEvent& aEvent );
64 void onEnter( wxMouseEvent& WXUNUSED( aEvent ) );
65 void onLeave( wxMouseEvent& WXUNUSED( aEvent ) );
66 void onTimer( wxTimerEvent& WXUNUSED( aEvent ) );
67 void onScroll( wxScrollWinEvent& aEvent );
68 void onCaptureLost( wxMouseEvent& WXUNUSED( aEvent ) );
69
70
76 void CaptureCursor( bool aEnabled ) override;
77
78
79 void PinCursorInsideNonAutoscrollArea( bool aWarpMouseCursor ) override;
80
82 VECTOR2D GetMousePosition( bool aWorldCoordinates = true ) const override;
83
85
87 VECTOR2D GetCursorPosition( bool aSnappingEnabled ) const override;
88
90 VECTOR2D GetRawCursorPosition( bool aSnappingEnabled = true ) const override;
91
92 void SetCursorPosition( const VECTOR2D& aPosition, bool warpView,
93 bool aTriggeredByArrows, long aArrowCommand ) override;
94
96 void SetCrossHairCursorPosition( const VECTOR2D& aPosition, bool aWarpView ) override;
97
99 void WarpMouseCursor( const VECTOR2D& aPosition, bool aWorldCoordinates = false,
100 bool aWarpView = false ) override;
101
103 void CenterOnCursor() override;
104
106 void UpdateScrollbars();
107
109 void CancelDrag();
110
111 void ForceCursorPosition( bool aEnabled,
112 const VECTOR2D& aPosition = VECTOR2D( 0, 0 ) ) override;
113
115 void LoadSettings() override;
116
119 static const wxEventType EVT_REFRESH_MOUSE;
120
121 std::unique_ptr<PROF_COUNTER> m_MotionEventCounter;
122
123private:
125 enum STATE
126 {
127 IDLE = 1,
131 };
132
136 void setState( STATE aNewState );
137
145 bool handleAutoPanning( const wxMouseEvent& aEvent );
146
153 void handleCursorCapture( int x, int y );
154
163 void refreshMouse( bool aSetModifiers);
164
168 wxPoint getMouseScreenPosition() const;
169
172
175
178
181
183 wxTimer m_panTimer;
184
187
190
193
194#ifdef __WXGTK3__
196 long int m_lastTimestamp;
197#endif
198
201
204
206 std::unique_ptr<ZOOM_CONTROLLER> m_zoomController;
207};
208} // namespace KIGFX
209
210#endif
An interface for classes handling user events controlling the view behavior such as zooming,...
VECTOR2D GetCursorPosition() const
Return the current cursor position in world coordinates.
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition: view.h:69
An implementation of class VIEW_CONTROLS for wxWidgets library.
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.
WX_VIEW_CONTROLS(VIEW *aView, EDA_DRAW_PANEL_GAL *aParentPanel)
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.
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).
A thread-safe event counter.
Definition: profile.h:226
The Cairo implementation of the graphics abstraction layer.
Definition: color4d.cpp:266
VECTOR2< double > VECTOR2D
Definition: vector2d.h:617