Changeset 5020 in orxonox.OLD for orxonox/trunk/src
- Timestamp:
- Aug 14, 2005, 11:44:49 PM (19 years ago)
- Location:
- orxonox/trunk/src/lib
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/trunk/src/lib/gui/gui_keys.cc
r4836 r5020 1 /* 1 /* 2 2 orxonox - the future of 3D-vertical-scrollers 3 3 … … 16 16 You should have received a copy of the GNU General Public License 17 17 along with this program; if not, write to the Free Software Foundation, 18 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 19 20 20 … … 38 38 { 39 39 Box* keysBox0; //!< The Frame that holds the keyOptions. 40 40 41 41 // keysFrame->setGroupName("Keyboard"); 42 42 keysBox0 = new Box('v'); … … 47 47 keysBox1 = new Box('h'); 48 48 { 49 50 51 52 53 54 55 56 49 PlayerKeys* player1; //!< The first Player's keys. 50 PlayerKeys* player2; //!< The seconds Player's keys. 51 52 player1 = new PlayerKeys(CONFIG_SECTION_PLAYER "1"); 53 player2 = new PlayerKeys(CONFIG_SECTION_PLAYER "2"); 54 55 keysBox1->fill(player1->getOpenButton()); 56 keysBox1->fill(player2->getOpenButton()); 57 57 } 58 58 keysBox0->fill(keysBox1); … … 63 63 keysFrame->fill(keysBox0); 64 64 } 65 65 66 66 // setting up the Input Windows that receives keystrokes. 67 67 this->inputWindow = new Window("inputWindow"); … … 72 72 #endif /* HAVE_GTK2 */ 73 73 this->inputWindow->fill(inputButton); 74 74 75 75 this->setMainWidget(keysFrame); 76 76 } … … 112 112 pKeysBox = new Box('v'); 113 113 { 114 115 116 117 118 119 120 121 122 123 124 125 #ifdef HAVE_GTK2 126 127 #endif /* HAVE_GTK2 */ 128 129 114 Button* closeButton; //!< The CloseButton for this key-settings. 115 116 pKeysBox->setGroupName(player); 117 pKeysBox->fill(addKey(CONFIG_NAME_PLAYER_UP, "UP")); 118 pKeysBox->fill(addKey(CONFIG_NAME_PLAYER_DOWN, "DOWN")); 119 pKeysBox->fill(addKey(CONFIG_NAME_PLAYER_LEFT, "LEFT")); 120 pKeysBox->fill(addKey(CONFIG_NAME_PLAYER_RIGHT, "RIGHT")); 121 pKeysBox->fill(addKey(CONFIG_NAME_PLAYER_FIRE, "SPACE")); 122 pKeysBox->fill(addKey(CONFIG_NAME_PLAYER_NEXT_WEAPON, "m")); 123 pKeysBox->fill(addKey(CONFIG_NAME_PLAYER_PREV_WEAPON, "n")); 124 closeButton = new Button("close"); 125 #ifdef HAVE_GTK2 126 closeButton->connectSignal("button_press_event", pKeyWindow, Window::windowClose); 127 #endif /* HAVE_GTK2 */ 128 129 pKeysBox->fill(closeButton); 130 130 } 131 131 pKeyFrame->fill(pKeysBox); … … 139 139 pKeyWindow->connectSignal("delete_event", pKeyWindow, Window::windowClose); 140 140 #endif /* HAVE_GTK2 */ 141 141 142 142 this->openButton = new Button(player); 143 143 #ifdef HAVE_GTK2 … … 174 174 keysBox = new Box('v'); 175 175 { 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 #ifdef HAVE_GTK2 192 193 #endif /* HAVE_GTK2 */ 194 195 176 Button* closeButton; //!< The CloseButton for this key-settings. 177 178 keysBox->setGroupName(CONFIG_SECTION_MISC_KEYS); 179 keysBox->fill(addKey(CONFIG_NAME_QUIT , "ESCAPE")); 180 keysBox->fill(addKey(CONFIG_NAME_PAUSE, "PAUSE")); 181 keysBox->fill(addKey(CONFIG_NAME_NEXT_WORLD, "x")); 182 keysBox->fill(addKey(CONFIG_NAME_PREV_WORLD, "z")); 183 keysBox->fill(addKey(CONFIG_NAME_VIEW0, "1")); 184 keysBox->fill(addKey(CONFIG_NAME_VIEW1, "2")); 185 keysBox->fill(addKey(CONFIG_NAME_VIEW2, "3")); 186 keysBox->fill(addKey(CONFIG_NAME_VIEW3, "4")); 187 keysBox->fill(addKey(CONFIG_NAME_VIEW4, "5")); 188 keysBox->fill(addKey(CONFIG_NAME_VIEW5, "6")); 189 190 closeButton = new Button("close"); 191 #ifdef HAVE_GTK2 192 closeButton->connectSignal("button_press_event", keyWindow, Window::windowClose); 193 #endif /* HAVE_GTK2 */ 194 195 keysBox->fill(closeButton); 196 196 } 197 197 keyFrame->fill(keysBox); … … 204 204 keyWindow->connectSignal("delete_event", keyWindow, Window::windowClose); 205 205 #endif /* HAVE_GTK2 */ 206 206 207 207 this->openButton = new Button("misc"); 208 208 #ifdef HAVE_GTK2 … … 254 254 GuiKeys::inputWindow->open(); 255 255 } 256 256 257 257 /** 258 258 * Function which gets keystrokes … … 281 281 strcpy(title, "RIGHT"); 282 282 break; 283 283 284 284 case GDK_space: 285 285 strcpy(title, "SPACE"); 286 286 break; 287 287 288 288 case GDK_Return: 289 289 strcpy(title, "RETURN"); 290 290 break; 291 291 292 292 // Special Keys // 293 293 case GDK_BackSpace: … … 361 361 strcpy(title, "INSERT"); 362 362 break; 363 363 364 364 case GDK_Escape: 365 365 strcpy(title, "ESCAPE"); … … 423 423 strcpy(title, "F12"); 424 424 break; 425 426 425 426 427 427 default: 428 428 char* tmp; -
orxonox/trunk/src/lib/util/ini_parser.cc
r5019 r5020 34 34 { 35 35 this->setClassID(CL_INI_PARSER, "IniParser"); 36 this->setName(fileName);37 36 38 37 this->currentEntry = NULL; … … 84 83 this->currentSection = NULL; 85 84 this->sections = NULL; 85 this->setName(NULL); 86 86 } 87 87 … … 98 98 if( fileName == NULL) 99 99 return false; 100 101 printf("1\n"); 100 this->setName(fileName); 101 102 102 if( (stream = fopen (fileName, "r")) == NULL) 103 103 { … … 107 107 else 108 108 { 109 printf("2\n");110 109 this->currentEntry = NULL; 111 110 this->currentSection = NULL; … … 134 133 { 135 134 *ptr = 0; 136 IniSection* newSection = new IniSection; 137 newSection->name = new char[strlen(buffer)+1]; 138 strcpy(newSection->name, buffer); 139 newSection->entries = new tList<IniEntry>; 140 this->currentSection = newSection; 141 this->sections->add(newSection); 135 this->addSection(buffer); 142 136 } 143 137 } … … 163 157 nameEnd[1] = '\0'; 164 158 165 IniEntry* newEntry = new IniEntry; 166 newEntry->value = new char[strlen(valueBegin)+1]; 167 strcpy(newEntry->value, valueBegin); 168 newEntry->name = new char[strlen (nameBegin)+1]; 169 strcpy(newEntry->name, nameBegin); 170 171 this->currentSection->entries->add(newEntry); 159 this->addVar(nameBegin, valueBegin); 172 160 } 173 161 } … … 175 163 fclose(stream); 176 164 return true; 165 } 166 167 /** 168 * opens a file and writes to it 169 * @param fileName: path and name of the new file to write to 170 * @return true on success false otherwise 171 */ 172 bool IniParser::writeFile(const char* fileName) 173 { 174 FILE* stream; //!< The stream we use to read the file. 175 if (sections != NULL) 176 deleteSections(); 177 if( fileName == NULL) 178 return false; 179 180 if( (stream = fopen (fileName, "w")) == NULL) 181 { 182 PRINTF(1)("IniParser could not open %s\n", fileName); 183 return false; 184 } 185 else 186 { 187 if (this->sections) 188 { 189 tIterator<IniSection>* sectionIt = this->sections->getIterator(); 190 IniSection* sectionEnum = sectionIt->nextElement(); 191 while (sectionEnum) 192 { 193 fprintf(stream, " [%s]\n", sectionEnum->name); 194 195 tIterator<IniEntry>* entryIt = sectionEnum->entries->getIterator(); 196 IniEntry* entryEnum = entryIt->nextElement(); 197 while (entryEnum) 198 { 199 fprintf(stream, " %s = %s\n", entryEnum->name, entryEnum->value); 200 201 entryEnum = entryIt->nextElement(); 202 } 203 delete entryIt; 204 205 sectionEnum = sectionIt->nextElement(); 206 } 207 delete sectionIt; 208 } 209 else 210 PRINTF(1)("%s no sections defined yet\n", fileName); 211 } 212 fclose(stream); 213 } 214 215 bool IniParser::addSection(const char* sectionName) 216 { 217 if (this->sections == NULL) 218 this->sections = new tList<IniSection>; 219 220 IniSection* newSection = new IniSection; 221 newSection->name = new char[strlen(sectionName)+1]; 222 strcpy(newSection->name, sectionName); 223 newSection->entries = new tList<IniEntry>; 224 this->currentSection = newSection; 225 this->sections->add(newSection); 177 226 } 178 227 … … 269 318 else 270 319 return true; 320 } 321 322 /** 323 * adds a new Entry to either the currentSection or the section called by sectionName 324 * @param entryName the Name of the Entry to add 325 * @param value the value to assign to this entry 326 * @param sectionName if NULL then this entry will be set to the currentSection 327 * otherwise to the section refered to by sectionName. 328 * If both are NULL no entry will be added 329 * @return true if everything is ok false on error 330 */ 331 bool IniParser::addVar(const char* entryName, const char* value, const char* sectionName) 332 { 333 IniSection* addSection = NULL; 334 if (sectionName != NULL) 335 { 336 tIterator<IniSection>* sectionIt = this->sections->getIterator(); 337 IniSection* sectionEnum = sectionIt->nextElement(); 338 while (sectionEnum) 339 { 340 if (!strcmp(sectionEnum->name, sectionName)) 341 { 342 addSection = sectionEnum; 343 break; 344 } 345 sectionEnum = sectionIt->nextElement(); 346 } 347 delete sectionIt; 348 } 349 else 350 addSection = this->currentSection; 351 352 if (addSection == NULL) 353 { 354 PRINTF(2)("section not found for value %s\n", entryName); 355 return false; 356 } 357 else 358 { 359 IniEntry* newEntry = new IniEntry; 360 newEntry->name = new char[strlen (entryName)+1]; 361 strcpy(newEntry->name, entryName); 362 newEntry->value = new char[strlen(value)+1]; 363 strcpy(newEntry->value, value); 364 this->currentSection->entries->add(newEntry); 365 return true; 366 } 271 367 } 272 368 … … 277 373 * @param defaultValue: what should be returned in case the entry cannot be found 278 374 * @return a pointer to a buffer conatining the value of the specified entry. This buffer will contain the data specified in defvalue in case the entry wasn't found 279 280 The returned pointer points to an internal buffer, so do not free it on your own. Do not give a NULL pointer to defvalue, this will certainly281 375 * 376 * The returned pointer points to an internal buffer, so do not free it on your own. Do not give a NULL pointer to defvalue, this will certainly 377 * lead to unwanted behaviour. 282 378 */ 283 379 const char* IniParser::getVar(const char* entryName, const char* sectionName, const char* defaultValue) const -
orxonox/trunk/src/lib/util/ini_parser.h
r5018 r5020 42 42 ~IniParser (); 43 43 44 bool readFile(const char* name); 44 bool readFile(const char* fileName); 45 bool writeFile(const char* fileName); 45 46 47 bool addSection(const char* sectionName); 46 48 bool getSection(const char* sectionName); 47 49 … … 52 54 bool isOpen() const { return (sections != NULL)?true:false; }; 53 55 56 bool addVar(const char* entryName, const char* value, const char* sectionName = NULL); 54 57 const char* getVar(const char* entryName, const char* sectionName, const char* defaultValue = "") const; 55 58
Note: See TracChangeset
for help on using the changeset viewer.