Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.
Note: See TracChangeset for help on using the changeset viewer.