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