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) 2020 KiCad Developers, see AUTHORS.txt for contributors.
7  *
8  * @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
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 <wx/wx.h>
37 
38 #include <view/view_controls.h>
39 
40 #include <memory>
41 
42 namespace KIGFX
43 {
44 
45 class ZOOM_CONTROLLER;
46 
50 class WX_VIEW_CONTROLS : public VIEW_CONTROLS, public wxEvtHandler
51 {
52 public:
53  WX_VIEW_CONTROLS( VIEW* aView, wxScrolledCanvas* aParentPanel );
54  virtual ~WX_VIEW_CONTROLS();
55 
57  void onWheel( wxMouseEvent& aEvent );
58  void onMotion( wxMouseEvent& aEvent );
59 #if wxCHECK_VERSION( 3, 1, 0 ) || defined( USE_OSX_MAGNIFY_EVENT )
60  void onMagnify( wxMouseEvent& aEvent );
61 #endif
62  void onButton( wxMouseEvent& aEvent );
63  void onEnter( wxMouseEvent& WXUNUSED( aEvent ) );
64  void onLeave( wxMouseEvent& WXUNUSED( aEvent ) );
65  void onTimer( wxTimerEvent& WXUNUSED( aEvent ) );
66  void onScroll( wxScrollWinEvent& aEvent );
67  void onCaptureLost( wxMouseEvent& WXUNUSED( aEvent ) );
68 
69 
75  void CaptureCursor( bool aEnabled ) override;
76 
77 
79  VECTOR2D GetMousePosition( bool aWorldCoordinates = true ) const override;
80 
82 
84  VECTOR2D GetCursorPosition( bool aSnappingEnabled ) const override;
85 
87  VECTOR2D GetRawCursorPosition( bool aSnappingEnabled = true ) const override;
88 
89  void SetCursorPosition( const VECTOR2D& aPosition, bool warpView,
90  bool aTriggeredByArrows, long aArrowCommand ) override;
91 
93  void SetCrossHairCursorPosition( const VECTOR2D& aPosition, bool aWarpView ) override;
94 
96  void WarpCursor( const VECTOR2D& aPosition, bool aWorldCoordinates = false,
97  bool aWarpView = false ) override;
98 
100  void CenterOnCursor() const override;
101 
103  void UpdateScrollbars();
104 
106  void CancelDrag();
107 
108  void ForceCursorPosition( bool aEnabled,
109  const VECTOR2D& aPosition = VECTOR2D( 0, 0 ) ) override;
110 
112  void LoadSettings() override;
113 
116  static const wxEventType EVT_REFRESH_MOUSE;
117 
118 private:
120  enum STATE
121  {
122  IDLE = 1,
126  };
127 
135  bool handleAutoPanning( const wxMouseEvent& aEvent );
136 
143  void handleCursorCapture( int x, int y );
144 
152  void refreshMouse();
153 
157  wxPoint getMouseScreenPosition() const;
158 
161 
163  wxScrolledCanvas* m_parentPanel;
164 
167 
170 
173 
175  wxTimer m_panTimer;
176 
179 
182 
185 
188 
189 #ifdef __WXGTK3__
190  long int m_lastTimestamp;
192 #endif
193 
196 
199 
201  std::unique_ptr<ZOOM_CONTROLLER> m_zoomController;
202 };
203 } // namespace KIGFX
204 
205 #endif
VECTOR2D m_lookStartPoint
Current direction of panning (only autopanning mode).
void LoadSettings() override
Event that forces mouse move event in the dispatcher (eg.
The Cairo implementation of the graphics abstraction layer.
Definition: color4d.cpp:175
Panning with mouse button pressed.
static const wxEventType EVT_REFRESH_MOUSE
An implementation of class VIEW_CONTROLS for wxWidgets library.
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_scrollScale
Current scrollbar position.
void UpdateScrollbars()
End any mouse drag action still in progress.
void onCaptureLost(wxMouseEvent &WXUNUSED(aEvent))
Zooming with mouse button pressed.
VECTOR2D GetRawCursorPosition(bool aSnappingEnabled=true) const override
Return the current cursor position in world coordinates ignoring the cursorUp position force mode.
void onWheel(wxMouseEvent &aEvent)
Handler functions.
Panning on approaching borders of the frame.
VECTOR2< double > VECTOR2D
Definition: vector2d.h:622
void SetCrossHairCursorPosition(const VECTOR2D &aPosition, bool aWarpView) override
void CaptureCursor(bool aEnabled) override
Force the cursor to stay within the drawing panel area.
An interface for classes handling user events controlling the view behavior such as zooming,...
STATE
< Possible states for WX_VIEW_CONTROLS.
void refreshMouse()
Send an event to refresh mouse position.
void handleCursorCapture(int x, int y)
Limit the cursor position to within the canvas by warping it.
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.
void ForceCursorPosition(bool aEnabled, const VECTOR2D &aPosition=VECTOR2D(0, 0)) override
Applies VIEW_CONTROLS settings from the program COMMON_SETTINGS.
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.
bool m_updateCursor
A #ZOOM_CONTROLLER that determines zoom steps. This is platform-specific.
double m_initialZoomScale
The mouse position when a drag zoom started.
VECTOR2I m_scrollPos
The zoom scale when a drag zoom started.
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.
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition: view.h:67
void CenterOnCursor() const override
Adjusts the scrollbars position to match the current viewport.
void onScroll(wxScrollWinEvent &aEvent)
VECTOR2D GetCursorPosition() const
Return the current cursor position in world coordinates.
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.