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 
84  virtual void DispatchWxCommand( wxCommandEvent& aEvent );
85 
86 private:
88  static const int MouseButtonCount = 3;
89 
92  static const int DragTimeThreshold = 300;
93 
96  static const int DragDistanceThreshold = 8;
97 
99  bool handleMouseButton( wxEvent& aEvent, int aIndex, bool aMotion );
100 
102  static int decodeModifiers( const wxKeyboardState* aState )
103  {
104  int mods = 0;
105 
106  if( aState->ControlDown() )
107  mods |= MD_CTRL;
108 
109  if( aState->AltDown() )
110  mods |= MD_ALT;
111 
112  if( aState->ShiftDown() )
113  mods |= MD_SHIFT;
114 
115  return mods;
116  }
117 
119  void updateUI();
120 
122  struct BUTTON_STATE;
123 
126 
128  std::vector<BUTTON_STATE*> m_buttons;
129 
131  KIGFX::VIEW* getView();
132 
135 
138 };
139 
140 #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: class_module.h:58
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.
Class TOOL_MANAGER.
Definition: tool_manager.h:49
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).
void updateUI()
Redraws the status bar and message panel.
std::vector< BUTTON_STATE * > m_buttons
State of mouse buttons.
Class TOOL_DISPATCHER.
virtual void DispatchWxCommand(wxCommandEvent &aEvent)
Function DispatchWxCommand() Processes wxCommands (mostly menu related events) and runs appropriate a...
Class ACTIONS.
Definition: actions.h:41
static const int DragTimeThreshold
The time threshold for a mouse button press that distinguishes between a single mouse click and a beg...
Class VIEW.
Definition: view.h:58
bool handleMouseButton(wxEvent &aEvent, int aIndex, bool aMotion)
Handles mouse related events (click, motion, dragging).
class 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.