00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef __EVENTMANAGER_H__
00017 #define __EVENTMANAGER_H__
00018
00019
00020 #include "../dependencies.h"
00021
00022
00023 typedef sigslot::signal1<void*> EventSlot;
00024
00025
00026
00028 class EventManager : public IEventReceiver
00029 {
00030 public:
00031
00032
00034 EventManager();
00036 ~EventManager();
00037
00039 void init();
00041 void clear();
00042
00043
00046 void refAdd();
00049 void refRelease();
00050
00051
00055 bool createEventGroup(const std::string &groupName);
00060 bool createEventSlot(const std::string &groupName, const std::string &slotName);
00061
00068 template<typename T>
00069 bool connectEventSignal(const std::string &groupName, const std::string &slotName,
00070 T *t, void (T::*m)(void*))
00071 {
00072
00073 std::map<std::string, std::map<std::string, EventSlot> >::iterator itGroups;
00074 itGroups = mEvents.find(groupName);
00075
00076 if(itGroups == mEvents.end())
00077 return false;
00078
00079 std::map<std::string, EventSlot> &group = itGroups->second;
00080
00081
00082 std::map<std::string, EventSlot>::iterator itSlots = group.find(slotName);
00083
00084 if(itSlots == group.end())
00085 return false;
00086
00087 EventSlot &signal = itSlots->second;
00088
00089
00090 signal.connect(t, m);
00091 return true;
00092 };
00093
00100 template<typename T>
00101 bool disconnectEventSignal(const std::string &groupName, const std::string &slotName,
00102 T *t, void (T::*m)(void*))
00103 {
00104
00105 std::map<std::string, std::map<std::string, EventSlot> >::iterator itGroups;
00106 itGroups = mEvents.find(groupName);
00107
00108 if(itGroups == mEvents.end())
00109 return false;
00110
00111 std::map<std::string, EventSlot> &group = itGroups->second;
00112
00113
00114 std::map<std::string, EventSlot>::iterator itSlots = group.find(slotName);
00115
00116 if(itSlots == group.end())
00117 return false;
00118
00119 EventSlot &signal = itSlots->second;
00120
00121
00122 signal.disconnect(t, m);
00123 return true;
00124 };
00125
00130 bool emitEvent(const std::string &groupName, const std::string &slotName, void* p = 0);
00131
00133 bool getIsKeyDown(EKEY_CODE keyCode) const;
00135 bool getIsKeyUp(EKEY_CODE keyCode) const;
00136
00138 s32 getMouseX() const;
00140 s32 getMouseY() const;
00142 const vector2di& getMousePos() const;
00144 f32 getMouseWheel() const;
00145
00147 void removeAllEventGroups();
00151 bool removeAllEventSlots(const std::string &groupName);
00155 bool removeEventGroup(const std::string &groupName);
00159 bool removeEventSlot(const std::string &groupName, const std::string &slotName);
00160
00163 virtual bool OnEvent(const SEvent &event);
00164
00165 private:
00166
00167
00168 void generateKeyMap();
00169
00170
00171 std::map<std::string, std::map<std::string, EventSlot> > mEvents;
00172
00173 bool mKeyState[KEY_KEY_CODES_COUNT];
00174 std::map<EKEY_CODE, std::string> mKeyMap;
00175
00176 vector2di mMousePos;
00177 f32 mMouseWheel;
00178
00179 };
00180
00181
00182
00184 extern void bindEventManager(asIScriptEngine *engine);
00185
00186 #endif