Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 1982 was 1979, checked in by bensch, 21 years ago

orxonox/branches/gui/guicc: added exec, and made menu autoSignalConnect

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