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 "eventchannel/command/ec_command.h"
40 #include "eventchannel/command/ec_icommandcontroller.h"
41 #include "eventchannel/command/ec_icommandlistener.h"
42 
43 #include "eventchannel/key/ec_ikeycontroller.h"
44 #include "eventchannel/key/ec_ikeylistener.h"
45 #include "eventchannel/key/ec_keyevent.h"
46 #include "eventchannel/key/ec_key.h"
47 
48 #include "eventchannel/mouse/ec_imousecontroller.h"
49 #include "eventchannel/mouse/ec_imouselistener.h"
50 #include "eventchannel/mouse/ec_mouseevent.h"
51 
52 #include "eventchannel/sdl/ec_isdleventcontroller.h"
53 #include "eventchannel/sdl/ec_isdleventlistener.h"
54 
55 namespace FIFE {
56 
57  class ICommandListener;
58  class InputEvent;
59  class MouseEvent;
60  class KeyEvent;
61  class IKeyFilter;
62 
65  class EventManager:
66  public ICommandController,
67  public IKeyController,
68  public IMouseController,
69  public ISdlEventController,
70  public IEventSource {
71  public:
74  EventManager();
75 
78  virtual ~EventManager();
79 
80  void addCommandListener(ICommandListener* listener);
83 
84  void dispatchCommand(Command& command);
85 
86  void addKeyListener(IKeyListener* listener);
87  void addKeyListenerFront(IKeyListener* listener);
88  void removeKeyListener(IKeyListener* listener);
89 
90  void addMouseListener(IMouseListener* listener);
91  void addMouseListenerFront(IMouseListener* listener);
92  void removeMouseListener(IMouseListener* listener);
93 
94  void addSdlEventListener(ISdlEventListener* listener);
97 
99 
104  void processEvents();
105 
106  void setKeyFilter(IKeyFilter* keyFilter);
107 
108  private:
109  // Helpers for processEvents
110  void processActiveEvent(SDL_Event event);
111  void processKeyEvent(SDL_Event event);
112  void processMouseEvent(SDL_Event event);
113  bool combineEvents(SDL_Event& event1, const SDL_Event& event2);
114 
115  // Events dispatchers - only dispatchSdlevent may reject the event.
116  bool dispatchSdlEvent(SDL_Event& evt);
117  void dispatchKeyEvent(KeyEvent& evt);
118  void dispatchMouseEvent(MouseEvent& evt);
119 
120  // Translate events
121  void fillModifiers(InputEvent& evt);
122  void fillKeyEvent(const SDL_Event& sdlevt, KeyEvent& keyevt);
123  void fillMouseEvent(const SDL_Event& sdlevt, MouseEvent& mouseevt);
124 
125  std::deque<ICommandListener*> m_commandlisteners;
126  std::deque<ICommandListener*> m_pending_commandlisteners;
127  std::deque<ICommandListener*> m_pending_commandlisteners_front;
128  std::deque<ICommandListener*> m_pending_cldeletions;
129 
130  std::deque<IKeyListener*> m_keylisteners;
131  std::deque<IKeyListener*> m_pending_keylisteners;
132  std::deque<IKeyListener*> m_pending_keylisteners_front;
133  std::deque<IKeyListener*> m_pending_kldeletions;
134 
135  std::deque<IMouseListener*> m_mouselisteners;
136  std::deque<IMouseListener*> m_pending_mouselisteners;
137  std::deque<IMouseListener*> m_pending_mouselisteners_front;
138  std::deque<IMouseListener*> m_pending_mldeletions;
139 
140  std::deque<ISdlEventListener*> m_sdleventlisteners;
141  std::deque<ISdlEventListener*> m_pending_sdleventlisteners;
142  std::deque<ISdlEventListener*> m_pending_sdleventlisteners_front;
143  std::deque<ISdlEventListener*> m_pending_sdldeletions;
144 
145  std::map<int, bool> m_keystatemap;
146  IKeyFilter* m_keyfilter;
147  int m_mousestate;
148  MouseEvent::MouseButtonType m_mostrecentbtn;
149 
150  };
151 } //FIFE
152 
153 #endif