Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/gui/src/lib/event/event_handler.h @ 7917

Last change on this file since 7917 was 7911, checked in by bensch, 19 years ago

gui: Only one copy of one eventListener can be assigned to one Event in each state. Everything else will be refused

File size: 2.3 KB
Line 
1/*!
2 * @file event_handler.h
3 * Definition of the EventHandler
4 *
5 */
6
7#ifndef _EVENT_HANDLER_H
8#define _EVENT_HANDLER_H
9
10#include "base_object.h"
11#include "key_mapper.h"
12#include "event_def.h"
13#include "event.h"
14#include <stack>
15#include <vector>
16
17// FORWARD DECLARATION
18class EventListener;
19
20//! The one Event Handler from Orxonox
21class EventHandler : public BaseObject {
22
23 public:
24  virtual ~EventHandler();
25  /** @returns a Pointer to the only object of this Class */
26  inline static EventHandler* getInstance() { if (!singletonRef) singletonRef = new EventHandler();  return singletonRef; };
27  void init();
28
29  void setState(elState state);
30  /** @returns the current state */
31  inline elState getState() const { return this->state; };
32
33  void pushState(elState state);
34  elState popState();
35
36  void subscribe(EventListener* el, elState state, int eventType);
37  void unsubscribe(EventListener* el, elState state, int eventType);
38  void unsubscribe(EventListener* el, elState state = ES_ALL);
39  void flush(elState state);
40  /** @returns true, if the @param state has @param eventType subscribed?? */
41  bool isSubscribed(elState state, int eventType);
42
43
44  void withUNICODE(elState state, bool enableUNICODE);
45  void grabEvents(bool grabEvents);
46  bool grabbedEvents() const { return this->eventsGrabbed; };
47
48  void process() const;
49  void dispachEvent(elState state, const Event& event) const;
50
51  static int eventFilter(const SDL_Event *event);
52  void debug() const;
53
54 private:
55  EventHandler();
56
57  bool findListener(std::vector<EventListener*>::iterator* it, elState state, int eventType, EventListener* listener);
58
59 private:
60  static EventHandler*         singletonRef;                    //!< the singleton reference
61
62  std::vector<EventListener*>  listeners[ES_NUMBER][EV_NUMBER]; //!< a list of registered listeners.
63  elState                      state;                           //!< the state of the event handlder.
64  std::stack<short>            stateStack;                      //!< a stack for the States we are in.
65  KeyMapper                    keyMapper;                       //!< reference to the key mapper.
66
67  bool                         bUNICODE[ES_NUMBER];             //!< If unicode should be enabled.
68  bool                         eventsGrabbed;                   //!< If the events should be grabbed
69};
70
71
72#endif /* _EVENT_HANDLER_H */
Note: See TracBrowser for help on using the repository browser.