Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 3464 in orxonox.OLD for orxonox/branches/updater/src


Ignore:
Timestamp:
Mar 9, 2005, 2:41:38 PM (20 years ago)
Author:
bensch
Message:

orxonox/branches/updater: made the loading and saving more modular.
thanks to patrick I now know the real meaning of virtual members.

Location:
orxonox/branches/updater/src/gui
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • orxonox/branches/updater/src/gui/orxonox_gui_exec.cc

    r3379 r3464  
    5050  this->saveSettings->saveability();
    5151  this->execBox->fill(this->saveSettings);
    52   this->verboseMode = new Menu("verbose mode", "no output", "error", "warning", "info", "lastItem");
     52  this->verboseMode = new Menu("verbose mode", "nothing", "error", "warning", "info", "lastItem");
    5353  this->verboseMode->setFlagName("verbose", "v", 0);
    5454  this->verboseMode->saveability();
     
    190190            space2under[0] = '_';
    191191          }
    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);
     192          fprintf(CONFIG_FILE, "%s = %s\n", Buffer, static_cast<Option*>(widget)->save());
    196193      }
    197194
     
    259256    {
    260257      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);
     258      if(widget->isOption >= 1)
     259          static_cast<Option*>(widget)->load(info->variableValue);
    268260    }
    269261}
  • orxonox/branches/updater/src/gui/orxonox_gui_gtk.cc

    r3316 r3464  
    11231123
    11241124/**
     1125   \brief saves an Option
     1126   \returns the String that should be saved.
     1127
     1128   this is a default Option save
     1129*/
     1130char* Option::save(void)
     1131{
     1132  char* value = new char [10];
     1133  sprintf (value, "%d", this->value);
     1134  return value;
     1135}
     1136
     1137/**
     1138   \brief loads an Option from of its loadString
     1139   \param loadString the string from which to load the data from
     1140*/
     1141void Option::load(char* loadString)
     1142{
     1143  this->value = atoi(loadString);
     1144  printf( "Loading %s: %s %d\n", this->title, loadString, value);
     1145  this->redraw();
     1146}
     1147
     1148/**
    11251149   \returns The saveable-state.
    11261150*/
     
    14481472  this->init();
    14491473  this->setTitle(menuname);
    1450    
     1474  va_list itemlist;                     //!< The list to readin multiple Options.
     1475
    14511476  char *itemName;
    14521477
     
    14801505{
    14811506  this->isOption = 2;
     1507  this->firstItem = NULL;
    14821508
    14831509  static_cast<Option*>(this)->init();
     
    14891515
    14901516}
    1491 
    14921517/**
    14931518   \brief Destroys a Menu.
     
    15001525    PRINTF(3)("deleting the Menu.\n");
    15011526  //! \todo destroy menu
     1527
     1528  // deleting all the items
     1529  Item* tmpItem = this->firstItem;
     1530  while(tmpItem)
     1531    {
     1532      delete []tmpItem->label;
     1533     
     1534      tmpItem = tmpItem->next;
     1535    }
    15021536 
    15031537  static_cast<Option*>(this)->destroy();
    15041538}
    15051539
     1540/**
     1541   \brief saves the Label of the Menu
     1542   \returns the name of the selected Menu-Item
     1543*/
     1544char* Menu::save(void)
     1545{
     1546  Item* tmpItem = this->firstItem;
     1547  for (int i = 0; i<this->value; i++)
     1548    tmpItem = tmpItem->next;
     1549     
     1550  return tmpItem->label;
     1551}
     1552
     1553/**
     1554   \brief loads a Menu from of its loadString
     1555   \param loadString the string from which to load the data from
     1556*/
     1557void Menu::load(char* loadString)
     1558{
     1559  Item* tmpItem = firstItem;
     1560  bool foundItem = false;
     1561  while (tmpItem)
     1562    {
     1563      if (!strcmp(loadString, tmpItem->label))
     1564        {foundItem = true; break;}
     1565      tmpItem = tmpItem->next;
     1566    }
     1567  if (foundItem)
     1568    this->value = tmpItem->itemNumber;
     1569  else
     1570    {
     1571      this->value = 0;
     1572      PRINTF(2)("Sorry, but %s has not been found in the Itemlist of %s\n", loadString, this->title);
     1573    }
     1574  PRINTF(3)( "Loading %s: setting to %d\n", this->title, this->value);
     1575  this->redraw();
     1576}
    15061577
    15071578/**
     
    15251596void Menu::addItem(char* itemName)
    15261597{
    1527 #ifdef HAVE_GTK2
    1528   this->item = gtk_menu_item_new_with_label(itemName);
    1529   gtk_menu_shell_append(GTK_MENU_SHELL(this->menu), this->item);
     1598  Item* tmpItem;
     1599  int i = 0;
     1600  if (!this->firstItem)
     1601    {
     1602      tmpItem = this->firstItem = new Item;
     1603    }
     1604  else
     1605    {
     1606      ++i;
     1607      tmpItem = this->firstItem;
     1608      while (tmpItem->next)
     1609        {
     1610          ++i;
     1611          tmpItem = tmpItem->next;
     1612        }
     1613      tmpItem = tmpItem->next = new Item;
     1614    }
     1615  tmpItem->next = NULL;
     1616  tmpItem->itemNumber = i;
     1617  tmpItem->label = new char[strlen(itemName)+1];
     1618  strcpy(tmpItem->label, itemName);
     1619#ifdef HAVE_GTK2
     1620  tmpItem->item = gtk_menu_item_new_with_label(itemName);
     1621  gtk_menu_shell_append(GTK_MENU_SHELL(this->menu), tmpItem->item);
    15301622#endif /* HAVE_GTK2 */
    15311623}
     
    16661758
    16671759/**
     1760   \brief creates the Optionlabel save-string
     1761   \returns the String to save.
     1762*/
     1763char* OptionLabel::save(void)
     1764{
     1765  return cValue;
     1766}
     1767
     1768/**
     1769   \brief loads an Option from of its loadString
     1770   \param loadString the string from which to load the data from
     1771*/
     1772void OptionLabel::load(char* loadString)
     1773{
     1774  PRINTF(3)( "Loading %s: setting to %s\n", this->title, loadString);
     1775  this->setValue(loadString);
     1776}
     1777
     1778/**
    16681779   \brief Creates a new default Label with no Text.
    16691780   You migth consider adding Label::setTitle with this.
  • orxonox/branches/updater/src/gui/orxonox_gui_gtk.h

    r3317 r3464  
    230230  void saveability(void);
    231231  void saveability(bool isSaveable);
     232  virtual char* save(void);
     233  virtual void load(char* loadString);
     234
    232235  bool isSaveable(void);
    233236  void setFlagName(char* flagname, int defaultvalue);
     
    304307  GtkWidget* item;                      //!< One Item From a Menu.
    305308#endif /* HAVE_GTK2 */
    306   va_list itemlist;                     //!< The list to readin multiple Options.
     309
     310  //! A Struct to handle information about the different Items of the Menu.
     311  struct Item
     312  {
     313    int itemNumber;             //!< The n-th item of the List
     314#ifdef HAVE_GTK2
     315    GtkWidget* item;            //!< The GTK-widget of the Item
     316#endif /* HAVE_GTK2 */
     317    char* label;                //!< The label of the Item
     318    Item* next;                 //!< Pointer to the next Item
     319  };
     320 
     321  Item* firstItem;
    307322 
    308323 public:
     
    311326  void init(void);
    312327  void destroy(void);
     328
     329  virtual char* save(void);
     330  virtual void load(char* loadString);
    313331 
    314332  void setTitle(char* title);
     
    332350  void setValue(char* newValue);
    333351  void setTitle(char* title);
     352
     353  virtual char* save(void);
     354  virtual void load(char* loadString);
     355
    334356  void redraw(void);
    335357  void changeOption(void);
Note: See TracChangeset for help on using the changeset viewer.