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
35namespace KIGFX
36{
37class 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
110
114
117
120
123};
124
125
131{
132public:
133 VIEW_CONTROLS( VIEW* aView ) :
134 m_view( aView ), m_cursorWarped( false )
135 {
136 }
137
139 {
140 }
141
148 virtual void SetGrabMouse( bool aEnabled )
149 {
150 m_settings.m_grabMouse = aEnabled;
151 }
152
159 virtual void SetAutoPan( bool aEnabled )
160 {
161 m_settings.m_autoPanEnabled = aEnabled;
162 }
163
169 virtual void EnableAutoPan( bool aEnabled )
170 {
172 }
173
179 virtual void SetAutoPanSpeed( float aSpeed )
180 {
181 m_settings.m_autoPanSpeed = aSpeed;
182 }
183
189 virtual void SetAutoPanAcceleration( float aAcceleration )
190 {
191 m_settings.m_autoPanAcceleration = aAcceleration;
192 }
193
199 virtual void SetAutoPanMargin( float aMargin )
200 {
201 m_settings.m_autoPanMargin = aMargin;
202 }
203
204 virtual void PinCursorInsideNonAutoscrollArea( bool aWarpMouseCursor ) = 0;
205
218 virtual VECTOR2D GetMousePosition( bool aWorldCoordinates = true ) const = 0;
219
231 {
233 }
234
241 virtual VECTOR2D GetRawCursorPosition( bool aSnappingEnabled = true ) const = 0;
242
254 virtual VECTOR2D GetCursorPosition( bool aEnableSnapping ) const = 0;
255
264 virtual void ForceCursorPosition( bool aEnabled, const VECTOR2D& aPosition = VECTOR2D( 0, 0 ) )
265 {
267 m_settings.m_forcedPosition = aPosition;
268 }
269
281 virtual void SetCursorPosition( const VECTOR2D& aPosition, bool aWarpView = true,
282 bool aTriggeredByArrows = false, long aArrowCommand = 0 ) = 0;
283
284
293 virtual void SetCrossHairCursorPosition( const VECTOR2D& aPosition, bool aWarpView = true ) = 0;
294
300 virtual void ShowCursor( bool aEnabled );
301
307 bool IsCursorShown() const;
308
314 virtual void CaptureCursor( bool aEnabled )
315 {
316 m_settings.m_cursorCaptured = aEnabled;
317 }
318
332 virtual void WarpMouseCursor( 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 {
351 }
352
357 virtual void CenterOnCursor() = 0;
358
362 virtual void Reset();
363
366 {
367 return m_settings;
368 }
369
371 void ApplySettings( const VC_SETTINGS& aSettings );
372
374 virtual void LoadSettings() {}
375
376protected:
379
382
385};
386} // namespace KIGFX
387
388#endif
An interface for classes handling user events controlling the view behavior such as zooming,...
virtual void CaptureCursor(bool aEnabled)
Force the cursor to stay within the drawing panel area.
virtual void ForceCursorPosition(bool aEnabled, const VECTOR2D &aPosition=VECTOR2D(0, 0))
Place the cursor immediately at a given point.
bool m_cursorWarped
Current VIEW_CONTROLS settings.
virtual void ShowCursor(bool aEnabled)
Enable or disables display of cursor.
virtual void SetAutoPanMargin(float aMargin)
Set the margin for autopanning (ie.
virtual void EnableAutoPan(bool aEnabled)
Turn on/off auto panning (user setting to disable it entirely).
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.
virtual void SetAutoPanAcceleration(float aAcceleration)
Set the speed of autopanning.
bool IsCursorWarpingEnabled() const
virtual void WarpMouseCursor(const VECTOR2D &aPosition, bool aWorldCoordinates=false, bool aWarpView=false)=0
If enabled (.
virtual void SetGrabMouse(bool aEnabled)
Turn on/off mouse grabbing.
virtual void Reset()
Restore the default VIEW_CONTROLS settings.
virtual void SetAutoPanSpeed(float aSpeed)
Set the speed of autopanning.
virtual void CenterOnCursor()=0
Set the viewport center to the current cursor position and warps the cursor to the screen center.
virtual void LoadSettings()
VC_SETTINGS m_settings
virtual void SetCrossHairCursorPosition(const VECTOR2D &aPosition, bool aWarpView=true)=0
Move the graphic crosshair cursor to the requested position expressed in world coordinates.
VECTOR2D GetCursorPosition() const
Return the current cursor position in world coordinates.
virtual VECTOR2D GetMousePosition(bool aWorldCoordinates=true) const =0
Return the current mouse pointer position.
virtual VECTOR2D GetCursorPosition(bool aEnableSnapping) const =0
Return the current cursor position in world coordinates.
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 SetAutoPan(bool aEnabled)
Turn on/off auto panning (this feature is used when there is a tool active (eg.
void ApplySettings(const VC_SETTINGS &aSettings)
Load new settings from program common settings.
VIEW * m_view
< Pointer to controlled VIEW.
virtual void PinCursorInsideNonAutoscrollArea(bool aWarpMouseCursor)=0
void EnableCursorWarping(bool aEnable)
Enable or disable warping the cursor.
const VC_SETTINGS & GetSettings() const
Apply VIEW_CONTROLS settings from an object.
VIEW_CONTROLS(VIEW *aView)
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition: view.h:69
MOUSE_DRAG_ACTION
The Cairo implementation of the graphics abstraction layer.
Definition: color4d.cpp:246
Structure to keep VIEW_CONTROLS settings for easy store/restore operations.
Definition: view_controls.h:42
float m_autoPanMargin
How fast is panning when in auto mode.
Definition: view_controls.h:79
VECTOR2D m_forcedPosition
Is the forced cursor position enabled.
Definition: view_controls.h:55
MOUSE_DRAG_ACTION m_dragLeft
bool m_horizontalPan
Enable the accelerating zoom controller.
Definition: view_controls.h:91
void Reset()
Flag determining the cursor visibility.
bool m_autoPanSettingEnabled
Distance from cursor to VIEW edge when panning is active.
Definition: view_controls.h:76
bool m_focusFollowSchPcb
Flag for turning on autopanning.
Definition: view_controls.h:70
float m_autoPanAcceleration
If the cursor is allowed to be warped.
Definition: view_controls.h:85
MOUSE_DRAG_ACTION m_dragMiddle
bool m_cursorCaptured
Should the cursor snap to grid or move freely.
Definition: view_controls.h:61
int m_zoomSpeed
When true, ignore zoom_speed and pick a platform-specific default.
Definition: view_controls.h:97
int m_scrollModifierZoom
What modifier key to enable horizontal pan with the (vertical) scroll wheel.
int m_scrollModifierPanH
What modifier key to enable vertical with the (vertical) scroll wheel.
VECTOR2D m_lastKeyboardCursorPosition
float m_autoPanSpeed
How fast does panning accelerate when approaching the window boundary.
Definition: view_controls.h:82
bool m_warpCursor
Enable horizontal panning with the horizontal scroll/trackpad input.
Definition: view_controls.h:88
MOUSE_DRAG_ACTION m_dragRight
Is last cursor motion event coming from keyboard arrow cursor motion action.
bool m_grabMouse
Flag for automatic focus switching between Schematic and PCB editors.
Definition: view_controls.h:67
bool m_zoomAcceleration
Zoom speed for the non-accelerating zoom controller.
Definition: view_controls.h:94
bool m_lastKeyboardCursorPositionValid
ACTIONS::CURSOR_UP, ACTIONS::CURSOR_DOWN, etc.
VC_SETTINGS()
Restore the default settings.
Definition: view_controls.h:43
bool m_zoomSpeedAuto
What modifier key to enable zoom with the (vertical) scroll wheel.
bool m_autoPanEnabled
Flag for turning on autopanning.
Definition: view_controls.h:73
bool m_snappingEnabled
Flag for grabbing the mouse cursor.
Definition: view_controls.h:64
bool m_showCursor
Forced cursor position (world coordinates).
Definition: view_controls.h:52
long m_lastKeyboardCursorCommand
Position of the above event.
bool m_forceCursorPosition
Should the cursor be locked within the parent window area.
Definition: view_controls.h:58
VECTOR2< double > VECTOR2D
Definition: vector2d.h:589