Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/event/event_handler.h @ 7792

Last change on this file since 7792 was 7756, checked in by bensch, 19 years ago

orxonox/trunk: Multiple Event Subscription Method
@patrick, do you approve of this, or do you think, that it is too much??

This is something i proposed some time ago, and it is nice, because one can overload the Commandos

File size: 2.2 KB
RevLine 
[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>
[7756]14#include <vector>
[4329]15
[4834]16// FORWARD DECLARATION
[4346]17class EventListener;
[4329]18
[4346]19//! The one Event Handler from Orxonox
20class EventHandler : public BaseObject {
21
[4329]22 public:
[4746]23  virtual ~EventHandler();
[4836]24  /** @returns a Pointer to the only object of this Class */
[4746]25  inline static EventHandler* getInstance() { if (!singletonRef) singletonRef = new EventHandler();  return singletonRef; };
[7256]26  void init();
[4407]27
[5093]28  /** @param state: to which the event handler shall change */
29  inline void setState(elState state) { this->state = state; };
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);
[4419]37  void unsubscribe(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
44  void withUNICODE(bool enableUNICODE);
[5978]45  void grabEvents(bool grabEvents);
[6054]46  bool grabbedEvents() const { return this->eventsGrabbed; };
[5786]47
[4352]48  void process();
[4346]49
[5237]50  static int eventFilter(const SDL_Event *event);
[4872]51  void debug() const;
52
[4329]53 private:
[4746]54  EventHandler();
[4352]55
[4368]56 private:
[7756]57  static EventHandler*         singletonRef;                    //!< the singleton reference
[4780]58
[7756]59  std::vector<EventListener*>  listeners[ES_NUMBER][EV_NUMBER]; //!< a list of registered listeners.
60  elState                      state;                           //!< the state of the event handlder.
61  std::stack<short>            stateStack;                      //!< a stack for the States we are in.
62  KeyMapper                    keyMapper;                       //!< reference to the key mapper.
[5388]63
[7756]64  bool                         bUNICODE;                        //!< If unicode should be enabled.
65  bool                         eventsGrabbed;                   //!< If the events should be grabbed
[4329]66};
67
[5237]68
[4346]69#endif /* _EVENT_HANDLER_H */
Note: See TracBrowser for help on using the repository browser.