Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 2007 in orxonox.OLD for orxonox


Ignore:
Timestamp:
Jun 22, 2004, 10:47:35 AM (20 years ago)
Author:
bensch
Message:

orxonox/branches/gui/guicc: added save and load rutine

Location:
orxonox/branches/gui/guicc
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • orxonox/branches/gui/guicc/orxonox_gui.cc

    r2003 r2007  
    2828  gtk_init (&argc, &argv);
    2929  gtk_rc_parse( "rc" );
    30 
     30 
    3131  orxonoxGUI = new Window("Graphical Orxonox Launcher");
    3232  orxonoxGUI->connectSignal ("destroy", orxonoxGUI->orxonox_gui_quit);
     
    5151 
    5252  orxonoxGUI->fill (windowBox);
     53  flags->setTextFromFlags (orxonoxGUI);
     54
     55  exec->setFilename ("test");
     56  exec->readFromFile (orxonoxGUI);
    5357  orxonoxGUI->listOptions();
    54   flags->setTextFromFlags (orxonoxGUI);
    55 
    56   /* TEST ENVIRONMENT
    57   Frame* Frametest = new Frame ("Test");
    58   orxonoxGUI->fill((Frame*) Frametest);
    59   Box* box = new Box ('v');
    60   Frametest->fill(box);
    61  
    62   CheckButton* button = new CheckButton("button");
    63   button->connectSignal ("clicked", orxonoxGUI->orxonox_gui_quit);
    64   box->fill(button);
    65   Slider* slider = new Slider("slider", 0, 100);
    66   slider->connectSignal ("value_changed", slider->OptionChange);
    67   box->fill(slider);
    68   Menu* menu = new Menu("menu1", "no output", "verbose", "debug", "lastItem");
    69   menu->connectSignal ("changed", menu->OptionChange);
    70   box->fill(menu);
    71   Menu* menu2 = new Menu("menu2", "no output", "verbose", "debug", "lastItem");
    72   menu2->connectSignal ("changed", menu->OptionChange);
    73   box->fill(menu2);
    74   orxonoxGUI->listOptions();
    75   */
     58
    7659  orxonoxGUI->showall ();
    7760
     
    206189   * Quits the orxonox_GUI
    207190   */
     191  exec->writeToFile (orxonoxGUI);
     192
    208193  gtk_main_quit();
    209194  return FALSE;
  • orxonox/branches/gui/guicc/orxonox_gui_exec.cc

    r1996 r2007  
    11#include "orxonox_gui_exec.h"
     2#include <iostream>
     3#include <string>
    24
    35OrxonoxGuiExec::OrxonoxGuiExec (Window* orxonoxGUI)
    46{
     7  configFile = (char*)malloc(256*sizeof(char));
     8
    59  execFrame = new Frame ("Execute-Tags:");
    610  execBox = new Box ('v');
     
    2731  return execFrame;
    2832}
     33
     34/* FILE HANDLING */
     35
     36void OrxonoxGuiExec::setFilename (char* filename)
     37{
     38 
     39  if (filename)
     40    sprintf(configFile, "%s", filename);
     41}
     42
     43void OrxonoxGuiExec::writeToFile (Widget* widget)
     44{
     45  CONFIG_FILE = fopen (configFile, "w");
     46  if (CONFIG_FILE)
     47    writeFileText (widget);
     48  fclose (CONFIG_FILE);
     49}
     50
     51void OrxonoxGuiExec::writeFileText (Widget* widget)
     52{
     53  if (widget->is_option >= 1)
     54    if  (strcmp (static_cast<Option*>(widget)->flag_name, "") || strcmp (static_cast<Option*>(widget)->flag_name_short, ""))
     55      {
     56        char Buffer[256];
     57        char* space2under;
     58        sprintf (Buffer, "%s", static_cast<Option*>(widget)->option_name);
     59        if (strchr (Buffer, '_'))
     60          cout << "Warning Optionname" << Buffer << " is not Valid for Saving, because it includes an underscore" << endl;
     61        while (space2under = strchr(Buffer, ' '))
     62          {
     63            sprintf (space2under, "_%s", space2under+1);
     64          }
     65        fprintf (CONFIG_FILE, "%s = %i\n", Buffer, static_cast<Option*>(widget)->value);
     66      }
     67  switch (widget->is_option)
     68    {
     69    case -1:
     70      writeFileText (static_cast<Container*>(widget)->down);
     71      break;
     72    case -2:
     73      writeFileText (static_cast<Box*>(widget)->down);
     74      break;
     75    }
     76 
     77  if (widget->next != NULL)
     78    writeFileText (widget->next);
     79}
     80
     81void OrxonoxGuiExec::readFromFile (Widget* widget)
     82{
     83  CONFIG_FILE = fopen (configFile, "r");
     84  if (CONFIG_FILE)
     85    {
     86      char Buffer[256] = "";
     87      char Variable[256]= "";
     88      int Value;
     89      while (fscanf (CONFIG_FILE, "%s", Buffer) != EOF)
     90        {
     91          if (!strcmp (Buffer, "="))
     92            {
     93              char* under2space;
     94              while (under2space = strchr(Variable, '_'))
     95                {
     96                  sprintf (under2space, " %s", under2space+1);
     97                }
     98             
     99              fscanf (CONFIG_FILE, "%s", Buffer);
     100              Value = atoi(Buffer);
     101              readFileText (widget, Variable, Value);
     102              sprintf (Variable, "");
     103            }
     104          sprintf (Variable, "%s", Buffer);
     105        }
     106
     107    }
     108   
     109}
     110
     111void OrxonoxGuiExec::readFileText (Widget* widget, char* variableName, int variableValue)
     112{
     113  if (widget->is_option >= 1)
     114    if (!strcmp (static_cast<Option*>(widget)->option_name, variableName))
     115        static_cast<Option*>(widget)->value = variableValue;
     116
     117  switch (widget->is_option)
     118    {
     119    case -1:
     120      readFileText (static_cast<Container*>(widget)->down, variableName, variableValue);
     121      break;
     122    case -2:
     123      readFileText (static_cast<Box*>(widget)->down, variableName, variableValue);
     124      break;
     125    }
     126
     127  if (widget->next != NULL)
     128    readFileText (widget->next, variableName, variableValue);
     129
     130
     131}
  • orxonox/branches/gui/guicc/orxonox_gui_exec.h

    r1980 r2007  
    33
    44#include "orxonox_gui.h"
     5#include <stdio.h>
     6using namespace std;
    57
    68class OrxonoxGuiExec
     
    1416  CheckButton* alwaysShow;
    1517  Button* quit;
    16    
     18  char* configFile;
     19  FILE* CONFIG_FILE;
    1720 public:
    1821  OrxonoxGuiExec (Window* orxonoxGUI);
     
    2023 
    2124  Frame* getFrame ();
     25 
     26  void setFilename (char* filename);
     27  void writeToFile (Widget* widget);
     28  void writeFileText (Widget* widget);
     29  void readFromFile (Widget* widget);
     30  void readFileText (Widget* widget, char* variableName, int variableValue);
     31
    2232};
    2333#endif /* _ORXONOX_GUI_EXEC_H */
Note: See TracChangeset for help on using the changeset viewer.