KiCad PCB EDA Suite
Loading...
Searching...
No Matches
tool_dispatcher.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) 2013 CERN
5 * Copyright (C) 2020 KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * @author Tomasz Wlostowski <[email protected]>
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
27#ifndef __TOOL_DISPATCHER_H
28#define __TOOL_DISPATCHER_H
29
30#include <vector>
31#include <wx/event.h>
32#include <tool/tool_event.h> // Needed for MD_ constants
33
34class TOOL_MANAGER;
35class PCB_BASE_FRAME;
36class ACTIONS;
37
38namespace KIGFX
39{
40class VIEW;
41}
42
51class TOOL_DISPATCHER : public wxEvtHandler
52{
53public:
57 TOOL_DISPATCHER( TOOL_MANAGER* aToolMgr );
58
59 virtual ~TOOL_DISPATCHER();
60
64 virtual void ResetState();
65
72 virtual void DispatchWxEvent( wxEvent& aEvent );
73
77 std::optional<TOOL_EVENT> GetToolEvent( wxKeyEvent* aKeyEvent, bool* aSpecialKeyFlag );
78
79private:
82 static const int DragTimeThreshold = 300;
83
87 static const int DragDistanceThreshold = 8;
88
93
95 bool handleMouseButton( wxEvent& aEvent, int aIndex, bool aMotion );
96
98 static int decodeModifiers( const wxKeyboardState* aState )
99 {
100 int mods = 0;
101
102 if( aState->ControlDown() )
103 mods |= MD_CTRL;
104
105 if( aState->AltDown() )
106 mods |= MD_ALT;
107
108 if( aState->ShiftDown() )
109 mods |= MD_SHIFT;
110
111 return mods;
112 }
113
115 struct BUTTON_STATE;
116
119
122
124 std::vector<BUTTON_STATE*> m_buttons;
125
128
131};
132
133#endif
Gather all the actions that are shared by tools.
Definition: actions.h:41
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition: view.h:68
Base PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
static const int DragDistanceThreshold
Mininum distance before drag is activated in the X axis.
static const int DragTimeThreshold
< The time threshold for a mouse button press that distinguishes between a single mouse click and a b...
virtual void ResetState()
Bring the dispatcher to its initial state.
virtual void DispatchWxEvent(wxEvent &aEvent)
Process wxEvents (mostly UI events), translate them to TOOL_EVENTs, and make tools handle those.
KIGFX::VIEW * getView()
Instance of tool manager that cooperates with the dispatcher.
int m_sysDragMinX
Maximum distance before drag is activated in the Y axis.
bool handleMouseButton(wxEvent &aEvent, int aIndex, bool aMotion)
Saves the state of key modifiers (Alt, Ctrl and so on).
int m_sysDragMinY
Handles mouse related events (click, motion, dragging).
VECTOR2D m_lastMousePosScreen
State of mouse buttons.
static int decodeModifiers(const wxKeyboardState *aState)
Stores all the information regarding a mouse button state.
TOOL_MANAGER * m_toolMgr
std::vector< BUTTON_STATE * > m_buttons
Returns the instance of VIEW, used by the application.
VECTOR2D m_lastMousePos
The last mouse cursor position (in world coordinates).
std::optional< TOOL_EVENT > GetToolEvent(wxKeyEvent *aKeyEvent, bool *aSpecialKeyFlag)
Map a wxWidgets key event to a TOOL_EVENT.
virtual ~TOOL_DISPATCHER()
Master controller class:
Definition: tool_manager.h:57
The Cairo implementation of the graphics abstraction layer.
Definition: color4d.cpp:247
@ MD_ALT
Definition: tool_event.h:144
@ MD_CTRL
Definition: tool_event.h:143
@ MD_SHIFT
Definition: tool_event.h:142