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-2019 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 
34 #ifndef __VIEW_CONTROLS_H
35 #define __VIEW_CONTROLS_H
36 
37 #include <math/box2.h>
38 
39 namespace KIGFX
40 {
41 class VIEW;
42 
43 
46 {
47  SELECT,
48  ZOOM,
49  PAN,
50  NONE
51 };
52 
53 
56 {
58  {
59  Reset();
60  }
61 
63  void Reset();
64 
67 
70 
73 
76 
79 
82 
85 
88 
91 
94 
97 
100 
103 
106 
109 
112 
115 
118 
121 
124 
127 
130 
133 
136 };
137 
138 
145 {
146 public:
147  VIEW_CONTROLS( VIEW* aView ) :
148  m_view( aView ), m_cursorWarped( false )
149  {
150  }
151 
152  virtual ~VIEW_CONTROLS()
153  {
154  }
155 
161  virtual void SetGrabMouse( bool aEnabled )
162  {
163  m_settings.m_grabMouse = aEnabled;
164  }
165 
172  virtual void SetAutoPan( bool aEnabled )
173  {
174  m_settings.m_autoPanEnabled = aEnabled;
175  }
176 
182  virtual void EnableAutoPan( bool aEnabled )
183  {
185  }
186 
192  virtual void SetAutoPanSpeed( float aSpeed )
193  {
194  m_settings.m_autoPanSpeed = aSpeed;
195  }
196 
202  virtual void SetAutoPanAcceleration( float aAcceleration )
203  {
204  m_settings.m_autoPanAcceleration = aAcceleration;
205  }
206 
212  virtual void SetAutoPanMargin( float aMargin )
213  {
214  m_settings.m_autoPanMargin = aMargin;
215  }
216 
226  virtual VECTOR2D GetMousePosition( bool aWorldCoordinates = true ) const = 0;
227 
236  {
238  }
239 
246  virtual VECTOR2D GetRawCursorPosition( bool aSnappingEnabled = true ) const = 0;
247 
256  virtual VECTOR2D GetCursorPosition( bool aEnableSnapping ) const = 0;
257 
264  virtual void ForceCursorPosition( bool aEnabled, const VECTOR2D& aPosition = VECTOR2D( 0, 0 ) )
265  {
267  m_settings.m_forcedPosition = aPosition;
268  }
269 
277  virtual void SetCursorPosition( const VECTOR2D& aPosition, bool aWarpView = true,
278  bool aTriggeredByArrows = false, long aArrowCommand = 0 ) = 0;
279 
280 
286  virtual void SetCrossHairCursorPosition( const VECTOR2D& aPosition, bool aWarpView = true ) = 0;
287 
288 
294  bool ForcedCursorPosition() const
295  {
297  }
298 
304  virtual void ShowCursor( bool aEnabled );
305 
311  bool IsCursorShown() const;
312 
318  virtual void CaptureCursor( bool aEnabled )
319  {
320  m_settings.m_cursorCaptured = aEnabled;
321  }
322 
328  inline bool IsCursorPositionForced() const
329  {
331  }
332 
343  virtual void WarpCursor( const VECTOR2D& aPosition, bool aWorldCoordinates = false,
344  bool aWarpView = false ) = 0;
345 
351  void EnableCursorWarping( bool aEnable )
352  {
353  m_settings.m_warpCursor = aEnable;
354  }
355 
361  {
362  return m_settings.m_warpCursor;
363  }
364 
370  virtual void CenterOnCursor() const = 0;
371 
376  virtual void Reset();
377 
379  const VC_SETTINGS& GetSettings() const
380  {
381  return m_settings;
382  }
383 
385  void ApplySettings( const VC_SETTINGS& aSettings );
386 
388  virtual void LoadSettings() {}
389 
390 protected:
393 
396 
399 };
400 } // namespace KIGFX
401 
402 #endif
virtual void ShowCursor(bool aEnabled)
Function ShowCursor() Enables or disables display of cursor.
void Reset()
Restores the default settings
virtual void SetAutoPanSpeed(float aSpeed)
Function SetAutoPanSpeed() Sets speed of autopanning.
MOUSE_DRAG_ACTION m_dragRight
What drag action to perform when the right button is pressed
MOUSE_DRAG_ACTION
Action to perform when the mouse is dragged
Definition: view_controls.h:45
float m_autoPanSpeed
How fast is panning when in auto mode
Definition: view_controls.h:93
virtual VECTOR2D GetMousePosition(bool aWorldCoordinates=true) const =0
Function GetMousePosition() Returns the current mouse pointer position.
Class CAIRO_GAL is the cairo implementation of the graphics abstraction layer.
Definition: color4d.cpp:175
bool m_snappingEnabled
Should the cursor snap to grid or move freely
Definition: view_controls.h:78
bool m_grabMouse
Flag for grabbing the mouse cursor
Definition: view_controls.h:81
void ApplySettings(const VC_SETTINGS &aSettings)
Applies VIEW_CONTROLS settings from an object
VIEW_CONTROLS(VIEW *aView)
VC_SETTINGS m_settings
Current VIEW_CONTROLS settings
VECTOR2D m_forcedPosition
Forced cursor position (world coordinates)
Definition: view_controls.h:69
virtual void SetCursorPosition(const VECTOR2D &aPosition, bool aWarpView=true, bool aTriggeredByArrows=false, long aArrowCommand=0)=0
Moves cursor to the requested position expressed in world coordinates.
virtual void SetAutoPanMargin(float aMargin)
Function SetAutoPanMArgin() Sets margin for autopanning (ie.
VIEW * m_view
Pointer to controlled VIEW.
virtual void Reset()
Function Reset() Restores the default VIEW_CONTROLS settings.
virtual void LoadSettings()
Load new settings from program common settings
const VC_SETTINGS & GetSettings() const
Returns the current VIEW_CONTROLS settings
virtual void CenterOnCursor() const =0
Function CenterOnCursor() Sets the viewport center to the current cursor position and warps the curso...
bool IsCursorPositionForced() const
Function IsCursorPositionForced() Returns true if the cursor position is set by one of the tools.
void EnableCursorWarping(bool aEnable)
Function EnableCursorWarping() Enables or disables warping the cursor.
int m_scrollModifierPanH
What modifier key to enable horizontal pan with the (vertical) scroll wheel
VECTOR2D m_lastKeyboardCursorPosition
Position of the above event
virtual void WarpCursor(const VECTOR2D &aPosition, bool aWorldCoordinates=false, bool aWarpView=false)=0
Function WarpCursor() If enabled (.
bool m_autoPanSettingEnabled
Flag for turning on autopanning
Definition: view_controls.h:87
bool m_forceCursorPosition
Is the forced cursor position enabled
Definition: view_controls.h:72
VECTOR2< double > VECTOR2D
Definition: vector2d.h:593
MOUSE_DRAG_ACTION m_dragMiddle
What drag action to perform when the middle button is pressed
bool m_zoomSpeedAuto
When true, ignore zoom_speed and pick a platform-specific default
virtual void CaptureCursor(bool aEnabled)
Function CaptureCursor() Forces the cursor to stay within the drawing panel area.
int m_scrollModifierZoom
What modifier key to enable zoom with the (vertical) scroll wheel
float m_autoPanAcceleration
How fast does panning accelerate when approaching the window boundary
Definition: view_controls.h:96
int m_zoomSpeed
Zoom speed for the non-accelerating zoom controller
Structure to keep VIEW_CONTROLS settings for easy store/restore operations
Definition: view_controls.h:55
bool IsCursorWarpingEnabled() const
Function IsCursorWarpingEnabled()
VIEW_CONTROLS is an interface for classes handling user events controlling the view behaviour (such a...
bool m_warpCursor
If the cursor is allowed to be warped
Definition: view_controls.h:99
virtual void ForceCursorPosition(bool aEnabled, const VECTOR2D &aPosition=VECTOR2D(0, 0))
Function ForceCursorPosition() Places the cursor immediately at a given point.
virtual void EnableAutoPan(bool aEnabled)
Function EnableAutoPan Turns on/off auto panning (user setting to disable it entirely).
virtual void SetCrossHairCursorPosition(const VECTOR2D &aPosition, bool aWarpView=true)=0
Moves the graphic crosshair cursor to the requested position expressed in world coordinates.
float m_autoPanMargin
Distance from cursor to VIEW edge when panning is active
Definition: view_controls.h:90
bool m_horizontalPan
Enable horizontal panning with the horizontal scroll/trackpad input
bool m_cursorWarped
Application warped the cursor, not the user (keyboard)
bool ForcedCursorPosition() const
Function ForcedCursorPosition() Returns true if the current cursor position is forced to a specific l...
bool m_autoPanEnabled
Flag for turning on autopanning
Definition: view_controls.h:84
virtual void SetAutoPan(bool aEnabled)
Function SetAutoPan Turns on/off auto panning (this feature is used when there is a tool active (eg.
bool m_zoomAcceleration
Enable the accelerating zoom controller
int m_scrollModifierPanV
What modifier key to enable vertical with the (vertical) scroll wheel
virtual void SetAutoPanAcceleration(float aAcceleration)
Function SetAutoPanSpeed() Sets speed of autopanning.
bool m_showCursor
Flag determining the cursor visibility
Definition: view_controls.h:66
virtual VECTOR2D GetRawCursorPosition(bool aSnappingEnabled=true) const =0
Returns the current cursor position in world coordinates - ingoring the cursorUp position force mode.
bool IsCursorShown() const
Function IsCursorShown() Returns true when cursor is visible.
long m_lastKeyboardCursorCommand
ACTIONS::CURSOR_UP, ACTIONS::CURSOR_DOWN, etc.
bool m_lastKeyboardCursorPositionValid
Is last cursor motion event coming from keyboard arrow cursor motion action
virtual void SetGrabMouse(bool aEnabled)
Function SetGrabMouse Turns on/off mouse grabbing.
VIEW.
Definition: view.h:63
bool m_cursorCaptured
Should the cursor be locked within the parent window area
Definition: view_controls.h:75
VECTOR2D GetCursorPosition() const
Returns the current cursor position in world coordinates.