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-2024 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;
37class ACTION_MENU;
38
39namespace KIGFX
40{
41class VIEW;
42}
43
52class TOOL_DISPATCHER : public wxEvtHandler
53{
54public:
58 TOOL_DISPATCHER( TOOL_MANAGER* aToolMgr );
59
60 virtual ~TOOL_DISPATCHER();
61
65 virtual void ResetState();
66
73 virtual void DispatchWxEvent( wxEvent& aEvent );
74
78 std::optional<TOOL_EVENT> GetToolEvent( wxKeyEvent* aKeyEvent, bool* aSpecialKeyFlag );
79
81
82private:
84 bool handleMouseButton( wxEvent& aEvent, int aIndex, bool aMotion );
85
88
90 static int decodeModifiers( const wxKeyboardState* aState )
91 {
92 int mods = 0;
93
94 if( aState->ControlDown() )
95 mods |= MD_CTRL;
96
97 if( aState->AltDown() )
98 mods |= MD_ALT;
99
100 if( aState->ShiftDown() )
101 mods |= MD_SHIFT;
102
103 return mods;
104 }
105
106private:
109 static const int DragTimeThreshold = 300;
110
114 static const int DragDistanceThreshold = 8;
115
118
121
123 struct BUTTON_STATE;
124 std::vector<BUTTON_STATE*> m_buttons;
125
128
131};
132
133#endif // TOOL_DISPATCHER_H
Gather all the actions that are shared by tools.
Definition: actions.h:41
Defines the structure of a menu based on ACTIONs.
Definition: action_menu.h:49
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
ACTION_MENU * GetCurrentMenu() const
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()
Saves the state of key modifiers (Alt, Ctrl and so on).
int m_sysDragMinX
Mininum distance before drag is activated in the X axis.
bool handleMouseButton(wxEvent &aEvent, int aIndex, bool aMotion)
< Handles mouse related events (click, motion, dragging).
int m_sysDragMinY
Maximum distance before drag is activated in the Y axis.
VECTOR2D m_lastMousePosScreen
The last mouse cursor position (in screen coordinates).
static int decodeModifiers(const wxKeyboardState *aState)
TOOL_MANAGER * m_toolMgr
The menu from the main menubar currently shown (if any; nullptr otherwise)
std::vector< BUTTON_STATE * > m_buttons
Instance of tool manager that cooperates with the dispatcher.
VECTOR2D m_lastMousePos
The last mouse cursor position (in world coordinates).
ACTION_MENU * m_currentMenu
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:62
The Cairo implementation of the graphics abstraction layer.
Definition: color4d.cpp:247
< Stores information about a mouse button state
@ MD_ALT
Definition: tool_event.h:144
@ MD_CTRL
Definition: tool_event.h:143
@ MD_SHIFT
Definition: tool_event.h:142