[4780] | 1 | /*! |
---|
[5039] | 2 | * @file event_handler.h |
---|
| 3 | * Definition of the EventHandler |
---|
| 4 | * |
---|
| 5 | */ |
---|
[4780] | 6 | |
---|
[4346] | 7 | #ifndef _EVENT_HANDLER_H |
---|
| 8 | #define _EVENT_HANDLER_H |
---|
[4329] | 9 | |
---|
| 10 | #include "base_object.h" |
---|
[4405] | 11 | #include "key_mapper.h" |
---|
[4352] | 12 | #include "event_def.h" |
---|
[7164] | 13 | #include <stack> |
---|
[4329] | 14 | |
---|
[4834] | 15 | // FORWARD DECLARATION |
---|
[4346] | 16 | class EventListener; |
---|
[4329] | 17 | |
---|
[4346] | 18 | //! The one Event Handler from Orxonox |
---|
| 19 | class EventHandler : public BaseObject { |
---|
| 20 | |
---|
[4329] | 21 | public: |
---|
[4746] | 22 | virtual ~EventHandler(); |
---|
[4836] | 23 | /** @returns a Pointer to the only object of this Class */ |
---|
[4746] | 24 | inline static EventHandler* getInstance() { if (!singletonRef) singletonRef = new EventHandler(); return singletonRef; }; |
---|
[7256] | 25 | void init(); |
---|
[4407] | 26 | |
---|
[5093] | 27 | /** @param state: to which the event handler shall change */ |
---|
| 28 | inline void setState(elState state) { this->state = state; }; |
---|
| 29 | /** @returns the current state */ |
---|
| 30 | inline elState getState() const { return this->state; }; |
---|
[4350] | 31 | |
---|
[5388] | 32 | void pushState(elState state); |
---|
| 33 | elState popState(); |
---|
| 34 | |
---|
[4405] | 35 | void subscribe(EventListener* el, elState state, int eventType); |
---|
[4419] | 36 | void unsubscribe(elState state, int eventType); |
---|
[4420] | 37 | void unsubscribe(EventListener* el, elState state = ES_ALL); |
---|
[4364] | 38 | void flush(elState state); |
---|
[5309] | 39 | /** @returns true, if the @param state has @param eventType subscribed?? */ |
---|
| 40 | inline bool isSubscribed(elState state, int eventType) { return(listeners[state][eventType] == NULL)?false:true; }; |
---|
[4346] | 41 | |
---|
[5786] | 42 | |
---|
| 43 | void withUNICODE(bool enableUNICODE); |
---|
[5978] | 44 | void grabEvents(bool grabEvents); |
---|
[6054] | 45 | bool grabbedEvents() const { return this->eventsGrabbed; }; |
---|
[5786] | 46 | |
---|
[4352] | 47 | void process(); |
---|
[4346] | 48 | |
---|
[5237] | 49 | static int eventFilter(const SDL_Event *event); |
---|
[4872] | 50 | void debug() const; |
---|
| 51 | |
---|
[4329] | 52 | private: |
---|
[4746] | 53 | EventHandler(); |
---|
[4352] | 54 | |
---|
[4368] | 55 | private: |
---|
[5210] | 56 | static EventHandler* singletonRef; //!< the singleton reference |
---|
[4780] | 57 | |
---|
[5388] | 58 | EventListener* listeners[ES_NUMBER][EV_NUMBER]; //!< a list of registered listeners. |
---|
| 59 | elState state; //!< the state of the event handlder. |
---|
[7164] | 60 | std::stack<short> stateStack; //!< a stack for the States we are in. |
---|
[5388] | 61 | KeyMapper* keyMapper; //!< reference to the key mapper. |
---|
| 62 | |
---|
[5786] | 63 | bool bUNICODE; //!< If unicode should be enabled. |
---|
[5978] | 64 | bool eventsGrabbed; //!< If the events should be grabbed |
---|
[4329] | 65 | }; |
---|
| 66 | |
---|
[5237] | 67 | |
---|
[4346] | 68 | #endif /* _EVENT_HANDLER_H */ |
---|