comparison engine/core/eventchannel/eventmanager.h @ 0:4a0efb7baf70

* Datasets becomes the new trunk and retires after that :-)
author mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
date Sun, 29 Jun 2008 18:44:17 +0000
parents
children 90005975cdbb
comparison
equal deleted inserted replaced
-1:000000000000 0:4a0efb7baf70
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 modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program 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 *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the *
18 * Free Software Foundation, Inc., *
19 * 51 Franklin St, 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 <vector>
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 #include "eventchannel/widget/ec_iwidgetcontroller.h"
56 #include "eventchannel/widget/ec_iwidgetlistener.h"
57 #include "eventchannel/widget/ec_widgetevent.h"
58
59 #include "eventchannel/trigger/ec_itriggercontroller.h"
60
61 namespace FIFE {
62
63 class ICommandListener;
64 class InputEvent;
65 class MouseEvent;
66 class KeyEvent;
67
68 /** Event Manager manages all events related to FIFE
69 */
70 class EventManager:
71 public ICommandController,
72 public IKeyController,
73 public IMouseController,
74 public ISdlEventController,
75 public IWidgetController,
76 public IEventSource,
77 public IWidgetListener,
78 public ITriggerController {
79 public:
80 /** Constructor.
81 */
82 EventManager();
83
84 /** Destructor
85 */
86 virtual ~EventManager();
87
88 void addCommandListener(ICommandListener* listener);
89 void removeCommandListener(ICommandListener* listener);
90 void dispatchCommand(Command& command);
91 void addKeyListener(IKeyListener* listener);
92 void removeKeyListener(IKeyListener* listener);
93 void addMouseListener(IMouseListener* listener);
94 void removeMouseListener(IMouseListener* listener);
95 void addSdlEventListener(ISdlEventListener* listener);
96 void removeSdlEventListener(ISdlEventListener* listener);
97 void addWidgetListener(IWidgetListener* listener);
98 void removeWidgetListener(IWidgetListener* listener);
99 EventSourceType getEventSourceType();
100 void setNonConsumableKeys(const std::vector<int>& keys);
101 std::vector<int> getNonConsumableKeys();
102
103 void onWidgetAction(WidgetEvent& evt);
104
105 void registerTrigger(Trigger& trigger);
106 void unregisterTrigger(Trigger& trigger);
107
108 /** Process the SDL event queue.
109 * This is to be called only by the engine itself once per frame.
110 * It passes appropriate events to their listeners
111 */
112 void processEvents();
113
114 private:
115 void dispatchKeyEvent(KeyEvent& evt);
116 void dispatchMouseEvent(MouseEvent& evt);
117 void dispatchSdlEvent(SDL_Event& evt);
118 void dispatchWidgetEvent(WidgetEvent& evt);
119 void fillModifiers(InputEvent& evt);
120 void fillKeyEvent(const SDL_Event& sdlevt, KeyEvent& keyevt);
121 void fillMouseEvent(const SDL_Event& sdlevt, MouseEvent& mouseevt);
122 void pollTriggers();
123
124 std::vector<ICommandListener*> m_commandlisteners;
125 std::vector<ICommandListener*> m_pending_commandlisteners;
126 std::vector<ICommandListener*> m_pending_cldeletions;
127
128 std::vector<IKeyListener*> m_keylisteners;
129 std::vector<IKeyListener*> m_pending_keylisteners;
130 std::vector<IKeyListener*> m_pending_kldeletions;
131
132 std::vector<IMouseListener*> m_mouselisteners;
133 std::vector<IMouseListener*> m_pending_mouselisteners;
134 std::vector<IMouseListener*> m_pending_mldeletions;
135
136 std::vector<ISdlEventListener*> m_sdleventlisteners;
137 std::vector<ISdlEventListener*> m_pending_sdleventlisteners;
138 std::vector<ISdlEventListener*> m_pending_sdldeletions;
139
140 std::vector<IWidgetListener*> m_widgetlisteners;
141 std::vector<IWidgetListener*> m_pending_widgetlisteners;
142 std::vector<IWidgetListener*> m_pending_wldeletions;
143
144 std::vector<int> m_nonconsumablekeys;
145 std::map<int, bool> m_keystatemap;
146 int m_mousestate;
147 MouseEvent::MouseButtonType m_mostrecentbtn;
148
149 std::list<Trigger*> m_triggers;
150 };
151 } //FIFE
152
153 #endif