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 class EDA_DRAW_PANEL_GAL;
39 
40 namespace KIGFX
41 {
46 class WX_VIEW_CONTROLS : public VIEW_CONTROLS, public wxEvtHandler
47 {
48 public:
49  WX_VIEW_CONTROLS( VIEW* aView, wxScrolledCanvas* aParentPanel );
51  {}
52 
54  void onWheel( wxMouseEvent& aEvent );
55  void onMotion( wxMouseEvent& aEvent );
56 #if wxCHECK_VERSION( 3, 1, 0 ) || defined( USE_OSX_MAGNIFY_EVENT )
57  void onMagnify( wxMouseEvent& aEvent );
58 #endif
59  void onButton( wxMouseEvent& aEvent );
60  void onEnter( wxMouseEvent& WXUNUSED( aEvent ) );
61  void onLeave( wxMouseEvent& WXUNUSED( aEvent ) );
62  void onTimer( wxTimerEvent& WXUNUSED( aEvent ) );
63  void onScroll( wxScrollWinEvent& aEvent );
64 
71  void SetGrabMouse( bool aEnabled ) override;
72 
74  VECTOR2D GetMousePosition( bool aWorldCoordinates = true ) const override;
75 
77 
79  VECTOR2D GetCursorPosition( bool aSnappingEnabled ) const override;
80 
82  VECTOR2D GetRawCursorPosition( bool aSnappingEnabled = true ) const override;
83 
84  void SetCursorPosition( const VECTOR2D& aPosition, bool warpView ) override;
85 
87  void WarpCursor( const VECTOR2D& aPosition, bool aWorldCoordinates = false,
88  bool aWarpView = false ) const override;
89 
91  void CenterOnCursor() const override;
92 
94  void UpdateScrollbars();
95 
98  static const wxEventType EVT_REFRESH_MOUSE;
99 
100 private:
102  enum STATE
103  {
104  IDLE = 1,
107  };
108 
117  bool handleAutoPanning( const wxMouseEvent& aEvent );
118 
124  void refreshMouse() const;
125 
128 
130  wxScrolledCanvas* m_parentPanel;
131 
134 
137 
140 
142  wxLongLong m_timeStamp;
143 
145  wxTimer m_panTimer;
146 
149 
152 
155 
158 };
159 } // namespace KIGFX
160 
161 #endif
VECTOR2D m_lookStartPoint
Stores information about the center of viewport when dragging has started.
void SetCursorPosition(const VECTOR2D &aPosition, bool warpView) override
Moves cursor to the requested position expressed in world coordinates.
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.
void refreshMouse() const
Sends an event to refresh mouse position.
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.
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.
VECTOR2D GetCursorPosition() const
Returns the current cursor position 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 onMotion(wxMouseEvent &aEvent)
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)
void WarpCursor(const VECTOR2D &aPosition, bool aWorldCoordinates=false, bool aWarpView=false) const override
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.
wxLongLong m_timeStamp
Used for determining time intervals between scroll & zoom events.
Class VIEW.
Definition: view.h:58
void CenterOnCursor() const override
Function CenterOnCursor() Sets the viewport center to the current cursor position and warps the curso...
void onScroll(wxScrollWinEvent &aEvent)
void onLeave(wxMouseEvent &WXUNUSED(aEvent))
VECTOR2D m_cursorPos
Current cursor position (world coordinates)
wxTimer m_panTimer
Timer repsonsible for handling autopanning.