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