Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 1976 in orxonox.OLD for orxonox


Ignore:
Timestamp:
Jun 18, 2004, 9:05:08 AM (20 years ago)
Author:
bensch
Message:

orxonox/branches/gui/guicc: added recursive option-Listing. Code-Design

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

Legend:

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

    r1974 r1976  
    1515  Frametest->fill(box);
    1616 
    17   CheckButton* button = new CheckButton("test");
     17  CheckButton* button = new CheckButton("button");
    1818  button->connectSignal ("clicked", orxonoxGUI->orxonox_gui_quit);
    1919  box->fill(button);
    20   Slider* slider = new Slider("testslider", 0, 100);
     20  Slider* slider = new Slider("slider", 0, 100);
    2121  slider->connectSignal ("value_changed", slider->OptionChange);
    2222  box->fill(slider);
    23   Menu* menu = new Menu("test1", "no output", "verbose", "debug", "lastItem");
     23  Menu* menu = new Menu("menu1", "no output", "verbose", "debug", "lastItem");
    2424  menu->connectSignal ("changed", menu->OptionChange);
    2525  box->fill(menu);
     26  Menu* menu2 = new Menu("menu2", "no output", "verbose", "debug", "lastItem");
     27  menu2->connectSignal ("changed", menu->OptionChange);
     28  box->fill(menu2);
     29  orxonoxGUI->listOptions();
    2630  orxonoxGUI->showall ();
    2731 
     
    3236
    3337/* WIDGET */
     38
     39void Widget::connectSignal (char* event, gint (*signal)(GtkWidget*, GdkEvent*, void *))
     40{
     41  /**
     42   * Connect any signal to any given Sub-widget
     43   */
     44  g_signal_connect (G_OBJECT (this->widget), event, G_CALLBACK (signal), NULL);
     45}
     46
     47void Widget::connectSignal (char* event, gint (*signal)( GtkWidget*, Widget *))
     48{
     49  /**
     50   * Connect a signal with additionally passing the whole Object
     51   */
     52  g_signal_connect (G_OBJECT (this->widget), event, G_CALLBACK (signal), this);
     53}
     54
    3455void Widget::show()
    3556{
     
    4061}
    4162
    42 void Widget::connectSignal (char* event, gint ( *signal)( GtkWidget*, GdkEvent*, void *))
    43 {
    44   /**
    45    * Connect any signal to any given Sub-widget
    46    */
    47   g_signal_connect (G_OBJECT (this->widget), event, G_CALLBACK (signal), NULL);
    48 }
    49 
    50 void Widget::connectSignal (char* event, gint ( *signal)( GtkWidget*, Widget *))
    51 {
    52   /**
    53    * Connect a signal with additionally passing the whole Object
    54    */
    55   g_signal_connect (G_OBJECT (this->widget), event, G_CALLBACK (signal), this);
     63void Widget::listOptions ()
     64{
     65  /**
     66   * This is For listing all the Options witch are located beneath this Widget.
     67   */
     68  if (this->is_option >= 1)
     69    cout << static_cast<Option*>(this)->option_name <<" is : " << static_cast<Option*>(this)->value <<endl;
     70
     71  if (this->next != NULL)
     72    this->next->listOptions ();
     73
     74  switch (this->is_option)
     75    {
     76    case -1:
     77      static_cast<Container*>(this)->down->listOptions ();
     78      break;
     79    case -2:
     80      static_cast<Box*>(this)->down->listOptions ();
     81      break;
     82    }
    5683}
    5784
     
    6390   * fill any given Container with a lowerwidet
    6491   */
    65   gtk_container_add (GTK_CONTAINER(this->widget), lowerWidget->widget);
    66   this->down = lowerWidget;
     92  if (this->down == NULL)
     93    {
     94      gtk_container_add (GTK_CONTAINER (this->widget), lowerWidget->widget);
     95      this->down = lowerWidget;
     96    }
     97  else
     98    cout << "!!error!! You try to put more than one Widget into a container.\nnot including this item."<<endl;
    6799}
    68100
     
    76108   * Creating a Window
    77109   */
     110  is_option = -1;
    78111  widget = gtk_window_new (GTK_WINDOW_TOPLEVEL);
    79   gtk_window_set_policy(GTK_WINDOW(widget), TRUE, TRUE, TRUE);
     112  gtk_window_set_policy (GTK_WINDOW(widget), TRUE, TRUE, TRUE);
     113  next = NULL;
     114  down = NULL;
    80115}
    81116
     
    85120   * Creating a Window with passing a name
    86121   */
     122  is_option = -1;
    87123  widget = gtk_window_new (GTK_WINDOW_TOPLEVEL);
    88   gtk_window_set_policy(GTK_WINDOW(widget), TRUE, TRUE, TRUE);
    89   this->setTitle(windowName);
     124  gtk_window_set_policy (GTK_WINDOW (widget), TRUE, TRUE, TRUE);
     125  this->setTitle (windowName);
    90126}
    91127
     
    114150
    115151
    116 gint Window::orxonox_gui_quit ( GtkWidget *widget, GdkEvent *event, gpointer data)
     152gint Window::orxonox_gui_quit (GtkWidget *widget, GdkEvent *event, gpointer data)
    117153{
    118154  /**
     
    131167   * Creates a new Frame without a name
    132168   */
     169  is_option = -1;
     170  next = NULL;
     171  down = NULL;
    133172  widget = gtk_frame_new ("");
    134173}
     
    138177   * Creates a new Frame with name title
    139178   */
     179  is_option = -1;
     180  next = NULL;
     181  down = NULL;
    140182  widget = gtk_frame_new (title);
    141183}
     
    164206   * Creates a new horizontal Box
    165207   */
     208  is_option = -2;
     209  next = NULL;
     210  down = NULL;
    166211  widget = gtk_hbox_new(FALSE, 0);
    167212}
     
    171216   * Creates a new Box if boxtype is 'v' it will be vertically, if 'h' it will be horizontally
    172217   */
     218  is_option = -2;
     219  next = NULL;
     220  down = NULL;
    173221  if (boxtype == 'v')
    174222    {
    175       widget = gtk_vbox_new(FALSE, 0);
     223      widget = gtk_vbox_new (FALSE, 0);
    176224    }
    177225  else
    178226    {
    179       widget = gtk_hbox_new(FALSE, 0);
     227      widget = gtk_hbox_new (FALSE, 0);
    180228    }
    181229}
     
    193241   * Fill a Box with its lowerwidgets
    194242   */
    195   gtk_box_pack_start (GTK_BOX(this->widget), lowerWidget->widget, TRUE, TRUE, 0);
     243  gtk_box_pack_start (GTK_BOX (this->widget), lowerWidget->widget, TRUE, TRUE, 0);
     244  if (this->down == NULL)
     245    this->down = lowerWidget;
     246  else
     247    {
     248      Widget* tmp;
     249      tmp = this->down;
     250      while (tmp->next != NULL)
     251        {
     252          tmp = tmp->next;
     253        }
     254      tmp->next = lowerWidget;
     255    }
    196256}
    197257
     
    205265   * Creates a new Button with name buttonname
    206266   */
    207   widget = gtk_button_new_with_label(buttonname);
     267  is_option = 0;
     268  next = NULL;
    208269  option_name = buttonname;
     270  widget = gtk_button_new_with_label (buttonname);
    209271}
    210272
    211273/* CHECKBUTTON */
    212 CheckButton::CheckButton(char* buttonname)
     274CheckButton::CheckButton (char* buttonname)
    213275{
    214276  /**
    215277   * Creates a new CheckButton with name buttonname
    216278   */
    217   widget = gtk_check_button_new_with_label(buttonname);
     279  is_option = 1;
     280  next = NULL;
    218281  option_name = buttonname;
     282  widget = gtk_check_button_new_with_label (buttonname);
    219283}
    220284
     
    225289   * Creates a new Slider with name slidername a beginning value of start and an end value of end.
    226290   */
     291  is_option = 1;
     292  next = NULL;
     293  option_name = slidername;
    227294  widget = gtk_hscale_new_with_range (start, end, 5);
    228295  value = start;
    229   option_name = slidername;
    230296}
    231297
     
    235301   * Writes value, if changed on the slider, to the object.
    236302   */
    237   static_cast<Slider*>(slider)->value = (int)gtk_range_get_value (GTK_RANGE((Slider*)slider->widget));
     303  static_cast<Slider*>(slider)->value = (int)gtk_range_get_value (GTK_RANGE ((Slider*)slider->widget));
    238304  cout << static_cast<Slider*>(slider)->value << endl;
    239305}
    240306
    241307
    242 Menu::Menu(char* menuname, ...)
     308Menu::Menu (char* menuname, ...)
    243309{
    244310  /**
    245311   * Creates an Menu-Item-list out of multiple input. Consider, that the last input argument has to be "lastItem" for this to work.
    246312   */
     313  is_option = 1;
     314  next = NULL;
     315  option_name = menuname;
    247316  char *tmp;
    248317  va_list itemlist;
    249   widget = gtk_option_menu_new();
     318  widget = gtk_option_menu_new ();
    250319  GtkWidget* menu = gtk_menu_new ();
    251320  GtkWidget* item;
    252321
    253   va_start(itemlist, menuname);
    254   while (strcmp(tmp = va_arg(itemlist, char*), "lastItem"))
     322  va_start (itemlist, menuname);
     323  while (strcmp (tmp = va_arg (itemlist, char*), "lastItem"))
    255324    {
    256325      item = gtk_menu_item_new_with_label (tmp);
     
    267336   * Writes value, if changed on the Menu, to the object.
    268337   */
    269   static_cast<Menu*>(menu)->value = (int)gtk_option_menu_get_history (GTK_OPTION_MENU(menu->widget));
    270   cout << static_cast<Menu*>(menu)->value << endl;
    271 }
     338  static_cast<Menu*>(menu)->value = (int)gtk_option_menu_get_history (GTK_OPTION_MENU (menu->widget));
     339  cout << static_cast<Menu*>(menu)->option_name << " changed to : " << static_cast<Menu*>(menu)->value << endl;
     340}
  • orxonox/branches/gui/guicc/orxonox_gui.h

    r1974 r1976  
    2222 public:
    2323  Widget* next;
    24   GtkWidget* widget; 
     24  GtkWidget* widget;
     25  int is_option;
    2526
    2627  //virtual void create ();
    2728  //  void addWidget ();
    28   void connectSignal (char* event, gint (*signal)( GtkWidget*, GdkEvent*, void *));
    29   void connectSignal (char* event, gint (*signal)(GtkWidget*,  Widget *));
     29  void connectSignal (char* event, gint (*signal)(GtkWidget*, GdkEvent*, void *));
     30  void connectSignal (char* event, gint (*signal)(GtkWidget*, Widget *));
    3031  void show ();
     32  void listOptions ();
     33
    3134};
    3235
     
    5659  void setTitle (char* title);
    5760  void showall ();
    58   static gint orxonox_gui_quit ( GtkWidget *widget, GdkEvent *event, gpointer data);
     61  static gint orxonox_gui_quit (GtkWidget *widget, GdkEvent *event, gpointer data);
    5962};
    6063
     
    7679  ~Box (void);
    7780
     81  Widget* down;
    7882  void fill (Widget *lowerWidget);
    7983
     
    107111 public:
    108112  Slider (char* slidername,int start, int end);
    109   ~Slider();
     113  ~Slider ();
    110114  int i;
    111115  static gint OptionChange (GtkWidget *widget, Widget* slider);
     
    115119{
    116120 public:
    117   Menu(char* menuname, ...);
    118   ~Menu();
     121  Menu (char* menuname, ...);
     122  ~Menu ();
    119123
    120124  static gint OptionChange (GtkWidget *widget, Widget* menu);
    121125};
    122126   
    123 //gint orxonox_gui_quit ( GtkWidget *widget, GdkEvent *event, gpointer data);
     127//gint orxonox_gui_quit (GtkWidget *widget, GdkEvent *event, gpointer data);
    124128
    125129#endif /* _ORXONOX_GUI_H */
Note: See TracChangeset for help on using the changeset viewer.