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 The 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, see <https://www.gnu.org/licenses/>.
21 */
22
23#ifndef TOOL_DISPATCHER_H
24#define TOOL_DISPATCHER_H
25
26#include <vector>
27#include <wx/event.h>
28#include <wx/longlong.h>
29#include <tool/tool_event.h> // Needed for MD_ constants
30
31class TOOL_MANAGER;
32class PCB_BASE_FRAME;
33class ACTIONS;
34class ACTION_MENU;
35
36namespace KIGFX
37{
38class VIEW;
39}
40
49class TOOL_DISPATCHER : public wxEvtHandler
50{
51public:
55 TOOL_DISPATCHER( TOOL_MANAGER* aToolMgr );
56
57 virtual ~TOOL_DISPATCHER();
58
62 virtual void ResetState();
63
70 virtual void DispatchWxEvent( wxEvent& aEvent );
71
75 std::optional<TOOL_EVENT> GetToolEvent( wxKeyEvent* aKeyEvent, bool* aSpecialKeyFlag );
76
79 static const int AutoRepeatWindowMs = 250;
80
96 static bool ShouldDropAutoRepeat( int aKeyCode, wxLongLong aNowMs, bool aKeyIsDown,
97 int& aLastKey, wxLongLong& aLastTimeMs );
98
99private:
101 bool handleMouseButton( wxEvent& aEvent, int aIndex, bool aMotion );
102
106 void flushPendingClicks();
107
115 bool isStaleAutoRepeat( const wxKeyEvent& aKeyEvent );
116
119
122 static int decodeModifiers( const wxKeyboardState* aState );
123
124private:
127 static const int DragTimeThreshold = 300;
128
132 static const int DragDistanceThreshold = 8;
133
136
139
141 struct BUTTON_STATE;
142 std::vector<BUTTON_STATE*> m_buttons;
143
148
150 wxLongLong m_lastKeyTime;
151
154};
155
156#endif // TOOL_DISPATCHER_H
Gather all the actions that are shared by tools.
Definition actions.h:44
Define the structure of a menu based on ACTIONs.
Definition action_menu.h:43
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition view.h:63
Base PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
static const int DragDistanceThreshold
The distance threshold for mouse cursor that distinguishes between a single mouse click and a beginni...
static const int DragTimeThreshold
The time threshold for a mouse button press that distinguishes between a single mouse click and a beg...
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.
static const int AutoRepeatWindowMs
The maximum gap (ms) between two events of the same key for them to count as one OS auto-repeat burst...
KIGFX::VIEW * getView()
Returns the instance of VIEW, used by the application.
int m_sysDragMinX
Minimum distance before drag is activated in the X axis.
wxLongLong m_lastKeyTime
Local time (ms) at which m_lastKeyCode was last processed.
bool handleMouseButton(wxEvent &aEvent, int aIndex, bool aMotion)
Handles mouse related events (click, motion, dragging).
static bool ShouldDropAutoRepeat(int aKeyCode, wxLongLong aNowMs, bool aKeyIsDown, int &aLastKey, wxLongLong &aLastTimeMs)
Pure decision used to discard backlogged OS key auto-repeat events.
int m_sysDragMinY
Maximum distance before drag is activated in the Y axis.
static int decodeModifiers(const wxKeyboardState *aState)
Returns the state of key modifiers (Alt, Ctrl and so on) as OR'ed list of bits (MD_CTRL,...
void flushPendingClicks()
Processes any pending mouse clicks that have been physically completed but not yet dispatched.
VECTOR2D m_lastMousePosScreen
The last mouse cursor position (in screen coordinates).
TOOL_MANAGER * m_toolMgr
Instance of tool manager that cooperates with the dispatcher.
TOOL_DISPATCHER(TOOL_MANAGER *aToolMgr)
bool isStaleAutoRepeat(const wxKeyEvent &aKeyEvent)
Decide whether a keyboard event must be dropped because it is a backlogged OS key auto-repeat event d...
std::vector< BUTTON_STATE * > m_buttons
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.
int m_lastKeyCode
Key code of the key that was last processed, or 0 when no key is armed.
Master controller class:
The Cairo implementation of the graphics abstraction layer.
Definition eda_group.h:29
Store information about a mouse button state.
VECTOR2< double > VECTOR2D
Definition vector2d.h:682