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 | #include "orxonox_gui_keys.h" |
---|
35 | |
---|
36 | Window* orxonoxGUI; |
---|
37 | OrxonoxGuiVideo* video; |
---|
38 | OrxonoxGuiAudio* audio; |
---|
39 | OrxonoxGuiExec* exec; |
---|
40 | OrxonoxGuiFlags* flags; |
---|
41 | OrxonoxGuiBanner* banner; |
---|
42 | OrxonoxGuiKeys* keys; |
---|
43 | |
---|
44 | int main( int argc, char *argv[] ) |
---|
45 | { |
---|
46 | OrxonoxGui* orxonoxgui = new OrxonoxGui(argc, argv); |
---|
47 | return 0; |
---|
48 | } |
---|
49 | |
---|
50 | /* ORXONOXGUI */ |
---|
51 | |
---|
52 | /** |
---|
53 | * Initializes the Gui |
---|
54 | */ |
---|
55 | OrxonoxGui::OrxonoxGui (int argc, char *argv[]) |
---|
56 | { |
---|
57 | gtk_init (&argc, &argv); |
---|
58 | gtk_rc_parse( "rc" ); |
---|
59 | |
---|
60 | orxonoxGUI = new Window("Graphical Orxonox Launcher"); |
---|
61 | orxonoxGUI->connectSignal ("destroy", orxonoxGUI->orxonox_gui_quit); |
---|
62 | orxonoxGUI->connectSignal ("delete_event", orxonoxGUI->orxonox_gui_quit); |
---|
63 | |
---|
64 | Box* windowBox = new Box ('h'); |
---|
65 | |
---|
66 | banner = new OrxonoxGuiBanner(); |
---|
67 | windowBox->fill (banner->getWidget()); |
---|
68 | |
---|
69 | Box* optionBox = new Box ('v'); |
---|
70 | |
---|
71 | Box* avBox = new Box ('h'); |
---|
72 | |
---|
73 | video = new OrxonoxGuiVideo (); |
---|
74 | avBox->fill (video->getWidget ()); |
---|
75 | audio = new OrxonoxGuiAudio (); |
---|
76 | avBox->fill (audio->getWidget ()); |
---|
77 | |
---|
78 | optionBox->fill (avBox); |
---|
79 | |
---|
80 | keys = new OrxonoxGuiKeys (); |
---|
81 | optionBox->fill (keys->getWidget ()); |
---|
82 | |
---|
83 | exec = new OrxonoxGuiExec (orxonoxGUI); |
---|
84 | optionBox->fill (exec->getWidget ()); |
---|
85 | |
---|
86 | flags = new OrxonoxGuiFlags (orxonoxGUI); |
---|
87 | |
---|
88 | |
---|
89 | optionBox->fill (flags->getWidget ()); |
---|
90 | windowBox->fill (optionBox); |
---|
91 | |
---|
92 | orxonoxGUI->fill (windowBox); |
---|
93 | flags->setTextFromFlags (orxonoxGUI); |
---|
94 | |
---|
95 | exec->setFilename ("~/.orxonox.conf"); |
---|
96 | exec->readFromFile (orxonoxGUI); |
---|
97 | orxonoxGUI->walkThrough(orxonoxGUI->listOptions); |
---|
98 | |
---|
99 | orxonoxGUI->showall (); |
---|
100 | |
---|
101 | |
---|
102 | gtk_main(); |
---|
103 | } |
---|
104 | |
---|
105 | /* WIDGET */ |
---|
106 | |
---|
107 | /** |
---|
108 | \brief deletes any given Widget |
---|
109 | This is still pretty crappy. |
---|
110 | */ |
---|
111 | Widget::~Widget() |
---|
112 | { |
---|
113 | // cout << "hiding: " <<this->label <<"\n"; |
---|
114 | this->hide(); |
---|
115 | // cout << "check if Packer: "<<this->label <<"\n"; |
---|
116 | if (this->is_option < 0) |
---|
117 | { |
---|
118 | // cout << "get Down "<<this->label <<"\n"; |
---|
119 | static_cast<Packer*>(this)->down->~Widget(); |
---|
120 | } |
---|
121 | // cout << "next != NULL?: " <<this->label <<"\n"; |
---|
122 | if (this->next != NULL) |
---|
123 | this->next->~Widget(); |
---|
124 | cout << "delete Widget: " <<this->label <<"\n"; |
---|
125 | // delete widget; |
---|
126 | } |
---|
127 | |
---|
128 | /** |
---|
129 | * Initializes a widget. |
---|
130 | * Nothing to do here. |
---|
131 | */ |
---|
132 | void Widget::init() |
---|
133 | { |
---|
134 | return; |
---|
135 | } |
---|
136 | |
---|
137 | /** |
---|
138 | * makes the widget visible. |
---|
139 | */ |
---|
140 | void Widget::show() |
---|
141 | { |
---|
142 | gtk_widget_show (this->widget); |
---|
143 | } |
---|
144 | |
---|
145 | /** |
---|
146 | * hides the widget. |
---|
147 | */ |
---|
148 | void Widget::hide() |
---|
149 | { |
---|
150 | gtk_widget_hide (this->widget); |
---|
151 | } |
---|
152 | |
---|
153 | /** |
---|
154 | \brief Sets the resolution of a specific widget to the given size. |
---|
155 | \param width the width of the widget to set. |
---|
156 | \param height the height of the widget to set. |
---|
157 | */ |
---|
158 | void Widget::setSize(int width, int height) |
---|
159 | { |
---|
160 | gtk_widget_set_usize (this->widget, width, height); |
---|
161 | } |
---|
162 | |
---|
163 | /** |
---|
164 | * Connect any signal to any given Sub-widget |
---|
165 | */ |
---|
166 | void Widget::connectSignal (char* event, gint (*signal)(GtkWidget*, GdkEvent*, void *)) |
---|
167 | { |
---|
168 | g_signal_connect (G_OBJECT (this->widget), event, G_CALLBACK (signal), NULL); |
---|
169 | } |
---|
170 | |
---|
171 | /** |
---|
172 | * Connect a signal with additionally passing the whole Object |
---|
173 | */ |
---|
174 | void Widget::connectSignal (char* event, gint (*signal)( GtkWidget*, Widget *)) |
---|
175 | { |
---|
176 | g_signal_connect (G_OBJECT (this->widget), event, G_CALLBACK (signal), this); |
---|
177 | } |
---|
178 | |
---|
179 | /** |
---|
180 | * Connect a signal with additionally passing a whole external Object |
---|
181 | */ |
---|
182 | void Widget::connectSignal (char* event, void* extObj, gint (*signal)(GtkWidget*, GdkEvent*, void *)) |
---|
183 | { |
---|
184 | g_signal_connect (G_OBJECT (this->widget), event, G_CALLBACK (signal), extObj); |
---|
185 | } |
---|
186 | |
---|
187 | /** |
---|
188 | * Moves through all the Widgets downwards from this and executes the function on them. |
---|
189 | \param function must be of type void and takes a Widget* as an Input. |
---|
190 | |
---|
191 | */ |
---|
192 | void Widget::walkThrough (void (*function)(Widget*)) |
---|
193 | { |
---|
194 | function(this); |
---|
195 | if (this->is_option < 0) |
---|
196 | { |
---|
197 | static_cast<Packer*>(this)->down->walkThrough (function); |
---|
198 | } |
---|
199 | |
---|
200 | if (this->next != NULL) |
---|
201 | this->next->walkThrough(function); |
---|
202 | } |
---|
203 | |
---|
204 | /** |
---|
205 | * This is for listing the option of "widget" |
---|
206 | \param widget specifies the widget that should be listed |
---|
207 | */ |
---|
208 | void Widget::listOptions (Widget* widget) |
---|
209 | { |
---|
210 | if (widget->is_option >= 1) |
---|
211 | cout << static_cast<Option*>(widget)->label <<" is : " << static_cast<Option*>(widget)->value <<endl; |
---|
212 | } |
---|
213 | |
---|
214 | /** |
---|
215 | * This is for setting the option of "widget" |
---|
216 | \param widget specifies the widget that should be set. |
---|
217 | */ |
---|
218 | void Widget::setOptions (Widget* widget) |
---|
219 | { |
---|
220 | if (widget->is_option >= 1) |
---|
221 | static_cast<Option*>(widget)->redraw();// <<" is : " << static_cast<Option*>(this)->value <<endl; |
---|
222 | } |
---|
223 | |
---|
224 | //void deleteWidget(Widget* lastWidget) |
---|
225 | |
---|
226 | |
---|
227 | /* PACKERS */ |
---|
228 | |
---|
229 | /** |
---|
230 | * Initializes a Packer. |
---|
231 | * nothing to do here |
---|
232 | */ |
---|
233 | void Packer::init (void) |
---|
234 | { |
---|
235 | return; |
---|
236 | } |
---|
237 | |
---|
238 | /* CONTAINERS */ |
---|
239 | |
---|
240 | /** |
---|
241 | * Initializes a Container. |
---|
242 | * nothing to do here |
---|
243 | */ |
---|
244 | void Container::init (void) |
---|
245 | { |
---|
246 | return; |
---|
247 | } |
---|
248 | |
---|
249 | /** |
---|
250 | * Fills a Container with lowerWidget. |
---|
251 | * It does this by filling up the down pointer only if down points to NULL. |
---|
252 | \param lowerWidget the Widget that should be filled into the Container. |
---|
253 | */ |
---|
254 | void Container::fill (Widget *lowerWidget) |
---|
255 | { |
---|
256 | if (this->down == NULL) |
---|
257 | { |
---|
258 | gtk_container_add (GTK_CONTAINER (this->widget), lowerWidget->widget); |
---|
259 | this->down = lowerWidget; |
---|
260 | } |
---|
261 | else |
---|
262 | cout << "!!error!! You try to put more than one Widget into a container.\nnot including this item."<<endl; |
---|
263 | } |
---|
264 | |
---|
265 | // gtk_container_set_border_width (GTK_CONTAINER (widget), 5); |
---|
266 | |
---|
267 | /* WINDOW */ |
---|
268 | |
---|
269 | /** |
---|
270 | * Creating a new Window without a Name |
---|
271 | */ |
---|
272 | Window::Window (void) |
---|
273 | { |
---|
274 | this->init(); |
---|
275 | } |
---|
276 | |
---|
277 | /** |
---|
278 | * Creating a Window with a name |
---|
279 | \param windowName the name the window should get. |
---|
280 | */ |
---|
281 | Window::Window (char* windowName) |
---|
282 | { |
---|
283 | this->init(); |
---|
284 | this->setTitle (windowName); |
---|
285 | } |
---|
286 | |
---|
287 | /** |
---|
288 | *initializes a new Window |
---|
289 | */ |
---|
290 | void Window::init() |
---|
291 | { |
---|
292 | isOpen = true; |
---|
293 | is_option = -1; |
---|
294 | label = ""; |
---|
295 | next = NULL; |
---|
296 | down = NULL; |
---|
297 | widget = gtk_window_new (GTK_WINDOW_TOPLEVEL); |
---|
298 | gtk_window_set_policy (GTK_WINDOW(widget), TRUE, TRUE, TRUE); |
---|
299 | #if !defined(__WIN32__) |
---|
300 | gtk_window_set_decorated (GTK_WINDOW (widget), FALSE); |
---|
301 | #endif |
---|
302 | gtk_container_set_border_width (GTK_CONTAINER (widget), 3); |
---|
303 | } |
---|
304 | |
---|
305 | /** |
---|
306 | * Shows all Widgets that are included within this->widget. |
---|
307 | */ |
---|
308 | void Window::showall () |
---|
309 | { |
---|
310 | isOpen = true; |
---|
311 | gtk_widget_show_all (widget); |
---|
312 | } |
---|
313 | |
---|
314 | /** |
---|
315 | * Set The Window-title to title |
---|
316 | \param title title the Window should get. |
---|
317 | */ |
---|
318 | void Window::setTitle (char* title) |
---|
319 | { |
---|
320 | label=title; |
---|
321 | gtk_window_set_title (GTK_WINDOW (widget), title); |
---|
322 | } |
---|
323 | |
---|
324 | /** |
---|
325 | * Quits the orxonox_GUI. |
---|
326 | * This can be called as a Signal and is therefor static |
---|
327 | \param widget The widget that called this function |
---|
328 | \param event the event that happened to execute this function |
---|
329 | \param data some data passed with the Signal |
---|
330 | */ |
---|
331 | gint Window::orxonox_gui_quit (GtkWidget *widget, GdkEvent *event, gpointer data) |
---|
332 | { |
---|
333 | if (exec->shouldsave()) |
---|
334 | exec->writeToFile (orxonoxGUI); |
---|
335 | |
---|
336 | gtk_main_quit(); |
---|
337 | return FALSE; |
---|
338 | } |
---|
339 | |
---|
340 | |
---|
341 | /* FRAME */ |
---|
342 | |
---|
343 | /** |
---|
344 | * Creates a new Frame without a name |
---|
345 | */ |
---|
346 | Frame::Frame (void) |
---|
347 | { |
---|
348 | this->init(); |
---|
349 | } |
---|
350 | |
---|
351 | /** |
---|
352 | * Creates a new Frame with name title |
---|
353 | */ |
---|
354 | Frame::Frame (char* title) |
---|
355 | { |
---|
356 | this->init(); |
---|
357 | this->setTitle(title); |
---|
358 | } |
---|
359 | |
---|
360 | /** |
---|
361 | * Initializes a new Frame with default settings |
---|
362 | */ |
---|
363 | void Frame::init() |
---|
364 | { |
---|
365 | is_option = -1; |
---|
366 | label = ""; |
---|
367 | next = NULL; |
---|
368 | down = NULL; |
---|
369 | widget = gtk_frame_new (""); |
---|
370 | gtk_container_set_border_width (GTK_CONTAINER (widget), 3); |
---|
371 | } |
---|
372 | |
---|
373 | /** |
---|
374 | * Sets the Frames name to title |
---|
375 | \param title The title the Frame should get. |
---|
376 | */ |
---|
377 | void Frame::setTitle (char* title) |
---|
378 | { |
---|
379 | label = title; |
---|
380 | gtk_frame_set_label (GTK_FRAME (widget), title); |
---|
381 | } |
---|
382 | |
---|
383 | // EVENTBOX // |
---|
384 | |
---|
385 | /** |
---|
386 | * Creates a new EventBox with default settings. |
---|
387 | */ |
---|
388 | EventBox::EventBox () |
---|
389 | { |
---|
390 | this->init(); |
---|
391 | } |
---|
392 | /** |
---|
393 | * Creates a new EventBox with name title |
---|
394 | \param title title the Eventbox should get (only data-structure-internal) |
---|
395 | */ |
---|
396 | EventBox::EventBox (char* title) |
---|
397 | { |
---|
398 | this->init(); |
---|
399 | this->setTitle(title); |
---|
400 | |
---|
401 | } |
---|
402 | |
---|
403 | /** |
---|
404 | * Initializes a new EventBox |
---|
405 | */ |
---|
406 | void EventBox::init(void) |
---|
407 | { |
---|
408 | is_option = -1; |
---|
409 | label = "eventBox"; |
---|
410 | next = NULL; |
---|
411 | down = NULL; |
---|
412 | widget = gtk_event_box_new (); |
---|
413 | gtk_container_set_border_width (GTK_CONTAINER (widget), 3); |
---|
414 | |
---|
415 | } |
---|
416 | |
---|
417 | /** |
---|
418 | * Sets the Title of the EventBox (not implemented) |
---|
419 | \param title Name the EventBox should get (only datastructure-internal). |
---|
420 | */ |
---|
421 | void EventBox::setTitle (char* title) |
---|
422 | { |
---|
423 | label = title; |
---|
424 | } |
---|
425 | |
---|
426 | /* BOX */ |
---|
427 | |
---|
428 | /** |
---|
429 | * Creates a new horizontal Box |
---|
430 | */ |
---|
431 | Box::Box (void) |
---|
432 | { |
---|
433 | this->init('h'); |
---|
434 | } |
---|
435 | |
---|
436 | /** |
---|
437 | * Creates a new Box of type boxtype |
---|
438 | \param boxtype if 'v' the Box will be vertically, if 'h' the Box will be horizontally |
---|
439 | */ |
---|
440 | Box::Box (char boxtype) |
---|
441 | { |
---|
442 | this->init(boxtype); |
---|
443 | } |
---|
444 | |
---|
445 | /** |
---|
446 | * Initializes a new Box with type boxtype |
---|
447 | \param boxtype see Box(char boxtype) |
---|
448 | */ |
---|
449 | void Box::init(char boxtype) |
---|
450 | { |
---|
451 | is_option = -2; |
---|
452 | label = "box"; |
---|
453 | next = NULL; |
---|
454 | down = NULL; |
---|
455 | if (boxtype == 'v') |
---|
456 | { |
---|
457 | widget = gtk_vbox_new (FALSE, 0); |
---|
458 | } |
---|
459 | else |
---|
460 | { |
---|
461 | widget = gtk_hbox_new (FALSE, 0); |
---|
462 | } |
---|
463 | } |
---|
464 | |
---|
465 | /** |
---|
466 | * Fills a box with a given Widget. |
---|
467 | * It does this by apending the first one to its down-pointer and all its following ones to the preceding next-pointer. The last one will receive a NULL pointer as Next |
---|
468 | \param lowerWidget the next Widget that should be appendet to this Box |
---|
469 | */ |
---|
470 | void Box::fill (Widget *lowerWidget) |
---|
471 | { |
---|
472 | /** |
---|
473 | * Fill a Box with its lowerwidgets |
---|
474 | */ |
---|
475 | gtk_box_pack_start (GTK_BOX (this->widget), lowerWidget->widget, TRUE, TRUE, 0); |
---|
476 | if (this->down == NULL) |
---|
477 | this->down = lowerWidget; |
---|
478 | else |
---|
479 | { |
---|
480 | Widget* tmp; |
---|
481 | tmp = this->down; |
---|
482 | while (tmp->next != NULL) |
---|
483 | { |
---|
484 | tmp = tmp->next; |
---|
485 | } |
---|
486 | tmp->next = lowerWidget; |
---|
487 | } |
---|
488 | } |
---|
489 | |
---|
490 | /* IMAGE */ |
---|
491 | |
---|
492 | /** |
---|
493 | * Creates a new Image |
---|
494 | \param imagename the location of the Image on the Hard Disc |
---|
495 | */ |
---|
496 | Image::Image (char* imagename) |
---|
497 | { |
---|
498 | this->init(); |
---|
499 | widget = gtk_image_new_from_file (imagename); |
---|
500 | label = imagename; |
---|
501 | } |
---|
502 | |
---|
503 | /** |
---|
504 | * Initializes a new Image |
---|
505 | */ |
---|
506 | void Image::init() |
---|
507 | { |
---|
508 | is_option = 0; |
---|
509 | label = ""; |
---|
510 | next = NULL; |
---|
511 | } |
---|
512 | |
---|
513 | |
---|
514 | /* OPTION */ |
---|
515 | |
---|
516 | /** |
---|
517 | * Initializes a new Option: nothing to do here |
---|
518 | */ |
---|
519 | void Option::init() |
---|
520 | { |
---|
521 | return; |
---|
522 | } |
---|
523 | |
---|
524 | /** |
---|
525 | * This sets The FlagName of an Option and defines its default Values |
---|
526 | !! Options will be saved if flagname is different from "" !! |
---|
527 | \param flagname the Name that will be displayed in the output |
---|
528 | \param defaultvalue the default Value for this Option (see definition of defaultvalue |
---|
529 | */ |
---|
530 | void Option::setFlagName (char* flagname, int defaultvalue) |
---|
531 | { |
---|
532 | flag_name = flagname; |
---|
533 | default_value = defaultvalue; |
---|
534 | cout << "Set Flagname of " << label << " to " << flagname << endl; |
---|
535 | } |
---|
536 | |
---|
537 | /** |
---|
538 | * see Option::setFlagName (char* flagname, int defaultvalue) |
---|
539 | \param flagname the Name that will be displayed in the output |
---|
540 | \param defaultvalue the default Value for this Option (see definition of defaultvalue |
---|
541 | \param flagnameshort a short flagname to be displayed in the output |
---|
542 | */ |
---|
543 | void Option::setFlagName (char* flagname, char* flagnameshort, int defaultvalue) |
---|
544 | { |
---|
545 | flag_name = flagname; |
---|
546 | flag_name_short = flagnameshort; |
---|
547 | default_value = defaultvalue; |
---|
548 | cout << "Set Flagname of " << label << " to " << flagname << endl; |
---|
549 | } |
---|
550 | |
---|
551 | |
---|
552 | /* BUTTON */ |
---|
553 | |
---|
554 | /** |
---|
555 | * Creates a new Button with a buttonname |
---|
556 | \param buttonname sets the Name of the Button |
---|
557 | */ |
---|
558 | Button::Button(char* buttonname) |
---|
559 | { |
---|
560 | this->init(); |
---|
561 | this->setTitle(buttonname); |
---|
562 | } |
---|
563 | |
---|
564 | /** |
---|
565 | * Initializes a new Button |
---|
566 | */ |
---|
567 | void Button::init(void) |
---|
568 | { |
---|
569 | is_option = 0; |
---|
570 | value = 0; |
---|
571 | next = NULL; |
---|
572 | label =""; |
---|
573 | flag_name = ""; |
---|
574 | flag_name_short = ""; |
---|
575 | default_value = 0; |
---|
576 | widget = gtk_button_new_with_label (""); |
---|
577 | } |
---|
578 | |
---|
579 | /** |
---|
580 | * Sets a new name to the Button |
---|
581 | \param title The name the Button should get |
---|
582 | */ |
---|
583 | void Button::setTitle (char *title) |
---|
584 | { |
---|
585 | label = title; |
---|
586 | gtk_button_set_label (GTK_BUTTON(widget), title); |
---|
587 | } |
---|
588 | |
---|
589 | /** |
---|
590 | * redraws the Button |
---|
591 | * not implemented yet |
---|
592 | */ |
---|
593 | void Button::redraw () |
---|
594 | { |
---|
595 | } |
---|
596 | |
---|
597 | /* CHECKBUTTON */ |
---|
598 | |
---|
599 | /** |
---|
600 | * Creates a new CheckButton with an ame |
---|
601 | \param buttonname The name the CheckButton should display. |
---|
602 | */ |
---|
603 | CheckButton::CheckButton (char* buttonname) |
---|
604 | { |
---|
605 | this->init(); |
---|
606 | this->setTitle(buttonname); |
---|
607 | |
---|
608 | this->connectSignal ("clicked", this->OptionChange); |
---|
609 | } |
---|
610 | |
---|
611 | /** |
---|
612 | * Initiali a new CheckButton with default settings |
---|
613 | */ |
---|
614 | void CheckButton::init(void) |
---|
615 | { |
---|
616 | is_option = 1; |
---|
617 | value = 0; |
---|
618 | next = NULL; |
---|
619 | label = ""; |
---|
620 | flag_name = ""; |
---|
621 | flag_name_short = ""; |
---|
622 | default_value = 0; |
---|
623 | widget = gtk_check_button_new_with_label (""); |
---|
624 | } |
---|
625 | |
---|
626 | /** |
---|
627 | * Sets a new Title to a CheckButton |
---|
628 | \param title The new Name the CheckButton should display. |
---|
629 | */ |
---|
630 | void CheckButton::setTitle(char* title) |
---|
631 | { |
---|
632 | label = title; |
---|
633 | gtk_button_set_label(GTK_BUTTON(widget), title); |
---|
634 | } |
---|
635 | |
---|
636 | |
---|
637 | /** |
---|
638 | * Signal OptionChange writes the Value from the CheckButton to its Object-Database. |
---|
639 | \param widget The widget(CheckButton) that has a changed Value |
---|
640 | \param checkbutton the CheckButton-Object that should receive the change. |
---|
641 | */ |
---|
642 | gint CheckButton::OptionChange (GtkWidget *widget, Widget* checkbutton) |
---|
643 | { |
---|
644 | static_cast<CheckButton*>(checkbutton)->value = (int)gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON ((CheckButton*)checkbutton->widget)); |
---|
645 | flags->setTextFromFlags(orxonoxGUI); |
---|
646 | cout << static_cast<CheckButton*>(checkbutton)->label << " set to: " << static_cast<CheckButton*>(checkbutton)->value << endl; |
---|
647 | } |
---|
648 | |
---|
649 | /** |
---|
650 | * Redraws the CheckButton (if option has changed). |
---|
651 | * Example: if new settings are loaded the Button must be redrawn for the GUI to display that Change |
---|
652 | */ |
---|
653 | void CheckButton::redraw () |
---|
654 | { |
---|
655 | gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), value); |
---|
656 | } |
---|
657 | |
---|
658 | /* SLIDER */ |
---|
659 | |
---|
660 | /** |
---|
661 | * Creates a new Slider |
---|
662 | \param slidername The data-structure-name of the slider. |
---|
663 | \param start The minimal Value of the slider. |
---|
664 | \param end The maximal Value of the slider. |
---|
665 | */ |
---|
666 | Slider::Slider (char* slidername, int start, int end) |
---|
667 | { |
---|
668 | this->init(start, end); |
---|
669 | this->setValue(start); |
---|
670 | this->setTitle(slidername); |
---|
671 | this->connectSignal ("value_changed", this->OptionChange); |
---|
672 | } |
---|
673 | |
---|
674 | /** |
---|
675 | * Initializes a Slider with start and end Values |
---|
676 | * params: see Slider::Slider (char* slidername, int start, int end) |
---|
677 | */ |
---|
678 | void Slider::init(int start, int end) |
---|
679 | { |
---|
680 | is_option = 2; |
---|
681 | value = 0; |
---|
682 | next = NULL; |
---|
683 | label = ""; |
---|
684 | flag_name = ""; |
---|
685 | flag_name_short = ""; |
---|
686 | default_value = 0; |
---|
687 | widget = gtk_hscale_new_with_range (start, end, 5); |
---|
688 | } |
---|
689 | |
---|
690 | /** |
---|
691 | * Sets a new Title to the Slider |
---|
692 | \param title The new Name of the slider |
---|
693 | */ |
---|
694 | void Slider::setTitle(char* title) |
---|
695 | { |
---|
696 | label = title; |
---|
697 | } |
---|
698 | |
---|
699 | /** |
---|
700 | * Setting a new value to the Slider. |
---|
701 | * Maybe you also require a Slider::redraw() for this to display |
---|
702 | */ |
---|
703 | void Slider::setValue(int value) |
---|
704 | { |
---|
705 | this->value = value; |
---|
706 | } |
---|
707 | |
---|
708 | /** |
---|
709 | * Signal OptionChange writes the Value from the Slider to its Object-Database. |
---|
710 | \param widget The widget(Slider) that has a changed Value |
---|
711 | \param slider the Slider-Object that should receive the change. |
---|
712 | */ |
---|
713 | gint Slider::OptionChange (GtkWidget *widget, Widget* slider) |
---|
714 | { |
---|
715 | static_cast<Slider*>(slider)->value = (int)gtk_range_get_value (GTK_RANGE ((Slider*)slider->widget)); |
---|
716 | flags->setTextFromFlags(orxonoxGUI); |
---|
717 | cout << static_cast<Slider*>(slider)->label << " set to: "<< static_cast<Slider*>(slider)->value << endl; |
---|
718 | } |
---|
719 | |
---|
720 | /** |
---|
721 | * Redraws the widget |
---|
722 | * Example: see void CheckButton::redraw () |
---|
723 | */ |
---|
724 | void Slider::redraw () |
---|
725 | { |
---|
726 | gtk_range_set_value (GTK_RANGE (widget), value); |
---|
727 | } |
---|
728 | |
---|
729 | /* MENU */ |
---|
730 | |
---|
731 | /** |
---|
732 | * Creates a Menu-Item-list out of multiple input. |
---|
733 | * !! Consider, that the last input argument has to be "lastItem" for this to work!! |
---|
734 | \param menuname The Database-Name of this Menu |
---|
735 | \param ... items to be added to this Menu. !! Consider, that the last input argument has to be "lastItem" for this to work!! |
---|
736 | */ |
---|
737 | Menu::Menu (char* menuname, ...) |
---|
738 | { |
---|
739 | this->init(); |
---|
740 | this->setTitle(menuname); |
---|
741 | |
---|
742 | char *itemName; |
---|
743 | |
---|
744 | va_start (itemlist, menuname); |
---|
745 | while (strcmp (itemName = va_arg (itemlist, char*), "lastItem")) |
---|
746 | { |
---|
747 | this->addItem(itemName); |
---|
748 | } |
---|
749 | va_end(itemlist); |
---|
750 | |
---|
751 | gtk_option_menu_set_menu (GTK_OPTION_MENU (widget), menu); |
---|
752 | this->connectSignal ("changed", this->OptionChange); |
---|
753 | } |
---|
754 | |
---|
755 | /** |
---|
756 | * Initializes a new Menu with no items |
---|
757 | */ |
---|
758 | void Menu::init(void) |
---|
759 | { |
---|
760 | is_option = 2; |
---|
761 | value = 0; |
---|
762 | next = NULL; |
---|
763 | flag_name = ""; |
---|
764 | flag_name_short = ""; |
---|
765 | default_value = 0; |
---|
766 | widget = gtk_option_menu_new (); |
---|
767 | menu = gtk_menu_new (); |
---|
768 | |
---|
769 | } |
---|
770 | |
---|
771 | /** |
---|
772 | * Sets the Database-Name of this Menu |
---|
773 | \param title Database-Name to be set. |
---|
774 | */ |
---|
775 | void Menu::setTitle(char* title) |
---|
776 | { |
---|
777 | label = title; |
---|
778 | } |
---|
779 | |
---|
780 | /** |
---|
781 | * appends a new Item to the Menu-List. |
---|
782 | \param itemName the itemName to be appendet. |
---|
783 | */ |
---|
784 | void Menu::addItem (char* itemName) |
---|
785 | { |
---|
786 | item = gtk_menu_item_new_with_label (itemName); |
---|
787 | gtk_menu_shell_append(GTK_MENU_SHELL (menu), item); |
---|
788 | } |
---|
789 | |
---|
790 | /** |
---|
791 | * Signal OptionChange writes the Value from the Menu to its Object-Database. |
---|
792 | \param widget The widget(Menu) that has a changed Value |
---|
793 | \param menu the Menu-Object that should receive the change. |
---|
794 | */gint Menu::OptionChange (GtkWidget *widget, Widget* menu) |
---|
795 | { |
---|
796 | static_cast<Menu*>(menu)->value = (int)gtk_option_menu_get_history (GTK_OPTION_MENU (menu->widget)); |
---|
797 | flags->setTextFromFlags(orxonoxGUI); |
---|
798 | cout << static_cast<Menu*>(menu)->label << " changed to : " << static_cast<Menu*>(menu)->value << endl; |
---|
799 | } |
---|
800 | |
---|
801 | /** |
---|
802 | * Redraws the widget |
---|
803 | * Example: see void CheckButton::redraw () |
---|
804 | */ |
---|
805 | void Menu::redraw () |
---|
806 | { |
---|
807 | gtk_option_menu_set_history (GTK_OPTION_MENU (widget), value); |
---|
808 | } |
---|
809 | |
---|
810 | /** |
---|
811 | * Creates a new default Label with no Text. |
---|
812 | * You migth consider adding Label::setTitle with this. |
---|
813 | */ |
---|
814 | Label:: Label () |
---|
815 | { |
---|
816 | this->init(); |
---|
817 | } |
---|
818 | |
---|
819 | /** |
---|
820 | * Creates a new Label with a Text. |
---|
821 | \param text The text to be displayed. |
---|
822 | */ |
---|
823 | Label:: Label (char* text) |
---|
824 | { |
---|
825 | this->init(); |
---|
826 | this->setText(text); |
---|
827 | } |
---|
828 | |
---|
829 | /** |
---|
830 | * initializes a new Label |
---|
831 | */ |
---|
832 | void Label::init(void) |
---|
833 | { |
---|
834 | is_option = 0; |
---|
835 | label = ""; |
---|
836 | next = NULL; |
---|
837 | widget = gtk_label_new (""); |
---|
838 | gtk_label_set_line_wrap (GTK_LABEL(widget), TRUE); |
---|
839 | } |
---|
840 | |
---|
841 | /** |
---|
842 | * Sets a new Text to a Label. |
---|
843 | \param text The text to be inserted into the Label. |
---|
844 | */ |
---|
845 | void Label::setText (char * text) |
---|
846 | { |
---|
847 | label = text; |
---|
848 | gtk_label_set_text (GTK_LABEL (this->widget), text); |
---|
849 | } |
---|
850 | |
---|
851 | /** |
---|
852 | * get the Text of a Label |
---|
853 | \return The Text the Label holds. |
---|
854 | */ |
---|
855 | char* Label::getText () |
---|
856 | { |
---|
857 | return ((char*)gtk_label_get_text (GTK_LABEL (this->widget))); |
---|
858 | } |
---|