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, bool aTriggeredByArrows ) override;
89 
91  void SetCrossHairCursorPosition( const VECTOR2D& aPosition, bool aWarpView ) override;
92 
94  void WarpCursor( const VECTOR2D& aPosition, bool aWorldCoordinates = false,
95  bool aWarpView = false ) override;
96 
98  void CenterOnCursor() const override;
99 
101  void UpdateScrollbars();
102 
103  void ForceCursorPosition( bool aEnabled, const VECTOR2D& aPosition = VECTOR2D( 0, 0 ) ) override;
104 
107  static const wxEventType EVT_REFRESH_MOUSE;
108 
109 private:
111  enum STATE
112  {
113  IDLE = 1,
116  };
117 
126  bool handleAutoPanning( const wxMouseEvent& aEvent );
127 
133  void refreshMouse();
134 
138  wxPoint getMouseScreenPosition() const;
139 
142 
144  wxScrolledCanvas* m_parentPanel;
145 
148 
151 
154 
156  wxTimer m_panTimer;
157 
160 
163 
165  long int m_lastTimestamp;
166 
169 
172 
174  std::unique_ptr<ZOOM_CONTROLLER> m_zoomController;
175 };
176 } // namespace KIGFX
177 
178 #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: class_module.h:57
static const wxEventType EVT_REFRESH_MOUSE
Event that forces mouse move event in the dispatcher (eg.
Class WX_VIEW_CONTROLS is a specific implementation of class VIEW_CONTROLS for wxWidgets library...
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)
long int m_lastTimestamp
Last event timestamp to remove duplicates.
VECTOR2D m_scrollScale
Ratio used for scaling world coordinates to scrollbar position.
void UpdateScrollbars()
Adjusts the scrollbars position to match the current viewport.
wxPoint getMouseScreenPosition() const
Gets the cursor position in the screen coordinates.
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:586
VECTOR2D GetCursorPosition() const
Returns the current cursor position in world coordinates.
void SetCrossHairCursorPosition(const VECTOR2D &aPosition, bool aWarpView) override
Moves the graphic crosshair cursor to the requested position expressed in world coordinates.
Class VIEW_CONTROLS is an interface for classes handling user events controlling the view behaviour (...
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.
STATE m_state
Current state of VIEW_CONTROLS.
Class 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)
void SetCursorPosition(const VECTOR2D &aPosition, bool warpView, bool aTriggeredByArrows) override
Moves cursor to the requested position expressed in world coordinates.
void onLeave(wxMouseEvent &WXUNUSED(aEvent))
VECTOR2D m_cursorPos
Current cursor position (world coordinates)
wxTimer m_panTimer
Timer repsonsible for handling autopanning.