Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/trunk/gui/orxonox_gui_gtk.cc @ 3187

Last change on this file since 3187 was 3187, checked in by bensch, 19 years ago

orxonox/trunk/gui: doxygen-tags… it's very much.

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