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  * @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, you may find one here:
20  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21  * or you may search the http://www.gnu.org website for the version 2 license,
22  * or you may write to the Free Software Foundation, Inc.,
23  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24  */
25 
31 #ifndef __WX_VIEW_CONTROLS_H
32 #define __WX_VIEW_CONTROLS_H
33 
34 #include <wx/wx.h>
35 
36 #include <view/view_controls.h>
37 
38 #include <memory>
39 
40 class EDA_DRAW_PANEL_GAL;
41 
42 namespace KIGFX
43 {
44 
45 class ZOOM_CONTROLLER;
46 
51 class WX_VIEW_CONTROLS : public VIEW_CONTROLS, public wxEvtHandler
52 {
53 public:
54  WX_VIEW_CONTROLS( VIEW* aView, wxScrolledCanvas* 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 
75  void SetGrabMouse( bool aEnabled ) 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,
89  bool aTriggeredByArrows, long aArrowCommand ) override;
90 
92  void SetCrossHairCursorPosition( const VECTOR2D& aPosition, bool aWarpView ) override;
93 
95  void WarpCursor( const VECTOR2D& aPosition, bool aWorldCoordinates = false,
96  bool aWarpView = false ) override;
97 
99  void CenterOnCursor() const override;
100 
102  void UpdateScrollbars();
103 
104  void ForceCursorPosition( bool aEnabled, const VECTOR2D& aPosition = VECTOR2D( 0, 0 ) ) override;
105 
108  static const wxEventType EVT_REFRESH_MOUSE;
109 
110 private:
112  enum STATE
113  {
114  IDLE = 1,
117  };
118 
127  bool handleAutoPanning( const wxMouseEvent& aEvent );
128 
134  void refreshMouse();
135 
140 
143 
145  wxScrolledCanvas* m_parentPanel;
146 
149 
152 
155 
157  wxTimer m_panTimer;
158 
161 
164 
165 #ifdef __WXGTK3__
166  long int m_lastTimestamp;
168 #endif
169 
172 
175 
177  std::unique_ptr<ZOOM_CONTROLLER> m_zoomController;
178 };
179 } // namespace KIGFX
180 
181 #endif
VECTOR2D m_lookStartPoint
Stores information about the center of viewport when dragging has started.
Class CAIRO_GAL is the cairo implementation of the graphics abstraction layer.
Definition: color4d.cpp:131
static const wxEventType EVT_REFRESH_MOUSE
Event that forces mouse move event in the dispatcher (eg.
WX_VIEW_CONTROLS is a specific implementation of class VIEW_CONTROLS for wxWidgets library.
wxPoint getMouseScreenPosition() const
Gets the cursor position in the screen coordinates.
VIEW_CONTROLS class definition.
VECTOR2D GetMousePosition(bool aWorldCoordinates=true) const override
Function GetMousePosition() Returns the current mouse pointer position.
std::unique_ptr< ZOOM_CONTROLLER > m_zoomController
a ZOOM_CONTROLLER that determines zoom steps. This is platform-specific.
void onButton(wxMouseEvent &aEvent)
VECTOR2D m_scrollScale
Ratio used for scaling world coordinates to scrollbar position.
void UpdateScrollbars()
Adjusts the scrollbars position to match the current viewport.
VECTOR2D GetRawCursorPosition(bool aSnappingEnabled=true) const override
Returns the current cursor position in world coordinates - ingoring the cursorUp position force mode.
void onWheel(wxMouseEvent &aEvent)
Handler functions.
Panning with mouse button pressed.
VECTOR2< double > VECTOR2D
Definition: vector2d.h:593
void SetCrossHairCursorPosition(const VECTOR2D &aPosition, bool aWarpView) override
Moves the graphic crosshair cursor to the requested position expressed in world coordinates.
VIEW_CONTROLS is an interface for classes handling user events controlling the view behaviour (such a...
STATE
Possible states for WX_VIEW_CONTROLS.
void SetGrabMouse(bool aEnabled) override
Function SetGrabMouse() Enables/disables mouse cursor grabbing (limits the movement field only to the...
void refreshMouse()
Sends an event to refresh mouse position.
void onMotion(wxMouseEvent &aEvent)
void WarpCursor(const VECTOR2D &aPosition, bool aWorldCoordinates=false, bool aWarpView=false) override
void ForceCursorPosition(bool aEnabled, const VECTOR2D &aPosition=VECTOR2D(0, 0)) override
Function ForceCursorPosition() Places the cursor immediately at a given point.
wxScrolledCanvas * m_parentPanel
Panel that is affected by VIEW_CONTROLS.
void onTimer(wxTimerEvent &WXUNUSED(aEvent))
VECTOR2D m_panDirection
Current direction of panning (only autopanning mode)
bool m_updateCursor
Flag deciding whether the cursor position should be calculated using the mouse position.
VECTOR2I m_scrollPos
Current scrollbar position.
WX_VIEW_CONTROLS(VIEW *aView, wxScrolledCanvas *aParentPanel)
bool handleAutoPanning(const wxMouseEvent &aEvent)
Function handleAutoPanning() Computes new viewport settings while in autopanning mode.
void onEnter(wxMouseEvent &WXUNUSED(aEvent))
VECTOR2D m_dragStartPoint
Stores information about point where dragging has started.
void SetCursorPosition(const VECTOR2D &aPosition, bool warpView, bool aTriggeredByArrows, long aArrowCommand) override
Moves cursor to the requested position expressed in world coordinates.
STATE m_state
Current state of VIEW_CONTROLS.
VIEW.
Definition: view.h:61
void CenterOnCursor() const override
Function CenterOnCursor() Sets the viewport center to the current cursor position and warps the curso...
void onScroll(wxScrollWinEvent &aEvent)
VECTOR2D GetCursorPosition() const
Returns the current cursor position in world coordinates.
void onLeave(wxMouseEvent &WXUNUSED(aEvent))
VECTOR2D m_cursorPos
Current cursor position (world coordinates)
wxTimer m_panTimer
Timer repsonsible for handling autopanning.