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 | |
---|
27 | #include <iostream> |
---|
28 | |
---|
29 | #include "orxonox_gui_gtk.h" |
---|
30 | |
---|
31 | |
---|
32 | using namespace std; |
---|
33 | |
---|
34 | // temporarily. |
---|
35 | #include "orxonox_gui_flags.h" |
---|
36 | #include "orxonox_gui_exec.h" |
---|
37 | extern Window* orxonoxGUI; |
---|
38 | extern OrxonoxGuiFlags* flags; |
---|
39 | extern OrxonoxGuiExec* exec; |
---|
40 | |
---|
41 | #ifdef HAVE_GTK2 |
---|
42 | bool initGTK(int argc, char *argv[]) |
---|
43 | { |
---|
44 | gtk_init (&argc, &argv); |
---|
45 | gtk_rc_parse( "rc" ); |
---|
46 | } |
---|
47 | bool mainloopGTK(void) |
---|
48 | { |
---|
49 | gtk_main(); |
---|
50 | } |
---|
51 | #endif /* HAVE_GTK2 */ |
---|
52 | |
---|
53 | /* WIDGET */ |
---|
54 | |
---|
55 | /** |
---|
56 | \brief deletes any given Widget |
---|
57 | This is still pretty crappy. |
---|
58 | */ |
---|
59 | Widget::~Widget() |
---|
60 | { |
---|
61 | // cout << "hiding: " <<this->label <<"\n"; |
---|
62 | this->hide(); |
---|
63 | // cout << "check if Packer: "<<this->label <<"\n"; |
---|
64 | if (this->isOption < 0) |
---|
65 | { |
---|
66 | // cout << "get Down "<<this->label <<"\n"; |
---|
67 | static_cast<Packer*>(this)->down->~Widget(); |
---|
68 | } |
---|
69 | // cout << "next != NULL?: " <<this->label <<"\n"; |
---|
70 | if (this->next != NULL) |
---|
71 | this->next->~Widget(); |
---|
72 | cout << "delete Widget: " <<this->label <<"\n"; |
---|
73 | // delete widget; |
---|
74 | } |
---|
75 | |
---|
76 | /** |
---|
77 | \brief Initializes a widget. |
---|
78 | Initializes the next Pointer and the other Widget-specific Defaults. |
---|
79 | */ |
---|
80 | void Widget::init() |
---|
81 | { |
---|
82 | next = NULL; |
---|
83 | label = NULL; |
---|
84 | return; |
---|
85 | } |
---|
86 | |
---|
87 | /** |
---|
88 | \brief makes the widget visible. |
---|
89 | */ |
---|
90 | void Widget::show() |
---|
91 | { |
---|
92 | #ifdef HAVE_GTK2 |
---|
93 | gtk_widget_show (this->widget); |
---|
94 | #endif /* HAVE_GTK2 */ |
---|
95 | } |
---|
96 | |
---|
97 | /** |
---|
98 | \brief hides the widget. |
---|
99 | */ |
---|
100 | void Widget::hide() |
---|
101 | { |
---|
102 | #ifdef HAVE_GTK2 |
---|
103 | gtk_widget_hide (this->widget); |
---|
104 | #endif /* HAVE_GTK2 */ |
---|
105 | } |
---|
106 | |
---|
107 | /** |
---|
108 | \brief Sets the resolution of a specific widget to the given size. |
---|
109 | \param width the width of the widget to set. |
---|
110 | \param height the height of the widget to set. |
---|
111 | */ |
---|
112 | void Widget::setSize(int width, int height) |
---|
113 | { |
---|
114 | #ifdef HAVE_GTK2 |
---|
115 | gtk_widget_set_usize (this->widget, width, height); |
---|
116 | #endif /* HAVE_GTK2 */ |
---|
117 | } |
---|
118 | |
---|
119 | #ifdef HAVE_GTK2 |
---|
120 | /** |
---|
121 | \brief Connect any signal to any given Sub-widget |
---|
122 | */ |
---|
123 | gulong Widget::connectSignal (char* event, gint (*signal)(GtkWidget*, GdkEvent*, void *)) |
---|
124 | { |
---|
125 | return g_signal_connect (G_OBJECT (this->widget), event, G_CALLBACK (signal), NULL); |
---|
126 | } |
---|
127 | |
---|
128 | /** |
---|
129 | \brief Connect a signal with additionally passing the whole Object |
---|
130 | */ |
---|
131 | gulong Widget::connectSignal (char* event, gint (*signal)( GtkWidget*, Widget *)) |
---|
132 | { |
---|
133 | return g_signal_connect (G_OBJECT (this->widget), event, G_CALLBACK (signal), this); |
---|
134 | } |
---|
135 | |
---|
136 | /** |
---|
137 | \brief Connect a signal with additionally passing a whole external Object |
---|
138 | */ |
---|
139 | gulong Widget::connectSignal (char* event, void* extObj, gint (*signal)(GtkWidget*, GdkEvent*, void *)) |
---|
140 | { |
---|
141 | return g_signal_connect (G_OBJECT (this->widget), event, G_CALLBACK (signal), extObj); |
---|
142 | } |
---|
143 | |
---|
144 | /** |
---|
145 | \brief Connect a signal with additionally passing a whole external Object |
---|
146 | */ |
---|
147 | gulong Widget::connectSignal (char* event, void* extObj, gint (*signal)(GtkWidget*, GdkEventKey*, void *)) |
---|
148 | { |
---|
149 | return g_signal_connect (G_OBJECT (this->widget), event, G_CALLBACK (signal), extObj); |
---|
150 | } |
---|
151 | |
---|
152 | void Widget::disconnectSignal (gulong signalID) |
---|
153 | { |
---|
154 | g_signal_handler_disconnect (G_OBJECT (this->widget), signalID); |
---|
155 | } |
---|
156 | #endif /* HAVE_GTK2 */ |
---|
157 | |
---|
158 | /** |
---|
159 | \brief Moves through all the Widgets downwards from this and executes the function on them. |
---|
160 | \param function must be of type void and takes a Widget* as an Input. |
---|
161 | */ |
---|
162 | void Widget::walkThrough (void (*function)(Widget*)) |
---|
163 | { |
---|
164 | function(this); |
---|
165 | if (this->isOption < 0) |
---|
166 | { |
---|
167 | static_cast<Packer*>(this)->down->walkThrough (function); |
---|
168 | } |
---|
169 | |
---|
170 | if (this->next != NULL) |
---|
171 | this->next->walkThrough(function); |
---|
172 | } |
---|
173 | |
---|
174 | /** |
---|
175 | \brief This is for listing the option of "widget" |
---|
176 | \param widget specifies the widget that should be listed |
---|
177 | */ |
---|
178 | void Widget::listOptions (Widget* widget) |
---|
179 | { |
---|
180 | if (widget->isOption < 0 && static_cast<Packer*>(widget)->groupName) |
---|
181 | cout << "[" << static_cast<Packer*>(widget)->groupName << "]\n"; |
---|
182 | if (widget->isOption >= 1 && widget->isOption <= 3) |
---|
183 | cout << " " << static_cast<Option*>(widget)->label <<" is : " << static_cast<Option*>(widget)->value <<endl; |
---|
184 | else if (widget->isOption == 5) |
---|
185 | cout << " " << static_cast<Option*>(widget)->label <<" is : " << static_cast<OptionLabel*>(widget)->cValue <<endl; |
---|
186 | } |
---|
187 | |
---|
188 | /** |
---|
189 | \brief This is for setting the option of "widget" |
---|
190 | \param widget specifies the widget that should be set. |
---|
191 | */ |
---|
192 | void Widget::setOptions (Widget* widget) |
---|
193 | { |
---|
194 | if (widget->isOption >= 1) |
---|
195 | static_cast<Option*>(widget)->redraw();// <<" is : " << static_cast<Option*>(this)->value <<endl; |
---|
196 | } |
---|
197 | |
---|
198 | #ifdef HAVE_GTK2 |
---|
199 | gint Widget::doNothingSignal (GtkWidget *widget, GdkEvent* event, void* nothing) |
---|
200 | { |
---|
201 | } |
---|
202 | #endif /* HAVE_GTK2 */ |
---|
203 | |
---|
204 | //void deleteWidget(Widget* lastWidget) |
---|
205 | |
---|
206 | |
---|
207 | /* PACKERS */ |
---|
208 | |
---|
209 | /** |
---|
210 | \brief Initializes a Packer. |
---|
211 | Sets the down-pinter to NULL and other PackerSpecific-values to their defaults. |
---|
212 | */ |
---|
213 | void Packer::init (void) |
---|
214 | { |
---|
215 | down = NULL; |
---|
216 | groupName = NULL; |
---|
217 | |
---|
218 | |
---|
219 | static_cast<Widget*>(this)->init(); |
---|
220 | return; |
---|
221 | } |
---|
222 | |
---|
223 | /** |
---|
224 | \brief Sets the group name under which all the lower widgets of this will be saved. |
---|
225 | \param name The name of the group. |
---|
226 | */ |
---|
227 | void Packer::setGroupName (char* name) |
---|
228 | { |
---|
229 | if (groupName) |
---|
230 | delete groupName; |
---|
231 | groupName = new char [strlen(name)+1]; |
---|
232 | strcpy(groupName, name); |
---|
233 | } |
---|
234 | |
---|
235 | /** |
---|
236 | \brief Retrieves the group name under which all the lower widgets of this will be saved. |
---|
237 | \returns name The name of the group. |
---|
238 | */ |
---|
239 | char* Packer::getGroupName (void) |
---|
240 | { |
---|
241 | return groupName; |
---|
242 | } |
---|
243 | |
---|
244 | /* CONTAINERS */ |
---|
245 | |
---|
246 | /** |
---|
247 | \brief Initializes a Container. |
---|
248 | sets the Container-Specific defaults. |
---|
249 | */ |
---|
250 | void Container::init (void) |
---|
251 | { |
---|
252 | isOption = -1; |
---|
253 | |
---|
254 | static_cast<Packer*>(this)->init(); |
---|
255 | |
---|
256 | return; |
---|
257 | } |
---|
258 | |
---|
259 | /** |
---|
260 | \briefFills a Container with lowerWidget. |
---|
261 | It does this by filling up the down pointer only if down points to NULL. |
---|
262 | \param lowerWidget the Widget that should be filled into the Container. |
---|
263 | */ |
---|
264 | void Container::fill (Widget *lowerWidget) |
---|
265 | { |
---|
266 | if (this->down == NULL) |
---|
267 | { |
---|
268 | #ifdef HAVE_GTK2 |
---|
269 | gtk_container_add (GTK_CONTAINER (this->widget), lowerWidget->widget); |
---|
270 | #endif /* HAVE_GTK2 */ |
---|
271 | this->down = lowerWidget; |
---|
272 | } |
---|
273 | else |
---|
274 | cout << "!!error!! You try to put more than one Widget into a Container. \nNot including this item.\nThis is only possible with Boxes.\n"<<endl; |
---|
275 | } |
---|
276 | |
---|
277 | // gtk_container_set_border_width (GTK_CONTAINER (widget), 5); |
---|
278 | |
---|
279 | /* WINDOW */ |
---|
280 | |
---|
281 | Window* Window::mainWindow = NULL; |
---|
282 | |
---|
283 | void Window::addWindow(Window* windowToAdd) |
---|
284 | { |
---|
285 | if (!mainWindow) |
---|
286 | { |
---|
287 | mainWindow = windowToAdd; |
---|
288 | return; |
---|
289 | } |
---|
290 | |
---|
291 | Widget* tmpWindow = mainWindow; |
---|
292 | while (tmpWindow->next) |
---|
293 | tmpWindow = tmpWindow->next; |
---|
294 | tmpWindow->next = windowToAdd; |
---|
295 | |
---|
296 | return; |
---|
297 | } |
---|
298 | |
---|
299 | |
---|
300 | |
---|
301 | /** |
---|
302 | \brief Creating a new Window without a Name |
---|
303 | */ |
---|
304 | Window::Window (void) |
---|
305 | { |
---|
306 | this->init(); |
---|
307 | } |
---|
308 | |
---|
309 | /** |
---|
310 | \brief Creating a Window with a name |
---|
311 | \param windowName the name the window should get. |
---|
312 | */ |
---|
313 | Window::Window (char* windowName) |
---|
314 | { |
---|
315 | this->init(); |
---|
316 | this->setTitle (windowName); |
---|
317 | } |
---|
318 | |
---|
319 | /** |
---|
320 | \brief initializes a new Window |
---|
321 | */ |
---|
322 | void Window::init() |
---|
323 | { |
---|
324 | if (!mainWindow) |
---|
325 | mainWindow = this; |
---|
326 | |
---|
327 | isOpen = false; |
---|
328 | |
---|
329 | static_cast<Container*>(this)->init(); |
---|
330 | |
---|
331 | #ifdef HAVE_GTK2 |
---|
332 | widget = gtk_window_new (GTK_WINDOW_TOPLEVEL); |
---|
333 | gtk_window_set_policy (GTK_WINDOW(widget), TRUE, TRUE, TRUE); |
---|
334 | #if !defined(__WIN32__) |
---|
335 | // gtk_window_set_decorated (GTK_WINDOW (widget), FALSE); |
---|
336 | #endif |
---|
337 | gtk_container_set_border_width (GTK_CONTAINER (widget), 3); |
---|
338 | #endif /* HAVE_GTK2 */ |
---|
339 | } |
---|
340 | |
---|
341 | /** |
---|
342 | \brief Shows all Widgets that are included within this->widget. |
---|
343 | */ |
---|
344 | void Window::showall () |
---|
345 | { |
---|
346 | if (!isOpen) |
---|
347 | { |
---|
348 | // printf ("showall\n"); |
---|
349 | #ifdef HAVE_GTK2 |
---|
350 | gtk_widget_show_all (widget); |
---|
351 | #endif /* HAVE_GTK2 */ |
---|
352 | isOpen = true; |
---|
353 | } |
---|
354 | else |
---|
355 | { |
---|
356 | // printf ("showone\n"); |
---|
357 | #ifdef HAVE_GTK2 |
---|
358 | gtk_widget_show (widget); |
---|
359 | #endif /* HAVE_GTK2 */ |
---|
360 | } |
---|
361 | } |
---|
362 | |
---|
363 | /** |
---|
364 | \brief Set The Window-title to title |
---|
365 | \param title title the Window should get. |
---|
366 | */ |
---|
367 | void Window::setTitle (char* title) |
---|
368 | { |
---|
369 | if (label) |
---|
370 | delete label; |
---|
371 | label = new char[strlen(title)+1]; |
---|
372 | strcpy(label, title); |
---|
373 | #ifdef HAVE_GTK2 |
---|
374 | gtk_window_set_title (GTK_WINDOW (widget), title); |
---|
375 | #endif /* HAVE_GTK2 */ |
---|
376 | } |
---|
377 | |
---|
378 | /** |
---|
379 | \brief opens up a Window and fixes the Focus to it |
---|
380 | */ |
---|
381 | void Window::open() |
---|
382 | { |
---|
383 | if (this != mainWindow) |
---|
384 | { |
---|
385 | isOpen = true; |
---|
386 | #ifdef HAVE_GTK2 |
---|
387 | gtk_widget_show_all(widget); |
---|
388 | gtk_grab_add(widget); |
---|
389 | #endif /* HAVE_GTK2 */ |
---|
390 | } |
---|
391 | } |
---|
392 | |
---|
393 | /** |
---|
394 | \brief closes up a Window and removes the Focus from it |
---|
395 | */ |
---|
396 | void Window::close() |
---|
397 | { |
---|
398 | if (this != mainWindow) |
---|
399 | { |
---|
400 | isOpen = false; |
---|
401 | #ifdef HAVE_GTK2 |
---|
402 | gtk_grab_remove(widget); |
---|
403 | gtk_widget_hide (widget); |
---|
404 | #endif /* HAVE_GTK2 */ |
---|
405 | } |
---|
406 | } |
---|
407 | |
---|
408 | #ifdef HAVE_GTK2 |
---|
409 | /** |
---|
410 | \brief opens up a window (not topmost Window). |
---|
411 | this is the Signal that does it. !!SIGNALS ARE STATIC!! |
---|
412 | \param widget the widget that did it! |
---|
413 | \param event the event that did it! |
---|
414 | \param window the Window that should be opened |
---|
415 | */ |
---|
416 | gint Window::windowOpen (GtkWidget *widget, GdkEvent* event, void* window) |
---|
417 | { |
---|
418 | static_cast<Window*>(window)->open(); |
---|
419 | } |
---|
420 | |
---|
421 | /** |
---|
422 | \brief closes a window (not topmost Window). |
---|
423 | this is the Signal that does it. !!SIGNALS ARE STATIC!! |
---|
424 | \param widget the widget that did it! |
---|
425 | \param event the event that did it! |
---|
426 | \param window the Window that should be closed |
---|
427 | */ |
---|
428 | gint Window::windowClose (GtkWidget *widget, GdkEvent* event, void* window) |
---|
429 | { |
---|
430 | static_cast<Window*>(window)->close(); |
---|
431 | } |
---|
432 | |
---|
433 | /** |
---|
434 | * Quits the orxonox_GUI. |
---|
435 | * This can be called as a Signal and is therefor static |
---|
436 | \param widget The widget that called this function |
---|
437 | \param event the event that happened to execute this function |
---|
438 | \param data some data passed with the Signal |
---|
439 | */ |
---|
440 | gint Window::orxonox_gui_quit (GtkWidget *widget, GdkEvent *event, gpointer data) |
---|
441 | { |
---|
442 | if (exec->shouldsave()) |
---|
443 | exec->writeToFile (Window::mainWindow); |
---|
444 | |
---|
445 | gtk_main_quit(); |
---|
446 | return FALSE; |
---|
447 | } |
---|
448 | #endif /* HAVE_GTK2 */ |
---|
449 | |
---|
450 | |
---|
451 | /* FRAME */ |
---|
452 | |
---|
453 | /** |
---|
454 | \brief Creates a new Frame without a name |
---|
455 | */ |
---|
456 | Frame::Frame (void) |
---|
457 | { |
---|
458 | this->init(); |
---|
459 | } |
---|
460 | |
---|
461 | /** |
---|
462 | \brief Creates a new Frame with name title |
---|
463 | */ |
---|
464 | Frame::Frame (char* title) |
---|
465 | { |
---|
466 | this->init(); |
---|
467 | this->setTitle(title); |
---|
468 | } |
---|
469 | |
---|
470 | /** |
---|
471 | \brief Initializes a new Frame with default settings |
---|
472 | */ |
---|
473 | void Frame::init() |
---|
474 | { |
---|
475 | static_cast<Container*>(this)->init(); |
---|
476 | |
---|
477 | #ifdef HAVE_GTK2 |
---|
478 | widget = gtk_frame_new (""); |
---|
479 | gtk_container_set_border_width (GTK_CONTAINER (widget), 3); |
---|
480 | #endif /* HAVE_GTK2 */ |
---|
481 | } |
---|
482 | |
---|
483 | /** |
---|
484 | \brief Sets the Frames name to title |
---|
485 | \param title The title the Frame should get. |
---|
486 | */ |
---|
487 | void Frame::setTitle (char* title) |
---|
488 | { |
---|
489 | if (label) |
---|
490 | delete label; |
---|
491 | label = new char[strlen(title)+1]; |
---|
492 | strcpy(label, title); |
---|
493 | #ifdef HAVE_GTK2 |
---|
494 | gtk_frame_set_label (GTK_FRAME (widget), title); |
---|
495 | #endif /* HAVE_GTK2 */ |
---|
496 | } |
---|
497 | |
---|
498 | // EVENTBOX // |
---|
499 | |
---|
500 | /** |
---|
501 | \brief Creates a new EventBox with default settings. |
---|
502 | */ |
---|
503 | EventBox::EventBox () |
---|
504 | { |
---|
505 | this->init(); |
---|
506 | } |
---|
507 | /** |
---|
508 | \brief Creates a new EventBox with name title |
---|
509 | \param title title the Eventbox should get (only data-structure-internal) |
---|
510 | */ |
---|
511 | EventBox::EventBox (char* title) |
---|
512 | { |
---|
513 | this->init(); |
---|
514 | this->setTitle(title); |
---|
515 | } |
---|
516 | |
---|
517 | /** |
---|
518 | \brief Initializes a new EventBox |
---|
519 | */ |
---|
520 | void EventBox::init(void) |
---|
521 | { |
---|
522 | isOption = -1; |
---|
523 | |
---|
524 | static_cast<Container*>(this)->init(); |
---|
525 | |
---|
526 | #ifdef HAVE_GTK2 |
---|
527 | widget = gtk_event_box_new (); |
---|
528 | gtk_container_set_border_width (GTK_CONTAINER (widget), 3); |
---|
529 | #endif /* HAVE_GTK2 */ |
---|
530 | } |
---|
531 | |
---|
532 | /** |
---|
533 | \brief Sets the Title of the EventBox (not implemented) |
---|
534 | \param title Name the EventBox should get (only datastructure-internal). |
---|
535 | */ |
---|
536 | void EventBox::setTitle (char* title) |
---|
537 | { |
---|
538 | if (label) |
---|
539 | delete label; |
---|
540 | label = new char[strlen(title)+1]; |
---|
541 | strcpy(label, title); |
---|
542 | } |
---|
543 | |
---|
544 | /* BOX */ |
---|
545 | |
---|
546 | /** |
---|
547 | \brief Creates a new horizontal Box |
---|
548 | */ |
---|
549 | Box::Box (void) |
---|
550 | { |
---|
551 | this->init('h'); |
---|
552 | } |
---|
553 | |
---|
554 | /** |
---|
555 | \brief Creates a new Box of type boxtype |
---|
556 | \param boxtype if 'v' the Box will be vertically, if 'h' the Box will be horizontally |
---|
557 | */ |
---|
558 | Box::Box (char boxtype) |
---|
559 | { |
---|
560 | this->init(boxtype); |
---|
561 | } |
---|
562 | |
---|
563 | /** |
---|
564 | \brief Initializes a new Box with type boxtype |
---|
565 | \param boxtype see Box(char boxtype) |
---|
566 | */ |
---|
567 | void Box::init(char boxtype) |
---|
568 | { |
---|
569 | isOption = -2; |
---|
570 | |
---|
571 | static_cast<Packer*>(this)->init(); |
---|
572 | #ifdef HAVE_GTK2 |
---|
573 | if (boxtype == 'v') |
---|
574 | { |
---|
575 | widget = gtk_vbox_new (FALSE, 0); |
---|
576 | } |
---|
577 | else |
---|
578 | { |
---|
579 | widget = gtk_hbox_new (FALSE, 0); |
---|
580 | } |
---|
581 | #endif /* HAVE_GTK2 */ |
---|
582 | |
---|
583 | } |
---|
584 | |
---|
585 | /** |
---|
586 | \brief Fills a box with a given Widget. |
---|
587 | 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 |
---|
588 | \param lowerWidget the next Widget that should be appendet to this Box |
---|
589 | */ |
---|
590 | void Box::fill (Widget *lowerWidget) |
---|
591 | { |
---|
592 | #ifdef HAVE_GTK2 |
---|
593 | gtk_box_pack_start (GTK_BOX (this->widget), lowerWidget->widget, TRUE, TRUE, 0); |
---|
594 | #endif /* HAVE_GTK2 */ |
---|
595 | if (this->down == NULL) |
---|
596 | this->down = lowerWidget; |
---|
597 | else |
---|
598 | { |
---|
599 | Widget* tmp; |
---|
600 | tmp = this->down; |
---|
601 | while (tmp->next != NULL) |
---|
602 | { |
---|
603 | tmp = tmp->next; |
---|
604 | } |
---|
605 | tmp->next = lowerWidget; |
---|
606 | } |
---|
607 | } |
---|
608 | |
---|
609 | /* IMAGE */ |
---|
610 | |
---|
611 | /** |
---|
612 | \brief Creates a new Image |
---|
613 | \param imagename the location of the Image on the Hard Disc |
---|
614 | */ |
---|
615 | Image::Image (char* imagename) |
---|
616 | { |
---|
617 | if (label) |
---|
618 | delete label; |
---|
619 | label = new char[strlen(imagename)+1]; |
---|
620 | strcpy(label, imagename); |
---|
621 | |
---|
622 | this->init(); |
---|
623 | #ifdef HAVE_GTK2 |
---|
624 | widget = gtk_image_new_from_file (imagename); |
---|
625 | #endif /* HAVE_GTK2 */ |
---|
626 | } |
---|
627 | |
---|
628 | /** |
---|
629 | \brief Initializes a new Image |
---|
630 | */ |
---|
631 | void Image::init() |
---|
632 | { |
---|
633 | isOption = 0; |
---|
634 | |
---|
635 | static_cast<Widget*>(this)->init(); |
---|
636 | } |
---|
637 | |
---|
638 | |
---|
639 | /* OPTION */ |
---|
640 | |
---|
641 | /** |
---|
642 | \brief Initializes a new Option. |
---|
643 | sets all Option-Specific-Values to their defaults. |
---|
644 | */ |
---|
645 | void Option::init() |
---|
646 | { |
---|
647 | value = 0; |
---|
648 | flagName = NULL; |
---|
649 | flagNameShort = NULL; |
---|
650 | saveable = false; |
---|
651 | defaultValue = 0; |
---|
652 | |
---|
653 | static_cast<Widget*>(this)->init(); |
---|
654 | |
---|
655 | return; |
---|
656 | } |
---|
657 | |
---|
658 | /** |
---|
659 | \brief This sets The FlagName of an Option and defines its default Values |
---|
660 | !! Options will be saved if flagname is different from "" !! |
---|
661 | \param flagname the Name that will be displayed in the output |
---|
662 | \param defaultvalue the default Value for this Option (see definition of defaultvalue |
---|
663 | */ |
---|
664 | void Option::setFlagName (char* flagname, int defaultvalue) |
---|
665 | { |
---|
666 | if (flagName) |
---|
667 | delete flagName; |
---|
668 | flagName = new char [strlen(flagname)+1]; |
---|
669 | strcpy(flagName, flagname); |
---|
670 | defaultValue = defaultvalue; |
---|
671 | |
---|
672 | // cout << "Set Flagname of " << label << " to " << flagname << endl; |
---|
673 | } |
---|
674 | |
---|
675 | /** |
---|
676 | \brief see Option::setFlagName (char* flagname, int defaultvalue) |
---|
677 | \param flagname the Name that will be displayed in the output |
---|
678 | \param defaultvalue the default Value for this Option (see definition of defaultvalue |
---|
679 | \param flagnameshort a short flagname to be displayed in the output |
---|
680 | */ |
---|
681 | void Option::setFlagName (char* flagname, char* flagnameshort, int defaultvalue) |
---|
682 | { |
---|
683 | if (flagName) |
---|
684 | delete flagName; |
---|
685 | flagName = new char [strlen(flagname)+1]; |
---|
686 | strcpy(flagName, flagname); |
---|
687 | |
---|
688 | if (flagNameShort) |
---|
689 | delete flagNameShort; |
---|
690 | flagNameShort = new char [strlen(flagnameshort)+1]; |
---|
691 | strcpy(flagNameShort, flagnameshort); |
---|
692 | defaultValue = defaultvalue; |
---|
693 | // cout << "Set Flagname of " << label << " to " << flagname << endl; |
---|
694 | } |
---|
695 | |
---|
696 | |
---|
697 | /* BUTTON */ |
---|
698 | |
---|
699 | /** |
---|
700 | \brief Creates a new Button with a buttonname |
---|
701 | \param buttonname sets the Name of the Button |
---|
702 | */ |
---|
703 | Button::Button(char* buttonname) |
---|
704 | { |
---|
705 | this->init(); |
---|
706 | this->setTitle(buttonname); |
---|
707 | } |
---|
708 | |
---|
709 | /** |
---|
710 | \brief Initializes a new Button |
---|
711 | */ |
---|
712 | void Button::init(void) |
---|
713 | { |
---|
714 | isOption = 0; |
---|
715 | |
---|
716 | static_cast<Option*>(this)->init(); |
---|
717 | |
---|
718 | #ifdef HAVE_GTK2 |
---|
719 | widget = gtk_button_new_with_label (""); |
---|
720 | #endif /* HAVE_GTK2 */ |
---|
721 | } |
---|
722 | |
---|
723 | /** |
---|
724 | \brief Sets a new name to the Button |
---|
725 | \param title The name the Button should get |
---|
726 | */ |
---|
727 | void Button::setTitle (char *title) |
---|
728 | { |
---|
729 | if (label) |
---|
730 | delete label; |
---|
731 | label = new char[strlen(title)+1]; |
---|
732 | strcpy(label, title); |
---|
733 | #ifdef HAVE_GTK2 |
---|
734 | gtk_button_set_label (GTK_BUTTON(widget), title); |
---|
735 | #endif /* HAVE_GTK2 */ |
---|
736 | } |
---|
737 | |
---|
738 | /** |
---|
739 | \brief redraws the Button |
---|
740 | not implemented yet |
---|
741 | */ |
---|
742 | void Button::redraw () |
---|
743 | { |
---|
744 | } |
---|
745 | |
---|
746 | /* CHECKBUTTON */ |
---|
747 | |
---|
748 | /** |
---|
749 | \brief Creates a new CheckButton with an ame |
---|
750 | \param buttonname The name the CheckButton should display. |
---|
751 | */ |
---|
752 | CheckButton::CheckButton (char* buttonname) |
---|
753 | { |
---|
754 | this->init(); |
---|
755 | this->setTitle(buttonname); |
---|
756 | |
---|
757 | #ifdef HAVE_GTK2 |
---|
758 | this->connectSignal ("clicked", this->OptionChange); |
---|
759 | #endif /* HAVE_GTK2 */ |
---|
760 | } |
---|
761 | |
---|
762 | /** |
---|
763 | \brief Initialize a new CheckButton with default settings |
---|
764 | */ |
---|
765 | void CheckButton::init(void) |
---|
766 | { |
---|
767 | isOption = 1; |
---|
768 | |
---|
769 | static_cast<Option*>(this)->init(); |
---|
770 | |
---|
771 | #ifdef HAVE_GTK2 |
---|
772 | widget = gtk_check_button_new_with_label (""); |
---|
773 | #endif /* HAVE_GTK2 */ |
---|
774 | } |
---|
775 | |
---|
776 | /** |
---|
777 | \brief Sets a new Title to a CheckButton |
---|
778 | \param title The new Name the CheckButton should display. |
---|
779 | */ |
---|
780 | void CheckButton::setTitle(char* title) |
---|
781 | { |
---|
782 | if (label) |
---|
783 | delete label; |
---|
784 | label = new char[strlen(title)+1]; |
---|
785 | strcpy(label, title); |
---|
786 | #ifdef HAVE_GTK2 |
---|
787 | gtk_button_set_label(GTK_BUTTON(widget), title); |
---|
788 | #endif /* HAVE_GTK2 */ |
---|
789 | } |
---|
790 | |
---|
791 | bool CheckButton::isActive() |
---|
792 | { |
---|
793 | #ifdef HAVE_GTK2 |
---|
794 | return gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)); |
---|
795 | #endif /* HAVE_GTK2 */ |
---|
796 | } |
---|
797 | |
---|
798 | #ifdef HAVE_GTK2 |
---|
799 | /** |
---|
800 | \brief Signal OptionChange writes the Value from the CheckButton to its Object-Database. |
---|
801 | \param widget The widget(CheckButton) that has a changed Value |
---|
802 | \param checkbutton the CheckButton-Object that should receive the change. |
---|
803 | */ |
---|
804 | gint CheckButton::OptionChange (GtkWidget *widget, Widget* checkbutton) |
---|
805 | { |
---|
806 | static_cast<CheckButton*>(checkbutton)->value = (int)gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON ((CheckButton*)checkbutton->widget)); |
---|
807 | flags->setTextFromFlags(orxonoxGUI); ////// must be different!!! |
---|
808 | cout << static_cast<CheckButton*>(checkbutton)->label << " set to: " << static_cast<CheckButton*>(checkbutton)->value << endl; |
---|
809 | } |
---|
810 | #endif /* HAVE_GTK2 */ |
---|
811 | |
---|
812 | /** |
---|
813 | \brief Redraws the CheckButton (if option has changed). |
---|
814 | Example: if new settings are loaded the Button must be redrawn for the GUI to display that Change |
---|
815 | */ |
---|
816 | void CheckButton::redraw () |
---|
817 | { |
---|
818 | #ifdef HAVE_GTK2 |
---|
819 | gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), value); |
---|
820 | #endif /* HAVE_GTK2 */ |
---|
821 | } |
---|
822 | |
---|
823 | /* SLIDER */ |
---|
824 | |
---|
825 | /** |
---|
826 | \brief Creates a new Slider |
---|
827 | \param slidername The data-structure-name of the slider. |
---|
828 | \param start The minimal Value of the slider. |
---|
829 | \param end The maximal Value of the slider. |
---|
830 | */ |
---|
831 | Slider::Slider (char* slidername, int start, int end) |
---|
832 | { |
---|
833 | this->init(start, end); |
---|
834 | this->setValue(start); |
---|
835 | this->setTitle(slidername); |
---|
836 | #ifdef HAVE_GTK2 |
---|
837 | this->connectSignal ("value_changed", this->OptionChange); |
---|
838 | #endif /* HAVE_GTK2 */ |
---|
839 | } |
---|
840 | |
---|
841 | /** |
---|
842 | \brief Initializes a Slider with start and end Values |
---|
843 | params: see Slider::Slider (char* slidername, int start, int end) |
---|
844 | */ |
---|
845 | void Slider::init(int start, int end) |
---|
846 | { |
---|
847 | isOption = 2; |
---|
848 | |
---|
849 | static_cast<Option*>(this)->init(); |
---|
850 | |
---|
851 | #ifdef HAVE_GTK2 |
---|
852 | widget = gtk_hscale_new_with_range (start, end, 5); |
---|
853 | #endif /* HAVE_GTK2 */ |
---|
854 | } |
---|
855 | |
---|
856 | /** |
---|
857 | \brief Sets a new Title to the Slider |
---|
858 | \param title The new Name of the slider |
---|
859 | */ |
---|
860 | void Slider::setTitle(char* title) |
---|
861 | { |
---|
862 | if (label) |
---|
863 | delete label; |
---|
864 | label = new char[strlen(title)+1]; |
---|
865 | strcpy(label, title); |
---|
866 | } |
---|
867 | |
---|
868 | /** |
---|
869 | \brief Setting a new value to the Slider. |
---|
870 | Maybe you also require a Slider::redraw() for this to display |
---|
871 | */ |
---|
872 | void Slider::setValue(int value) |
---|
873 | { |
---|
874 | this->value = value; |
---|
875 | } |
---|
876 | |
---|
877 | #ifdef HAVE_GTK2 |
---|
878 | /** |
---|
879 | \brief Signal OptionChange writes the Value from the Slider to its Object-Database. |
---|
880 | \param widget The widget(Slider) that has a changed Value |
---|
881 | \param slider the Slider-Object that should receive the change. |
---|
882 | */ |
---|
883 | gint Slider::OptionChange (GtkWidget *widget, Widget* slider) |
---|
884 | { |
---|
885 | static_cast<Slider*>(slider)->value = (int)gtk_range_get_value (GTK_RANGE ((Slider*)slider->widget)); |
---|
886 | flags->setTextFromFlags(orxonoxGUI); //// must be different !!! |
---|
887 | cout << static_cast<Slider*>(slider)->label << " set to: "<< static_cast<Slider*>(slider)->value << endl; |
---|
888 | } |
---|
889 | #endif /* HAVE_GTK2 */ |
---|
890 | |
---|
891 | /** |
---|
892 | \brief Redraws the widget |
---|
893 | Example: see void CheckButton::redraw () |
---|
894 | */ |
---|
895 | void Slider::redraw () |
---|
896 | { |
---|
897 | #ifdef HAVE_GTK2 |
---|
898 | gtk_range_set_value (GTK_RANGE (widget), value); |
---|
899 | #endif /* HAVE_GTK2 */ |
---|
900 | } |
---|
901 | |
---|
902 | /* MENU */ |
---|
903 | |
---|
904 | /** |
---|
905 | \brief Creates a Menu-Item-list out of multiple input. |
---|
906 | !! Consider, that the last input argument has to be "lastItem" for this to work!! |
---|
907 | \param menuname The Database-Name of this Menu |
---|
908 | \param ... items to be added to this Menu. !! Consider, that the last input argument has to be "lastItem" for this to work!! |
---|
909 | */ |
---|
910 | Menu::Menu (char* menuname, ...) |
---|
911 | { |
---|
912 | this->init(); |
---|
913 | this->setTitle(menuname); |
---|
914 | |
---|
915 | char *itemName; |
---|
916 | |
---|
917 | #ifdef HAVE_GTK2 /////////////////////// REINPLEMENT |
---|
918 | va_start (itemlist, menuname); |
---|
919 | while (strcmp (itemName = va_arg (itemlist, char*), "lastItem")) |
---|
920 | { |
---|
921 | this->addItem(itemName); |
---|
922 | } |
---|
923 | va_end(itemlist); |
---|
924 | #endif /* HAVE_GTK2 */ |
---|
925 | |
---|
926 | #ifdef HAVE_GTK2 |
---|
927 | gtk_option_menu_set_menu (GTK_OPTION_MENU (widget), menu); |
---|
928 | this->connectSignal ("changed", this->OptionChange); |
---|
929 | #endif /* HAVE_GTK2 */ |
---|
930 | } |
---|
931 | |
---|
932 | /** |
---|
933 | \brief Initializes a new Menu with no items |
---|
934 | */ |
---|
935 | void Menu::init(void) |
---|
936 | { |
---|
937 | isOption = 2; |
---|
938 | |
---|
939 | static_cast<Option*>(this)->init(); |
---|
940 | |
---|
941 | #ifdef HAVE_GTK2 |
---|
942 | widget = gtk_option_menu_new (); |
---|
943 | menu = gtk_menu_new (); |
---|
944 | #endif /* HAVE_GTK2 */ |
---|
945 | |
---|
946 | } |
---|
947 | |
---|
948 | /** |
---|
949 | * Sets the Database-Name of this Menu |
---|
950 | \param title Database-Name to be set. |
---|
951 | */ |
---|
952 | void Menu::setTitle(char* title) |
---|
953 | { |
---|
954 | if (label) |
---|
955 | delete label; |
---|
956 | label = new char[strlen(title)+1]; |
---|
957 | strcpy(label, title); |
---|
958 | } |
---|
959 | |
---|
960 | /** |
---|
961 | \brief appends a new Item to the Menu-List. |
---|
962 | \param itemName the itemName to be appendet. |
---|
963 | */ |
---|
964 | void Menu::addItem (char* itemName) |
---|
965 | { |
---|
966 | #ifdef HAVE_GTK2 |
---|
967 | item = gtk_menu_item_new_with_label (itemName); |
---|
968 | gtk_menu_shell_append(GTK_MENU_SHELL (menu), item); |
---|
969 | #endif /* HAVE_GTK2 */ |
---|
970 | } |
---|
971 | |
---|
972 | #ifdef HAVE_GTK2 |
---|
973 | /** |
---|
974 | \brief Signal OptionChange writes the Value from the Menu to its Object-Database. |
---|
975 | \param widget The widget(Menu) that has a changed Value |
---|
976 | \param menu the Menu-Object that should receive the change. |
---|
977 | */ |
---|
978 | gint Menu::OptionChange (GtkWidget *widget, Widget* menu) |
---|
979 | { |
---|
980 | static_cast<Menu*>(menu)->value = (int)gtk_option_menu_get_history (GTK_OPTION_MENU (menu->widget)); |
---|
981 | flags->setTextFromFlags(orxonoxGUI); //// must be different !!! |
---|
982 | cout << static_cast<Menu*>(menu)->label << " changed to : " << static_cast<Menu*>(menu)->value << endl; |
---|
983 | } |
---|
984 | #endif /* HAVE_GTK2 */ |
---|
985 | |
---|
986 | /** |
---|
987 | \brief Redraws the widget |
---|
988 | Example: see void CheckButton::redraw () |
---|
989 | */ |
---|
990 | void Menu::redraw () |
---|
991 | { |
---|
992 | #ifdef HAVE_GTK2 |
---|
993 | gtk_option_menu_set_history (GTK_OPTION_MENU (widget), value); |
---|
994 | #endif /* HAVE_GTK2 */ |
---|
995 | } |
---|
996 | |
---|
997 | OptionLabel::OptionLabel(char* label, char* value) |
---|
998 | { |
---|
999 | init(); |
---|
1000 | setTitle(label); |
---|
1001 | setValue(value); |
---|
1002 | } |
---|
1003 | |
---|
1004 | void OptionLabel::init(void) |
---|
1005 | { |
---|
1006 | static_cast<Option*>(this)->init(); |
---|
1007 | isOption = 5; |
---|
1008 | cValue = NULL; |
---|
1009 | |
---|
1010 | #ifdef HAVE_GTK2 |
---|
1011 | widget = gtk_label_new (""); |
---|
1012 | #endif /* HAVE_GTK2 */ |
---|
1013 | } |
---|
1014 | |
---|
1015 | void OptionLabel::setValue(char* newValue) |
---|
1016 | { |
---|
1017 | if (cValue) |
---|
1018 | delete cValue; |
---|
1019 | cValue = new char [strlen(newValue)+1]; |
---|
1020 | strcpy(cValue, newValue); |
---|
1021 | #ifdef HAVE_GTK2 |
---|
1022 | gtk_label_set_text (GTK_LABEL (widget), cValue); |
---|
1023 | #endif /* HAVE_GTK2 */ |
---|
1024 | } |
---|
1025 | |
---|
1026 | void OptionLabel::setTitle(char* title) |
---|
1027 | { |
---|
1028 | if (label) |
---|
1029 | delete label; |
---|
1030 | label = new char [strlen(title)+1]; |
---|
1031 | strcpy(label, title); |
---|
1032 | #ifdef HAVE_GTK2 |
---|
1033 | gtk_label_set_text (GTK_LABEL (widget), title); |
---|
1034 | #endif /* HAVE_GTK2 */ |
---|
1035 | } |
---|
1036 | |
---|
1037 | void OptionLabel::redraw(void) |
---|
1038 | { |
---|
1039 | |
---|
1040 | } |
---|
1041 | |
---|
1042 | /** |
---|
1043 | \brief Creates a new default Label with no Text. |
---|
1044 | You migth consider adding Label::setTitle with this. |
---|
1045 | */ |
---|
1046 | Label::Label () |
---|
1047 | { |
---|
1048 | this->init(); |
---|
1049 | } |
---|
1050 | |
---|
1051 | /** |
---|
1052 | \brief Creates a new Label with a Text. |
---|
1053 | \param text The text to be displayed. |
---|
1054 | */ |
---|
1055 | Label:: Label (char* text) |
---|
1056 | { |
---|
1057 | this->init(); |
---|
1058 | this->setText(text); |
---|
1059 | } |
---|
1060 | |
---|
1061 | /** |
---|
1062 | \brief initializes a new Label |
---|
1063 | */ |
---|
1064 | void Label::init(void) |
---|
1065 | { |
---|
1066 | isOption = 0; |
---|
1067 | |
---|
1068 | static_cast<Widget*>(this)->init(); |
---|
1069 | |
---|
1070 | #ifdef HAVE_GTK2 |
---|
1071 | widget = gtk_label_new (""); |
---|
1072 | gtk_label_set_line_wrap (GTK_LABEL(widget), TRUE); |
---|
1073 | #endif /* HAVE_GTK2 */ |
---|
1074 | } |
---|
1075 | |
---|
1076 | /** |
---|
1077 | \brief Sets a new Text to a Label. |
---|
1078 | \param text The text to be inserted into the Label. |
---|
1079 | */ |
---|
1080 | void Label::setText (char* text) |
---|
1081 | { |
---|
1082 | if (label) |
---|
1083 | delete label; |
---|
1084 | label = new char[strlen(text)+1]; |
---|
1085 | strcpy(label, text); |
---|
1086 | #ifdef HAVE_GTK2 |
---|
1087 | gtk_label_set_text (GTK_LABEL (this->widget), text); |
---|
1088 | #endif /* HAVE_GTK2 */ |
---|
1089 | } |
---|
1090 | |
---|
1091 | /** |
---|
1092 | \brief get the Text of a Label |
---|
1093 | \return The Text the Label holds. |
---|
1094 | */ |
---|
1095 | char* Label::getText () |
---|
1096 | { |
---|
1097 | return label; |
---|
1098 | } |
---|