Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/trunk/gui/orxonox_gui.cc @ 2634

Last change on this file since 2634 was 2623, checked in by bensch, 20 years ago

orxonox/trunk/gui: better comments

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