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  * @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
25 #ifndef __TOOL_DISPATCHER_H
26 #define __TOOL_DISPATCHER_H
27 
28 #include <vector>
29 #include <wx/event.h>
30 #include <tool/tool_event.h>
31 
32 class TOOL_MANAGER;
33 class PCB_BASE_FRAME;
34 class ACTIONS;
35 
36 namespace KIGFX
37 {
38 class VIEW;
39 }
40 
51 class TOOL_DISPATCHER : public wxEvtHandler
52 {
53 public:
60  TOOL_DISPATCHER( TOOL_MANAGER* aToolMgr, ACTIONS *aActions );
61 
62  virtual ~TOOL_DISPATCHER();
63 
68  virtual void ResetState();
69 
76  virtual void DispatchWxEvent( wxEvent& aEvent );
77 
82  OPT<TOOL_EVENT> GetToolEvent( wxKeyEvent* aKeyEvent, bool* aSpecialKeyFlag );
83 
90  virtual void DispatchWxCommand( wxCommandEvent& aEvent );
91 
92 private:
94  static const int MouseButtonCount = 3;
95 
98  static const int DragTimeThreshold = 300;
99 
102  static const int DragDistanceThreshold = 8;
103 
105  bool handleMouseButton( wxEvent& aEvent, int aIndex, bool aMotion );
106 
108  static int decodeModifiers( const wxKeyboardState* aState )
109  {
110  int mods = 0;
111 
112  if( aState->ControlDown() )
113  mods |= MD_CTRL;
114 
115  if( aState->AltDown() )
116  mods |= MD_ALT;
117 
118  if( aState->ShiftDown() )
119  mods |= MD_SHIFT;
120 
121  return mods;
122  }
123 
125  struct BUTTON_STATE;
126 
129 
131  std::vector<BUTTON_STATE*> m_buttons;
132 
134  KIGFX::VIEW* getView();
135 
138 
141 };
142 
143 #endif
static int decodeModifiers(const wxKeyboardState *aState)
Saves the state of key modifiers (Alt, Ctrl and so on).
ACTIONS * m_actions
Instance of an actions list that handles legacy action translation
Class CAIRO_GAL is the cairo implementation of the graphics abstraction layer.
Definition: color4d.cpp:175
static const int MouseButtonCount
Number of mouse buttons that is handled in events.
static const int DragDistanceThreshold
The distance threshold for mouse cursor that disinguishes between a single mouse click and a beginnin...
virtual ~TOOL_DISPATCHER()
virtual void ResetState()
Function ResetState() Brings the dispatcher to its initial state.
TOOL_DISPATCHER(TOOL_MANAGER *aToolMgr, ACTIONS *aActions)
Constructor.
TOOL_MANAGER.
Definition: tool_manager.h:51
Stores information about a mouse button state
virtual void DispatchWxEvent(wxEvent &aEvent)
Function DispatchWxEvent() Processes wxEvents (mostly UI events), translates them to TOOL_EVENTs,...
VECTOR2D m_lastMousePos
The last mouse cursor position (in world coordinates).
std::vector< BUTTON_STATE * > m_buttons
State of mouse buttons.
TOOL_DISPATCHER.
OPT< TOOL_EVENT > GetToolEvent(wxKeyEvent *aKeyEvent, bool *aSpecialKeyFlag)
Function GetToolEvent() Maps a wxWidgets key event to a TOOL_EVENT.
virtual void DispatchWxCommand(wxCommandEvent &aEvent)
Function DispatchWxCommand() Processes wxCommands (mostly menu related events) and runs appropriate a...
boost::optional< T > OPT
Definition: optional.h:7
ACTIONS.
Definition: actions.h:43
static const int DragTimeThreshold
The time threshold for a mouse button press that distinguishes between a single mouse click and a beg...
VIEW.
Definition: view.h:61
bool handleMouseButton(wxEvent &aEvent, int aIndex, bool aMotion)
Handles mouse related events (click, motion, dragging).
PCB_BASE_FRAME basic PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
KIGFX::VIEW * getView()
Returns the instance of VIEW, used by the application.
TOOL_MANAGER * m_toolMgr
Instance of tool manager that cooperates with the dispatcher.