FIFE  2008.0
 All Classes Namespaces Functions Variables Enumerations Enumerator Pages
eventmanager.h
1 /***************************************************************************
2  * Copyright (C) 2005-2008 by the FIFE team *
3  * http://www.fifengine.de *
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"
40 #include "eventchannel/command/ec_command.h"
41 #include "eventchannel/command/ec_icommandcontroller.h"
42 #include "eventchannel/command/ec_icommandlistener.h"
43 
44 #include "eventchannel/key/ec_ikeycontroller.h"
45 #include "eventchannel/key/ec_ikeylistener.h"
46 #include "eventchannel/key/ec_keyevent.h"
47 #include "eventchannel/key/ec_key.h"
48 
49 #include "eventchannel/mouse/ec_imousecontroller.h"
50 #include "eventchannel/mouse/ec_imouselistener.h"
51 #include "eventchannel/mouse/ec_mouseevent.h"
52 
53 #include "eventchannel/sdl/ec_isdleventcontroller.h"
54 #include "eventchannel/sdl/ec_isdleventlistener.h"
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 setMouseAcceleration(bool acceleration);
123 
126  bool getMouseAcceleration() const;
127 
128  private:
129  // Helpers for processEvents
130  void processActiveEvent(SDL_Event event);
131  void processKeyEvent(SDL_Event event);
132  void processMouseEvent(SDL_Event event);
133  bool combineEvents(SDL_Event& event1, const SDL_Event& event2);
134 
135  // Events dispatchers - only dispatchSdlevent may reject the event.
136  bool dispatchSdlEvent(SDL_Event& evt);
137  void dispatchKeyEvent(KeyEvent& evt);
138  void dispatchMouseEvent(MouseEvent& evt);
139 
140  // Translate events
141  void fillModifiers(InputEvent& evt);
142  void fillKeyEvent(const SDL_Event& sdlevt, KeyEvent& keyevt);
143  void fillMouseEvent(const SDL_Event& sdlevt, MouseEvent& mouseevt);
144 
145  std::deque<ICommandListener*> m_commandlisteners;
146  std::deque<ICommandListener*> m_pending_commandlisteners;
147  std::deque<ICommandListener*> m_pending_commandlisteners_front;
148  std::deque<ICommandListener*> m_pending_cldeletions;
149 
150  std::deque<IKeyListener*> m_keylisteners;
151  std::deque<IKeyListener*> m_pending_keylisteners;
152  std::deque<IKeyListener*> m_pending_keylisteners_front;
153  std::deque<IKeyListener*> m_pending_kldeletions;
154 
155  std::deque<IMouseListener*> m_mouselisteners;
156  std::deque<IMouseListener*> m_pending_mouselisteners;
157  std::deque<IMouseListener*> m_pending_mouselisteners_front;
158  std::deque<IMouseListener*> m_pending_mldeletions;
159 
160  std::deque<ISdlEventListener*> m_sdleventlisteners;
161  std::deque<ISdlEventListener*> m_pending_sdleventlisteners;
162  std::deque<ISdlEventListener*> m_pending_sdleventlisteners_front;
163  std::deque<ISdlEventListener*> m_pending_sdldeletions;
164 
165  std::map<int32_t, bool> m_keystatemap;
166  IKeyFilter* m_keyfilter;
167  int32_t m_mousestate;
168  MouseEvent::MouseButtonType m_mostrecentbtn;
169 
170  // m_mousesensitivity is the mouse speed factor - 1, so a value of 0 won't
171  // influence mouse speed, a value of 1 would double the speed and
172  // -.5 would make it half the speed
173  float m_mousesensitivity;
174  bool m_acceleration;
175  bool m_warp;
176  bool m_enter;
177  uint16_t m_oldx;
178  uint16_t m_oldy;
179  uint32_t m_lastticks;
180  float m_oldvelocity;
181 
182  };
183 } //FIFE
184 
185 #endif
void removeMouseListener(IMouseListener *listener)
float getMouseSensitivity() const
bool getMouseAcceleration() const
void addKeyListenerFront(IKeyListener *listener)
void addSdlEventListener(ISdlEventListener *listener)
void dispatchCommand(Command &command)
void addCommandListenerFront(ICommandListener *listener)
void removeCommandListener(ICommandListener *listener)
void addCommandListener(ICommandListener *listener)
EventSourceType getEventSourceType()
void removeKeyListener(IKeyListener *listener)
void addMouseListener(IMouseListener *listener)
virtual ~EventManager()
void setMouseAcceleration(bool acceleration)
void addSdlEventListenerFront(ISdlEventListener *listener)
void setMouseSensitivity(float sensitivity)
void addMouseListenerFront(IMouseListener *listener)
void addKeyListener(IKeyListener *listener)
void removeSdlEventListener(ISdlEventListener *listener)