FIFE
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
eventmanager.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005-2013 by the FIFE team *
3  * http://www.fifengine.net *
4  * This file is part of FIFE. *
5  * *
6  * FIFE is free software; you can redistribute it and/or *
7  * modify it under the terms of the GNU Lesser General Public *
8  * License as published by the Free Software Foundation; either *
9  * version 2.1 of the License, or (at your option) any later version. *
10  * *
11  * This library is distributed in the hope that it will be useful, *
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
14  * Lesser General Public License for more details. *
15  * *
16  * You should have received a copy of the GNU Lesser General Public *
17  * License along with this library; if not, write to the *
18  * Free Software Foundation, Inc., *
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
20  ***************************************************************************/
21 
22 #ifndef FIFE_EVENTCHANNEL_EVENTMANAGER_H
23 #define FIFE_EVENTCHANNEL_EVENTMANAGER_H
24 
25 // Standard C++ library includes
26 //
27 #include <deque>
28 #include <map>
29 #include <list>
30 
31 // 3rd party library includes
32 //
33 
34 // FIFE includes
35 // These includes are split up in two parts, separated by one empty line
36 // First block: files included from the FIFE root src directory
37 // Second block: files included from the same folder
38 //
39 #include "util/base/fife_stdint.h"
43 
48 
52 
55 
56 namespace FIFE {
57 
58  class ICommandListener;
59  class InputEvent;
60  class MouseEvent;
61  class KeyEvent;
62  class IKeyFilter;
63 
66  class EventManager:
67  public ICommandController,
68  public IKeyController,
69  public IMouseController,
70  public ISdlEventController,
71  public IEventSource {
72  public:
75  EventManager();
76 
79  virtual ~EventManager();
80 
81  void addCommandListener(ICommandListener* listener);
84 
85  void dispatchCommand(Command& command);
86 
87  void addKeyListener(IKeyListener* listener);
88  void addKeyListenerFront(IKeyListener* listener);
89  void removeKeyListener(IKeyListener* listener);
90 
91  void addMouseListener(IMouseListener* listener);
92  void addMouseListenerFront(IMouseListener* listener);
93  void removeMouseListener(IMouseListener* listener);
94 
95  void addSdlEventListener(ISdlEventListener* listener);
98 
100 
105  void processEvents();
106 
107  void setKeyFilter(IKeyFilter* keyFilter);
108 
112  void setMouseSensitivity(float sensitivity);
113 
116  float getMouseSensitivity() const;
117 
122  void setMouseAccelerationEnabled(bool acceleration);
123 
128  bool isMouseAccelerationEnabled() const;
129 
130  private:
131  // Helpers for processEvents
132  void processActiveEvent(SDL_Event event);
133  void processKeyEvent(SDL_Event event);
134  void processMouseEvent(SDL_Event event);
135  bool combineEvents(SDL_Event& event1, const SDL_Event& event2);
136 
137  // Events dispatchers - only dispatchSdlevent may reject the event.
138  bool dispatchSdlEvent(SDL_Event& evt);
139  void dispatchKeyEvent(KeyEvent& evt);
140  void dispatchMouseEvent(MouseEvent& evt);
141 
142  // Translate events
143  void fillModifiers(InputEvent& evt);
144  void fillKeyEvent(const SDL_Event& sdlevt, KeyEvent& keyevt);
145  void fillMouseEvent(const SDL_Event& sdlevt, MouseEvent& mouseevt);
146 
147  std::deque<ICommandListener*> m_commandlisteners;
148  std::deque<ICommandListener*> m_pending_commandlisteners;
149  std::deque<ICommandListener*> m_pending_commandlisteners_front;
150  std::deque<ICommandListener*> m_pending_cldeletions;
151 
152  std::deque<IKeyListener*> m_keylisteners;
153  std::deque<IKeyListener*> m_pending_keylisteners;
154  std::deque<IKeyListener*> m_pending_keylisteners_front;
155  std::deque<IKeyListener*> m_pending_kldeletions;
156 
157  std::deque<IMouseListener*> m_mouselisteners;
158  std::deque<IMouseListener*> m_pending_mouselisteners;
159  std::deque<IMouseListener*> m_pending_mouselisteners_front;
160  std::deque<IMouseListener*> m_pending_mldeletions;
161 
162  std::deque<ISdlEventListener*> m_sdleventlisteners;
163  std::deque<ISdlEventListener*> m_pending_sdleventlisteners;
164  std::deque<ISdlEventListener*> m_pending_sdleventlisteners_front;
165  std::deque<ISdlEventListener*> m_pending_sdldeletions;
166 
167  std::map<int32_t, bool> m_keystatemap;
169  int32_t m_mousestate;
171 
172  // m_mousesensitivity is the mouse speed factor - 1, so a value of 0 won't
173  // influence mouse speed, a value of 1 would double the speed and
174  // -.5 would make it half the speed
177  bool m_warp;
178  bool m_enter;
183 
184  };
185 } //FIFE
186 
187 #endif
void removeMouseListener(IMouseListener *listener)
Removes an added listener from the controller.
float getMouseSensitivity() const
Gets mouse sensitivity.
Listener of SDL events.
void addKeyListenerFront(IKeyListener *listener)
Adds a listener to the front of the listener deque Listener will be notified via the corresponding ev...
Class for mouse events.
Definition: ec_mouseevent.h:42
Controller provides a way to receive events from the system Using this interface, clients can subscri...
Controller provides a way to receive events from the system Using this interface, clients can subscri...
IKeyFilter * m_keyfilter
Definition: eventmanager.h:168
Controller provides a way to receive events from the system Using this interface, clients can subscri...
Definition: ec_ikeyfilter.h:42
Base class for input events (like mouse and keyboard)
Definition: ec_inputevent.h:42
std::deque< IKeyListener * > m_pending_keylisteners
Definition: eventmanager.h:153
std::deque< IMouseListener * > m_pending_mouselisteners
Definition: eventmanager.h:158
std::deque< ISdlEventListener * > m_pending_sdleventlisteners_front
Definition: eventmanager.h:164
Controller provides a way to receive events from the system Using this interface, clients can subscri...
bool combineEvents(SDL_Event &event1, const SDL_Event &event2)
Listener of command events.
void addSdlEventListener(ISdlEventListener *listener)
Adds a listener to the back of the listener deque Listener will be notified via the corresponding eve...
void dispatchCommand(Command &command)
Use this method to send command to command listeners.
void addCommandListenerFront(ICommandListener *listener)
Adds a listener to the front of the listener deque Listener will be notified via the corresponding ev...
Listener of mouse events.
void setMouseAccelerationEnabled(bool acceleration)
Sets mouse acceleration if mouse acceleration is enabled, then the mouse sensitivity is used as speed...
std::deque< IKeyListener * > m_pending_kldeletions
Definition: eventmanager.h:155
void removeCommandListener(ICommandListener *listener)
Removes an added listener from the controller.
void dispatchMouseEvent(MouseEvent &evt)
std::deque< ISdlEventListener * > m_pending_sdleventlisteners
Definition: eventmanager.h:163
void addCommandListener(ICommandListener *listener)
Adds a listener to the back of the listener deque Listener will be notified via the corresponding eve...
std::deque< IKeyListener * > m_keylisteners
Definition: eventmanager.h:152
std::deque< ICommandListener * > m_pending_cldeletions
Definition: eventmanager.h:150
Class for commands Commands are arbitrary events e.g.
Definition: ec_command.h:44
Controller provides a way to receive events from the system Using this interface, clients can subscri...
std::map< int32_t, bool > m_keystatemap
Definition: eventmanager.h:167
void fillMouseEvent(const SDL_Event &sdlevt, MouseEvent &mouseevt)
EventSourceType getEventSourceType()
Gets the source type of this event.
std::deque< IMouseListener * > m_pending_mouselisteners_front
Definition: eventmanager.h:159
unsigned short uint16_t
Definition: core.h:39
void setKeyFilter(IKeyFilter *keyFilter)
std::deque< IMouseListener * > m_mouselisteners
Definition: eventmanager.h:157
void removeKeyListener(IKeyListener *listener)
Removes an added listener from the controller.
EventManager()
Constructor.
Event Manager manages all events related to FIFE.
Definition: eventmanager.h:66
void fillKeyEvent(const SDL_Event &sdlevt, KeyEvent &keyevt)
std::deque< IMouseListener * > m_pending_mldeletions
Definition: eventmanager.h:160
MouseButtonType
Mouse button types.
Definition: ec_mouseevent.h:64
MouseEvent::MouseButtonType m_mostrecentbtn
Definition: eventmanager.h:170
std::deque< IKeyListener * > m_pending_keylisteners_front
Definition: eventmanager.h:154
bool isMouseAccelerationEnabled() const
Returns if mouse acceleration is enabled or not.
Class for key events.
Definition: ec_keyevent.h:45
void addMouseListener(IMouseListener *listener)
Adds a listener to the back of the listener deque Listener will be notified via the corresponding eve...
std::deque< ISdlEventListener * > m_sdleventlisteners
Definition: eventmanager.h:162
void processKeyEvent(SDL_Event event)
virtual ~EventManager()
Destructor.
bool dispatchSdlEvent(SDL_Event &evt)
Listener of key events.
EventSourceType
Types for different event sources.
void processMouseEvent(SDL_Event event)
void fillModifiers(InputEvent &evt)
void addSdlEventListenerFront(ISdlEventListener *listener)
Adds a listener to the front of the listener deque Listener will be notified via the corresponding ev...
void setMouseSensitivity(float sensitivity)
Sets mouse sensitivity The sensitivity is limited to the range -0.99 - 10.0.
unsigned int uint32_t
Definition: core.h:40
Representation of event source (a thing sending events)
std::deque< ICommandListener * > m_commandlisteners
Definition: eventmanager.h:147
void processEvents()
Process the SDL event queue.
void addMouseListenerFront(IMouseListener *listener)
Adds a listener to the front of the listener deque Listener will be notified via the corresponding ev...
std::deque< ICommandListener * > m_pending_commandlisteners_front
Definition: eventmanager.h:149
std::deque< ISdlEventListener * > m_pending_sdldeletions
Definition: eventmanager.h:165
std::deque< ICommandListener * > m_pending_commandlisteners
Definition: eventmanager.h:148
void addKeyListener(IKeyListener *listener)
Adds a listener to the back of the listener deque Listener will be notified via the corresponding eve...
void dispatchKeyEvent(KeyEvent &evt)
void processActiveEvent(SDL_Event event)
void removeSdlEventListener(ISdlEventListener *listener)
Removes an added listener from the controller.