Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/heathaze/src/lib/event/event_handler.h @ 10772

Last change on this file since 10772 was 9876, checked in by bensch, 18 years ago

compiles better on Windows

File size: 2.7 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  ObjectListDeclaration(EventHandler);
24public:
25  virtual ~EventHandler();
26  /** @returns a Pointer to the only object of this Class */
27  inline static EventHandler* getInstance() { if (!singletonRef) singletonRef = new EventHandler();  return singletonRef; };
28  void init();
29
30  void setState(elState state);
31  /** @returns the current state */
32inline elState getState() const { return this->state; };
33
34  void pushState(elState state);
35  elState popState();
36
37  void subscribe(EventListener* el, elState state, int eventType);
38  void unsubscribe(EventListener* el, elState state, int eventType);
39  void unsubscribe(EventListener* el, elState state = ES_ALL);
40  void flush(elState state);
41  /** @returns true, if the @param state has @param eventType subscribed?? */
42  bool isSubscribed(elState state, int eventType);
43
44  /** @param key the key to check @returns true if key is pressed */
45  bool isPressed(SDLKey key) const { return this->keyState[key]; };
46
47  void withUNICODE(elState state, bool enableUNICODE);
48  void grabEvents(bool grabEvents);
49  bool grabbedEvents() const { return this->eventsGrabbed; };
50
51  void process() const;
52  void dispachEvent(elState state, const Event& event) const;
53
54  static int eventFilter(const SDL_Event *event);
55  void debug() const;
56
57  static const std::string& ELStateToString(elState state);
58  static elState StringToELState(const std::string& stateName);
59
60  static int releaseMouse(void* p);
61
62private:
63  EventHandler();
64
65  bool findListener(std::vector<EventListener*>::iterator* it, elState state, int eventType, EventListener* listener);
66
67public:
68  static const std::string     stateNames[];
69
70private:
71  static EventHandler*         singletonRef;                    //!< the singleton reference
72
73  std::vector<EventListener*>  listeners[ESTATE_NUMBER][EV_NUMBER]; //!< a list of registered listeners.
74  elState                      state;                           //!< the state of the event handlder.
75  std::stack<short>            stateStack;                      //!< a stack for the States we are in.
76  KeyMapper                    keyMapper;                       //!< reference to the key mapper.
77
78  bool                         bUNICODE[ESTATE_NUMBER];             //!< If unicode should be enabled.
79  bool                         eventsGrabbed;                   //!< If the events should be grabbed
80
81  Uint8*                       keyState;
82};
83
84
85#endif /* _EVENT_HANDLER_H */
Note: See TracBrowser for help on using the repository browser.