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;
81  m_lastKeyboardCursorPosition = { 0.0, 0.0 };
83 }
84 
85 
86 void VIEW_CONTROLS::ApplySettings( const VC_SETTINGS& aSettings )
87 {
88  ShowCursor( aSettings.m_showCursor );
89  CaptureCursor( aSettings.m_cursorCaptured );
90  SetGrabMouse( aSettings.m_grabMouse );
91  SetAutoPan( aSettings.m_autoPanEnabled );
92  SetAutoPanMargin( aSettings.m_autoPanMargin );
93  SetAutoPanSpeed( aSettings.m_autoPanSpeed );
95 }
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
float m_autoPanSpeed
How fast is panning when in auto mode
Definition: view_controls.h:93
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
VIEW_CONTROLS class definition.
void SetCursorEnabled(bool aCursorEnabled)
Enable/disable cursor.
void ApplySettings(const VC_SETTINGS &aSettings)
Applies VIEW_CONTROLS settings from an object
VC_SETTINGS m_settings
Current VIEW_CONTROLS settings
VECTOR2D m_forcedPosition
Forced cursor position (world coordinates)
Definition: view_controls.h:69
GAL * GetGAL() const
Function GetGAL() Returns the GAL this view is using to draw graphical primitives.
Definition: view.h:182
virtual void SetAutoPanMargin(float aMargin)
Function SetAutoPanMArgin() Sets 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()
Function Reset() Restores the default VIEW_CONTROLS settings.
int m_scrollModifierPanH
What modifier key to enable horizontal pan with the (vertical) scroll wheel
VECTOR2D m_lastKeyboardCursorPosition
Position of the above event
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
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 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.
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_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
bool m_showCursor
Flag determining the cursor visibility
Definition: view_controls.h:66
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.
bool m_cursorCaptured
Should the cursor be locked within the parent window area
Definition: view_controls.h:75