Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

compiles better on Windows

File size: 2.7 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"
[7919]13#include "event.h"
[7164]14#include <stack>
[7756]15#include <vector>
[4329]16
[4834]17// FORWARD DECLARATION
[4346]18class EventListener;
[4329]19
[4346]20//! The one Event Handler from Orxonox
[8148]21class EventHandler : public BaseObject
22{
[9869]23  ObjectListDeclaration(EventHandler);
[8148]24public:
[4746]25  virtual ~EventHandler();
[4836]26  /** @returns a Pointer to the only object of this Class */
[4746]27  inline static EventHandler* getInstance() { if (!singletonRef) singletonRef = new EventHandler();  return singletonRef; };
[7256]28  void init();
[4407]29
[7919]30  void setState(elState state);
[5093]31  /** @returns the current state */
[8148]32inline elState getState() const { return this->state; };
[4350]33
[5388]34  void pushState(elState state);
35  elState popState();
36
[4405]37  void subscribe(EventListener* el, elState state, int eventType);
[7868]38  void unsubscribe(EventListener* el, elState state, int eventType);
[4420]39  void unsubscribe(EventListener* el, elState state = ES_ALL);
[4364]40  void flush(elState state);
[5309]41  /** @returns true, if the @param state has @param eventType subscribed?? */
[7756]42  bool isSubscribed(elState state, int eventType);
[4346]43
[8743]44  /** @param key the key to check @returns true if key is pressed */
45  bool isPressed(SDLKey key) const { return this->keyState[key]; };
[5786]46
[7919]47  void withUNICODE(elState state, bool enableUNICODE);
[5978]48  void grabEvents(bool grabEvents);
[6054]49  bool grabbedEvents() const { return this->eventsGrabbed; };
[5786]50
[7919]51  void process() const;
52  void dispachEvent(elState state, const Event& event) const;
[4346]53
[5237]54  static int eventFilter(const SDL_Event *event);
[4872]55  void debug() const;
56
[8148]57  static const std::string& ELStateToString(elState state);
58  static elState StringToELState(const std::string& stateName);
59
[8623]60  static int releaseMouse(void* p);
61
[8148]62private:
[4746]63  EventHandler();
[4352]64
[7919]65  bool findListener(std::vector<EventListener*>::iterator* it, elState state, int eventType, EventListener* listener);
66
[8148]67public:
68  static const std::string     stateNames[];
69
70private:
[7756]71  static EventHandler*         singletonRef;                    //!< the singleton reference
[4780]72
[9876]73  std::vector<EventListener*>  listeners[ESTATE_NUMBER][EV_NUMBER]; //!< a list of registered listeners.
[7756]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.
[5388]77
[9876]78  bool                         bUNICODE[ESTATE_NUMBER];             //!< If unicode should be enabled.
[7756]79  bool                         eventsGrabbed;                   //!< If the events should be grabbed
[8743]80
81  Uint8*                       keyState;
[4329]82};
83
[5237]84
[4346]85#endif /* _EVENT_HANDLER_H */
Note: See TracBrowser for help on using the repository browser.