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 #include "ReferenceCounted.h"
00022
00023
00024 typedef sigslot::signal1<void*> EventSlot;
00025
00026
00027
00029 class EventManager : public IEventReceiver, public ReferenceCounted
00030 {
00031 public:
00032
00033
00035 EventManager();
00037 ~EventManager();
00038
00040 void init();
00042 void clear();
00043
00044
00047 void grab();
00050 void drop();
00051
00052
00056 bool createEventGroup(const std::string &groupName);
00061 bool createEventSlot(const std::string &groupName, const std::string &slotName);
00062
00069 template<typename T>
00070 bool connectEventSignal(const std::string &groupName, const std::string &slotName,
00071 T *t, void (T::*m)(void*))
00072 {
00073
00074 std::map<std::string, std::map<std::string, EventSlot> >::iterator itGroups;
00075 itGroups = mEvents.find(groupName);
00076
00077 if(itGroups == mEvents.end())
00078 return false;
00079
00080 std::map<std::string, EventSlot> &group = itGroups->second;
00081
00082
00083 std::map<std::string, EventSlot>::iterator itSlots = group.find(slotName);
00084
00085 if(itSlots == group.end())
00086 return false;
00087
00088 EventSlot &signal = itSlots->second;
00089
00090
00091 signal.connect(t, m);
00092 return true;
00093 };
00094
00100 template<typename T>
00101 bool disconnectEventSignal(const std::string &groupName, const std::string &slotName, T *t)
00102 {
00103
00104 std::map<std::string, std::map<std::string, EventSlot> >::iterator itGroups;
00105 itGroups = mEvents.find(groupName);
00106
00107 if(itGroups == mEvents.end())
00108 return false;
00109
00110 std::map<std::string, EventSlot> &group = itGroups->second;
00111
00112
00113 std::map<std::string, EventSlot>::iterator itSlots = group.find(slotName);
00114
00115 if(itSlots == group.end())
00116 return false;
00117
00118 EventSlot &signal = itSlots->second;
00119
00120
00121 signal.disconnect(t);
00122 return true;
00123 };
00124
00129 bool emitEvent(const std::string &groupName, const std::string &slotName, void* p = 0);
00130
00132 bool getIsKeyDown(EKEY_CODE keyCode) const;
00134 bool getIsKeyUp(EKEY_CODE keyCode) const;
00135
00137 s32 getMouseX() const;
00139 s32 getMouseY() const;
00141 const vector2di& getMousePos() const;
00143 f32 getMouseWheel() const;
00144
00146 void removeEventGroups();
00150 bool removeEventSlots(const std::string &groupName);
00154 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 #endif