KiCad PCB EDA Suite
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) 2013-2021 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  */
28 
29 #ifndef __VIEW_CONTROLS_H
30 #define __VIEW_CONTROLS_H
31 
32 #include <math/box2.h>
34 
35 namespace KIGFX
36 {
37 class VIEW;
38 
39 
42 {
44  {
45  Reset();
46  }
47 
49  void Reset();
50 
53 
56 
59 
62 
65 
68 
71 
74 
77 
80 
83 
86 
89 
92 
95 
98 
101 
104 
107 
111 
114 
117 
120 };
121 
122 
128 {
129 public:
130  VIEW_CONTROLS( VIEW* aView ) :
131  m_view( aView ), m_cursorWarped( false )
132  {
133  }
134 
135  virtual ~VIEW_CONTROLS()
136  {
137  }
138 
145  virtual void SetGrabMouse( bool aEnabled )
146  {
147  m_settings.m_grabMouse = aEnabled;
148  }
149 
156  virtual void SetAutoPan( bool aEnabled )
157  {
158  m_settings.m_autoPanEnabled = aEnabled;
159  }
160 
166  virtual void EnableAutoPan( bool aEnabled )
167  {
169  }
170 
176  virtual void SetAutoPanSpeed( float aSpeed )
177  {
178  m_settings.m_autoPanSpeed = aSpeed;
179  }
180 
186  virtual void SetAutoPanAcceleration( float aAcceleration )
187  {
188  m_settings.m_autoPanAcceleration = aAcceleration;
189  }
190 
196  virtual void SetAutoPanMargin( float aMargin )
197  {
198  m_settings.m_autoPanMargin = aMargin;
199  }
200 
211  virtual VECTOR2D GetMousePosition( bool aWorldCoordinates = true ) const = 0;
212 
222  {
224  }
225 
232  virtual VECTOR2D GetRawCursorPosition( bool aSnappingEnabled = true ) const = 0;
233 
243  virtual VECTOR2D GetCursorPosition( bool aEnableSnapping ) const = 0;
244 
251  virtual void ForceCursorPosition( bool aEnabled, const VECTOR2D& aPosition = VECTOR2D( 0, 0 ) )
252  {
254  m_settings.m_forcedPosition = aPosition;
255  }
256 
266  virtual void SetCursorPosition( const VECTOR2D& aPosition, bool aWarpView = true,
267  bool aTriggeredByArrows = false, long aArrowCommand = 0 ) = 0;
268 
269 
276  virtual void SetCrossHairCursorPosition( const VECTOR2D& aPosition, bool aWarpView = true ) = 0;
277 
282  bool ForcedCursorPosition() const
283  {
285  }
286 
292  virtual void ShowCursor( bool aEnabled );
293 
299  bool IsCursorShown() const;
300 
306  virtual void CaptureCursor( bool aEnabled )
307  {
308  m_settings.m_cursorCaptured = aEnabled;
309  }
310 
316  inline bool IsCursorPositionForced() const
317  {
319  }
320 
332  virtual void WarpCursor( const VECTOR2D& aPosition, bool aWorldCoordinates = false,
333  bool aWarpView = false ) = 0;
334 
340  void EnableCursorWarping( bool aEnable )
341  {
342  m_settings.m_warpCursor = aEnable;
343  }
344 
349  {
350  return m_settings.m_warpCursor;
351  }
352 
357  virtual void CenterOnCursor() const = 0;
358 
362  virtual void Reset();
363 
365  const VC_SETTINGS& GetSettings() const
366  {
367  return m_settings;
368  }
369 
371  void ApplySettings( const VC_SETTINGS& aSettings );
372 
374  virtual void LoadSettings() {}
375 
376 protected:
379 
382 
385 };
386 } // namespace KIGFX
387 
388 #endif
virtual void ShowCursor(bool aEnabled)
Enable or disables display of cursor.
void Reset()
Flag determining the cursor visibility.
virtual void SetAutoPanSpeed(float aSpeed)
Set the speed of autopanning.
MOUSE_DRAG_ACTION m_dragRight
Is last cursor motion event coming from keyboard arrow cursor motion action.
float m_autoPanSpeed
How fast does panning accelerate when approaching the window boundary.
Definition: view_controls.h:79
virtual VECTOR2D GetMousePosition(bool aWorldCoordinates=true) const =0
Return the current mouse pointer position.
The Cairo implementation of the graphics abstraction layer.
Definition: color4d.cpp:236
bool m_snappingEnabled
Flag for grabbing the mouse cursor.
Definition: view_controls.h:64
VC_SETTINGS()
Restore the default settings.
Definition: view_controls.h:43
bool m_grabMouse
Flag for turning on autopanning.
Definition: view_controls.h:67
void ApplySettings(const VC_SETTINGS &aSettings)
Load new settings from program common settings.
VIEW_CONTROLS(VIEW *aView)
VC_SETTINGS m_settings
VECTOR2D m_forcedPosition
Is the forced cursor position enabled.
Definition: view_controls.h:55
virtual void SetCursorPosition(const VECTOR2D &aPosition, bool aWarpView=true, bool aTriggeredByArrows=false, long aArrowCommand=0)=0
Move cursor to the requested position expressed in world coordinates.
virtual void SetAutoPanMargin(float aMargin)
Set the margin for autopanning (ie.
VIEW * m_view
< Pointer to controlled VIEW.
virtual void Reset()
Restore the default VIEW_CONTROLS settings.
virtual void LoadSettings()
const VC_SETTINGS & GetSettings() const
Apply VIEW_CONTROLS settings from an object.
virtual void CenterOnCursor() const =0
Set the viewport center to the current cursor position and warps the cursor to the screen center.
bool IsCursorPositionForced() const
Return true if the cursor position is set by one of the tools.
void EnableCursorWarping(bool aEnable)
Enable or disable warping the cursor.
int m_scrollModifierPanH
What modifier key to enable vertical with the (vertical) scroll wheel.
VECTOR2D m_lastKeyboardCursorPosition
virtual void WarpCursor(const VECTOR2D &aPosition, bool aWorldCoordinates=false, bool aWarpView=false)=0
If enabled (.
MOUSE_DRAG_ACTION
bool m_autoPanSettingEnabled
Distance from cursor to VIEW edge when panning is active.
Definition: view_controls.h:73
MOUSE_DRAG_ACTION m_dragLeft
bool m_forceCursorPosition
Should the cursor be locked within the parent window area.
Definition: view_controls.h:58
VECTOR2< double > VECTOR2D
Definition: vector2d.h:622
MOUSE_DRAG_ACTION m_dragMiddle
bool m_zoomSpeedAuto
What modifier key to enable zoom with the (vertical) scroll wheel.
Definition: view_controls.h:97
virtual void CaptureCursor(bool aEnabled)
Force the cursor to stay within the drawing panel area.
int m_scrollModifierZoom
What modifier key to enable horizontal pan with the (vertical) scroll wheel.
float m_autoPanAcceleration
If the cursor is allowed to be warped.
Definition: view_controls.h:82
int m_zoomSpeed
When true, ignore zoom_speed and pick a platform-specific default.
Definition: view_controls.h:94
Structure to keep VIEW_CONTROLS settings for easy store/restore operations.
Definition: view_controls.h:41
bool IsCursorWarpingEnabled() const
An interface for classes handling user events controlling the view behavior such as zooming,...
bool m_warpCursor
Enable horizontal panning with the horizontal scroll/trackpad input.
Definition: view_controls.h:85
virtual void ForceCursorPosition(bool aEnabled, const VECTOR2D &aPosition=VECTOR2D(0, 0))
Place the cursor immediately at a given point.
virtual void EnableAutoPan(bool aEnabled)
Turn on/off auto panning (user setting to disable it entirely).
virtual void SetCrossHairCursorPosition(const VECTOR2D &aPosition, bool aWarpView=true)=0
Move the graphic crosshair cursor to the requested position expressed in world coordinates.
float m_autoPanMargin
How fast is panning when in auto mode.
Definition: view_controls.h:76
bool m_horizontalPan
Enable the accelerating zoom controller.
Definition: view_controls.h:88
bool m_cursorWarped
Current VIEW_CONTROLS settings.
bool ForcedCursorPosition() const
Return true if the current cursor position is forced to a specific location, ignoring the mouse curso...
bool m_autoPanEnabled
Flag for turning on autopanning.
Definition: view_controls.h:70
virtual void SetAutoPan(bool aEnabled)
Turn on/off auto panning (this feature is used when there is a tool active (eg.
bool m_zoomAcceleration
Zoom speed for the non-accelerating zoom controller.
Definition: view_controls.h:91
virtual void SetAutoPanAcceleration(float aAcceleration)
Set the speed of autopanning.
bool m_showCursor
Forced cursor position (world coordinates).
Definition: view_controls.h:52
virtual VECTOR2D GetRawCursorPosition(bool aSnappingEnabled=true) const =0
Return the current cursor position in world coordinates ignoring the cursorUp position force mode.
bool IsCursorShown() const
Return true when cursor is visible.
long m_lastKeyboardCursorCommand
Position of the above event.
bool m_lastKeyboardCursorPositionValid
ACTIONS::CURSOR_UP, ACTIONS::CURSOR_DOWN, etc.
virtual void SetGrabMouse(bool aEnabled)
Turn on/off mouse grabbing.
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition: view.h:68
bool m_cursorCaptured
Should the cursor snap to grid or move freely.
Definition: view_controls.h:61
VECTOR2D GetCursorPosition() const
Return the current cursor position in world coordinates.