Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/trunk/gui/orxonox_gui.cc @ 2581

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

orxonox/trunk/gui: gui now ready for including Orxonox-Crew-Logo

File size: 12.8 KB
Line 
1/*
2   orxonox - the future of 3D-vertical-scrollers
3
4   Copyright (C) 2004 orx
5
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation; either version 2, or (at your option)
9   any later version.
10
11   This program is distributed in the hope that it will be useful,
12   but WITHOUT ANY WARRANTY; without even the implied warranty of
13   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   GNU General Public License for more details.
15
16   You should have received a copy of the GNU General Public License
17   along with this program; if not, write to the Free Software Foundation,
18   Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 
19
20
21   ### File Specific:
22   main-programmer: Benjamin Grauer
23
24*/
25
26#include <iostream.h>
27
28#include "orxonox_gui.h"
29#include "orxonox_gui_video.h"
30#include "orxonox_gui_audio.h"
31#include "orxonox_gui_exec.h"
32#include "orxonox_gui_flags.h"
33#include "orxonox_gui_banner.h"
34
35  Window* orxonoxGUI;
36  OrxonoxGuiVideo* video;
37  OrxonoxGuiAudio* audio;
38  OrxonoxGuiExec* exec;
39  OrxonoxGuiFlags* flags;
40  OrxonoxGuiBanner* banner;
41
42int main( int argc, char *argv[] )
43{
44  OrxonoxGui* orxonoxgui = new OrxonoxGui(argc, argv);
45  return 0;
46}
47
48/* ORXONOXGUI */
49
50OrxonoxGui::OrxonoxGui (int argc, char *argv[])
51{
52  /**
53   * Initializes the Gui
54   */
55  gtk_init (&argc, &argv);
56  gtk_rc_parse( "rc" );
57 
58  orxonoxGUI = new Window("Graphical Orxonox Launcher");
59  orxonoxGUI->connectSignal ("destroy", orxonoxGUI->orxonox_gui_quit);
60  orxonoxGUI->connectSignal ("delete_event", orxonoxGUI->orxonox_gui_quit);
61 
62  Box* windowBox = new Box ('h');
63
64  banner = new OrxonoxGuiBanner();
65  windowBox->fill (banner->getEventBox());
66 
67  Box* optionBox = new Box ('v');
68 
69  Box* avBox = new Box ('h');
70
71  video = new OrxonoxGuiVideo ();
72  avBox->fill (video->getFrame ());
73  audio = new OrxonoxGuiAudio ();
74  avBox->fill (audio->getFrame ());
75     
76  optionBox->fill (avBox);
77   
78  exec = new OrxonoxGuiExec (orxonoxGUI);
79  optionBox->fill (exec->getFrame ());
80
81  flags = new OrxonoxGuiFlags (orxonoxGUI);
82
83
84  optionBox->fill (flags->getFrame ());
85  windowBox->fill (optionBox);
86 
87  orxonoxGUI->fill (windowBox);
88  flags->setTextFromFlags (orxonoxGUI);
89
90  exec->setFilename ("~/.orxonox.conf");
91  exec->readFromFile (orxonoxGUI);
92  orxonoxGUI->listOptions();
93
94  orxonoxGUI->showall ();
95
96 
97  gtk_main();
98}
99
100/* WIDGET */
101
102void Widget::connectSignal (char* event, gint (*signal)(GtkWidget*, GdkEvent*, void *))
103{
104  /**
105   * Connect any signal to any given Sub-widget
106   */
107  g_signal_connect (G_OBJECT (this->widget), event, G_CALLBACK (signal), NULL);
108}
109
110void Widget::connectSignal (char* event, gint (*signal)( GtkWidget*, Widget *))
111{
112  /**
113   * Connect a signal with additionally passing the whole Object
114   */
115g_signal_connect (G_OBJECT (this->widget), event, G_CALLBACK (signal), this);
116}
117
118void Widget::connectSignal (char* event, void* extObj, gint (*signal)(GtkWidget*, GdkEvent*, void *))
119{
120  /**
121   * Connect a signal with additionally passing a whole external Object
122   */
123  g_signal_connect (G_OBJECT (this->widget), event, G_CALLBACK (signal), extObj);
124}
125void Widget::show()
126{
127  /**
128   * Function to Show any Widget
129   */
130  gtk_widget_show (widget);
131}
132
133void Widget::listOptions ()
134{
135  /**
136   * This is For listing all the Options witch are located beneath this Widget.
137   */
138  if (this->is_option >= 1)
139    cout << static_cast<Option*>(this)->option_name <<" is : " << static_cast<Option*>(this)->value <<endl;
140
141  switch (this->is_option)
142    {
143    case -1:
144      static_cast<Container*>(this)->down->listOptions ();
145      break;
146    case -2:
147      static_cast<Box*>(this)->down->listOptions ();
148      break;
149    } 
150
151  if (this->next != NULL)
152    this->next->listOptions ();
153}
154
155void Widget::setOptions ()
156{
157  /**
158   * This is For listing all the Options witch are located beneath this Widget.
159   */
160  if (this->is_option >= 1)
161    static_cast<Option*>(this)->redraw();// <<" is : " << static_cast<Option*>(this)->value <<endl;
162
163  switch (this->is_option)
164    {
165    case -1:
166      static_cast<Container*>(this)->down->setOptions ();
167      break;
168    case -2:
169      static_cast<Box*>(this)->down->setOptions ();
170      break;
171    } 
172
173  if (this->next != NULL)
174    this->next->setOptions ();
175}
176
177/* CONTAINERS*/
178
179void Container::fill (Widget *lowerWidget)
180{
181  /**
182   * fill any given Container with a lowerwidet
183   */
184  if (this->down == NULL)
185    {
186      gtk_container_add (GTK_CONTAINER (this->widget), lowerWidget->widget);
187      this->down = lowerWidget;
188    }
189  else
190    cout << "!!error!! You try to put more than one Widget into a container.\nnot including this item."<<endl;
191}
192
193// gtk_container_set_border_width (GTK_CONTAINER (widget), 5);
194
195/* WINDOW */
196
197Window::Window (void)
198{
199  /**
200   * Creating a Window
201   */
202  is_option = -1;
203  next = NULL;
204  down = NULL;
205  widget = gtk_window_new (GTK_WINDOW_TOPLEVEL);
206  gtk_window_set_policy (GTK_WINDOW(widget), TRUE, TRUE, TRUE);
207  gtk_container_set_border_width (GTK_CONTAINER (widget), 3);
208}
209
210Window::Window (char* windowName)
211{
212  /**
213   * Creating a Window with passing a name
214   */
215  is_option = -1;
216  next = NULL;
217  down = NULL;
218  widget = gtk_window_new (GTK_WINDOW_TOPLEVEL);
219  gtk_window_set_policy (GTK_WINDOW (widget), TRUE, TRUE, TRUE);
220  gtk_container_set_border_width (GTK_CONTAINER (widget), 3);
221  gtk_window_set_decorated (GTK_WINDOW (widget), FALSE);
222  this->setTitle (windowName);
223}
224
225Window::~Window ()
226{
227  /**
228   * Destoying a Window (very BAD implemented)
229   */
230  gtk_widget_hide (widget);
231 
232}
233
234void Window::showall ()
235{
236  /**
237   * Shows all Widgets that are included within this Widget
238   */
239  gtk_widget_show_all  (widget);
240}
241
242void Window::setTitle (char* title)
243{
244  /**
245   * Set The Window title to title
246   */
247  gtk_window_set_title (GTK_WINDOW (widget), title);
248}
249
250
251gint Window::orxonox_gui_quit (GtkWidget *widget, GdkEvent *event, gpointer data)
252{
253  /**
254   * Quits the orxonox_GUI
255   */
256  if (exec->shouldsave())
257    exec->writeToFile (orxonoxGUI);
258
259  gtk_main_quit();
260  return FALSE;
261}
262
263
264/* FRAME */
265
266Frame::Frame (void)
267{
268  /**
269   * Creates a new Frame without a name
270   */
271  is_option = -1;
272  next = NULL;
273  down = NULL;
274  widget = gtk_frame_new ("");
275  gtk_container_set_border_width (GTK_CONTAINER (widget), 3);
276}
277Frame::Frame (char* title)
278{
279  /**
280   * Creates a new Frame with name title
281   */
282  is_option = -1;
283  next = NULL;
284  down = NULL;
285  widget = gtk_frame_new (title);
286  gtk_container_set_border_width (GTK_CONTAINER (widget), 3);
287}
288Frame::~Frame ()
289{
290  /**
291   * Destroys given Frame (not implemented yet)
292   */
293}
294
295void Frame::setTitle (char* title)
296{
297  /**
298   * Sets the Frames name to title
299   */
300  gtk_frame_set_label (GTK_FRAME (widget), title);
301}
302
303// EVENTBOX //
304EventBox::EventBox ()
305{
306  is_option = -1;
307  next = NULL;
308  down = NULL;
309  widget = gtk_event_box_new ();
310  gtk_container_set_border_width (GTK_CONTAINER (widget), 3);
311}
312
313EventBox::EventBox (char* title)
314{
315  /**
316   * Creates a new EventBox with name title
317   */
318  is_option = -1;
319  next = NULL;
320  down = NULL;
321  widget = gtk_event_box_new ();
322  gtk_container_set_border_width (GTK_CONTAINER (widget), 3);
323
324}
325void EventBox::setTitle (char* title)
326{
327  /**
328   * Sets the EventBoxes name to title
329   */
330  //  gtk_frame_set_label (GTK_FRAME (widget), title);
331}
332EventBox::~EventBox ()
333{
334}
335
336
337/* BOX */
338
339Box::Box (void)
340{
341  /**
342   * Creates a new horizontal Box
343   */
344  is_option = -2;
345  next = NULL;
346  down = NULL;
347  widget = gtk_hbox_new(FALSE, 0);
348}
349Box::Box (char boxtype)
350{
351  /**
352   * Creates a new Box if boxtype is 'v' it will be vertically, if 'h' it will be horizontally
353   */
354  is_option = -2;
355  next = NULL;
356  down = NULL;
357  if (boxtype == 'v')
358    {
359      widget = gtk_vbox_new (FALSE, 0);
360    }
361  else
362    {
363      widget = gtk_hbox_new (FALSE, 0);
364    }
365}
366
367Box::~Box ()
368{
369  /**
370   * Destroys given Frame (not implemented yet)
371   */
372}
373
374void Box::fill (Widget *lowerWidget)
375{
376  /**
377   * Fill a Box with its lowerwidgets
378   */
379  gtk_box_pack_start (GTK_BOX (this->widget), lowerWidget->widget, TRUE, TRUE, 0);
380  if (this->down == NULL)
381    this->down = lowerWidget;
382  else
383    {
384      Widget* tmp;
385      tmp = this->down;
386      while (tmp->next != NULL)
387        {
388          tmp = tmp->next;
389        }
390      tmp->next = lowerWidget;
391    }
392}
393
394/* IMAGE */
395
396Image::Image (char* imagename)
397{
398  is_option = 0;
399  next = NULL;
400  widget = gtk_image_new_from_file (imagename);
401}
402
403
404/* OPTION */
405
406void Option::setFlagName (char* flagname, int defaultvalue)
407{
408  flag_name = flagname;
409  default_value = defaultvalue;
410  cout << "Set Flagname of " << option_name << " to " << flagname << endl;
411}
412
413void Option::setFlagName (char* flagname, char* flagnameshort,  int defaultvalue)
414{
415  /**
416   * \brief Sets the Flagname of an Option. If it is set different then "" this Option will be saved to the Configurationfile
417   */
418  flag_name = flagname;
419  flag_name_short = flagnameshort;
420  default_value = defaultvalue;
421  cout << "Set Flagname of " << option_name << " to " << flagname << endl;
422}
423
424
425/* BUTTON */
426Button::Button(char* buttonname)
427{
428  /**
429   * Creates a new Button with name buttonname
430   */
431  is_option = 0;
432  value = 0;
433  next = NULL;
434  option_name = buttonname;
435  flag_name = "";
436  flag_name_short = "";
437  default_value = 0;
438  widget = gtk_button_new_with_label (buttonname);
439}
440
441void Button::redraw ()
442{
443}
444
445/* CHECKBUTTON */
446CheckButton::CheckButton (char* buttonname)
447{
448  /**
449   * Creates a new CheckButton with name buttonname
450   */
451  is_option = 1;
452  value = 0;
453  next = NULL;
454  option_name = buttonname;
455  flag_name = "";
456  flag_name_short = "";
457  default_value = 0;
458  widget = gtk_check_button_new_with_label (buttonname);
459
460  this->connectSignal ("clicked", this->OptionChange);
461}
462
463gint CheckButton::OptionChange (GtkWidget *widget, Widget* checkbutton)
464{
465  /**
466   * Writes value, if changed on the checkbutton, to the object.
467   */
468  static_cast<CheckButton*>(checkbutton)->value = (int)gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON ((CheckButton*)checkbutton->widget));
469  flags->setTextFromFlags(orxonoxGUI);
470  cout << static_cast<CheckButton*>(checkbutton)->option_name << " set to: " << static_cast<CheckButton*>(checkbutton)->value << endl;
471}
472
473void CheckButton::redraw ()
474{
475  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), value);
476}
477
478/* SLIDER */
479Slider::Slider (char* slidername, int start, int end)
480{
481  /**
482   * Creates a new Slider with name slidername a beginning value of start and an end value of end.
483   */
484  is_option = 2;
485  value = 0;
486  next = NULL;
487  option_name = slidername;
488  flag_name = "";
489  flag_name_short = "";
490  default_value = 0;
491  widget = gtk_hscale_new_with_range (start, end, 5);
492  value = start;
493
494  this->connectSignal ("value_changed", this->OptionChange);
495}
496
497gint Slider::OptionChange (GtkWidget *widget, Widget* slider)
498{
499  /**
500   * Writes value, if changed on the slider, to the object.
501   */
502  static_cast<Slider*>(slider)->value = (int)gtk_range_get_value (GTK_RANGE ((Slider*)slider->widget));
503  flags->setTextFromFlags(orxonoxGUI);
504  cout << static_cast<Slider*>(slider)->option_name << " set to: "<< static_cast<Slider*>(slider)->value << endl;
505}
506
507void Slider::redraw ()
508{
509  gtk_range_set_value (GTK_RANGE (widget), value);
510}
511
512Menu::Menu (char* menuname, ...)
513{
514  /**
515   * Creates an Menu-Item-list out of multiple input. Consider, that the last input argument has to be "lastItem" for this to work.
516   */
517  is_option = 2;
518  value = 0;
519  next = NULL;
520  option_name = menuname;
521  flag_name = "";
522  flag_name_short = "";
523  default_value = 0;
524  char *tmp;
525  va_list itemlist;
526  widget = gtk_option_menu_new ();
527  GtkWidget* menu = gtk_menu_new ();
528  GtkWidget* item;
529
530  va_start (itemlist, menuname);
531  while (strcmp (tmp = va_arg (itemlist, char*), "lastItem"))
532    {
533      item = gtk_menu_item_new_with_label (tmp);
534      gtk_menu_shell_append(GTK_MENU_SHELL (menu), item);
535    }
536  va_end(itemlist);
537
538  gtk_option_menu_set_menu (GTK_OPTION_MENU (widget), menu);
539  this->connectSignal ("changed", this->OptionChange);
540}
541
542gint Menu::OptionChange (GtkWidget *widget, Widget* menu)
543{
544  /**
545   * Writes value, if changed on the Menu, to the object.
546   */
547  static_cast<Menu*>(menu)->value = (int)gtk_option_menu_get_history (GTK_OPTION_MENU (menu->widget));
548  flags->setTextFromFlags(orxonoxGUI);
549  cout << static_cast<Menu*>(menu)->option_name << " changed to : " << static_cast<Menu*>(menu)->value << endl;
550}
551
552void Menu::redraw ()
553{
554  gtk_option_menu_set_history (GTK_OPTION_MENU (widget), value);
555}
556
557Label:: Label ()
558{
559  is_option = 0;
560  next = NULL;
561  widget = gtk_label_new ("");
562  gtk_widget_set_usize (widget, 260, 60);
563  gtk_label_set_line_wrap (GTK_LABEL(widget), TRUE);
564}
565
566Label:: Label (char* text)
567{
568  is_option = 0;
569  next = NULL;
570  widget = gtk_label_new (text);
571  gtk_label_set_line_wrap (GTK_LABEL(widget), TRUE);
572}
573
574Label::~Label ()
575{}
576 
577void Label::setText (char * text)
578{
579  gtk_label_set_text (GTK_LABEL (this->widget), text);
580}
581
582char* Label::getText ()
583{
584  return ((char*)gtk_label_get_text (GTK_LABEL (this->widget)));
585}
Note: See TracBrowser for help on using the repository browser.