Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/branches/gui/guicc/orxonox_gui.cc @ 1997

Last change on this file since 1997 was 1997, checked in by bensch, 20 years ago

orxonox/branches/gui/guicc: flags now have the ability to update. (Main-Variables maid global to orxonox_gui)

File size: 10.1 KB
Line 
1#include <iostream.h>
2
3#include "orxonox_gui.h"
4#include "orxonox_gui_video.h"
5#include "orxonox_gui_audio.h"
6#include "orxonox_gui_exec.h"
7#include "orxonox_gui_flags.h"
8
9  Window* orxonoxGUI;
10  OrxonoxGuiVideo* video;
11  OrxonoxGuiAudio* audio;
12  OrxonoxGuiExec* exec;
13  OrxonoxGuiFlags* flags; 
14
15int main( int argc, char *argv[] )
16{
17  OrxonoxGui* orxonoxgui = new OrxonoxGui(argc, argv);
18  return 0;
19}
20
21/* ORXONOXGUI */
22
23OrxonoxGui::OrxonoxGui (int argc, char *argv[])
24{
25  /**
26   * Initializes the Gui
27   */
28  gtk_init (&argc, &argv);
29
30
31  orxonoxGUI = new Window("Graphical Orxonox Launcher");
32  orxonoxGUI->connectSignal ("destroy", orxonoxGUI->orxonox_gui_quit);
33  orxonoxGUI->connectSignal ("delete_event", orxonoxGUI->orxonox_gui_quit);
34 
35  Box* windowBox = new Box ('v');
36 
37  Box* avBox = new Box ('h');
38
39  video = new OrxonoxGuiVideo ();
40  avBox->fill (video->getFrame ());
41  audio = new OrxonoxGuiAudio ();
42  avBox->fill (audio->getFrame ());
43     
44  windowBox->fill (avBox);
45   
46  exec = new OrxonoxGuiExec (orxonoxGUI);
47  windowBox->fill (exec->getFrame ());
48
49  flags = new OrxonoxGuiFlags (orxonoxGUI);
50  windowBox->fill (flags->getFrame ());
51 
52  orxonoxGUI->fill (windowBox);
53  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  */
76  orxonoxGUI->showall ();
77
78 
79  gtk_main();
80}
81
82/* WIDGET */
83
84void Widget::connectSignal (char* event, gint (*signal)(GtkWidget*, GdkEvent*, void *))
85{
86  /**
87   * Connect any signal to any given Sub-widget
88   */
89  g_signal_connect (G_OBJECT (this->widget), event, G_CALLBACK (signal), NULL);
90}
91
92void Widget::connectSignal (char* event, gint (*signal)( GtkWidget*, Widget *))
93{
94  /**
95   * Connect a signal with additionally passing the whole Object
96   */
97  g_signal_connect (G_OBJECT (this->widget), event, G_CALLBACK (signal), this);
98}
99
100void Widget::show()
101{
102  /**
103   * Function to Show any Widget
104   */
105  gtk_widget_show (widget);
106}
107
108void Widget::listOptions ()
109{
110  /**
111   * This is For listing all the Options witch are located beneath this Widget.
112   */
113  if (this->is_option >= 1)
114    cout << static_cast<Option*>(this)->option_name <<" is : " << static_cast<Option*>(this)->value <<endl;
115
116  switch (this->is_option)
117    {
118    case -1:
119      static_cast<Container*>(this)->down->listOptions ();
120      break;
121    case -2:
122      static_cast<Box*>(this)->down->listOptions ();
123      break;
124    } 
125
126  if (this->next != NULL)
127    this->next->listOptions ();
128
129
130}
131
132/* CONTAINERS*/
133
134void Container::fill (Widget *lowerWidget)
135{
136  /**
137   * fill any given Container with a lowerwidet
138   */
139  if (this->down == NULL)
140    {
141      gtk_container_add (GTK_CONTAINER (this->widget), lowerWidget->widget);
142      this->down = lowerWidget;
143    }
144  else
145    cout << "!!error!! You try to put more than one Widget into a container.\nnot including this item."<<endl;
146}
147
148// gtk_container_set_border_width (GTK_CONTAINER (widget), 5);
149
150/* WINDOW */
151
152Window::Window (void)
153{
154  /**
155   * Creating a Window
156   */
157  is_option = -1;
158  next = NULL;
159  down = NULL;
160  widget = gtk_window_new (GTK_WINDOW_TOPLEVEL);
161  gtk_window_set_policy (GTK_WINDOW(widget), TRUE, TRUE, TRUE);
162}
163
164Window::Window (char* windowName)
165{
166  /**
167   * Creating a Window with passing a name
168   */
169  is_option = -1;
170  next = NULL;
171  down = NULL;
172  widget = gtk_window_new (GTK_WINDOW_TOPLEVEL);
173  gtk_window_set_policy (GTK_WINDOW (widget), TRUE, TRUE, TRUE);
174  this->setTitle (windowName);
175}
176
177Window::~Window ()
178{
179  /**
180   * Destoying a Window (not implemented)
181   */
182}
183
184void Window::showall ()
185{
186  /**
187   * Shows all Widgets that are included within this Widget
188   */
189  gtk_widget_show_all  (widget);
190}
191
192void Window::setTitle (char* title)
193{
194  /**
195   * Set The Window title to title
196   */
197  gtk_window_set_title (GTK_WINDOW (widget), title);
198}
199
200
201gint Window::orxonox_gui_quit (GtkWidget *widget, GdkEvent *event, gpointer data)
202{
203  /**
204   * Quits the orxonox_GUI
205   */
206  gtk_main_quit();
207  return FALSE;
208}
209
210
211/* FRAME */
212
213Frame::Frame (void)
214{
215  /**
216   * Creates a new Frame without a name
217   */
218  is_option = -1;
219  next = NULL;
220  down = NULL;
221  widget = gtk_frame_new ("");
222}
223Frame::Frame (char* title)
224{
225  /**
226   * Creates a new Frame with name title
227   */
228  is_option = -1;
229  next = NULL;
230  down = NULL;
231  widget = gtk_frame_new (title);
232}
233Frame::~Frame ()
234{
235  /**
236   * Destroys given Frame (not implemented yet)
237   */
238}
239
240void Frame::setTitle (char* title)
241{
242  /**
243   * Sets the Frames name to title
244   */
245  gtk_frame_set_label (GTK_FRAME (widget), title);
246}
247
248
249
250/* BOX */
251
252Box::Box (void)
253{
254  /**
255   * Creates a new horizontal Box
256   */
257  is_option = -2;
258  next = NULL;
259  down = NULL;
260  widget = gtk_hbox_new(FALSE, 0);
261}
262Box::Box (char boxtype)
263{
264  /**
265   * Creates a new Box if boxtype is 'v' it will be vertically, if 'h' it will be horizontally
266   */
267  is_option = -2;
268  next = NULL;
269  down = NULL;
270  if (boxtype == 'v')
271    {
272      widget = gtk_vbox_new (FALSE, 0);
273    }
274  else
275    {
276      widget = gtk_hbox_new (FALSE, 0);
277    }
278}
279
280Box::~Box ()
281{
282  /**
283   * Destroys given Frame (not implemented yet)
284   */
285}
286
287void Box::fill (Widget *lowerWidget)
288{
289  /**
290   * Fill a Box with its lowerwidgets
291   */
292  gtk_box_pack_start (GTK_BOX (this->widget), lowerWidget->widget, TRUE, TRUE, 0);
293  if (this->down == NULL)
294    this->down = lowerWidget;
295  else
296    {
297      Widget* tmp;
298      tmp = this->down;
299      while (tmp->next != NULL)
300        {
301          tmp = tmp->next;
302        }
303      tmp->next = lowerWidget;
304    }
305}
306
307
308/* OPTION */
309
310void Option::setFlagName (char* flagname, int defaultvalue)
311{
312  flag_name = flagname;
313  default_value = defaultvalue;
314  cout << "Set Flagname of " << option_name << " to " << flagname << endl;
315}
316
317void Option::setFlagName (char* flagname, char* flagnameshort,  int defaultvalue)
318{
319  /**
320   * \brief Sets the Flagname of an Option. If it is set different then "" this Option will be saved to the Configurationfile
321   */
322  flag_name = flagname;
323  flag_name_short = flagnameshort;
324  default_value = defaultvalue;
325  cout << "Set Flagname of " << option_name << " to " << flagname << endl;
326}
327
328
329/* BUTTON */
330Button::Button(char* buttonname)
331{
332  /**
333   * Creates a new Button with name buttonname
334   */
335  is_option = 0;
336  value = 0;
337  next = NULL;
338  option_name = buttonname;
339  flag_name = "";
340  flag_name_short = "";
341  default_value = 0;
342  widget = gtk_button_new_with_label (buttonname);
343}
344
345/* CHECKBUTTON */
346CheckButton::CheckButton (char* buttonname)
347{
348  /**
349   * Creates a new CheckButton with name buttonname
350   */
351  is_option = 1;
352  value = 0;
353  next = NULL;
354  option_name = buttonname;
355  flag_name = "";
356  flag_name_short = "";
357  default_value = 0;
358  widget = gtk_check_button_new_with_label (buttonname);
359
360  this->connectSignal ("clicked", this->OptionChange);
361}
362
363gint CheckButton::OptionChange (GtkWidget *widget, Widget* checkbutton)
364{
365  /**
366   * Writes value, if changed on the checkbutton, to the object.
367   */
368  static_cast<CheckButton*>(checkbutton)->value = (int)gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON ((CheckButton*)checkbutton->widget));
369  flags->setTextFromFlags(orxonoxGUI);
370  cout << static_cast<CheckButton*>(checkbutton)->option_name << " set to: " << static_cast<CheckButton*>(checkbutton)->value << endl;
371}
372
373/* SLIDER */
374Slider::Slider (char* slidername, int start, int end)
375{
376  /**
377   * Creates a new Slider with name slidername a beginning value of start and an end value of end.
378   */
379  is_option = 2;
380  value = 0;
381  next = NULL;
382  option_name = slidername;
383  flag_name = "";
384  flag_name_short = "";
385  default_value = 0;
386  widget = gtk_hscale_new_with_range (start, end, 5);
387  value = start;
388
389  this->connectSignal ("value_changed", this->OptionChange);
390}
391
392gint Slider::OptionChange (GtkWidget *widget, Widget* slider)
393{
394  /**
395   * Writes value, if changed on the slider, to the object.
396   */
397  static_cast<Slider*>(slider)->value = (int)gtk_range_get_value (GTK_RANGE ((Slider*)slider->widget));
398  flags->setTextFromFlags(orxonoxGUI);
399  cout << static_cast<Slider*>(slider)->option_name << " set to: "<< static_cast<Slider*>(slider)->value << endl;
400}
401
402Menu::Menu (char* menuname, ...)
403{
404  /**
405   * Creates an Menu-Item-list out of multiple input. Consider, that the last input argument has to be "lastItem" for this to work.
406   */
407  is_option = 2;
408  value = 0;
409  next = NULL;
410  option_name = menuname;
411  flag_name = "";
412  flag_name_short = "";
413  default_value = 0;
414  char *tmp;
415  va_list itemlist;
416  widget = gtk_option_menu_new ();
417  GtkWidget* menu = gtk_menu_new ();
418  GtkWidget* item;
419
420  va_start (itemlist, menuname);
421  while (strcmp (tmp = va_arg (itemlist, char*), "lastItem"))
422    {
423      item = gtk_menu_item_new_with_label (tmp);
424      gtk_menu_shell_append(GTK_MENU_SHELL (menu), item);
425    }
426  va_end(itemlist);
427
428  gtk_option_menu_set_menu (GTK_OPTION_MENU (widget), menu);
429  this->connectSignal ("changed", this->OptionChange);
430}
431
432gint Menu::OptionChange (GtkWidget *widget, Widget* menu)
433{
434  /**
435   * Writes value, if changed on the Menu, to the object.
436   */
437  static_cast<Menu*>(menu)->value = (int)gtk_option_menu_get_history (GTK_OPTION_MENU (menu->widget));
438  flags->setTextFromFlags(orxonoxGUI);
439  cout << static_cast<Menu*>(menu)->option_name << " changed to : " << static_cast<Menu*>(menu)->value << endl;
440}
441
442Label:: Label ()
443{
444  is_option = 0;
445  next = NULL;
446  widget = gtk_label_new ("");
447  gtk_widget_set_usize (widget, 260, 60);
448  gtk_label_set_line_wrap (GTK_LABEL(widget), TRUE);
449}
450Label::~Label ()
451{}
452 
453void Label::setText (char * text)
454{
455  gtk_label_set_text (GTK_LABEL (this->widget), text);
456}
457
458char* Label::getText ()
459{
460  return ((char*)gtk_label_get_text (GTK_LABEL (this->widget)));
461}
Note: See TracBrowser for help on using the repository browser.