eventmanager.h
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef FIFE_EVENTCHANNEL_EVENTMANAGER_H
00023 #define FIFE_EVENTCHANNEL_EVENTMANAGER_H
00024
00025
00026
00027 #include <deque>
00028 #include <map>
00029 #include <list>
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 #include "eventchannel/command/ec_command.h"
00040 #include "eventchannel/command/ec_icommandcontroller.h"
00041 #include "eventchannel/command/ec_icommandlistener.h"
00042
00043 #include "eventchannel/key/ec_ikeycontroller.h"
00044 #include "eventchannel/key/ec_ikeylistener.h"
00045 #include "eventchannel/key/ec_keyevent.h"
00046 #include "eventchannel/key/ec_key.h"
00047
00048 #include "eventchannel/mouse/ec_imousecontroller.h"
00049 #include "eventchannel/mouse/ec_imouselistener.h"
00050 #include "eventchannel/mouse/ec_mouseevent.h"
00051
00052 #include "eventchannel/sdl/ec_isdleventcontroller.h"
00053 #include "eventchannel/sdl/ec_isdleventlistener.h"
00054
00055 #include "eventchannel/trigger/ec_itriggercontroller.h"
00056
00057 namespace FIFE {
00058
00059 class ICommandListener;
00060 class InputEvent;
00061 class MouseEvent;
00062 class KeyEvent;
00063 class IKeyFilter;
00064
00067 class EventManager:
00068 public ICommandController,
00069 public IKeyController,
00070 public IMouseController,
00071 public ISdlEventController,
00072 public IEventSource,
00073 public ITriggerController {
00074 public:
00077 EventManager();
00078
00081 virtual ~EventManager();
00082
00083 void addCommandListener(ICommandListener* listener);
00084 void addCommandListenerFront(ICommandListener* listener);
00085 void removeCommandListener(ICommandListener* listener);
00086 void dispatchCommand(Command& command);
00087 void addKeyListener(IKeyListener* listener);
00088 void addKeyListenerFront(IKeyListener* listener);
00089 void removeKeyListener(IKeyListener* listener);
00090 void addMouseListener(IMouseListener* listener);
00091 void addMouseListenerFront(IMouseListener* listener);
00092 void removeMouseListener(IMouseListener* listener);
00093 void addSdlEventListener(ISdlEventListener* listener);
00094 void addSdlEventListenerFront(ISdlEventListener* listener);
00095 void removeSdlEventListener(ISdlEventListener* listener);
00096 EventSourceType getEventSourceType();
00097
00098 void registerTrigger(Trigger& trigger);
00099 void unregisterTrigger(Trigger& trigger);
00100
00105 void processEvents();
00106
00107 void setKeyFilter(IKeyFilter* keyFilter);
00108
00109 private:
00110
00111 void processActiveEvent(SDL_Event event);
00112 void processKeyEvent(SDL_Event event);
00113 void processMouseEvent(SDL_Event event);
00114 bool combineEvents(SDL_Event& event1, const SDL_Event& event2);
00115
00116
00117 bool dispatchSdlEvent(SDL_Event& evt);
00118 void dispatchKeyEvent(KeyEvent& evt);
00119 void dispatchMouseEvent(MouseEvent& evt);
00120
00121
00122 void fillModifiers(InputEvent& evt);
00123 void fillKeyEvent(const SDL_Event& sdlevt, KeyEvent& keyevt);
00124 void fillMouseEvent(const SDL_Event& sdlevt, MouseEvent& mouseevt);
00125
00126 void pollTriggers();
00127
00128 std::deque<ICommandListener*> m_commandlisteners;
00129 std::deque<ICommandListener*> m_pending_commandlisteners;
00130 std::deque<ICommandListener*> m_pending_commandlisteners_front;
00131 std::deque<ICommandListener*> m_pending_cldeletions;
00132
00133 std::deque<IKeyListener*> m_keylisteners;
00134 std::deque<IKeyListener*> m_pending_keylisteners;
00135 std::deque<IKeyListener*> m_pending_keylisteners_front;
00136 std::deque<IKeyListener*> m_pending_kldeletions;
00137
00138 std::deque<IMouseListener*> m_mouselisteners;
00139 std::deque<IMouseListener*> m_pending_mouselisteners;
00140 std::deque<IMouseListener*> m_pending_mouselisteners_front;
00141 std::deque<IMouseListener*> m_pending_mldeletions;
00142
00143 std::deque<ISdlEventListener*> m_sdleventlisteners;
00144 std::deque<ISdlEventListener*> m_pending_sdleventlisteners;
00145 std::deque<ISdlEventListener*> m_pending_sdleventlisteners_front;
00146 std::deque<ISdlEventListener*> m_pending_sdldeletions;
00147
00148 std::map<int, bool> m_keystatemap;
00149 IKeyFilter* m_keyfilter;
00150 int m_mousestate;
00151 MouseEvent::MouseButtonType m_mostrecentbtn;
00152
00153 std::list<Trigger*> m_triggers;
00154 };
00155 }
00156
00157 #endif