KiCad PCB EDA Suite
view_controls.cpp
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-2015 CERN
6  * @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
7  * @author Maciej Suminski <maciej.suminski@cern.ch>
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; either version 2
12  * of the License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, you may find one here:
21  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
22  * or you may search the http://www.gnu.org website for the version 2 license,
23  * or you may write to the Free Software Foundation, Inc.,
24  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
25  */
26 
28 #include <tool/actions.h>
29 #include <view/view.h>
30 #include <view/view_controls.h>
31 
32 using namespace KIGFX;
33 
34 void VIEW_CONTROLS::ShowCursor( bool aEnabled )
35 {
36  m_settings.m_showCursor = aEnabled;
37  m_view->GetGAL()->SetCursorEnabled( aEnabled );
38 }
39 
40 
42 {
43  // this only says if the VIEW_CONTROLS say the cursor should be
44  // shown: m_view->GetGAL()->IsCursorEnabled() will say if the GAL is
45  // actually going to do show the cursor or not
46  return m_settings.m_showCursor;
47 }
48 
49 
51 {
52  // Get the default settings from the default constructor
55 }
56 
57 
59 {
60  m_showCursor = false;
61  m_forceCursorPosition = false;
62  m_cursorCaptured = false;
63  m_snappingEnabled = true;
64  m_grabMouse = false;
65  m_autoPanEnabled = false;
67  m_autoPanMargin = 0.02f;
68  m_autoPanSpeed = 0.15f;
69  m_autoPanAcceleration = 5.0f;
70  m_warpCursor = false;
71  m_horizontalPan = false;
72  m_zoomAcceleration = false;
73  m_zoomSpeed = 5;
74  m_zoomSpeedAuto = true;
76  m_scrollModifierPanH = WXK_CONTROL;
77  m_scrollModifierPanV = WXK_SHIFT;
82  m_lastKeyboardCursorPosition = { 0.0, 0.0 };
84 }
85 
86 
87 void VIEW_CONTROLS::ApplySettings( const VC_SETTINGS& aSettings )
88 {
89  ShowCursor( aSettings.m_showCursor );
90  CaptureCursor( aSettings.m_cursorCaptured );
91  SetGrabMouse( aSettings.m_grabMouse );
92  SetAutoPan( aSettings.m_autoPanEnabled );
93  SetAutoPanMargin( aSettings.m_autoPanMargin );
94  SetAutoPanSpeed( aSettings.m_autoPanSpeed );
96 }
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
The Cairo implementation of the graphics abstraction layer.
Definition: color4d.cpp:175
bool m_snappingEnabled
Flag for grabbing the mouse cursor.
Definition: view_controls.h:64
bool m_grabMouse
Flag for turning on autopanning.
Definition: view_controls.h:67
void SetCursorEnabled(bool aCursorEnabled)
Enable/disable cursor.
void ApplySettings(const VC_SETTINGS &aSettings)
Load new settings from program common settings.
VC_SETTINGS m_settings
VECTOR2D m_forcedPosition
Is the forced cursor position enabled.
Definition: view_controls.h:55
GAL * GetGAL() const
Return the #GAL this view is using to draw graphical primitives.
Definition: view.h:189
virtual void SetAutoPanMargin(float aMargin)
Set the margin for autopanning (ie.
static LIB_PART * dummy()
Used when a LIB_PART is not found in library to draw a dummy shape.
VIEW * m_view
< Pointer to controlled VIEW.
virtual void Reset()
Restore the default VIEW_CONTROLS settings.
int m_scrollModifierPanH
What modifier key to enable vertical with the (vertical) scroll wheel.
VECTOR2D m_lastKeyboardCursorPosition
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
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 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.
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_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
bool m_showCursor
Forced cursor position (world coordinates).
Definition: view_controls.h:52
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.
bool m_cursorCaptured
Should the cursor snap to grid or move freely.
Definition: view_controls.h:61