KiCad PCB EDA Suite
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>
5  * Copyright (C) 2013-2015 CERN
6  * @author Tomasz Wlostowski <>
7  * @author Maciej Suminski <>
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
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  *
22  * or you may search the 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  */
28 #include <tool/actions.h>
29 #include <view/view.h>
30 #include <view/view_controls.h>
32 using namespace KIGFX;
34 void VIEW_CONTROLS::ShowCursor( bool aEnabled )
35 {
36  m_settings.m_showCursor = aEnabled;
37  m_view->GetGAL()->SetCursorEnabled( aEnabled );
38 }
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 }
51 {
52  // Get the default settings from the default constructor
55 }
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 = 1.5f;
70  m_warpCursor = false;
71  m_enableMousewheelPan = false;
72  m_panWithRightButton = false;
73  m_panWithLeftButton = false;
75  m_lastKeyboardCursorPosition = { 0.0, 0.0 };
77 }
80 void VIEW_CONTROLS::ApplySettings( const VC_SETTINGS& aSettings )
81 {
82  ShowCursor( aSettings.m_showCursor );
83  CaptureCursor( aSettings.m_cursorCaptured );
84  SetSnapping( aSettings.m_snappingEnabled );
85  SetGrabMouse( aSettings.m_grabMouse );
86  SetAutoPan( aSettings.m_autoPanEnabled );
87  SetAutoPanMargin( aSettings.m_autoPanMargin );
88  SetAutoPanSpeed( aSettings.m_autoPanSpeed );
91 }
bool m_enableMousewheelPan
Mousewheel (2-finger touchpad) panning
Definition: view_controls.h:91
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.
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: color4d.cpp:131
bool m_snappingEnabled
Should the cursor snap to grid or move freely
Definition: view_controls.h:67
bool m_grabMouse
Flag for grabbing the mouse cursor
Definition: view_controls.h:70
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:58
virtual void SetSnapping(bool aEnabled)
Function SetSnapping() Enables/disables snapping cursor to grid.
GAL * GetGAL() const
Function GetGAL() Returns the GAL this view is using to draw graphical primitives.
Definition: view.h:180
bool m_panWithRightButton
Allow panning with the right button in addition to middle
Definition: view_controls.h:94
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.
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
virtual void CaptureCursor(bool aEnabled)
Function CaptureCursor() Forces the cursor to stay within the drawing panel area.
float m_autoPanAcceleration
How fast does panning accelerate when approaching the window boundary
Definition: view_controls.h:85
Structure to keep VIEW_CONTROLS settings for easy store/restore operations
Definition: view_controls.h:44
bool m_warpCursor
If the cursor is allowed to be warped
Definition: view_controls.h:88
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:79
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.
virtual void SetAutoPanAcceleration(float aAcceleration)
Function SetAutoPanSpeed() Sets speed of autopanning.
bool m_showCursor
Flag determining the cursor visibility
Definition: view_controls.h:55
bool IsCursorShown() const
Function IsCursorShown() Returns true when cursor is visible.
long m_lastKeyboardCursorCommand
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:64
bool m_panWithLeftButton
Allow panning with the left button in addition to middle
Definition: view_controls.h:97