Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/branches/john/gui/orxonox_gui.cc @ 3147

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

orxonox/trunk: merged guicc and the new Configure.ac to the Trunk. Now I have to Check if everything compiles on windows.

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