Changeset 4369 in orxonox.OLD for orxonox/trunk/src/util/event
- Timestamp:
- May 28, 2005, 4:18:58 PM (20 years ago)
- Location:
- orxonox/trunk/src/util/event
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/trunk/src/util/event/event_handler.cc
r4366 r4369 74 74 } 75 75 76 77 /**78 \brief loads new key bindings from a file79 \param filename: The path and name of the file to load the bindings from80 */81 void EventHandler::loadKeyBindings (const char* fileName)82 {83 FILE* stream;84 85 PRINTF(4)("Loading key bindings from %s\n", fileName);86 87 // remove old bindings if present88 if( this->keyAliases != NULL)89 {90 free (this->keyAliases);91 this->keyAliases = NULL;92 }93 94 // create parser95 IniParser parser(fileName);96 if( parser.getSection (CONFIG_SECTION_PLAYER "1") == -1)97 {98 PRINTF(1)("Could not find key bindings " CONFIG_SECTION_PLAYER"1 in %s\n", fileName);99 return;100 }101 // allocate empty lookup table102 this->keyAliases = (KeyBindings*) calloc (1, sizeof (KeyBindings));103 104 char namebuf[256];105 char valuebuf[256];106 memset (namebuf, 0, 256);107 memset (valuebuf, 0, 256);108 int* index;109 110 while( parser.nextVar (namebuf, valuebuf) != -1)111 {112 //index = nameToIndex (valuebuf);113 int c;114 if( (c = keynameToSDLK (valuebuf)) != -1)115 {116 index[1] = c; index[0] = 0;117 }118 if( (c = buttonnameToSDLB (valuebuf)) != -1)119 {120 index[1] = c; index[0] = 1;121 }122 123 switch( index[0])124 {125 case 0:126 PRINTF(4)("Key binding %d(%s) set to %s\n", index[1], SDLKToKeyname( index[1]), namebuf);127 strcpy (this->keyAliases->keys[index[1]], namebuf);128 break;129 case 1:130 PRINTF(4)("Button binding %d(%s) set to %s\n", index[1], SDLBToButtonname( index[1]), namebuf);131 strcpy (this->keyAliases->buttons[index[1]], namebuf);132 break;133 default:134 break;135 }136 memset (namebuf, 0, 256);137 memset (valuebuf, 0, 256);138 }139 140 141 // PARSE MISC SECTION142 if( parser.getSection (CONFIG_SECTION_MISC_KEYS) == -1)143 {144 PRINTF(1)("Could not find key bindings in %s\n", fileName);145 return;146 }147 148 while( parser.nextVar (namebuf, valuebuf) != -1)149 {150 //index = nameToIndex (valuebuf);151 int c;152 if( (c = keynameToSDLK (valuebuf)) != -1)153 {154 index[1] = c; index[0] = 0;155 }156 if( (c = buttonnameToSDLB (valuebuf)) != -1)157 {158 index[1] = c; index[0] = 1;159 }160 161 162 switch( index[0])163 {164 case 0:165 PRINTF(4)("Key binding %d(%s) set to %s\n", index[1], SDLKToKeyname( index[1]), namebuf);166 strcpy (keyAliases->keys[index[1]], namebuf);167 break;168 case 1:169 PRINTF(4)("Button binding %d(%s) set to %s\n", index[1], SDLBToButtonname( index[1]), namebuf);170 strcpy (keyAliases->buttons[index[1]], namebuf);171 break;172 default:173 break;174 }175 memset (namebuf, 0, 256);176 memset (valuebuf, 0, 256);177 }178 }179 76 180 77 -
orxonox/trunk/src/util/event/event_handler.h
r4368 r4369 40 40 void unsubscribeListener(int eventType, elState state); 41 41 void flush(elState state); 42 43 void loadKeyBindings(const char* fileName);44 42 45 43 void tick(float t); -
orxonox/trunk/src/util/event/key_mapper.cc
r4367 r4369 40 40 // delete what has to be deleted here 41 41 } 42 43 44 /** 45 \brief loads new key bindings from a file 46 \param filename: The path and name of the file to load the bindings from 47 */ 48 void KeyMapper::loadKeyBindings (const char* fileName) 49 { 50 FILE* stream; 51 52 PRINTF(4)("Loading key bindings from %s\n", fileName); 53 54 // remove old bindings if present 55 if( this->keyAliases != NULL) 56 { 57 free (this->keyAliases); 58 this->keyAliases = NULL; 59 } 60 61 // create parser 62 IniParser parser(fileName); 63 if( parser.getSection (CONFIG_SECTION_PLAYER "1") == -1) 64 { 65 PRINTF(1)("Could not find key bindings " CONFIG_SECTION_PLAYER"1 in %s\n", fileName); 66 return; 67 } 68 // allocate empty lookup table 69 this->keyAliases = (KeyBindings*) calloc (1, sizeof (KeyBindings)); 70 71 char namebuf[256]; 72 char valuebuf[256]; 73 memset (namebuf, 0, 256); 74 memset (valuebuf, 0, 256); 75 int* index; 76 77 while( parser.nextVar (namebuf, valuebuf) != -1) 78 { 79 //index = nameToIndex (valuebuf); 80 int c; 81 if( (c = keynameToSDLK (valuebuf)) != -1) 82 { 83 index[1] = c; index[0] = 0; 84 } 85 if( (c = buttonnameToSDLB (valuebuf)) != -1) 86 { 87 index[1] = c; index[0] = 1; 88 } 89 90 switch( index[0]) 91 { 92 case 0: 93 PRINTF(4)("Key binding %d(%s) set to %s\n", index[1], SDLKToKeyname( index[1]), namebuf); 94 strcpy (this->keyAliases->keys[index[1]], namebuf); 95 break; 96 case 1: 97 PRINTF(4)("Button binding %d(%s) set to %s\n", index[1], SDLBToButtonname( index[1]), namebuf); 98 strcpy (this->keyAliases->buttons[index[1]], namebuf); 99 break; 100 default: 101 break; 102 } 103 memset (namebuf, 0, 256); 104 memset (valuebuf, 0, 256); 105 } 106 107 108 // PARSE MISC SECTION 109 if( parser.getSection (CONFIG_SECTION_MISC_KEYS) == -1) 110 { 111 PRINTF(1)("Could not find key bindings in %s\n", fileName); 112 return; 113 } 114 115 while( parser.nextVar (namebuf, valuebuf) != -1) 116 { 117 //index = nameToIndex (valuebuf); 118 int c; 119 if( (c = keynameToSDLK (valuebuf)) != -1) 120 { 121 index[1] = c; index[0] = 0; 122 } 123 if( (c = buttonnameToSDLB (valuebuf)) != -1) 124 { 125 index[1] = c; index[0] = 1; 126 } 127 128 129 switch( index[0]) 130 { 131 case 0: 132 PRINTF(4)("Key binding %d(%s) set to %s\n", index[1], SDLKToKeyname( index[1]), namebuf); 133 strcpy (keyAliases->keys[index[1]], namebuf); 134 break; 135 case 1: 136 PRINTF(4)("Button binding %d(%s) set to %s\n", index[1], SDLBToButtonname( index[1]), namebuf); 137 strcpy (keyAliases->buttons[index[1]], namebuf); 138 break; 139 default: 140 break; 141 } 142 memset (namebuf, 0, 256); 143 memset (valuebuf, 0, 256); 144 } 145 }
Note: See TracChangeset
for help on using the changeset viewer.