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