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 | /** |
---|
43 | \brief Initializes the Guis GTK-stuff. |
---|
44 | \param argc the argument count. |
---|
45 | \param argv The Argument strings. |
---|
46 | */ |
---|
47 | bool initGTK(int argc, char *argv[]) |
---|
48 | { |
---|
49 | #ifdef HAVE_GTHREAD |
---|
50 | PRINTF(3)("Initializing the ThreadSystem of the GUI\n"); |
---|
51 | g_thread_init(NULL); |
---|
52 | gdk_threads_init(); |
---|
53 | #endif /* HAVE_GTHREAD */ |
---|
54 | gtk_init (&argc, &argv); |
---|
55 | gtk_rc_parse( "rc" ); |
---|
56 | } |
---|
57 | |
---|
58 | /** |
---|
59 | \brief enters the GTK-main-loop |
---|
60 | */ |
---|
61 | bool mainloopGTK(void) |
---|
62 | { |
---|
63 | gdk_threads_enter(); |
---|
64 | gtk_main(); |
---|
65 | gdk_threads_leave(); |
---|
66 | delete Window::mainWindow; |
---|
67 | } |
---|
68 | #endif /* HAVE_GTK2 */ |
---|
69 | |
---|
70 | |
---|
71 | ////////////////////////////// |
---|
72 | /// DEFINING WIDGET-CLASES /// |
---|
73 | ////////////////////////////// |
---|
74 | |
---|
75 | /* WIDGET */ |
---|
76 | |
---|
77 | /** |
---|
78 | \brief deletes any given Widget |
---|
79 | This is still pretty crappy. |
---|
80 | */ |
---|
81 | Widget::~Widget() |
---|
82 | { |
---|
83 | this->destroy(); |
---|
84 | } |
---|
85 | |
---|
86 | /** |
---|
87 | \brief Initializes a widget. |
---|
88 | Initializes the next Pointer and the other Widget-specific Defaults. |
---|
89 | */ |
---|
90 | void Widget::init() |
---|
91 | { |
---|
92 | next = NULL; |
---|
93 | this->title = NULL; |
---|
94 | return; |
---|
95 | } |
---|
96 | |
---|
97 | /** |
---|
98 | \brief Destroys a Widget |
---|
99 | */ |
---|
100 | void Widget::destroy(void) |
---|
101 | { |
---|
102 | if (this->title) |
---|
103 | { |
---|
104 | delete []this->title; |
---|
105 | } |
---|
106 | |
---|
107 | PRINTF(4)("deleting the Widget part.\n"); |
---|
108 | |
---|
109 | PRINTF(4)("deleting recursively\n"); |
---|
110 | |
---|
111 | // deleting next item if existent |
---|
112 | if (this->next) |
---|
113 | delete this->next; |
---|
114 | this->next = NULL; |
---|
115 | |
---|
116 | //! \todo not hiding widget, deleting. |
---|
117 | // this->hide(); |
---|
118 | // delete this->widget; |
---|
119 | } |
---|
120 | |
---|
121 | /** |
---|
122 | \brief makes the widget visible. |
---|
123 | */ |
---|
124 | void Widget::show() |
---|
125 | { |
---|
126 | #ifdef HAVE_GTK2 |
---|
127 | gtk_widget_show (this->widget); |
---|
128 | #endif /* HAVE_GTK2 */ |
---|
129 | } |
---|
130 | |
---|
131 | /** |
---|
132 | \brief hides the widget. |
---|
133 | */ |
---|
134 | void Widget::hide() |
---|
135 | { |
---|
136 | #ifdef HAVE_GTK2 |
---|
137 | gtk_widget_hide (this->widget); |
---|
138 | #endif /* HAVE_GTK2 */ |
---|
139 | } |
---|
140 | |
---|
141 | /** |
---|
142 | \brief Sets the resolution of a specific widget to the given size. |
---|
143 | \param width the width of the widget to set. |
---|
144 | \param height the height of the widget to set. |
---|
145 | */ |
---|
146 | void Widget::setSize(int width, int height) |
---|
147 | { |
---|
148 | #ifdef HAVE_GTK2 |
---|
149 | gtk_widget_set_usize (this->widget, width, height); |
---|
150 | #endif /* HAVE_GTK2 */ |
---|
151 | } |
---|
152 | |
---|
153 | /** |
---|
154 | \brief Moves through all the Widgets downwards from this and executes the function on them. |
---|
155 | \param function must be of type void and takes a Widget* as an Input. |
---|
156 | \param depth the current depth. if > 0 then the next Widget will also be walked through. |
---|
157 | */ |
---|
158 | void Widget::walkThrough (void (*function)(Widget*), unsigned int depth) |
---|
159 | { |
---|
160 | function(this); |
---|
161 | if (this->isOption < 0) |
---|
162 | { |
---|
163 | static_cast<Packer*>(this)->down->walkThrough (function, depth+1); |
---|
164 | } |
---|
165 | |
---|
166 | if (this->next && depth != 0) |
---|
167 | this->next->walkThrough(function, depth); |
---|
168 | } |
---|
169 | |
---|
170 | /** |
---|
171 | \brief Moves through all the Widgets downwards from this and executes the function on them. |
---|
172 | \param function must be of type void and takes a Widget* as an Input. |
---|
173 | \param data Additional Data you want to pass to the function. |
---|
174 | \param depth the current depth. if > 0 then the next Widget will also be walked through. |
---|
175 | */ |
---|
176 | void Widget::walkThrough (void (*function)(Widget*, void*), void* data, unsigned int depth) |
---|
177 | { |
---|
178 | function(this, data); |
---|
179 | if (this->isOption < 0) |
---|
180 | { |
---|
181 | static_cast<Packer*>(this)->down->walkThrough(function, data, depth+1); |
---|
182 | } |
---|
183 | if (this->next && depth != 0) |
---|
184 | this->next->walkThrough(function, data, depth); |
---|
185 | } |
---|
186 | |
---|
187 | /** |
---|
188 | \brief This is for listing the option of "widget" |
---|
189 | \param widget specifies the widget that should be listed |
---|
190 | */ |
---|
191 | void Widget::listOptions (Widget* widget) |
---|
192 | { |
---|
193 | if (widget->isOption < 0 && static_cast<Packer*>(widget)->groupName) |
---|
194 | cout << "[" << static_cast<Packer*>(widget)->groupName << "]\n"; |
---|
195 | if (widget->isOption >= 1 && widget->isOption <= 3) |
---|
196 | cout << " " << static_cast<Option*>(widget)->title <<" is : " << static_cast<Option*>(widget)->value <<endl; |
---|
197 | else if (widget->isOption == 5) |
---|
198 | cout << " " << static_cast<Option*>(widget)->title <<" is : " << static_cast<OptionLabel*>(widget)->cValue <<endl; |
---|
199 | } |
---|
200 | |
---|
201 | /** |
---|
202 | \brief This is for setting the option of "widget" |
---|
203 | \param widget specifies the widget that should be set. |
---|
204 | */ |
---|
205 | void Widget::setOptions (Widget* widget) |
---|
206 | { |
---|
207 | if (widget->isOption >= 1) |
---|
208 | static_cast<Option*>(widget)->redraw(); |
---|
209 | } |
---|
210 | |
---|
211 | #ifdef HAVE_GTK2 |
---|
212 | /** |
---|
213 | \brief Connect any signal to any given Sub-widget |
---|
214 | */ |
---|
215 | gulong Widget::connectSignal (char* event, gint (*signal)(GtkWidget*, GdkEvent*, void *)) |
---|
216 | { |
---|
217 | return g_signal_connect (G_OBJECT (this->widget), event, G_CALLBACK (signal), NULL); |
---|
218 | } |
---|
219 | |
---|
220 | /** |
---|
221 | \brief Connect a signal with additionally passing the whole Object |
---|
222 | */ |
---|
223 | gulong Widget::connectSignal (char* event, gint (*signal)( GtkWidget*, Widget *)) |
---|
224 | { |
---|
225 | return g_signal_connect (G_OBJECT (this->widget), event, G_CALLBACK (signal), this); |
---|
226 | } |
---|
227 | |
---|
228 | /** |
---|
229 | \brief Connect a signal with additionally passing a whole external Object |
---|
230 | */ |
---|
231 | gulong Widget::connectSignal (char* event, void* extObj, gint (*signal)(GtkWidget*, GdkEvent*, void *)) |
---|
232 | { |
---|
233 | return g_signal_connect (G_OBJECT (this->widget), event, G_CALLBACK (signal), extObj); |
---|
234 | } |
---|
235 | |
---|
236 | /** |
---|
237 | \brief Connect a signal with additionally passing a whole external Object |
---|
238 | */ |
---|
239 | gulong Widget::connectSignal (char* event, void* extObj, gint (*signal)(GtkWidget*, GdkEventKey*, void *)) |
---|
240 | { |
---|
241 | return g_signal_connect (G_OBJECT (this->widget), event, G_CALLBACK (signal), extObj); |
---|
242 | } |
---|
243 | |
---|
244 | void Widget::disconnectSignal (gulong signalID) |
---|
245 | { |
---|
246 | g_signal_handler_disconnect (G_OBJECT (this->widget), signalID); |
---|
247 | } |
---|
248 | |
---|
249 | /** |
---|
250 | \brief Signal that does absolutely nothing |
---|
251 | \param widget The widget that initiated the Signal |
---|
252 | \param event The event-type. |
---|
253 | \param nothing nothin. |
---|
254 | */ |
---|
255 | gint Widget::doNothingSignal (GtkWidget *widget, GdkEvent* event, void* nothing) |
---|
256 | { |
---|
257 | } |
---|
258 | #endif /* HAVE_GTK2 */ |
---|
259 | |
---|
260 | //void deleteWidget(Widget* lastWidget) |
---|
261 | |
---|
262 | |
---|
263 | /* PACKERS */ |
---|
264 | |
---|
265 | /** |
---|
266 | \brief Initializes a Packer. |
---|
267 | |
---|
268 | Sets the down-pinter to NULL and other PackerSpecific-values to their defaults. |
---|
269 | */ |
---|
270 | void Packer::init (void) |
---|
271 | { |
---|
272 | down = NULL; |
---|
273 | groupName = NULL; |
---|
274 | |
---|
275 | |
---|
276 | static_cast<Widget*>(this)->init(); |
---|
277 | return; |
---|
278 | } |
---|
279 | |
---|
280 | /** |
---|
281 | \brief Destroys a Packer. |
---|
282 | */ |
---|
283 | void Packer::destroy(void) |
---|
284 | { |
---|
285 | PRINTF(4)("deleting the Packer part.\n"); |
---|
286 | |
---|
287 | if (groupName) |
---|
288 | delete []groupName; |
---|
289 | |
---|
290 | //deleting recursively. |
---|
291 | if (this->down) |
---|
292 | delete this->down; |
---|
293 | this->down = NULL; |
---|
294 | |
---|
295 | static_cast<Widget*>(this)->destroy(); |
---|
296 | } |
---|
297 | |
---|
298 | /** |
---|
299 | \brief Sets the group name under which all the lower widgets of this will be saved. |
---|
300 | \param name The name of the group. |
---|
301 | */ |
---|
302 | void Packer::setGroupName (char* name) |
---|
303 | { |
---|
304 | if (groupName) |
---|
305 | delete groupName; |
---|
306 | groupName = new char [strlen(name)+1]; |
---|
307 | strcpy(groupName, name); |
---|
308 | } |
---|
309 | |
---|
310 | /** |
---|
311 | \brief Retrieves the group name under which all the lower widgets of this will be saved. |
---|
312 | \returns name The name of the group. |
---|
313 | */ |
---|
314 | char* Packer::getGroupName (void) |
---|
315 | { |
---|
316 | return groupName; |
---|
317 | } |
---|
318 | |
---|
319 | /* CONTAINERS */ |
---|
320 | |
---|
321 | /** |
---|
322 | \brief Initializes a Container. |
---|
323 | |
---|
324 | sets the Container-Specific defaults. |
---|
325 | */ |
---|
326 | void Container::init (void) |
---|
327 | { |
---|
328 | isOption = -1; |
---|
329 | |
---|
330 | static_cast<Packer*>(this)->init(); |
---|
331 | |
---|
332 | return; |
---|
333 | } |
---|
334 | |
---|
335 | /** |
---|
336 | \brief Destroys a Container. |
---|
337 | */ |
---|
338 | void Container::destroy(void) |
---|
339 | { |
---|
340 | PRINTF(4)("deleting the Container part.\n"); |
---|
341 | |
---|
342 | static_cast<Packer*>(this)->destroy(); |
---|
343 | } |
---|
344 | |
---|
345 | /** |
---|
346 | \briefFills a Container with lowerWidget. |
---|
347 | \param lowerWidget the Widget that should be filled into the Container. |
---|
348 | |
---|
349 | It does this by filling up the down pointer only if down points to NULL. |
---|
350 | */ |
---|
351 | void Container::fill (Widget *lowerWidget) |
---|
352 | { |
---|
353 | if (this->down == NULL) |
---|
354 | { |
---|
355 | #ifdef HAVE_GTK2 |
---|
356 | gtk_container_add (GTK_CONTAINER (this->widget), lowerWidget->widget); |
---|
357 | #endif /* HAVE_GTK2 */ |
---|
358 | this->down = lowerWidget; |
---|
359 | } |
---|
360 | else |
---|
361 | PRINTF(1)("!!error!! You try to put more than one Widget into a Container. \nNot including this item.\nThis is only possible with Boxes.\n"); |
---|
362 | } |
---|
363 | |
---|
364 | // gtk_container_set_border_width (GTK_CONTAINER (widget), 5); |
---|
365 | |
---|
366 | /* WINDOW */ |
---|
367 | |
---|
368 | Window* Window::mainWindow = NULL; |
---|
369 | |
---|
370 | /** |
---|
371 | \brief Adds a new Window Windows to the List of Windows. |
---|
372 | \param windowToAdd The Windows that should be added to the List |
---|
373 | \todo this instead of windowToAdd (possibly) |
---|
374 | */ |
---|
375 | void Window::addWindow(Window* windowToAdd) |
---|
376 | { |
---|
377 | if (!mainWindow) |
---|
378 | { |
---|
379 | mainWindow = windowToAdd; |
---|
380 | return; |
---|
381 | } |
---|
382 | |
---|
383 | Widget* tmpWindow = mainWindow; |
---|
384 | while (tmpWindow->next) |
---|
385 | tmpWindow = tmpWindow->next; |
---|
386 | tmpWindow->next = windowToAdd; |
---|
387 | |
---|
388 | return; |
---|
389 | } |
---|
390 | |
---|
391 | |
---|
392 | /** |
---|
393 | \brief Creating a new Window without a Name |
---|
394 | */ |
---|
395 | Window::Window (void) |
---|
396 | { |
---|
397 | this->init(); |
---|
398 | } |
---|
399 | |
---|
400 | /** |
---|
401 | \brief Creating a Window with a name |
---|
402 | \param windowName the name the window should get. |
---|
403 | */ |
---|
404 | |
---|
405 | Window::Window (char* windowName) |
---|
406 | { |
---|
407 | this->init(); |
---|
408 | this->setTitle (windowName); |
---|
409 | } |
---|
410 | |
---|
411 | /** |
---|
412 | \brief Destructs a Window. |
---|
413 | */ |
---|
414 | Window::~Window(void) |
---|
415 | { |
---|
416 | this->destroy(); |
---|
417 | } |
---|
418 | |
---|
419 | /** |
---|
420 | \brief initializes a new Window |
---|
421 | */ |
---|
422 | void Window::init() |
---|
423 | { |
---|
424 | if (!mainWindow) |
---|
425 | mainWindow = this; |
---|
426 | |
---|
427 | isOpen = false; |
---|
428 | |
---|
429 | static_cast<Container*>(this)->init(); |
---|
430 | |
---|
431 | #ifdef HAVE_GTK2 |
---|
432 | widget = gtk_window_new (GTK_WINDOW_TOPLEVEL); |
---|
433 | gtk_window_set_policy (GTK_WINDOW(widget), TRUE, TRUE, TRUE); |
---|
434 | #if !defined(__WIN32__) |
---|
435 | // gtk_window_set_decorated (GTK_WINDOW (widget), FALSE); |
---|
436 | #endif |
---|
437 | gtk_container_set_border_width (GTK_CONTAINER (widget), 3); |
---|
438 | #endif /* HAVE_GTK2 */ |
---|
439 | } |
---|
440 | |
---|
441 | /** |
---|
442 | \brief Destroys a Window. |
---|
443 | */ |
---|
444 | void Window::destroy(void) |
---|
445 | { |
---|
446 | if (this->title) |
---|
447 | PRINTF(3)("deleting the Window: %s\n", this->title); |
---|
448 | else |
---|
449 | PRINTF(3)("deleting the Window.\n"); |
---|
450 | |
---|
451 | this->hide(); |
---|
452 | static_cast<Container*>(this)->destroy(); |
---|
453 | |
---|
454 | } |
---|
455 | |
---|
456 | /** |
---|
457 | \brief Shows all Widgets that are included within this->widget. |
---|
458 | */ |
---|
459 | void Window::showall () |
---|
460 | { |
---|
461 | if (!isOpen) |
---|
462 | { |
---|
463 | // printf ("showall\n"); |
---|
464 | #ifdef HAVE_GTK2 |
---|
465 | gtk_widget_show_all (widget); |
---|
466 | #endif /* HAVE_GTK2 */ |
---|
467 | isOpen = true; |
---|
468 | } |
---|
469 | else |
---|
470 | { |
---|
471 | // printf ("showone\n"); |
---|
472 | #ifdef HAVE_GTK2 |
---|
473 | gtk_widget_show (widget); |
---|
474 | #endif /* HAVE_GTK2 */ |
---|
475 | } |
---|
476 | } |
---|
477 | |
---|
478 | /** |
---|
479 | \brief Set The Window-title to title |
---|
480 | \param title title the Window should get. |
---|
481 | */ |
---|
482 | void Window::setTitle (char* title) |
---|
483 | { |
---|
484 | if (this->title) |
---|
485 | delete []this->title; |
---|
486 | this->title = new char[strlen(title)+1]; |
---|
487 | strcpy(this->title, title); |
---|
488 | #ifdef HAVE_GTK2 |
---|
489 | gtk_window_set_title (GTK_WINDOW (widget), title); |
---|
490 | #endif /* HAVE_GTK2 */ |
---|
491 | } |
---|
492 | |
---|
493 | /** |
---|
494 | \brief opens up a Window and fixes the Focus to it |
---|
495 | */ |
---|
496 | void Window::open() |
---|
497 | { |
---|
498 | if (this != mainWindow) |
---|
499 | { |
---|
500 | isOpen = true; |
---|
501 | #ifdef HAVE_GTK2 |
---|
502 | gtk_widget_show_all(widget); |
---|
503 | gtk_grab_add(widget); |
---|
504 | #endif /* HAVE_GTK2 */ |
---|
505 | } |
---|
506 | } |
---|
507 | |
---|
508 | /** |
---|
509 | \brief closes up a Window and removes the Focus from it |
---|
510 | */ |
---|
511 | void Window::close() |
---|
512 | { |
---|
513 | if (this != mainWindow) |
---|
514 | { |
---|
515 | isOpen = false; |
---|
516 | #ifdef HAVE_GTK2 |
---|
517 | gtk_grab_remove(widget); |
---|
518 | gtk_widget_hide (widget); |
---|
519 | #endif /* HAVE_GTK2 */ |
---|
520 | } |
---|
521 | } |
---|
522 | |
---|
523 | #ifdef HAVE_GTK2 |
---|
524 | /** |
---|
525 | \brief opens up a window (not topmost Window). |
---|
526 | this is the Signal that does it. !!SIGNALS ARE STATIC!! |
---|
527 | \param widget the widget that did it. |
---|
528 | \param event the event that did it. |
---|
529 | \param window the Window that should be opened |
---|
530 | */ |
---|
531 | gint Window::windowOpen (GtkWidget *widget, GdkEvent* event, void* window) |
---|
532 | { |
---|
533 | static_cast<Window*>(window)->open(); |
---|
534 | } |
---|
535 | |
---|
536 | /** |
---|
537 | \brief closes a window (not topmost Window). |
---|
538 | this is the Signal that does it. !!SIGNALS ARE STATIC!! |
---|
539 | \param widget the widget that did it! |
---|
540 | \param event the event that did it! |
---|
541 | \param window the Window that should be closed |
---|
542 | */ |
---|
543 | gint Window::windowClose (GtkWidget *widget, GdkEvent* event, void* window) |
---|
544 | { |
---|
545 | static_cast<Window*>(window)->close(); |
---|
546 | } |
---|
547 | |
---|
548 | /** |
---|
549 | * Quits the orxonox_GUI. |
---|
550 | * This can be called as a Signal and is therefor static |
---|
551 | \param widget The widget that called this function |
---|
552 | \param event the event that happened to execute this function |
---|
553 | \param data some data passed with the Signal |
---|
554 | */ |
---|
555 | gint Window::orxonox_gui_quit (GtkWidget *widget, GdkEvent *event, gpointer data) |
---|
556 | { |
---|
557 | if (exec->shouldsave()) |
---|
558 | exec->writeToFile (Window::mainWindow); |
---|
559 | |
---|
560 | gtk_main_quit(); |
---|
561 | return FALSE; |
---|
562 | } |
---|
563 | #endif /* HAVE_GTK2 */ |
---|
564 | |
---|
565 | |
---|
566 | /* FRAME */ |
---|
567 | |
---|
568 | /** |
---|
569 | \brief Creates a new Frame without a name |
---|
570 | */ |
---|
571 | Frame::Frame (void) |
---|
572 | { |
---|
573 | this->init(); |
---|
574 | } |
---|
575 | |
---|
576 | /** |
---|
577 | \brief Creates a new Frame with name title |
---|
578 | */ |
---|
579 | Frame::Frame (char* title) |
---|
580 | { |
---|
581 | this->init(); |
---|
582 | this->setTitle(title); |
---|
583 | } |
---|
584 | |
---|
585 | /** |
---|
586 | \brief destrcucts a Frame |
---|
587 | */ |
---|
588 | Frame::~Frame() |
---|
589 | { |
---|
590 | this->destroy(); |
---|
591 | } |
---|
592 | |
---|
593 | /** |
---|
594 | \brief Initializes a new Frame with default settings |
---|
595 | */ |
---|
596 | void Frame::init() |
---|
597 | { |
---|
598 | static_cast<Container*>(this)->init(); |
---|
599 | |
---|
600 | #ifdef HAVE_GTK2 |
---|
601 | widget = gtk_frame_new (""); |
---|
602 | gtk_container_set_border_width (GTK_CONTAINER (widget), 3); |
---|
603 | #endif /* HAVE_GTK2 */ |
---|
604 | } |
---|
605 | |
---|
606 | /** |
---|
607 | \brief Destroys a Frame. |
---|
608 | */ |
---|
609 | void Frame::destroy(void) |
---|
610 | { |
---|
611 | if (this->title) |
---|
612 | PRINTF(3)("deleting the Frame: %s\n", this->title); |
---|
613 | else |
---|
614 | PRINTF(3)("deleting the Frame.\n"); |
---|
615 | |
---|
616 | static_cast<Container*>(this)->destroy(); |
---|
617 | } |
---|
618 | |
---|
619 | /** |
---|
620 | \brief Sets the Frames name to title |
---|
621 | \param title The title the Frame should get. |
---|
622 | */ |
---|
623 | void Frame::setTitle (char* title) |
---|
624 | { |
---|
625 | if (this->title) |
---|
626 | delete []this->title; |
---|
627 | this->title = new char[strlen(title)+1]; |
---|
628 | strcpy(this->title, title); |
---|
629 | #ifdef HAVE_GTK2 |
---|
630 | gtk_frame_set_label (GTK_FRAME (widget), title); |
---|
631 | #endif /* HAVE_GTK2 */ |
---|
632 | } |
---|
633 | |
---|
634 | // EVENTBOX // |
---|
635 | |
---|
636 | /** |
---|
637 | \brief Creates a new EventBox with default settings. |
---|
638 | */ |
---|
639 | EventBox::EventBox (void) |
---|
640 | { |
---|
641 | this->init(); |
---|
642 | } |
---|
643 | |
---|
644 | /** |
---|
645 | \brief Creates a new EventBox with name title |
---|
646 | \param title title the Eventbox should get (only data-structure-internal) |
---|
647 | */ |
---|
648 | EventBox::EventBox (char* title) |
---|
649 | { |
---|
650 | this->init(); |
---|
651 | this->setTitle(title); |
---|
652 | } |
---|
653 | |
---|
654 | /** |
---|
655 | \brief destructs an EventBox. |
---|
656 | */ |
---|
657 | EventBox::~EventBox(void) |
---|
658 | { |
---|
659 | this->destroy(); |
---|
660 | |
---|
661 | } |
---|
662 | |
---|
663 | /** |
---|
664 | \brief Initializes a new EventBox |
---|
665 | */ |
---|
666 | void EventBox::init(void) |
---|
667 | { |
---|
668 | isOption = -1; |
---|
669 | |
---|
670 | static_cast<Container*>(this)->init(); |
---|
671 | |
---|
672 | #ifdef HAVE_GTK2 |
---|
673 | widget = gtk_event_box_new (); |
---|
674 | gtk_container_set_border_width (GTK_CONTAINER (widget), 3); |
---|
675 | #endif /* HAVE_GTK2 */ |
---|
676 | } |
---|
677 | |
---|
678 | /** |
---|
679 | \brief Destroys an EventBox. |
---|
680 | */ |
---|
681 | void EventBox::destroy(void) |
---|
682 | { |
---|
683 | if (this->title) |
---|
684 | PRINTF(3)("deleting the EventBox: %s\n", this->title); |
---|
685 | else |
---|
686 | PRINTF(3)("deleting the EventBox.\n"); |
---|
687 | |
---|
688 | static_cast<Container*>(this)->destroy(); |
---|
689 | } |
---|
690 | |
---|
691 | /** |
---|
692 | \brief Sets the Title of the EventBox (not implemented) |
---|
693 | \param title Name the EventBox should get (only datastructure-internal). |
---|
694 | */ |
---|
695 | void EventBox::setTitle (char* title) |
---|
696 | { |
---|
697 | if (this->title) |
---|
698 | delete []this->title; |
---|
699 | this->title = new char[strlen(title)+1]; |
---|
700 | strcpy(this->title, title); |
---|
701 | } |
---|
702 | |
---|
703 | /* BOX */ |
---|
704 | |
---|
705 | /** |
---|
706 | \brief Creates a new horizontal Box |
---|
707 | */ |
---|
708 | Box::Box (void) |
---|
709 | { |
---|
710 | this->init('h'); |
---|
711 | } |
---|
712 | |
---|
713 | /** |
---|
714 | \brief Creates a new Box of type boxtype |
---|
715 | \param boxtype if 'v' the Box will be vertically, if 'h' the Box will be horizontally |
---|
716 | */ |
---|
717 | Box::Box (char boxtype) |
---|
718 | { |
---|
719 | this->init(boxtype); |
---|
720 | } |
---|
721 | |
---|
722 | /** |
---|
723 | \brief destructs a Box. |
---|
724 | */ |
---|
725 | Box::~Box(void) |
---|
726 | { |
---|
727 | this->destroy(); |
---|
728 | } |
---|
729 | |
---|
730 | /** |
---|
731 | \brief Initializes a new Box with type boxtype |
---|
732 | \param boxtype see Box(char boxtype) |
---|
733 | */ |
---|
734 | void Box::init(char boxtype) |
---|
735 | { |
---|
736 | isOption = -2; |
---|
737 | |
---|
738 | static_cast<Packer*>(this)->init(); |
---|
739 | #ifdef HAVE_GTK2 |
---|
740 | if (boxtype == 'v') |
---|
741 | { |
---|
742 | widget = gtk_vbox_new (FALSE, 0); |
---|
743 | } |
---|
744 | else |
---|
745 | { |
---|
746 | widget = gtk_hbox_new (FALSE, 0); |
---|
747 | } |
---|
748 | #endif /* HAVE_GTK2 */ |
---|
749 | } |
---|
750 | |
---|
751 | /** |
---|
752 | \brief Destroys a Box. |
---|
753 | */ |
---|
754 | void Box::destroy(void) |
---|
755 | { |
---|
756 | if (this->title) |
---|
757 | PRINTF(3)("deleting the Box: %s\n", this->title); |
---|
758 | else |
---|
759 | PRINTF(3)("deleting the Box.\n"); |
---|
760 | |
---|
761 | static_cast<Packer*>(this)->destroy(); |
---|
762 | } |
---|
763 | |
---|
764 | /** |
---|
765 | \brief Fills a box with a given Widget. |
---|
766 | \param lowerWidget the next Widget that should be appendet to this Box |
---|
767 | |
---|
768 | 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 |
---|
769 | */ |
---|
770 | void Box::fill (Widget *lowerWidget) |
---|
771 | { |
---|
772 | #ifdef HAVE_GTK2 |
---|
773 | gtk_box_pack_start (GTK_BOX (this->widget), lowerWidget->widget, TRUE, TRUE, 0); |
---|
774 | #endif /* HAVE_GTK2 */ |
---|
775 | if (this->down == NULL) |
---|
776 | this->down = lowerWidget; |
---|
777 | else |
---|
778 | { |
---|
779 | Widget* tmp; |
---|
780 | tmp = this->down; |
---|
781 | while (tmp->next != NULL) |
---|
782 | { |
---|
783 | tmp = tmp->next; |
---|
784 | } |
---|
785 | tmp->next = lowerWidget; |
---|
786 | } |
---|
787 | } |
---|
788 | |
---|
789 | /** |
---|
790 | \brief Sets the Title of a Box. |
---|
791 | \param title the new Title to set. |
---|
792 | */ |
---|
793 | void Box::setTitle(char* title) |
---|
794 | { |
---|
795 | if (this->title) |
---|
796 | delete []this->title; |
---|
797 | this->title = new char[strlen(title)+1]; |
---|
798 | strcpy(this->title, title); |
---|
799 | } |
---|
800 | |
---|
801 | /* OPTION */ |
---|
802 | |
---|
803 | /** |
---|
804 | \brief Initializes a new Option. |
---|
805 | sets all Option-Specific-Values to their defaults. |
---|
806 | */ |
---|
807 | void Option::init() |
---|
808 | { |
---|
809 | value = 0; |
---|
810 | flagName = NULL; |
---|
811 | flagNameShort = NULL; |
---|
812 | saveable = false; |
---|
813 | defaultValue = 0; |
---|
814 | |
---|
815 | static_cast<Widget*>(this)->init(); |
---|
816 | |
---|
817 | return; |
---|
818 | } |
---|
819 | |
---|
820 | /** |
---|
821 | \brief Destroys an Option. |
---|
822 | */ |
---|
823 | void Option::destroy(void) |
---|
824 | { |
---|
825 | PRINTF(4)("deleting the Option Part.\n"); |
---|
826 | if (flagName) |
---|
827 | delete []flagName; |
---|
828 | if (flagNameShort) |
---|
829 | delete []flagNameShort; |
---|
830 | |
---|
831 | static_cast<Widget*>(this)->destroy(); |
---|
832 | } |
---|
833 | |
---|
834 | /** |
---|
835 | \brief This sets The FlagName of an Option and defines its default Values |
---|
836 | !! Options will be saved if flagname is different from NULL !! |
---|
837 | \param flagname the Name that will be displayed in the output |
---|
838 | \param defaultvalue the default Value for this Option (see definition of defaultvalue |
---|
839 | */ |
---|
840 | void Option::setFlagName (char* flagname, int defaultvalue) |
---|
841 | { |
---|
842 | if (flagName) |
---|
843 | delete flagName; |
---|
844 | flagName = new char [strlen(flagname)+1]; |
---|
845 | strcpy(flagName, flagname); |
---|
846 | defaultValue = defaultvalue; |
---|
847 | |
---|
848 | // cout << "Set Flagname of " << this->title << " to " << flagname << endl; |
---|
849 | } |
---|
850 | |
---|
851 | /** |
---|
852 | \brief see Option::setFlagName (char* flagname, int defaultvalue) |
---|
853 | \param flagname the Name that will be displayed in the output |
---|
854 | \param defaultvalue the default Value for this Option (see definition of defaultvalue |
---|
855 | \param flagnameshort a short flagname to be displayed in the output |
---|
856 | */ |
---|
857 | void Option::setFlagName (char* flagname, char* flagnameshort, int defaultvalue) |
---|
858 | { |
---|
859 | if (flagName) |
---|
860 | delete flagName; |
---|
861 | flagName = new char [strlen(flagname)+1]; |
---|
862 | strcpy(flagName, flagname); |
---|
863 | |
---|
864 | if (flagNameShort) |
---|
865 | delete flagNameShort; |
---|
866 | flagNameShort = new char [strlen(flagnameshort)+1]; |
---|
867 | strcpy(flagNameShort, flagnameshort); |
---|
868 | defaultValue = defaultvalue; |
---|
869 | // cout << "Set Flagname of " << this->title << " to " << flagname << endl; |
---|
870 | } |
---|
871 | |
---|
872 | /** |
---|
873 | \brief Sets the saveable-state of the option to true. |
---|
874 | */ |
---|
875 | void Option::saveability(void) |
---|
876 | { |
---|
877 | this->saveable = true; |
---|
878 | } |
---|
879 | |
---|
880 | /** |
---|
881 | \brief Sets the saveable-state of the option. |
---|
882 | \param isSaveable the saveable-state to set. |
---|
883 | */ |
---|
884 | void Option::saveability(bool isSaveable) |
---|
885 | { |
---|
886 | this->saveable = isSaveable; |
---|
887 | } |
---|
888 | |
---|
889 | /** |
---|
890 | \returns The saveable-state. |
---|
891 | */ |
---|
892 | bool Option::isSaveable(void) |
---|
893 | { |
---|
894 | return this->saveable; |
---|
895 | } |
---|
896 | |
---|
897 | /* BUTTON */ |
---|
898 | |
---|
899 | /** |
---|
900 | \brief Creates a new Button with a buttonname |
---|
901 | \param buttonname sets the Name of the Button |
---|
902 | */ |
---|
903 | Button::Button(char* buttonname) |
---|
904 | { |
---|
905 | this->init(); |
---|
906 | this->setTitle(buttonname); |
---|
907 | } |
---|
908 | |
---|
909 | /** |
---|
910 | \brief destructs a Button. |
---|
911 | */ |
---|
912 | Button::~Button(void) |
---|
913 | { |
---|
914 | this->destroy(); |
---|
915 | } |
---|
916 | |
---|
917 | /** |
---|
918 | \brief Initializes a new Button |
---|
919 | */ |
---|
920 | void Button::init(void) |
---|
921 | { |
---|
922 | isOption = 0; |
---|
923 | |
---|
924 | static_cast<Option*>(this)->init(); |
---|
925 | |
---|
926 | #ifdef HAVE_GTK2 |
---|
927 | widget = gtk_button_new_with_label (""); |
---|
928 | #endif /* HAVE_GTK2 */ |
---|
929 | } |
---|
930 | |
---|
931 | /** |
---|
932 | \brief Destroys a Button. |
---|
933 | */ |
---|
934 | void Button::destroy(void) |
---|
935 | { |
---|
936 | if (this->title) |
---|
937 | PRINTF(3)("deleting the Label: %s\n", this->title); |
---|
938 | else |
---|
939 | PRINTF(3)("deleting the Label.\n"); |
---|
940 | |
---|
941 | static_cast<Option*>(this)->destroy(); |
---|
942 | } |
---|
943 | |
---|
944 | /** |
---|
945 | \brief Sets a new name to the Button |
---|
946 | \param title The name the Button should get |
---|
947 | */ |
---|
948 | void Button::setTitle (char *title) |
---|
949 | { |
---|
950 | if (this->title) |
---|
951 | delete []this->title; |
---|
952 | this->title = new char[strlen(title)+1]; |
---|
953 | strcpy(this->title, title); |
---|
954 | #ifdef HAVE_GTK2 |
---|
955 | gtk_button_set_label (GTK_BUTTON(widget), title); |
---|
956 | #endif /* HAVE_GTK2 */ |
---|
957 | } |
---|
958 | |
---|
959 | /** |
---|
960 | \brief redraws the Button |
---|
961 | not implemented yet |
---|
962 | */ |
---|
963 | void Button::redraw () |
---|
964 | { |
---|
965 | } |
---|
966 | |
---|
967 | /* CHECKBUTTON */ |
---|
968 | |
---|
969 | /** |
---|
970 | \brief Creates a new CheckButton with an ame |
---|
971 | \param buttonname The name the CheckButton should display. |
---|
972 | */ |
---|
973 | CheckButton::CheckButton (char* buttonname) |
---|
974 | { |
---|
975 | this->init(); |
---|
976 | this->setTitle(buttonname); |
---|
977 | |
---|
978 | #ifdef HAVE_GTK2 |
---|
979 | this->connectSignal ("clicked", this->OptionChange); |
---|
980 | #endif /* HAVE_GTK2 */ |
---|
981 | } |
---|
982 | |
---|
983 | /** |
---|
984 | \brief destructs a CheckButton. |
---|
985 | */ |
---|
986 | CheckButton::~CheckButton(void) |
---|
987 | { |
---|
988 | this->destroy(); |
---|
989 | } |
---|
990 | |
---|
991 | /** |
---|
992 | \brief Initialize a new CheckButton with default settings |
---|
993 | */ |
---|
994 | void CheckButton::init(void) |
---|
995 | { |
---|
996 | isOption = 1; |
---|
997 | |
---|
998 | static_cast<Option*>(this)->init(); |
---|
999 | |
---|
1000 | #ifdef HAVE_GTK2 |
---|
1001 | widget = gtk_check_button_new_with_label (""); |
---|
1002 | #endif /* HAVE_GTK2 */ |
---|
1003 | } |
---|
1004 | |
---|
1005 | /** |
---|
1006 | \brief Destroys a CheckButton. |
---|
1007 | */ |
---|
1008 | void CheckButton::destroy(void) |
---|
1009 | { |
---|
1010 | if (this->title) |
---|
1011 | PRINTF(3)("deleting the CheckButton: %s\n", this->title); |
---|
1012 | else |
---|
1013 | PRINTF(3)("deleting the CheckButton.\n"); |
---|
1014 | |
---|
1015 | static_cast<Option*>(this)->destroy(); |
---|
1016 | } |
---|
1017 | |
---|
1018 | /** |
---|
1019 | \brief Sets a new Title to a CheckButton |
---|
1020 | \param title The new Name the CheckButton should display. |
---|
1021 | */ |
---|
1022 | void CheckButton::setTitle(char* title) |
---|
1023 | { |
---|
1024 | if (this->title) |
---|
1025 | delete []this->title; |
---|
1026 | this->title = new char[strlen(title)+1]; |
---|
1027 | strcpy(this->title, title); |
---|
1028 | #ifdef HAVE_GTK2 |
---|
1029 | gtk_button_set_label(GTK_BUTTON(widget), title); |
---|
1030 | #endif /* HAVE_GTK2 */ |
---|
1031 | } |
---|
1032 | |
---|
1033 | bool CheckButton::isActive() |
---|
1034 | { |
---|
1035 | #ifdef HAVE_GTK2 |
---|
1036 | return gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)); |
---|
1037 | #endif /* HAVE_GTK2 */ |
---|
1038 | } |
---|
1039 | |
---|
1040 | #ifdef HAVE_GTK2 |
---|
1041 | /** |
---|
1042 | \brief Signal OptionChange writes the Value from the CheckButton to its Object-Database. |
---|
1043 | \param widget The widget(CheckButton) that has a changed Value |
---|
1044 | \param checkbutton the CheckButton-Object that should receive the change. |
---|
1045 | */ |
---|
1046 | gint CheckButton::OptionChange (GtkWidget *widget, Widget* checkbutton) |
---|
1047 | { |
---|
1048 | static_cast<CheckButton*>(checkbutton)->value = (int)gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON ((CheckButton*)checkbutton->widget)); |
---|
1049 | flags->setTextFromFlags(orxonoxGUI); ////// must be different!!! |
---|
1050 | cout << static_cast<CheckButton*>(checkbutton)->title << " set to: " << static_cast<CheckButton*>(checkbutton)->value << endl; |
---|
1051 | } |
---|
1052 | #endif /* HAVE_GTK2 */ |
---|
1053 | |
---|
1054 | /** |
---|
1055 | \brief Redraws the CheckButton (if option has changed). |
---|
1056 | Example: if new settings are loaded the Button must be redrawn for the GUI to display that Change |
---|
1057 | */ |
---|
1058 | void CheckButton::redraw () |
---|
1059 | { |
---|
1060 | #ifdef HAVE_GTK2 |
---|
1061 | gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), value); |
---|
1062 | #endif /* HAVE_GTK2 */ |
---|
1063 | } |
---|
1064 | |
---|
1065 | /* SLIDER */ |
---|
1066 | |
---|
1067 | /** |
---|
1068 | \brief Creates a new Slider |
---|
1069 | \param slidername The data-structure-name of the slider. |
---|
1070 | \param start The minimal Value of the slider. |
---|
1071 | \param end The maximal Value of the slider. |
---|
1072 | */ |
---|
1073 | Slider::Slider (char* slidername, int start, int end) |
---|
1074 | { |
---|
1075 | this->init(start, end); |
---|
1076 | this->setValue(start); |
---|
1077 | this->setTitle(slidername); |
---|
1078 | #ifdef HAVE_GTK2 |
---|
1079 | this->connectSignal ("value_changed", this->OptionChange); |
---|
1080 | #endif /* HAVE_GTK2 */ |
---|
1081 | } |
---|
1082 | |
---|
1083 | /** |
---|
1084 | \brief destructs a Slider. |
---|
1085 | */ |
---|
1086 | Slider::~Slider(void) |
---|
1087 | { |
---|
1088 | this->destroy(); |
---|
1089 | } |
---|
1090 | |
---|
1091 | /** |
---|
1092 | \brief Initializes a Slider with start and end Values |
---|
1093 | params: see Slider::Slider (char* slidername, int start, int end) |
---|
1094 | */ |
---|
1095 | void Slider::init(int start, int end) |
---|
1096 | { |
---|
1097 | isOption = 2; |
---|
1098 | |
---|
1099 | static_cast<Option*>(this)->init(); |
---|
1100 | |
---|
1101 | #ifdef HAVE_GTK2 |
---|
1102 | widget = gtk_hscale_new_with_range (start, end, 5); |
---|
1103 | #endif /* HAVE_GTK2 */ |
---|
1104 | } |
---|
1105 | |
---|
1106 | /** |
---|
1107 | \brief Destroys a Slider. |
---|
1108 | */ |
---|
1109 | void Slider::destroy(void) |
---|
1110 | { |
---|
1111 | if (this->title) |
---|
1112 | PRINTF(3)("deleting the Slider: %s\n", this->title); |
---|
1113 | else |
---|
1114 | PRINTF(3)("deleting the Slider.\n"); |
---|
1115 | |
---|
1116 | static_cast<Option*>(this)->destroy(); |
---|
1117 | |
---|
1118 | } |
---|
1119 | |
---|
1120 | /** |
---|
1121 | \brief Sets a new Title to the Slider |
---|
1122 | \param title The new Name of the slider |
---|
1123 | */ |
---|
1124 | void Slider::setTitle(char* title) |
---|
1125 | { |
---|
1126 | if (this->title) |
---|
1127 | delete []this->title; |
---|
1128 | this->title = new char[strlen(title)+1]; |
---|
1129 | strcpy(this->title, title); |
---|
1130 | } |
---|
1131 | |
---|
1132 | /** |
---|
1133 | \brief Setting a new value to the Slider. |
---|
1134 | Maybe you also require a Slider::redraw() for this to display |
---|
1135 | */ |
---|
1136 | void Slider::setValue(int value) |
---|
1137 | { |
---|
1138 | this->value = value; |
---|
1139 | } |
---|
1140 | |
---|
1141 | /** |
---|
1142 | \brief Redraws the widget |
---|
1143 | Example: see void CheckButton::redraw () |
---|
1144 | */ |
---|
1145 | void Slider::redraw () |
---|
1146 | { |
---|
1147 | #ifdef HAVE_GTK2 |
---|
1148 | gtk_range_set_value (GTK_RANGE (widget), value); |
---|
1149 | #endif /* HAVE_GTK2 */ |
---|
1150 | } |
---|
1151 | |
---|
1152 | #ifdef HAVE_GTK2 |
---|
1153 | /** |
---|
1154 | \brief Signal OptionChange writes the Value from the Slider to its Object-Database. |
---|
1155 | \param widget The widget(Slider) that has a changed Value |
---|
1156 | \param slider the Slider-Object that should receive the change. |
---|
1157 | */ |
---|
1158 | gint Slider::OptionChange (GtkWidget *widget, Widget* slider) |
---|
1159 | { |
---|
1160 | static_cast<Slider*>(slider)->value = (int)gtk_range_get_value (GTK_RANGE ((Slider*)slider->widget)); |
---|
1161 | flags->setTextFromFlags(orxonoxGUI); //// must be different !!! |
---|
1162 | cout << static_cast<Slider*>(slider)->title << " set to: "<< static_cast<Slider*>(slider)->value << endl; |
---|
1163 | } |
---|
1164 | #endif /* HAVE_GTK2 */ |
---|
1165 | |
---|
1166 | |
---|
1167 | /* MENU */ |
---|
1168 | |
---|
1169 | /** |
---|
1170 | \brief Creates a Menu-Item-list out of multiple input. |
---|
1171 | !! Consider, that the last input argument has to be "lastItem" for this to work!! |
---|
1172 | \param menuname The Database-Name of this Menu |
---|
1173 | \param ... items to be added to this Menu. !! Consider, that the last input argument has to be "lastItem" for this to work!! |
---|
1174 | */ |
---|
1175 | Menu::Menu (char* menuname, ...) |
---|
1176 | { |
---|
1177 | this->init(); |
---|
1178 | this->setTitle(menuname); |
---|
1179 | |
---|
1180 | char *itemName; |
---|
1181 | |
---|
1182 | #ifdef HAVE_GTK2 /////////////////////// REINPLEMENT |
---|
1183 | va_start (itemlist, menuname); |
---|
1184 | while (strcmp (itemName = va_arg (itemlist, char*), "lastItem")) |
---|
1185 | { |
---|
1186 | this->addItem(itemName); |
---|
1187 | } |
---|
1188 | va_end(itemlist); |
---|
1189 | #endif /* HAVE_GTK2 */ |
---|
1190 | |
---|
1191 | #ifdef HAVE_GTK2 |
---|
1192 | gtk_option_menu_set_menu (GTK_OPTION_MENU (widget), menu); |
---|
1193 | this->connectSignal ("changed", this->OptionChange); |
---|
1194 | #endif /* HAVE_GTK2 */ |
---|
1195 | } |
---|
1196 | |
---|
1197 | /** |
---|
1198 | \brief destructs a Menu. |
---|
1199 | */ |
---|
1200 | Menu::~Menu(void) |
---|
1201 | { |
---|
1202 | this->destroy(); |
---|
1203 | } |
---|
1204 | |
---|
1205 | /** |
---|
1206 | \brief Initializes a new Menu with no items |
---|
1207 | */ |
---|
1208 | void Menu::init(void) |
---|
1209 | { |
---|
1210 | isOption = 2; |
---|
1211 | |
---|
1212 | static_cast<Option*>(this)->init(); |
---|
1213 | |
---|
1214 | #ifdef HAVE_GTK2 |
---|
1215 | widget = gtk_option_menu_new (); |
---|
1216 | menu = gtk_menu_new (); |
---|
1217 | #endif /* HAVE_GTK2 */ |
---|
1218 | |
---|
1219 | } |
---|
1220 | |
---|
1221 | /** |
---|
1222 | \brief Destroys a Menu. |
---|
1223 | */ |
---|
1224 | void Menu::destroy(void) |
---|
1225 | { |
---|
1226 | if (this->title) |
---|
1227 | PRINTF(3)("deleting the Menu: %s\n", this->title); |
---|
1228 | else |
---|
1229 | PRINTF(3)("deleting the Menu.\n"); |
---|
1230 | //! \todo destroy menu |
---|
1231 | |
---|
1232 | static_cast<Option*>(this)->destroy(); |
---|
1233 | } |
---|
1234 | |
---|
1235 | |
---|
1236 | /** |
---|
1237 | * Sets the Database-Name of this Menu |
---|
1238 | \param title Database-Name to be set. |
---|
1239 | */ |
---|
1240 | void Menu::setTitle(char* title) |
---|
1241 | { |
---|
1242 | if (this->title) |
---|
1243 | delete []this->title; |
---|
1244 | this->title = new char[strlen(title)+1]; |
---|
1245 | strcpy(this->title, title); |
---|
1246 | } |
---|
1247 | |
---|
1248 | /** |
---|
1249 | \brief appends a new Item to the Menu-List. |
---|
1250 | \param itemName the itemName to be appendet. |
---|
1251 | */ |
---|
1252 | void Menu::addItem (char* itemName) |
---|
1253 | { |
---|
1254 | #ifdef HAVE_GTK2 |
---|
1255 | item = gtk_menu_item_new_with_label (itemName); |
---|
1256 | gtk_menu_shell_append(GTK_MENU_SHELL (menu), item); |
---|
1257 | #endif /* HAVE_GTK2 */ |
---|
1258 | } |
---|
1259 | |
---|
1260 | /** |
---|
1261 | \brief Redraws the widget |
---|
1262 | Example: see void CheckButton::redraw () |
---|
1263 | */ |
---|
1264 | void Menu::redraw () |
---|
1265 | { |
---|
1266 | #ifdef HAVE_GTK2 |
---|
1267 | gtk_option_menu_set_history (GTK_OPTION_MENU (widget), value); |
---|
1268 | #endif /* HAVE_GTK2 */ |
---|
1269 | } |
---|
1270 | |
---|
1271 | #ifdef HAVE_GTK2 |
---|
1272 | /** |
---|
1273 | \brief Signal OptionChange writes the Value from the Menu to its Object-Database. |
---|
1274 | \param widget The widget(Menu) that has a changed Value |
---|
1275 | \param menu the Menu-Object that should receive the change. |
---|
1276 | */ |
---|
1277 | gint Menu::OptionChange (GtkWidget *widget, Widget* menu) |
---|
1278 | { |
---|
1279 | static_cast<Menu*>(menu)->value = (int)gtk_option_menu_get_history (GTK_OPTION_MENU (menu->widget)); |
---|
1280 | flags->setTextFromFlags(orxonoxGUI); //// must be different !!! |
---|
1281 | cout << static_cast<Menu*>(menu)->title << " changed to : " << static_cast<Menu*>(menu)->value << endl; |
---|
1282 | } |
---|
1283 | #endif /* HAVE_GTK2 */ |
---|
1284 | |
---|
1285 | /* OPTION LABEL */ |
---|
1286 | |
---|
1287 | /** |
---|
1288 | \brief Creates a new OptionLabel with a LabelName and a Value. |
---|
1289 | \param label The name of the OptionLabel. |
---|
1290 | \param value The Value of the OptionLabel (what will be displayed). |
---|
1291 | */ |
---|
1292 | OptionLabel::OptionLabel(char* label, char* value) |
---|
1293 | { |
---|
1294 | init(); |
---|
1295 | setTitle(label); |
---|
1296 | setValue(value); |
---|
1297 | } |
---|
1298 | |
---|
1299 | /** |
---|
1300 | \brief destructs an OptionLabel. |
---|
1301 | */ |
---|
1302 | OptionLabel::~OptionLabel(void) |
---|
1303 | { |
---|
1304 | this->destroy(); |
---|
1305 | } |
---|
1306 | |
---|
1307 | /** |
---|
1308 | \brief Initializes an OptionLabel |
---|
1309 | */ |
---|
1310 | void OptionLabel::init(void) |
---|
1311 | { |
---|
1312 | static_cast<Option*>(this)->init(); |
---|
1313 | isOption = 5; |
---|
1314 | cValue = NULL; |
---|
1315 | |
---|
1316 | #ifdef HAVE_GTK2 |
---|
1317 | widget = gtk_label_new (""); |
---|
1318 | #endif /* HAVE_GTK2 */ |
---|
1319 | } |
---|
1320 | |
---|
1321 | /** |
---|
1322 | \brief Destroys a OptionLabel. |
---|
1323 | */ |
---|
1324 | void OptionLabel::destroy(void) |
---|
1325 | { |
---|
1326 | if (this->title) |
---|
1327 | PRINTF(3)("deleting the OptionLabel: %s\n", this->title); |
---|
1328 | else |
---|
1329 | PRINTF(3)("deleting the OptionLabel.\n"); |
---|
1330 | if (cValue) |
---|
1331 | delete []cValue; |
---|
1332 | |
---|
1333 | static_cast<Option*>(this)->destroy(); |
---|
1334 | } |
---|
1335 | |
---|
1336 | |
---|
1337 | /** |
---|
1338 | \brief Updates the value of an OptionLabel |
---|
1339 | \param newValue The new Name that should be displayed. |
---|
1340 | */ |
---|
1341 | void OptionLabel::setValue(char* newValue) |
---|
1342 | { |
---|
1343 | if (cValue) |
---|
1344 | delete cValue; |
---|
1345 | cValue = new char [strlen(newValue)+1]; |
---|
1346 | strcpy(cValue, newValue); |
---|
1347 | #ifdef HAVE_GTK2 |
---|
1348 | gtk_label_set_text (GTK_LABEL (widget), cValue); |
---|
1349 | #endif /* HAVE_GTK2 */ |
---|
1350 | } |
---|
1351 | |
---|
1352 | /** |
---|
1353 | \brief Sets a ned Title to the OptionLabel. |
---|
1354 | \param title The now title of the OptionLabel. |
---|
1355 | */ |
---|
1356 | void OptionLabel::setTitle(char* title) |
---|
1357 | { |
---|
1358 | if (this->title) |
---|
1359 | delete []this->title; |
---|
1360 | this->title = new char [strlen(title)+1]; |
---|
1361 | strcpy(this->title, title); |
---|
1362 | #ifdef HAVE_GTK2 |
---|
1363 | gtk_label_set_text (GTK_LABEL (widget), title); |
---|
1364 | #endif /* HAVE_GTK2 */ |
---|
1365 | } |
---|
1366 | |
---|
1367 | /** |
---|
1368 | \brief Redraws an OptionLabel (not implemented yet, but it works). |
---|
1369 | */ |
---|
1370 | void OptionLabel::redraw(void) |
---|
1371 | { |
---|
1372 | |
---|
1373 | } |
---|
1374 | |
---|
1375 | /** |
---|
1376 | \brief Creates a new default Label with no Text. |
---|
1377 | You migth consider adding Label::setTitle with this. |
---|
1378 | */ |
---|
1379 | Label::Label () |
---|
1380 | { |
---|
1381 | this->init(); |
---|
1382 | } |
---|
1383 | |
---|
1384 | /** |
---|
1385 | \brief Creates a new Label with a Text. |
---|
1386 | \param text The text to be displayed. |
---|
1387 | */ |
---|
1388 | Label:: Label (char* text) |
---|
1389 | { |
---|
1390 | this->init(); |
---|
1391 | this->setTitle(text); |
---|
1392 | } |
---|
1393 | |
---|
1394 | /** |
---|
1395 | \brief destructs a Label. |
---|
1396 | */ |
---|
1397 | Label::~Label(void) |
---|
1398 | { |
---|
1399 | this->destroy(); |
---|
1400 | } |
---|
1401 | |
---|
1402 | /** |
---|
1403 | \brief initializes a new Label |
---|
1404 | */ |
---|
1405 | void Label::init(void) |
---|
1406 | { |
---|
1407 | isOption = 0; |
---|
1408 | |
---|
1409 | static_cast<Widget*>(this)->init(); |
---|
1410 | |
---|
1411 | #ifdef HAVE_GTK2 |
---|
1412 | widget = gtk_label_new (""); |
---|
1413 | gtk_label_set_line_wrap (GTK_LABEL(widget), TRUE); |
---|
1414 | #endif /* HAVE_GTK2 */ |
---|
1415 | } |
---|
1416 | |
---|
1417 | /** |
---|
1418 | \brief Destroys a Label. |
---|
1419 | */ |
---|
1420 | void Label::destroy(void) |
---|
1421 | { |
---|
1422 | if (this->title) |
---|
1423 | PRINTF(3)("deleting the Label: %s\n", this->title); |
---|
1424 | else |
---|
1425 | PRINTF(3)("deleting the Label.\n"); |
---|
1426 | |
---|
1427 | static_cast<Widget*>(this)->destroy(); |
---|
1428 | } |
---|
1429 | |
---|
1430 | /** |
---|
1431 | \brief Sets a new Text to a Label. |
---|
1432 | \param text The text to be inserted into the Label. |
---|
1433 | */ |
---|
1434 | void Label::setTitle(char* text) |
---|
1435 | { |
---|
1436 | if (this->title) |
---|
1437 | delete []this->title; |
---|
1438 | this->title = new char[strlen(text)+1]; |
---|
1439 | strcpy(this->title, text); |
---|
1440 | #ifdef HAVE_GTK2 |
---|
1441 | gtk_label_set_text (GTK_LABEL (this->widget), text); |
---|
1442 | #endif /* HAVE_GTK2 */ |
---|
1443 | } |
---|
1444 | |
---|
1445 | /** |
---|
1446 | \brief get the Text of a Label |
---|
1447 | \return The Text the Label holds. |
---|
1448 | */ |
---|
1449 | char* Label::getText () |
---|
1450 | { |
---|
1451 | return this->title; |
---|
1452 | } |
---|
1453 | |
---|
1454 | /** |
---|
1455 | \brief Creates a new ProgressBar. |
---|
1456 | */ |
---|
1457 | ProgressBar::ProgressBar (void) |
---|
1458 | { |
---|
1459 | this->init (); |
---|
1460 | } |
---|
1461 | |
---|
1462 | /** |
---|
1463 | \brief Creates a new ProgressBar. |
---|
1464 | \param label The name you want to get the ProgressBar. |
---|
1465 | */ |
---|
1466 | ProgressBar::ProgressBar (char* label) |
---|
1467 | { |
---|
1468 | this->init(); |
---|
1469 | this->setTitle (label); |
---|
1470 | } |
---|
1471 | |
---|
1472 | /** |
---|
1473 | \brief destructs a ProgressBar |
---|
1474 | */ |
---|
1475 | ProgressBar::~ProgressBar () |
---|
1476 | { |
---|
1477 | this->destroy(); |
---|
1478 | } |
---|
1479 | |
---|
1480 | /** |
---|
1481 | \brief Initializes a ProgressBar |
---|
1482 | */ |
---|
1483 | void ProgressBar::init (void) |
---|
1484 | { |
---|
1485 | isOption = 0; |
---|
1486 | progress = 0.0; |
---|
1487 | totalSize = 0.0; |
---|
1488 | |
---|
1489 | static_cast<Widget*>(this)->init(); |
---|
1490 | #ifdef HAVE_GTK2 |
---|
1491 | adjustment = (GtkAdjustment*)gtk_adjustment_new(0, 0, 100, 0, 0, 0); |
---|
1492 | widget = gtk_progress_bar_new_with_adjustment(adjustment); |
---|
1493 | #endif /* HAVE_GTK2 */ |
---|
1494 | } |
---|
1495 | |
---|
1496 | /** |
---|
1497 | \brief Destroys a ProgressBar. |
---|
1498 | */ |
---|
1499 | void ProgressBar::destroy(void) |
---|
1500 | { |
---|
1501 | if (this->title) |
---|
1502 | PRINTF(3)("deleting the ProgressBar: %s\n", this->title); |
---|
1503 | else |
---|
1504 | PRINTF(3)("deleting the ProgressBar.\n"); |
---|
1505 | |
---|
1506 | static_cast<Widget*>(this)->destroy(); |
---|
1507 | } |
---|
1508 | |
---|
1509 | /** |
---|
1510 | \brief Sets a ned Title to the ProgressBar. |
---|
1511 | \param title The now title of the ProgressBar. |
---|
1512 | */ |
---|
1513 | void ProgressBar::setTitle(char* title) |
---|
1514 | { |
---|
1515 | if (this->title) |
---|
1516 | delete []this->title; |
---|
1517 | this->title = new char [strlen(title)+1]; |
---|
1518 | strcpy(this->title, title); |
---|
1519 | } |
---|
1520 | |
---|
1521 | /** |
---|
1522 | \brief Sets the Total size of the Bar. (ex. The maximum one can download) |
---|
1523 | */ |
---|
1524 | void ProgressBar::setTotalSize (double totalSize) |
---|
1525 | { |
---|
1526 | this->totalSize = totalSize; |
---|
1527 | } |
---|
1528 | |
---|
1529 | /** |
---|
1530 | \brief Sets the progress maximum is this->totalSize |
---|
1531 | */ |
---|
1532 | void ProgressBar::setProgress (double progress) |
---|
1533 | { |
---|
1534 | this->progress = progress; |
---|
1535 | |
---|
1536 | if (this->progress > this->totalSize) |
---|
1537 | this->progress = this->totalSize; |
---|
1538 | |
---|
1539 | #ifdef HAVE_GTK2 |
---|
1540 | gtk_progress_set_value(GTK_PROGRESS(widget), this->progress*100.0/this->totalSize); |
---|
1541 | #endif /* HAVE_GTK2 */ |
---|
1542 | PRINTF(3)("Progress: %f\n", progress*100.0/totalSize); |
---|
1543 | } |
---|
1544 | |
---|
1545 | /** |
---|
1546 | \brief returns the Progress Status |
---|
1547 | */ |
---|
1548 | double ProgressBar::getProgress (void) |
---|
1549 | { |
---|
1550 | return this->progress; |
---|
1551 | } |
---|
1552 | |
---|
1553 | /* IMAGE */ |
---|
1554 | |
---|
1555 | /** |
---|
1556 | \brief Creates a new Image |
---|
1557 | \param imagename the location of the Image on the Hard Disc |
---|
1558 | */ |
---|
1559 | Image::Image (char* imagename) |
---|
1560 | { |
---|
1561 | this->init(); |
---|
1562 | if (this->title) |
---|
1563 | delete []this->title; |
---|
1564 | this->title = new char[strlen(imagename)+1]; |
---|
1565 | strcpy(this->title, imagename); |
---|
1566 | |
---|
1567 | #ifdef HAVE_GTK2 |
---|
1568 | widget = gtk_image_new_from_file (imagename); |
---|
1569 | #endif /* HAVE_GTK2 */ |
---|
1570 | } |
---|
1571 | |
---|
1572 | /** |
---|
1573 | \brief destructs an Image. |
---|
1574 | */ |
---|
1575 | Image::~Image(void) |
---|
1576 | { |
---|
1577 | this->destroy(); |
---|
1578 | } |
---|
1579 | |
---|
1580 | /** |
---|
1581 | \brief Initializes a new Image |
---|
1582 | */ |
---|
1583 | void Image::init() |
---|
1584 | { |
---|
1585 | isOption = 0; |
---|
1586 | |
---|
1587 | static_cast<Widget*>(this)->init(); |
---|
1588 | } |
---|
1589 | |
---|
1590 | /** |
---|
1591 | \brief Destroys a Image. |
---|
1592 | */ |
---|
1593 | void Image::destroy(void) |
---|
1594 | { |
---|
1595 | if (this->title) |
---|
1596 | PRINTF(3)("deleting the Image: %s\n", this->title); |
---|
1597 | else |
---|
1598 | PRINTF(3)("deleting the Image.\n"); |
---|
1599 | |
---|
1600 | static_cast<Widget*>(this)->destroy(); |
---|
1601 | } |
---|
1602 | |
---|
1603 | /** |
---|
1604 | \brief Sets a ned Title to the Image. |
---|
1605 | \param title The now title of the OptionLabel. |
---|
1606 | */ |
---|
1607 | void Image::setTitle(char* title) |
---|
1608 | { |
---|
1609 | if (this->title) |
---|
1610 | delete []this->title; |
---|
1611 | this->title = new char [strlen(title)+1]; |
---|
1612 | strcpy(this->title, title); |
---|
1613 | } |
---|