KiCad PCB EDA Suite
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 <tomasz.wlostowski@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 
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 
34 class TOOL_MANAGER;
35 class PCB_BASE_FRAME;
36 class ACTIONS;
37 
38 namespace KIGFX
39 {
40 class VIEW;
41 }
42 
51 class TOOL_DISPATCHER : public wxEvtHandler
52 {
53 public:
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  OPT<TOOL_EVENT> GetToolEvent( wxKeyEvent* aKeyEvent, bool* aSpecialKeyFlag );
78 
79 private:
81  static const int MouseButtonCount = 3;
82 
85  static const int DragTimeThreshold = 300;
86 
89  static const int DragDistanceThreshold = 8;
90 
92  bool handleMouseButton( wxEvent& aEvent, int aIndex, bool aMotion );
93 
95  static int decodeModifiers( const wxKeyboardState* aState )
96  {
97  int mods = 0;
98 
99  if( aState->ControlDown() )
100  mods |= MD_CTRL;
101 
102  if( aState->AltDown() )
103  mods |= MD_ALT;
104 
105  if( aState->ShiftDown() )
106  mods |= MD_SHIFT;
107 
108  return mods;
109  }
110 
112  struct BUTTON_STATE;
113 
116 
118  std::vector<BUTTON_STATE*> m_buttons;
119 
121  KIGFX::VIEW* getView();
122 
125 };
126 
127 #endif
static int decodeModifiers(const wxKeyboardState *aState)
Stores all the information regarding a mouse button state.
The Cairo implementation of the graphics abstraction layer.
Definition: color4d.cpp:194
static const int MouseButtonCount
< Number of mouse buttons that is handled in events.
static const int DragDistanceThreshold
Handles mouse related events (click, motion, dragging).
virtual ~TOOL_DISPATCHER()
virtual void ResetState()
Bring the dispatcher to its initial state.
Master controller class:
Definition: tool_manager.h:54
< Stores information about a mouse button state
virtual void DispatchWxEvent(wxEvent &aEvent)
Process wxEvents (mostly UI events), translate them to TOOL_EVENTs, and make tools handle those.
VECTOR2D m_lastMousePos
The last mouse cursor position (in world coordinates).
std::vector< BUTTON_STATE * > m_buttons
Returns the instance of VIEW, used by the application.
OPT< TOOL_EVENT > GetToolEvent(wxKeyEvent *aKeyEvent, bool *aSpecialKeyFlag)
Map a wxWidgets key event to a TOOL_EVENT.
TOOL_DISPATCHER(TOOL_MANAGER *aToolMgr)
boost::optional< T > OPT
Definition: optional.h:7
Gather all the actions that are shared by tools.
Definition: actions.h:40
static const int DragTimeThreshold
The distance threshold for mouse cursor that distinguishes between a single mouse click and a beginni...
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition: view.h:67
bool handleMouseButton(wxEvent &aEvent, int aIndex, bool aMotion)
Saves the state of key modifiers (Alt, Ctrl and so on).
Base PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
KIGFX::VIEW * getView()
Instance of tool manager that cooperates with the dispatcher.
TOOL_MANAGER * m_toolMgr