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 <[email protected]>
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 
213  virtual VECTOR2D GetMousePosition( bool aWorldCoordinates = true ) const = 0;
214 
226  {
228  }
229 
236  virtual VECTOR2D GetRawCursorPosition( bool aSnappingEnabled = true ) const = 0;
237 
249  virtual VECTOR2D GetCursorPosition( bool aEnableSnapping ) const = 0;
250 
259  virtual void ForceCursorPosition( bool aEnabled, const VECTOR2D& aPosition = VECTOR2D( 0, 0 ) )
260  {
262  m_settings.m_forcedPosition = aPosition;
263  }
264 
276  virtual void SetCursorPosition( const VECTOR2D& aPosition, bool aWarpView = true,
277  bool aTriggeredByArrows = false, long aArrowCommand = 0 ) = 0;
278 
279 
288  virtual void SetCrossHairCursorPosition( const VECTOR2D& aPosition, bool aWarpView = true ) = 0;
289 
295  virtual void ShowCursor( bool aEnabled );
296 
302  bool IsCursorShown() const;
303 
309  virtual void CaptureCursor( bool aEnabled )
310  {
311  m_settings.m_cursorCaptured = aEnabled;
312  }
313 
327  virtual void WarpCursor( const VECTOR2D& aPosition, bool aWorldCoordinates = false,
328  bool aWarpView = false ) = 0;
329 
335  void EnableCursorWarping( bool aEnable )
336  {
337  m_settings.m_warpCursor = aEnable;
338  }
339 
344  {
345  return m_settings.m_warpCursor;
346  }
347 
352  virtual void CenterOnCursor() const = 0;
353 
357  virtual void Reset();
358 
360  const VC_SETTINGS& GetSettings() const
361  {
362  return m_settings;
363  }
364 
366  void ApplySettings( const VC_SETTINGS& aSettings );
367 
369  virtual void LoadSettings() {}
370 
371 protected:
374 
377 
380 };
381 } // namespace KIGFX
382 
383 #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:243
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.
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:621
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 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.