Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/branches/gui/guicc: added .h-files and rc to dist, and made a border for Containers.

File size: 10.5 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  gtk_rc_parse( "rc" );
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  gtk_container_set_border_width (GTK_CONTAINER (widget), 3);
163}
164
165Window::Window (char* windowName)
166{
167  /**
168   * Creating a Window with passing a name
169   */
170  is_option = -1;
171  next = NULL;
172  down = NULL;
173  widget = gtk_window_new (GTK_WINDOW_TOPLEVEL);
174  gtk_window_set_policy (GTK_WINDOW (widget), TRUE, TRUE, TRUE);
175  gtk_container_set_border_width (GTK_CONTAINER (widget), 3);
176  this->setTitle (windowName);
177}
178
179Window::~Window ()
180{
181  /**
182   * Destoying a Window (not implemented)
183   */
184}
185
186void Window::showall ()
187{
188  /**
189   * Shows all Widgets that are included within this Widget
190   */
191  gtk_widget_show_all  (widget);
192}
193
194void Window::setTitle (char* title)
195{
196  /**
197   * Set The Window title to title
198   */
199  gtk_window_set_title (GTK_WINDOW (widget), title);
200}
201
202
203gint Window::orxonox_gui_quit (GtkWidget *widget, GdkEvent *event, gpointer data)
204{
205  /**
206   * Quits the orxonox_GUI
207   */
208  gtk_main_quit();
209  return FALSE;
210}
211
212
213/* FRAME */
214
215Frame::Frame (void)
216{
217  /**
218   * Creates a new Frame without a name
219   */
220  is_option = -1;
221  next = NULL;
222  down = NULL;
223  widget = gtk_frame_new ("");
224  gtk_container_set_border_width (GTK_CONTAINER (widget), 3);
225}
226Frame::Frame (char* title)
227{
228  /**
229   * Creates a new Frame with name title
230   */
231  is_option = -1;
232  next = NULL;
233  down = NULL;
234  widget = gtk_frame_new (title);
235  gtk_container_set_border_width (GTK_CONTAINER (widget), 3);
236}
237Frame::~Frame ()
238{
239  /**
240   * Destroys given Frame (not implemented yet)
241   */
242}
243
244void Frame::setTitle (char* title)
245{
246  /**
247   * Sets the Frames name to title
248   */
249  gtk_frame_set_label (GTK_FRAME (widget), title);
250}
251
252
253
254/* BOX */
255
256Box::Box (void)
257{
258  /**
259   * Creates a new horizontal Box
260   */
261  is_option = -2;
262  next = NULL;
263  down = NULL;
264  widget = gtk_hbox_new(FALSE, 0);
265}
266Box::Box (char boxtype)
267{
268  /**
269   * Creates a new Box if boxtype is 'v' it will be vertically, if 'h' it will be horizontally
270   */
271  is_option = -2;
272  next = NULL;
273  down = NULL;
274  if (boxtype == 'v')
275    {
276      widget = gtk_vbox_new (FALSE, 0);
277    }
278  else
279    {
280      widget = gtk_hbox_new (FALSE, 0);
281    }
282}
283
284Box::~Box ()
285{
286  /**
287   * Destroys given Frame (not implemented yet)
288   */
289}
290
291void Box::fill (Widget *lowerWidget)
292{
293  /**
294   * Fill a Box with its lowerwidgets
295   */
296  gtk_box_pack_start (GTK_BOX (this->widget), lowerWidget->widget, TRUE, TRUE, 0);
297  if (this->down == NULL)
298    this->down = lowerWidget;
299  else
300    {
301      Widget* tmp;
302      tmp = this->down;
303      while (tmp->next != NULL)
304        {
305          tmp = tmp->next;
306        }
307      tmp->next = lowerWidget;
308    }
309}
310
311
312/* OPTION */
313
314void Option::setFlagName (char* flagname, int defaultvalue)
315{
316  flag_name = flagname;
317  default_value = defaultvalue;
318  cout << "Set Flagname of " << option_name << " to " << flagname << endl;
319}
320
321void Option::setFlagName (char* flagname, char* flagnameshort,  int defaultvalue)
322{
323  /**
324   * \brief Sets the Flagname of an Option. If it is set different then "" this Option will be saved to the Configurationfile
325   */
326  flag_name = flagname;
327  flag_name_short = flagnameshort;
328  default_value = defaultvalue;
329  cout << "Set Flagname of " << option_name << " to " << flagname << endl;
330}
331
332
333/* BUTTON */
334Button::Button(char* buttonname)
335{
336  /**
337   * Creates a new Button with name buttonname
338   */
339  is_option = 0;
340  value = 0;
341  next = NULL;
342  option_name = buttonname;
343  flag_name = "";
344  flag_name_short = "";
345  default_value = 0;
346  widget = gtk_button_new_with_label (buttonname);
347}
348
349/* CHECKBUTTON */
350CheckButton::CheckButton (char* buttonname)
351{
352  /**
353   * Creates a new CheckButton with name buttonname
354   */
355  is_option = 1;
356  value = 0;
357  next = NULL;
358  option_name = buttonname;
359  flag_name = "";
360  flag_name_short = "";
361  default_value = 0;
362  widget = gtk_check_button_new_with_label (buttonname);
363
364  this->connectSignal ("clicked", this->OptionChange);
365}
366
367gint CheckButton::OptionChange (GtkWidget *widget, Widget* checkbutton)
368{
369  /**
370   * Writes value, if changed on the checkbutton, to the object.
371   */
372  static_cast<CheckButton*>(checkbutton)->value = (int)gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON ((CheckButton*)checkbutton->widget));
373  flags->setTextFromFlags(orxonoxGUI);
374  cout << static_cast<CheckButton*>(checkbutton)->option_name << " set to: " << static_cast<CheckButton*>(checkbutton)->value << endl;
375}
376
377/* SLIDER */
378Slider::Slider (char* slidername, int start, int end)
379{
380  /**
381   * Creates a new Slider with name slidername a beginning value of start and an end value of end.
382   */
383  is_option = 2;
384  value = 0;
385  next = NULL;
386  option_name = slidername;
387  flag_name = "";
388  flag_name_short = "";
389  default_value = 0;
390  widget = gtk_hscale_new_with_range (start, end, 5);
391  value = start;
392
393  this->connectSignal ("value_changed", this->OptionChange);
394}
395
396gint Slider::OptionChange (GtkWidget *widget, Widget* slider)
397{
398  /**
399   * Writes value, if changed on the slider, to the object.
400   */
401  static_cast<Slider*>(slider)->value = (int)gtk_range_get_value (GTK_RANGE ((Slider*)slider->widget));
402  flags->setTextFromFlags(orxonoxGUI);
403  cout << static_cast<Slider*>(slider)->option_name << " set to: "<< static_cast<Slider*>(slider)->value << endl;
404}
405
406Menu::Menu (char* menuname, ...)
407{
408  /**
409   * Creates an Menu-Item-list out of multiple input. Consider, that the last input argument has to be "lastItem" for this to work.
410   */
411  is_option = 2;
412  value = 0;
413  next = NULL;
414  option_name = menuname;
415  flag_name = "";
416  flag_name_short = "";
417  default_value = 0;
418  char *tmp;
419  va_list itemlist;
420  widget = gtk_option_menu_new ();
421  GtkWidget* menu = gtk_menu_new ();
422  GtkWidget* item;
423
424  va_start (itemlist, menuname);
425  while (strcmp (tmp = va_arg (itemlist, char*), "lastItem"))
426    {
427      item = gtk_menu_item_new_with_label (tmp);
428      gtk_menu_shell_append(GTK_MENU_SHELL (menu), item);
429    }
430  va_end(itemlist);
431
432  gtk_option_menu_set_menu (GTK_OPTION_MENU (widget), menu);
433  this->connectSignal ("changed", this->OptionChange);
434}
435
436gint Menu::OptionChange (GtkWidget *widget, Widget* menu)
437{
438  /**
439   * Writes value, if changed on the Menu, to the object.
440   */
441  static_cast<Menu*>(menu)->value = (int)gtk_option_menu_get_history (GTK_OPTION_MENU (menu->widget));
442  flags->setTextFromFlags(orxonoxGUI);
443  cout << static_cast<Menu*>(menu)->option_name << " changed to : " << static_cast<Menu*>(menu)->value << endl;
444}
445
446Label:: Label ()
447{
448  is_option = 0;
449  next = NULL;
450  widget = gtk_label_new ("");
451  gtk_widget_set_usize (widget, 260, 60);
452  gtk_label_set_line_wrap (GTK_LABEL(widget), TRUE);
453}
454
455Label:: Label (char* text)
456{
457  is_option = 0;
458  next = NULL;
459  widget = gtk_label_new (text);
460  gtk_label_set_line_wrap (GTK_LABEL(widget), TRUE);
461}
462
463Label::~Label ()
464{}
465 
466void Label::setText (char * text)
467{
468  gtk_label_set_text (GTK_LABEL (this->widget), text);
469}
470
471char* Label::getText ()
472{
473  return ((char*)gtk_label_get_text (GTK_LABEL (this->widget)));
474}
Note: See TracBrowser for help on using the repository browser.