Changeset 3625 in orxonox.OLD for orxonox/trunk/src/lib
- Timestamp:
- Mar 22, 2005, 1:37:59 AM (20 years ago)
- Location:
- orxonox/trunk/src/lib/gui/gui
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/trunk/src/lib/gui/gui/orxonox_gui.cc
r3423 r3625 95 95 96 96 // Reading Values from File 97 exec->set Filename("~/.orxonox.conf");97 exec->setConfFile("~/.orxonox/orxonox.conf"); 98 98 exec->readFromFile(orxonoxGUI); 99 99 // Merging changes to the Options from appended flags. -
orxonox/trunk/src/lib/gui/gui/orxonox_gui_exec.cc
r3423 r3625 25 25 26 26 #include "orxonox_gui_exec.h" 27 27 28 #include <iostream> 28 29 #include <string> 30 31 #include <sys/stat.h> 32 #include <sys/types.h> 33 29 34 30 35 HashTable* orxonoxFlagHash; … … 50 55 this->saveSettings->saveability(); 51 56 this->execBox->fill(this->saveSettings); 52 this->verboseMode = new Menu("verbose mode", "no output", "error", "warning", "info", "lastItem");57 this->verboseMode = new Menu("verbose mode", "nothing", "error", "warning", "info", "lastItem"); 53 58 this->verboseMode->setFlagName("verbose", "v", 0); 54 59 this->verboseMode->saveability(); … … 90 95 91 96 /** 97 \brief sets the confDir and File-name out of an input-string 98 */ 99 void OrxonoxGuiExec::setConfFile(char* confFile) 100 { 101 char splitter = 102 #ifdef __WIN32__ 103 '\\'; 104 #else 105 '/'; 106 #endif 107 char* tmpConfFile = new char[strlen(confFile)+1]; 108 strcpy(tmpConfFile, confFile); 109 char* tmp = strrchr(tmpConfFile, splitter); 110 if (tmp) 111 { 112 tmp[0] = '\0'; 113 this->setConfDir(tmpConfFile); 114 this->setFileName(tmp+1); 115 } 116 else 117 { 118 this->setConfDir("~/"); 119 this->setFileName(tmpConfFile); 120 } 121 delete []tmp; 122 delete []tmpConfFile; 123 } 124 125 /** 126 \brief sets the Directory of the configuration files 127 \param confDir the Directory for the configuration files 128 */ 129 void OrxonoxGuiExec::setConfDir(char* confDir) 130 { 131 if (!strncmp(confDir, "~/", 2)) 132 { 133 char tmp[500]; 134 #ifdef __WIN32__ 135 strcpy(tmp, getenv("USERPROFILE")); 136 #else 137 strcpy(tmp, getenv("HOME")); 138 #endif 139 this->confDir = new char[strlen(tmp)+strlen(confDir)]; 140 sprintf(this->confDir, "%s%s", tmp, confDir+1); 141 } 142 else 143 { 144 this->confDir = new char[strlen(confDir)+1]; 145 strcpy(this->confDir, confDir); 146 } 147 PRINTF(3)("Config Directory is: %s.\n", this->confDir); 148 mkdir(this->confDir, 0755); 149 } 150 151 /** 92 152 \brief Sets the location of the configuration File. 93 \param file name the location of the configFile153 \param fileName the location of the configFile 94 154 95 155 \todo: memory allocation could be better. … … 97 157 The name will be parsed from ~/ to /home/[username] on unix and c:/Documents and Settings/username/Settings/ on Windows 98 158 */ 99 void OrxonoxGuiExec::setFilename(char* filename) 100 { 101 char* buffer = (char*)malloc(2048*sizeof(char)); 102 sprintf(buffer, "%s", filename); 103 if(!strncmp(buffer, "~/", 2)) 104 { 105 #ifdef __WIN32__ 106 sprintf(configFile, "%s/%s", getenv("USERPROFILE"), buffer+2); 107 #else 108 sprintf(configFile, "%s/%s", getenv("HOME"), buffer+2); 109 #endif 110 } 111 else if(buffer) 112 strcpy(this->configFile, buffer); 113 free (buffer); 159 void OrxonoxGuiExec::setFileName(char* fileName) 160 { 161 if (!this->confDir) 162 this->setConfDir("~/"); 163 this->configFile = new char[strlen(this->confDir)+strlen(fileName)+2]; 164 sprintf(this->configFile, "%s/%s", this->confDir, fileName); 165 PRINTF(3)("ConfigurationFile is %s.\n", this->configFile); 114 166 } 115 167 … … 117 169 \returns The name of the Configuration-File 118 170 */ 119 char* OrxonoxGuiExec::getConfigFile(void) 171 char* OrxonoxGuiExec::getConfigFile(void) const 120 172 { 121 173 return this->configFile; … … 190 242 space2under[0] = '_'; 191 243 } 192 if(widget->isOption <=3) 193 fprintf(CONFIG_FILE, "%s = %d\n", Buffer, static_cast<Option*>(widget)->value); 194 else if(widget->isOption == 5) 195 fprintf(CONFIG_FILE, "%s = %s\n", Buffer, static_cast<OptionLabel*>(widget)->cValue); 244 fprintf(CONFIG_FILE, "%s = %s\n", Buffer, static_cast<Option*>(widget)->save()); 196 245 } 197 246 … … 259 308 { 260 309 PRINT(3)("Located Option %s.\n", widget->title); 261 if(widget->isOption >= 1 && widget->isOption <= 3) 262 { 263 static_cast<Option*>(widget)->value = atoi(info->variableValue); 264 static_cast<Option*>(widget)->redraw(); //!< \todo change this to setValue. 265 } 266 else if(widget->isOption == 5) 267 static_cast<OptionLabel*>(widget)->setValue(info->variableValue); 310 if(widget->isOption >= 1) 311 static_cast<Option*>(widget)->load(info->variableValue); 268 312 } 269 313 } -
orxonox/trunk/src/lib/gui/gui/orxonox_gui_exec.h
r3452 r3625 22 22 CheckButton* alwaysShow; //!< A CheckButton, for if orxonox should start with or without gui. 23 23 Button* quit; //!< A Button to quit the Gui without starting orxonox. 24 char* confDir; //!< The directory of the orxonox-configuration-files. 24 25 char* configFile; //!< The name of the .orxonox.conf(ig)-file. 25 26 FILE* CONFIG_FILE; //!< Filehandler for reading and writing. … … 37 38 38 39 Widget* getWidget(void); 39 40 void setFilename(char* filename); 41 char* getConfigFile(void); 40 41 void setConfFile(char* confFile); 42 void setConfDir(char* confDir); 43 void setFileName(char* fileName); 44 char* getConfigFile(void) const; 42 45 int shouldsave(void); 43 46 void writeToFile(Widget* widget); -
orxonox/trunk/src/lib/gui/gui/orxonox_gui_gtk.cc
r3624 r3625 1032 1032 1033 1033 /** 1034 \brief saves an Option 1035 \returns the String that should be saved. 1036 1037 this is a default Option save 1038 */ 1039 char* Option::save(void) 1040 { 1041 char* value = new char [10]; 1042 sprintf (value, "%d", this->value); 1043 return value; 1044 } 1045 1046 /** 1047 \brief loads an Option from of its loadString 1048 \param loadString the string from which to load the data from 1049 */ 1050 void Option::load(char* loadString) 1051 { 1052 this->value = atoi(loadString); 1053 PRINT(3)("Loading %s: %s %d\n", this->title, loadString, value); 1054 this->redraw(); 1055 } 1056 1057 /** 1034 1058 \returns The saveable-state. 1035 1059 */ … … 1319 1343 this->init(); 1320 1344 this->setTitle(menuname); 1321 1345 va_list itemlist; //!< The list to readin multiple Options. 1346 1322 1347 char *itemName; 1323 1348 … … 1371 1396 1372 1397 /** 1398 \brief saves the Label of the Menu 1399 \returns the name of the selected Menu-Item 1400 */ 1401 char* Menu::save(void) 1402 { 1403 MenuItem* tmpItem = this->firstItem; 1404 for (int i = 0; i<this->value; i++) 1405 tmpItem = tmpItem->next; 1406 1407 return tmpItem->name; 1408 } 1409 1410 /** 1411 \brief loads a Menu from of its loadString 1412 \param loadString the string from which to load the data from 1413 */ 1414 void Menu::load(char* loadString) 1415 { 1416 MenuItem* tmpItem = firstItem; 1417 bool foundItem = false; 1418 while (tmpItem) 1419 { 1420 if (!strcmp(loadString, tmpItem->name)) 1421 {foundItem = true; break;} 1422 tmpItem = tmpItem->next; 1423 } 1424 if (foundItem) 1425 this->value = tmpItem->itemNumber; 1426 else 1427 { 1428 this->value = 0; 1429 PRINTF(2)("Sorry, but %s has not been found in the Itemlist of %s\n", loadString, this->title); 1430 } 1431 PRINTF(3)( "Loading %s: setting to %d\n", this->title, this->value); 1432 this->redraw(); 1433 } 1434 1435 /** 1373 1436 \brief appends a new Item to the Menu-List. 1374 1437 \param itemName the itemName to be appendet. … … 1377 1440 { 1378 1441 if (!this->firstItem) 1379 this->firstItem = this->currItem = new MenuItem; 1442 { 1443 this->firstItem = this->currItem = new MenuItem; 1444 this->currItem->itemNumber = 0; 1445 } 1380 1446 else 1381 this->currItem = this->currItem->next = new MenuItem; 1447 { 1448 int tmpI = this->currItem->itemNumber; 1449 this->currItem = this->currItem->next = new MenuItem; 1450 this->currItem->itemNumber = tmpI+1; 1451 } 1382 1452 1383 1453 this->currItem->name = new char[strlen(itemName)+1]; 1384 1454 strcpy(this->currItem->name, itemName); 1455 1385 1456 #ifdef HAVE_GTK2 1386 1457 this->currItem->item = gtk_menu_item_new_with_label(itemName); … … 1499 1570 1500 1571 /** 1572 \brief creates the Optionlabel save-string 1573 \returns the String to save. 1574 */ 1575 char* OptionLabel::save(void) 1576 { 1577 return cValue; 1578 } 1579 1580 /** 1581 \brief loads an Option from of its loadString 1582 \param loadString the string from which to load the data from 1583 */ 1584 void OptionLabel::load(char* loadString) 1585 { 1586 PRINTF(3)( "Loading %s: setting to %s\n", this->title, loadString); 1587 this->setValue(loadString); 1588 } 1589 1590 /** 1501 1591 \brief Creates a new default Label with no Text. 1502 1592 You migth consider adding Label::setTitle with this. -
orxonox/trunk/src/lib/gui/gui/orxonox_gui_gtk.h
r3624 r3625 217 217 void saveability(void); 218 218 void saveability(bool isSaveable); 219 virtual char* save(void); 220 virtual void load(char* loadString); 221 219 222 bool isSaveable(void); 220 223 void setFlagName(char* flagname, int defaultvalue); … … 286 289 GtkWidget* menu; //!< The menu That will hold the Options. 287 290 #endif /* HAVE_GTK2 */ 288 va_list itemlist; //!< The list to readin multiple Options. 289 291 290 292 //! A struct to handle the MenuItems 291 293 struct MenuItem 292 294 { 293 char* name; //!< The name of this entry. 295 char* name; //!< The name of this entry. 296 int itemNumber; //!< The n'th entry of this menu; 294 297 #ifdef HAVE_GTK2 295 298 GtkWidget* item; //!< One Item From a Menu. … … 305 308 virtual ~Menu(void); 306 309 void init(void); 310 311 virtual char* save(void); 312 virtual void load(char* loadString); 307 313 308 314 void addItem(char* itemName); … … 322 328 323 329 void setValue(char* newValue); 330 331 virtual char* save(void); 332 virtual void load(char* loadString); 333 324 334 void redraw(void); 325 335 void changeOption(void);
Note: See TracChangeset
for help on using the changeset viewer.