| 
                Last change
                  on this file since 4354 was
                  4354,
                  checked in by patrick, 20 years ago
           | 
        
        
          | 
               
orxonox/trunk: implemented event subscribe function 
 
           | 
        
        | 
            File size:
            1.4 KB
           | 
      
      
        
  | Line |   | 
|---|
| 1 | /*!  | 
|---|
| 2 |     \file event_handler.h | 
|---|
| 3 |     \brief 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 "event_def.h" | 
|---|
| 12 |  | 
|---|
| 13 | class EventListener; | 
|---|
| 14 | template<class T> class tList; | 
|---|
| 15 |  | 
|---|
| 16 |  | 
|---|
| 17 | #define N_STD_KEYS SDLK_LAST | 
|---|
| 18 | #define N_BUTTONS 6 | 
|---|
| 19 | #define DEFAULT_KEYBIND_FILE "~/.orxonox/orxonox.conf" | 
|---|
| 20 |  | 
|---|
| 21 | typedef enum elState | 
|---|
| 22 |   { | 
|---|
| 23 |     ES_GAME, | 
|---|
| 24 |     ES_GAME_MENU, | 
|---|
| 25 |     ES_MENU, | 
|---|
| 26 |  | 
|---|
| 27 |     ES_NUMBER, | 
|---|
| 28 |   }; | 
|---|
| 29 |  | 
|---|
| 30 | //! Key aliasing structure | 
|---|
| 31 | /** | 
|---|
| 32 |    This structure contains the key aliasing information, e.g. the command strings that | 
|---|
| 33 |    have been bound to the keys. | 
|---|
| 34 | */ | 
|---|
| 35 | typedef struct | 
|---|
| 36 | { | 
|---|
| 37 |   char keys[N_STD_KEYS][CMD_LENGHT]; | 
|---|
| 38 |   char buttons[N_BUTTONS][CMD_LENGHT]; | 
|---|
| 39 | } KeyBindings; | 
|---|
| 40 |  | 
|---|
| 41 |  | 
|---|
| 42 | //! The one Event Handler from Orxonox | 
|---|
| 43 | class EventHandler : public BaseObject { | 
|---|
| 44 |  | 
|---|
| 45 |  public: | 
|---|
| 46 |   static EventHandler* getInstance(void); | 
|---|
| 47 |   virtual ~EventHandler(void); | 
|---|
| 48 |  | 
|---|
| 49 |   void setState(elState state); | 
|---|
| 50 |  | 
|---|
| 51 |   void subscribeListener(EventListener* el, elState state, int eventType); | 
|---|
| 52 |   void unsubscribeListener(EventListener* el, elState state); | 
|---|
| 53 |   void unsubscribeListener(int eventType, elState state); | 
|---|
| 54 |   void flush(); | 
|---|
| 55 |    | 
|---|
| 56 |   void loadKeyBindings(const char* fileName); | 
|---|
| 57 |  | 
|---|
| 58 |   void tick(float t); | 
|---|
| 59 |   void process(); | 
|---|
| 60 |  | 
|---|
| 61 |  private: | 
|---|
| 62 |   EventHandler(void); | 
|---|
| 63 |  | 
|---|
| 64 |   static EventHandler* singletonRef; | 
|---|
| 65 |  | 
|---|
| 66 |   KeyBindings* keyAliases; | 
|---|
| 67 |   EventListener*** listeners;                         //!< a list of registered listeners | 
|---|
| 68 |   elState state; | 
|---|
| 69 |  | 
|---|
| 70 | }; | 
|---|
| 71 |  | 
|---|
| 72 | #endif /* _EVENT_HANDLER_H */ | 
|---|
       
      
      Note: See 
TracBrowser
        for help on using the repository browser.