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 | |
---|
42 | int main( int argc, char *argv[] ) |
---|
43 | { |
---|
44 | OrxonoxGui* orxonoxgui = new OrxonoxGui(argc, argv); |
---|
45 | return 0; |
---|
46 | } |
---|
47 | |
---|
48 | /* ORXONOXGUI */ |
---|
49 | |
---|
50 | OrxonoxGui::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 | |
---|
102 | void 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 | |
---|
110 | void Widget::connectSignal (char* event, gint (*signal)( GtkWidget*, Widget *)) |
---|
111 | { |
---|
112 | /** |
---|
113 | * Connect a signal with additionally passing the whole Object |
---|
114 | */ |
---|
115 | g_signal_connect (G_OBJECT (this->widget), event, G_CALLBACK (signal), this); |
---|
116 | } |
---|
117 | |
---|
118 | void 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 | } |
---|
125 | void Widget::show() |
---|
126 | { |
---|
127 | /** |
---|
128 | * Function to Show any Widget |
---|
129 | */ |
---|
130 | gtk_widget_show (widget); |
---|
131 | } |
---|
132 | |
---|
133 | void 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 | |
---|
155 | void 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 | |
---|
179 | void 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 | |
---|
197 | Window::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 | |
---|
210 | Window::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 | #if !defined(__WIN32__) |
---|
222 | gtk_window_set_decorated (GTK_WINDOW (widget), FALSE); |
---|
223 | #endif |
---|
224 | this->setTitle (windowName); |
---|
225 | } |
---|
226 | |
---|
227 | Window::~Window () |
---|
228 | { |
---|
229 | /** |
---|
230 | * Destoying a Window (very BAD implemented) |
---|
231 | */ |
---|
232 | gtk_widget_hide (widget); |
---|
233 | |
---|
234 | } |
---|
235 | |
---|
236 | void Window::showall () |
---|
237 | { |
---|
238 | /** |
---|
239 | * Shows all Widgets that are included within this Widget |
---|
240 | */ |
---|
241 | gtk_widget_show_all (widget); |
---|
242 | } |
---|
243 | |
---|
244 | void Window::setTitle (char* title) |
---|
245 | { |
---|
246 | /** |
---|
247 | * Set The Window title to title |
---|
248 | */ |
---|
249 | gtk_window_set_title (GTK_WINDOW (widget), title); |
---|
250 | } |
---|
251 | |
---|
252 | |
---|
253 | gint Window::orxonox_gui_quit (GtkWidget *widget, GdkEvent *event, gpointer data) |
---|
254 | { |
---|
255 | /** |
---|
256 | * Quits the orxonox_GUI |
---|
257 | */ |
---|
258 | if (exec->shouldsave()) |
---|
259 | exec->writeToFile (orxonoxGUI); |
---|
260 | |
---|
261 | gtk_main_quit(); |
---|
262 | return FALSE; |
---|
263 | } |
---|
264 | |
---|
265 | |
---|
266 | /* FRAME */ |
---|
267 | |
---|
268 | Frame::Frame (void) |
---|
269 | { |
---|
270 | /** |
---|
271 | * Creates a new Frame without a name |
---|
272 | */ |
---|
273 | is_option = -1; |
---|
274 | next = NULL; |
---|
275 | down = NULL; |
---|
276 | widget = gtk_frame_new (""); |
---|
277 | gtk_container_set_border_width (GTK_CONTAINER (widget), 3); |
---|
278 | } |
---|
279 | Frame::Frame (char* title) |
---|
280 | { |
---|
281 | /** |
---|
282 | * Creates a new Frame with name title |
---|
283 | */ |
---|
284 | is_option = -1; |
---|
285 | next = NULL; |
---|
286 | down = NULL; |
---|
287 | widget = gtk_frame_new (title); |
---|
288 | gtk_container_set_border_width (GTK_CONTAINER (widget), 3); |
---|
289 | } |
---|
290 | Frame::~Frame () |
---|
291 | { |
---|
292 | /** |
---|
293 | * Destroys given Frame (not implemented yet) |
---|
294 | */ |
---|
295 | } |
---|
296 | |
---|
297 | void Frame::setTitle (char* title) |
---|
298 | { |
---|
299 | /** |
---|
300 | * Sets the Frames name to title |
---|
301 | */ |
---|
302 | gtk_frame_set_label (GTK_FRAME (widget), title); |
---|
303 | } |
---|
304 | |
---|
305 | // EVENTBOX // |
---|
306 | EventBox::EventBox () |
---|
307 | { |
---|
308 | is_option = -1; |
---|
309 | next = NULL; |
---|
310 | down = NULL; |
---|
311 | widget = gtk_event_box_new (); |
---|
312 | gtk_container_set_border_width (GTK_CONTAINER (widget), 3); |
---|
313 | } |
---|
314 | |
---|
315 | EventBox::EventBox (char* title) |
---|
316 | { |
---|
317 | /** |
---|
318 | * Creates a new EventBox with name title |
---|
319 | */ |
---|
320 | is_option = -1; |
---|
321 | next = NULL; |
---|
322 | down = NULL; |
---|
323 | widget = gtk_event_box_new (); |
---|
324 | gtk_container_set_border_width (GTK_CONTAINER (widget), 3); |
---|
325 | |
---|
326 | } |
---|
327 | void EventBox::setTitle (char* title) |
---|
328 | { |
---|
329 | /** |
---|
330 | * Sets the EventBoxes name to title |
---|
331 | */ |
---|
332 | // gtk_frame_set_label (GTK_FRAME (widget), title); |
---|
333 | } |
---|
334 | EventBox::~EventBox () |
---|
335 | { |
---|
336 | } |
---|
337 | |
---|
338 | |
---|
339 | /* BOX */ |
---|
340 | |
---|
341 | Box::Box (void) |
---|
342 | { |
---|
343 | /** |
---|
344 | * Creates a new horizontal Box |
---|
345 | */ |
---|
346 | is_option = -2; |
---|
347 | next = NULL; |
---|
348 | down = NULL; |
---|
349 | widget = gtk_hbox_new(FALSE, 0); |
---|
350 | } |
---|
351 | Box::Box (char boxtype) |
---|
352 | { |
---|
353 | /** |
---|
354 | * Creates a new Box if boxtype is 'v' it will be vertically, if 'h' it will be horizontally |
---|
355 | */ |
---|
356 | is_option = -2; |
---|
357 | next = NULL; |
---|
358 | down = NULL; |
---|
359 | if (boxtype == 'v') |
---|
360 | { |
---|
361 | widget = gtk_vbox_new (FALSE, 0); |
---|
362 | } |
---|
363 | else |
---|
364 | { |
---|
365 | widget = gtk_hbox_new (FALSE, 0); |
---|
366 | } |
---|
367 | } |
---|
368 | |
---|
369 | Box::~Box () |
---|
370 | { |
---|
371 | /** |
---|
372 | * Destroys given Frame (not implemented yet) |
---|
373 | */ |
---|
374 | } |
---|
375 | |
---|
376 | void Box::fill (Widget *lowerWidget) |
---|
377 | { |
---|
378 | /** |
---|
379 | * Fill a Box with its lowerwidgets |
---|
380 | */ |
---|
381 | gtk_box_pack_start (GTK_BOX (this->widget), lowerWidget->widget, TRUE, TRUE, 0); |
---|
382 | if (this->down == NULL) |
---|
383 | this->down = lowerWidget; |
---|
384 | else |
---|
385 | { |
---|
386 | Widget* tmp; |
---|
387 | tmp = this->down; |
---|
388 | while (tmp->next != NULL) |
---|
389 | { |
---|
390 | tmp = tmp->next; |
---|
391 | } |
---|
392 | tmp->next = lowerWidget; |
---|
393 | } |
---|
394 | } |
---|
395 | |
---|
396 | /* IMAGE */ |
---|
397 | |
---|
398 | Image::Image (char* imagename) |
---|
399 | { |
---|
400 | is_option = 0; |
---|
401 | next = NULL; |
---|
402 | widget = gtk_image_new_from_file (imagename); |
---|
403 | } |
---|
404 | |
---|
405 | |
---|
406 | /* OPTION */ |
---|
407 | |
---|
408 | void Option::setFlagName (char* flagname, int defaultvalue) |
---|
409 | { |
---|
410 | flag_name = flagname; |
---|
411 | default_value = defaultvalue; |
---|
412 | cout << "Set Flagname of " << option_name << " to " << flagname << endl; |
---|
413 | } |
---|
414 | |
---|
415 | void Option::setFlagName (char* flagname, char* flagnameshort, int defaultvalue) |
---|
416 | { |
---|
417 | /** |
---|
418 | * \brief Sets the Flagname of an Option. If it is set different then "" this Option will be saved to the Configurationfile |
---|
419 | */ |
---|
420 | flag_name = flagname; |
---|
421 | flag_name_short = flagnameshort; |
---|
422 | default_value = defaultvalue; |
---|
423 | cout << "Set Flagname of " << option_name << " to " << flagname << endl; |
---|
424 | } |
---|
425 | |
---|
426 | |
---|
427 | /* BUTTON */ |
---|
428 | Button::Button(char* buttonname) |
---|
429 | { |
---|
430 | /** |
---|
431 | * Creates a new Button with name buttonname |
---|
432 | */ |
---|
433 | is_option = 0; |
---|
434 | value = 0; |
---|
435 | next = NULL; |
---|
436 | option_name = buttonname; |
---|
437 | flag_name = ""; |
---|
438 | flag_name_short = ""; |
---|
439 | default_value = 0; |
---|
440 | widget = gtk_button_new_with_label (buttonname); |
---|
441 | } |
---|
442 | |
---|
443 | void Button::redraw () |
---|
444 | { |
---|
445 | } |
---|
446 | |
---|
447 | /* CHECKBUTTON */ |
---|
448 | CheckButton::CheckButton (char* buttonname) |
---|
449 | { |
---|
450 | /** |
---|
451 | * Creates a new CheckButton with name buttonname |
---|
452 | */ |
---|
453 | is_option = 1; |
---|
454 | value = 0; |
---|
455 | next = NULL; |
---|
456 | option_name = buttonname; |
---|
457 | flag_name = ""; |
---|
458 | flag_name_short = ""; |
---|
459 | default_value = 0; |
---|
460 | widget = gtk_check_button_new_with_label (buttonname); |
---|
461 | |
---|
462 | this->connectSignal ("clicked", this->OptionChange); |
---|
463 | } |
---|
464 | |
---|
465 | gint CheckButton::OptionChange (GtkWidget *widget, Widget* checkbutton) |
---|
466 | { |
---|
467 | /** |
---|
468 | * Writes value, if changed on the checkbutton, to the object. |
---|
469 | */ |
---|
470 | static_cast<CheckButton*>(checkbutton)->value = (int)gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON ((CheckButton*)checkbutton->widget)); |
---|
471 | flags->setTextFromFlags(orxonoxGUI); |
---|
472 | cout << static_cast<CheckButton*>(checkbutton)->option_name << " set to: " << static_cast<CheckButton*>(checkbutton)->value << endl; |
---|
473 | } |
---|
474 | |
---|
475 | void CheckButton::redraw () |
---|
476 | { |
---|
477 | gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), value); |
---|
478 | } |
---|
479 | |
---|
480 | /* SLIDER */ |
---|
481 | Slider::Slider (char* slidername, int start, int end) |
---|
482 | { |
---|
483 | /** |
---|
484 | * Creates a new Slider with name slidername a beginning value of start and an end value of end. |
---|
485 | */ |
---|
486 | is_option = 2; |
---|
487 | value = 0; |
---|
488 | next = NULL; |
---|
489 | option_name = slidername; |
---|
490 | flag_name = ""; |
---|
491 | flag_name_short = ""; |
---|
492 | default_value = 0; |
---|
493 | widget = gtk_hscale_new_with_range (start, end, 5); |
---|
494 | value = start; |
---|
495 | |
---|
496 | this->connectSignal ("value_changed", this->OptionChange); |
---|
497 | } |
---|
498 | |
---|
499 | gint Slider::OptionChange (GtkWidget *widget, Widget* slider) |
---|
500 | { |
---|
501 | /** |
---|
502 | * Writes value, if changed on the slider, to the object. |
---|
503 | */ |
---|
504 | static_cast<Slider*>(slider)->value = (int)gtk_range_get_value (GTK_RANGE ((Slider*)slider->widget)); |
---|
505 | flags->setTextFromFlags(orxonoxGUI); |
---|
506 | cout << static_cast<Slider*>(slider)->option_name << " set to: "<< static_cast<Slider*>(slider)->value << endl; |
---|
507 | } |
---|
508 | |
---|
509 | void Slider::redraw () |
---|
510 | { |
---|
511 | gtk_range_set_value (GTK_RANGE (widget), value); |
---|
512 | } |
---|
513 | |
---|
514 | Menu::Menu (char* menuname, ...) |
---|
515 | { |
---|
516 | /** |
---|
517 | * Creates an Menu-Item-list out of multiple input. Consider, that the last input argument has to be "lastItem" for this to work. |
---|
518 | */ |
---|
519 | is_option = 2; |
---|
520 | value = 0; |
---|
521 | next = NULL; |
---|
522 | option_name = menuname; |
---|
523 | flag_name = ""; |
---|
524 | flag_name_short = ""; |
---|
525 | default_value = 0; |
---|
526 | char *tmp; |
---|
527 | va_list itemlist; |
---|
528 | widget = gtk_option_menu_new (); |
---|
529 | GtkWidget* menu = gtk_menu_new (); |
---|
530 | GtkWidget* item; |
---|
531 | |
---|
532 | va_start (itemlist, menuname); |
---|
533 | while (strcmp (tmp = va_arg (itemlist, char*), "lastItem")) |
---|
534 | { |
---|
535 | item = gtk_menu_item_new_with_label (tmp); |
---|
536 | gtk_menu_shell_append(GTK_MENU_SHELL (menu), item); |
---|
537 | } |
---|
538 | va_end(itemlist); |
---|
539 | |
---|
540 | gtk_option_menu_set_menu (GTK_OPTION_MENU (widget), menu); |
---|
541 | this->connectSignal ("changed", this->OptionChange); |
---|
542 | } |
---|
543 | |
---|
544 | gint Menu::OptionChange (GtkWidget *widget, Widget* menu) |
---|
545 | { |
---|
546 | /** |
---|
547 | * Writes value, if changed on the Menu, to the object. |
---|
548 | */ |
---|
549 | static_cast<Menu*>(menu)->value = (int)gtk_option_menu_get_history (GTK_OPTION_MENU (menu->widget)); |
---|
550 | flags->setTextFromFlags(orxonoxGUI); |
---|
551 | cout << static_cast<Menu*>(menu)->option_name << " changed to : " << static_cast<Menu*>(menu)->value << endl; |
---|
552 | } |
---|
553 | |
---|
554 | void Menu::redraw () |
---|
555 | { |
---|
556 | gtk_option_menu_set_history (GTK_OPTION_MENU (widget), value); |
---|
557 | } |
---|
558 | |
---|
559 | Label:: Label () |
---|
560 | { |
---|
561 | is_option = 0; |
---|
562 | next = NULL; |
---|
563 | widget = gtk_label_new (""); |
---|
564 | gtk_widget_set_usize (widget, 260, 60); |
---|
565 | gtk_label_set_line_wrap (GTK_LABEL(widget), TRUE); |
---|
566 | } |
---|
567 | |
---|
568 | Label:: Label (char* text) |
---|
569 | { |
---|
570 | is_option = 0; |
---|
571 | next = NULL; |
---|
572 | widget = gtk_label_new (text); |
---|
573 | gtk_label_set_line_wrap (GTK_LABEL(widget), TRUE); |
---|
574 | } |
---|
575 | |
---|
576 | Label::~Label () |
---|
577 | {} |
---|
578 | |
---|
579 | void Label::setText (char * text) |
---|
580 | { |
---|
581 | gtk_label_set_text (GTK_LABEL (this->widget), text); |
---|
582 | } |
---|
583 | |
---|
584 | char* Label::getText () |
---|
585 | { |
---|
586 | return ((char*)gtk_label_get_text (GTK_LABEL (this->widget))); |
---|
587 | } |
---|