- Timestamp:
- May 28, 2005, 12:56:01 AM (20 years ago)
- Location:
- orxonox/trunk/src/util/event
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/trunk/src/util/event/event.h
r4350 r4352 8 8 #define _EVENT_H 9 9 10 #define CMD_LENGHT 1611 10 12 11 #include "base_object.h" 12 #include "event_def.h" 13 13 14 14 -
orxonox/trunk/src/util/event/event_handler.cc
r4350 r4352 19 19 #include "event_listener.h" 20 20 21 #include "ini_parser.h" 22 #include "keynames.h" 23 21 24 #include "SDL_keysym.h" 22 25 … … 29 32 EventHandler::EventHandler () 30 33 { 31 34 this->setClassID(CL_EVENT_HANDLER, "EventHandler"); 32 35 33 this->listeners = new EventListener*[SDLK_LAST]; 36 this->listeners = new EventListener**[ES_NUMBER]; 37 for(int i = 0; i < ES_NUMBER; ++i) 38 this->listeners[i] = new EventListener*[SDLK_LAST]; 34 39 } 35 40 … … 56 61 { 57 62 EventHandler::singletonRef = NULL; 63 } 58 64 65 66 /** 67 \brief loads new key bindings from a file 68 \param filename: The path and name of the file to load the bindings from 69 */ 70 void EventHandler::loadKeyBindings (const char* fileName) 71 { 72 FILE* stream; 73 74 PRINTF(4)("Loading key bindings from %s\n", fileName); 75 76 // remove old bindings if present 77 if( this->keyAliases != NULL) 78 { 79 free (this->keyAliases); 80 this->keyAliases = NULL; 81 } 82 83 // create parser 84 IniParser parser(fileName); 85 if( parser.getSection (CONFIG_SECTION_PLAYER "1") == -1) 86 { 87 PRINTF(1)("Could not find key bindings " CONFIG_SECTION_PLAYER"1 in %s\n", fileName); 88 return; 89 } 90 // allocate empty lookup table 91 this->keyAliases = (KeyBindings*) calloc (1, sizeof (KeyBindings)); 92 93 char namebuf[256]; 94 char valuebuf[256]; 95 memset (namebuf, 0, 256); 96 memset (valuebuf, 0, 256); 97 int* index; 98 99 while( parser.nextVar (namebuf, valuebuf) != -1) 100 { 101 //index = nameToIndex (valuebuf); 102 int c; 103 if( (c = keynameToSDLK (valuebuf)) != -1) 104 { 105 index[1] = c; index[0] = 0; 106 } 107 if( (c = buttonnameToSDLB (valuebuf)) != -1) 108 { 109 index[1] = c; index[0] = 1; 110 } 111 112 switch( index[0]) 113 { 114 case 0: 115 PRINTF(4)("Key binding %d(%s) set to %s\n", index[1], SDLKToKeyname( index[1]), namebuf); 116 strcpy (this->keyAliases->keys[index[1]], namebuf); 117 break; 118 case 1: 119 PRINTF(4)("Button binding %d(%s) set to %s\n", index[1], SDLBToButtonname( index[1]), namebuf); 120 strcpy (this->keyAliases->buttons[index[1]], namebuf); 121 break; 122 default: 123 break; 124 } 125 memset (namebuf, 0, 256); 126 memset (valuebuf, 0, 256); 127 } 128 129 130 // PARSE MISC SECTION 131 if( parser.getSection (CONFIG_SECTION_MISC_KEYS) == -1) 132 { 133 PRINTF(1)("Could not find key bindings in %s\n", fileName); 134 return; 135 } 136 137 while( parser.nextVar (namebuf, valuebuf) != -1) 138 { 139 //index = nameToIndex (valuebuf); 140 int c; 141 if( (c = keynameToSDLK (valuebuf)) != -1) 142 { 143 index[1] = c; index[0] = 0; 144 } 145 if( (c = buttonnameToSDLB (valuebuf)) != -1) 146 { 147 index[1] = c; index[0] = 1; 148 } 149 150 151 switch( index[0]) 152 { 153 case 0: 154 PRINTF(4)("Key binding %d(%s) set to %s\n", index[1], SDLKToKeyname( index[1]), namebuf); 155 strcpy (keyAliases->keys[index[1]], namebuf); 156 break; 157 case 1: 158 PRINTF(4)("Button binding %d(%s) set to %s\n", index[1], SDLBToButtonname( index[1]), namebuf); 159 strcpy (keyAliases->buttons[index[1]], namebuf); 160 break; 161 default: 162 break; 163 } 164 memset (namebuf, 0, 256); 165 memset (valuebuf, 0, 256); 166 } 59 167 } 168 -
orxonox/trunk/src/util/event/event_handler.h
r4350 r4352 9 9 10 10 #include "base_object.h" 11 #include "event_def.h" 11 12 12 13 class EventListener; 13 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" 14 20 15 21 typedef enum elState … … 21 27 ES_NUMBER, 22 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; 23 40 24 41 … … 39 56 40 57 void tick(float t); 58 void process(); 41 59 42 60 private: 43 61 EventHandler(void); 62 44 63 static EventHandler* singletonRef; 45 64 46 EventListener** listeners; //!< a list of registered listeners 65 KeyBindings* keyAliases; 66 EventListener*** listeners; //!< a list of registered listeners 47 67 48 68 }; -
orxonox/trunk/src/util/event/event_listener.h
r4346 r4352 9 9 10 10 #include "base_object.h" 11 #include "event_def.h" 11 12 12 13
Note: See TracChangeset
for help on using the changeset viewer.