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-2016 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 
45 {
47  {
48  Reset();
49  }
50 
52  void Reset();
53 
56 
59 
62 
65 
68 
71 
74 
77 
80 
83 
86 
89 
92 
95 
98 
101 };
102 
103 
110 {
111 public:
112  VIEW_CONTROLS( VIEW* aView ) : m_view( aView )
113  {
114  }
115 
116  virtual ~VIEW_CONTROLS()
117  {
118  }
119 
126  virtual void SetSnapping( bool aEnabled )
127  {
128  m_settings.m_snappingEnabled = aEnabled;
129  }
130 
136  virtual void SetGrabMouse( bool aEnabled )
137  {
138  m_settings.m_grabMouse = aEnabled;
139  }
140 
147  virtual void SetAutoPan( bool aEnabled )
148  {
149  m_settings.m_autoPanEnabled = aEnabled;
150  }
151 
157  virtual void EnableAutoPan( bool aEnabled )
158  {
159  m_settings.m_autoPanSettingEnabled = aEnabled;
160  }
161 
167  virtual void SetAutoPanSpeed( float aSpeed )
168  {
169  m_settings.m_autoPanSpeed = aSpeed;
170  }
171 
177  virtual void SetAutoPanMargin( float aMargin )
178  {
179  m_settings.m_autoPanMargin = aMargin;
180  }
181 
191  virtual VECTOR2D GetMousePosition( bool aWorldCoordinates = true ) const = 0;
192 
201  {
202  return GetCursorPosition( m_settings.m_snappingEnabled );
203  }
204 
211  virtual VECTOR2D GetRawCursorPosition( bool aSnappingEnabled = true ) const = 0;
212 
221  virtual VECTOR2D GetCursorPosition( bool aEnableSnapping ) const = 0;
222 
229  virtual void ForceCursorPosition( bool aEnabled, const VECTOR2D& aPosition = VECTOR2D( 0, 0 ) )
230  {
231  m_settings.m_forceCursorPosition = aEnabled;
232  m_settings.m_forcedPosition = aPosition;
233  }
234 
242  virtual void SetCursorPosition( const VECTOR2D& aPosition, bool aWarpView = true, bool aTriggeredByArrows = false ) = 0;
243 
244 
250  virtual void SetCrossHairCursorPosition( const VECTOR2D& aPosition, bool aWarpView = true ) = 0;
251 
252 
258  bool ForcedCursorPosition() const
259  {
260  return m_settings.m_forceCursorPosition;
261  }
262 
268  virtual void ShowCursor( bool aEnabled );
269 
275  bool IsCursorShown() const;
276 
282  virtual void CaptureCursor( bool aEnabled )
283  {
284  m_settings.m_cursorCaptured = aEnabled;
285  }
286 
292  inline bool IsCursorPositionForced() const
293  {
294  return m_settings.m_forceCursorPosition;
295  }
296 
307  virtual void WarpCursor( const VECTOR2D& aPosition, bool aWorldCoordinates = false,
308  bool aWarpView = false ) = 0;
309 
315  void EnableCursorWarping( bool aEnable )
316  {
317  m_settings.m_warpCursor = aEnable;
318  }
319 
325  {
326  return m_settings.m_warpCursor;
327  }
328 
334  virtual void EnableMousewheelPan( bool aEnable )
335  {
336  m_settings.m_enableMousewheelPan = aEnable;
337  }
338 
343  virtual bool IsMousewheelPanEnabled() const
344  {
345  return m_settings.m_enableMousewheelPan;
346  }
347 
353  virtual void CenterOnCursor() const = 0;
354 
355  void SetAdditionalPanButtons( bool aLeft = false, bool aRight = false )
356  {
357  m_settings.m_panWithLeftButton = aLeft;
358  m_settings.m_panWithRightButton = aRight;
359  }
360 
365  virtual void Reset();
366 
368  const VC_SETTINGS& GetSettings() const
369  {
370  return m_settings;
371  }
372 
374  void ApplySettings( const VC_SETTINGS& aSettings );
375 
376 protected:
379 
382 
385 };
386 } // namespace KIGFX
387 
388 #endif
bool m_enableMousewheelPan
Mousewheel (2-finger touchpad) panning
Definition: view_controls.h:88
void Reset()
Restores the default settings
virtual void SetAutoPanSpeed(float aSpeed)
Function SetAutoPanSpeed() Sets speed of autopanning.
float m_autoPanSpeed
How fast is panning when in auto mode
Definition: view_controls.h:82
Class CAIRO_GAL is the cairo implementation of the graphics abstraction layer.
Definition: class_module.h:57
bool m_snappingEnabled
Should the cursor snap to grid or move freely
Definition: view_controls.h:67
bool IsCursorPositionForced() const
Function IsCursorPositionForced() Returns true if the cursor position is set by one of the tools...
bool m_grabMouse
Flag for grabbing the mouse cursor
Definition: view_controls.h:70
VIEW_CONTROLS(VIEW *aView)
VC_SETTINGS m_settings
Current VIEW_CONTROLS settings
virtual void EnableMousewheelPan(bool aEnable)
Function EnableMousewheelPan() Enables or disables mousewheel panning.
VECTOR2D m_forcedPosition
Forced cursor position (world coordinates)
Definition: view_controls.h:58
virtual void SetSnapping(bool aEnabled)
Function SetSnapping() Enables/disables snapping cursor to grid.
bool m_panWithRightButton
Allow panning with the right button in addition to middle
Definition: view_controls.h:91
virtual void SetAutoPanMargin(float aMargin)
Function SetAutoPanMArgin() Sets margin for autopanning (ie.
VIEW * m_view
Pointer to controlled VIEW.
void EnableCursorWarping(bool aEnable)
Function EnableCursorWarping() Enables or disables warping the cursor.
VECTOR2D m_lastKeyboardCursorPosition
Position of the above event
bool m_autoPanSettingEnabled
Flag for turning on autopanning
Definition: view_controls.h:76
bool m_forceCursorPosition
Is the forced cursor position enabled
Definition: view_controls.h:61
VECTOR2< double > VECTOR2D
Definition: vector2d.h:586
virtual void CaptureCursor(bool aEnabled)
Function CaptureCursor() Forces the cursor to stay within the drawing panel area. ...
virtual bool IsMousewheelPanEnabled() const
Function IsMousewheelPanEnabled()
VECTOR2D GetCursorPosition() const
Returns the current cursor position in world coordinates.
Structure to keep VIEW_CONTROLS settings for easy store/restore operations
Definition: view_controls.h:44
Class VIEW_CONTROLS is an interface for classes handling user events controlling the view behaviour (...
bool m_warpCursor
If the cursor is allowed to be warped
Definition: view_controls.h:85
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).
float m_autoPanMargin
Distance from cursor to VIEW edge when panning is active
Definition: view_controls.h:79
bool m_cursorWarped
Application warped the cursor, not the user (keyboard)
bool m_autoPanEnabled
Flag for turning on autopanning
Definition: view_controls.h:73
virtual void SetAutoPan(bool aEnabled)
Function SetAutoPan Turns on/off auto panning (this feature is used when there is a tool active (eg...
const VC_SETTINGS & GetSettings() const
Returns the current VIEW_CONTROLS settings
void SetAdditionalPanButtons(bool aLeft=false, bool aRight=false)
bool m_showCursor
Flag determining the cursor visibility
Definition: view_controls.h:55
bool m_lastKeyboardCursorPositionValid
Is last cursor motion event coming from keyboard arrow cursor motion action
Definition: view_controls.h:97
bool IsCursorWarpingEnabled() const
Function IsCursorWarpingEnabled()
virtual void SetGrabMouse(bool aEnabled)
Function SetGrabMouse Turns on/off mouse grabbing.
bool ForcedCursorPosition() const
Function ForcedCursorPosition() Returns true if the current cursor position is forced to a specific l...
Class VIEW.
Definition: view.h:61
bool m_cursorCaptured
Should the cursor be locked within the parent window area
Definition: view_controls.h:64
bool m_panWithLeftButton
Allow panning with the left button in addition to middle
Definition: view_controls.h:94