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  class IMouseFilter;
64 
67  class EventManager:
68  public ICommandController,
69  public IKeyController,
70  public IMouseController,
71  public ISdlEventController,
72  public IEventSource {
73  public:
76  EventManager();
77 
80  virtual ~EventManager();
81 
82  void addCommandListener(ICommandListener* listener);
85 
86  void dispatchCommand(Command& command);
87 
88  void addKeyListener(IKeyListener* listener);
89  void addKeyListenerFront(IKeyListener* listener);
90  void removeKeyListener(IKeyListener* listener);
91 
92  void addMouseListener(IMouseListener* listener);
93  void addMouseListenerFront(IMouseListener* listener);
94  void removeMouseListener(IMouseListener* listener);
95 
96  void addSdlEventListener(ISdlEventListener* listener);
99 
101 
106  void processEvents();
107 
108  void setKeyFilter(IKeyFilter* keyFilter);
109 
110  void setMouseFilter(IMouseFilter* mouseFilter);
111 
115  void setMouseSensitivity(float sensitivity);
116 
119  float getMouseSensitivity() const;
120 
125  void setMouseAccelerationEnabled(bool acceleration);
126 
131  bool isMouseAccelerationEnabled() const;
132 
133  private:
134  // Helpers for processEvents
135  void processActiveEvent(SDL_Event event);
136  void processKeyEvent(SDL_Event event);
137  void processMouseEvent(SDL_Event event);
138  bool combineEvents(SDL_Event& event1, const SDL_Event& event2);
139 
140  // Events dispatchers - only dispatchSdlevent may reject the event.
141  bool dispatchSdlEvent(SDL_Event& evt);
142  void dispatchKeyEvent(KeyEvent& evt);
143  void dispatchMouseEvent(MouseEvent& evt);
144 
145  // Translate events
146  void fillModifiers(InputEvent& evt);
147  void fillKeyEvent(const SDL_Event& sdlevt, KeyEvent& keyevt);
148  void fillMouseEvent(const SDL_Event& sdlevt, MouseEvent& mouseevt);
149 
150  std::deque<ICommandListener*> m_commandlisteners;
151  std::deque<ICommandListener*> m_pending_commandlisteners;
152  std::deque<ICommandListener*> m_pending_commandlisteners_front;
153  std::deque<ICommandListener*> m_pending_cldeletions;
154 
155  std::deque<IKeyListener*> m_keylisteners;
156  std::deque<IKeyListener*> m_pending_keylisteners;
157  std::deque<IKeyListener*> m_pending_keylisteners_front;
158  std::deque<IKeyListener*> m_pending_kldeletions;
159 
160  std::deque<IMouseListener*> m_mouselisteners;
161  std::deque<IMouseListener*> m_pending_mouselisteners;
162  std::deque<IMouseListener*> m_pending_mouselisteners_front;
163  std::deque<IMouseListener*> m_pending_mldeletions;
164 
165  std::deque<ISdlEventListener*> m_sdleventlisteners;
166  std::deque<ISdlEventListener*> m_pending_sdleventlisteners;
167  std::deque<ISdlEventListener*> m_pending_sdleventlisteners_front;
168  std::deque<ISdlEventListener*> m_pending_sdldeletions;
169 
170  std::map<int32_t, bool> m_keystatemap;
173  int32_t m_mousestate;
175 
176  // m_mousesensitivity is the mouse speed factor - 1, so a value of 0 won't
177  // influence mouse speed, a value of 1 would double the speed and
178  // -.5 would make it half the speed
181  bool m_warp;
182  bool m_enter;
187 
188  };
189 } //FIFE
190 
191 #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:171
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:156
std::deque< IMouseListener * > m_pending_mouselisteners
Definition: eventmanager.h:161
std::deque< ISdlEventListener * > m_pending_sdleventlisteners_front
Definition: eventmanager.h:167
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 setMouseFilter(IMouseFilter *mouseFilter)
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:158
void removeCommandListener(ICommandListener *listener)
Removes an added listener from the controller.
IMouseFilter * m_mousefilter
Definition: eventmanager.h:172
void dispatchMouseEvent(MouseEvent &evt)
std::deque< ISdlEventListener * > m_pending_sdleventlisteners
Definition: eventmanager.h:166
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:155
std::deque< ICommandListener * > m_pending_cldeletions
Definition: eventmanager.h:153
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:170
void fillMouseEvent(const SDL_Event &sdlevt, MouseEvent &mouseevt)
Controller provides a way to receive events from the system Using this interface, clients can subscri...
EventSourceType getEventSourceType()
Gets the source type of this event.
std::deque< IMouseListener * > m_pending_mouselisteners_front
Definition: eventmanager.h:162
unsigned short uint16_t
Definition: core.h:39
void setKeyFilter(IKeyFilter *keyFilter)
std::deque< IMouseListener * > m_mouselisteners
Definition: eventmanager.h:160
void removeKeyListener(IKeyListener *listener)
Removes an added listener from the controller.
EventManager()
Constructor.
Event Manager manages all events related to FIFE.
Definition: eventmanager.h:67
void fillKeyEvent(const SDL_Event &sdlevt, KeyEvent &keyevt)
std::deque< IMouseListener * > m_pending_mldeletions
Definition: eventmanager.h:163
MouseButtonType
Mouse button types.
Definition: ec_mouseevent.h:64
MouseEvent::MouseButtonType m_mostrecentbtn
Definition: eventmanager.h:174
std::deque< IKeyListener * > m_pending_keylisteners_front
Definition: eventmanager.h:157
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:165
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:150
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:152
std::deque< ISdlEventListener * > m_pending_sdldeletions
Definition: eventmanager.h:168
std::deque< ICommandListener * > m_pending_commandlisteners
Definition: eventmanager.h:151
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.