Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/branches/gui/guicc: added video and audio frames. made default signal connection to slider and checkbutton

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