Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/trunk/src/lib/gui/gui/gui_gtk.h @ 4338

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

orxonox/trunk: merged branches/physics back to the trunk
merged with command
svn merge -r 3866:HEAD . ../../trunk/
many conflict that i tried to resolv
@patrick: i hope i did not interfere with your stuff :/

File size: 14.3 KB
RevLine 
[3156]1/*!
[4048]2 \file gui_gtk.h
[3156]3 \brief Contains all th different Widgets.
4*/
[4048]5#ifndef _GUI_GTK_H
6#define _GUI_GTK_H
[3147]7
[3164]8#if HAVE_CONFIG_H
9#include <config.h> 
10#endif
11
[3493]12#include "debug.h"
[4091]13#include "globals.h"
[3423]14
[3165]15#ifdef HAVE_GTK2
[3144]16#include <gtk/gtkmain.h>
17#include <gtk/gtkwindow.h>
18#include <gtk/gtkframe.h>
19#include <gtk/gtkhbox.h>
20#include <gtk/gtkvbox.h>
21#include <gtk/gtkbutton.h>
22#include <gtk/gtkcheckbutton.h>
23#include <gtk/gtkhscale.h>
24#include <gtk/gtkoptionmenu.h>
25#include <gtk/gtkmenu.h>
26#include <gtk/gtkmenuitem.h>
27#include <gtk/gtklabel.h>
28#include <gtk/gtkimage.h>
29#include <gtk/gtkeventbox.h>
[3423]30#include <gtk/gtkprogressbar.h>
[4068]31#include <gtk/gtkfilesel.h>
[3165]32#endif /* HAVE_GTK2 */
[3144]33
[4046]34// enumerator for different GuiOption-Types
[4071]35enum GUI_OPTION {GUI_BOX = -2,
36                 GUI_CONTAINER = -1,
[4046]37                 GUI_NOTHING = 0,
38                 GUI_BOOL = 1,
39                 GUI_INT = 2,
40                 GUI_FLOAT = 3,
41                 GUI_CHAR = 4,
42                 GUI_CHAR_ARRAY = 5};
43
[4052]44extern char* executable;
[4039]45
[3423]46bool initGUI(int argc, char* argv[]);
47bool mainloopGUI(void);
[3164]48
[3144]49//! This is the topmost object that can be displayed all others are derived from it.
50class Widget
51{
52 private:
[3187]53
[3144]54 public:
[3623]55  Widget(void);
[3423]56  virtual ~Widget(void);
[3144]57
[3423]58  void show(void);
59  void hide(void);
60  void setSize(int width, int height);
[4046]61
[3624]62  virtual void setTitle(const char* title);  //!< An abstract Function, that sets the title of Widgets.
[4338]63  virtual const char* getTitle(void) const { return this->title; };
[3423]64
65  Widget* findWidgetByName(char* name, unsigned int depth);
66  void walkThrough(void(*function)(Widget*), unsigned int depth);
67  void walkThrough(void(*function)(Widget*, void*), void* data, unsigned int depth);
[4071]68   static void listOptionsAndGroups(Widget* widget);
69   static void listOptions(Widget* widget);
70   static void listOptions(Widget* widget, void* data);
71   Widget* findOptionByNumber(int* number, unsigned int depth);
72   static void listGroups(Widget* widget);
73   static void listGroups(Widget* widget, void* data);
[4132]74   static void printHelp(Widget* widget);
[4071]75   Widget* findGroupByNumber(int* number, unsigned int depth);
76   static void setOptions(Widget* widget);
77   static void redrawOptions(Widget* widget);
78   static void flagCheck(Widget* widget, void* flagName);
[3423]79 
[3165]80#ifdef HAVE_GTK2
[3423]81  // Connection - Functions
82  gulong connectSignal(char* event, gint(*signal)(GtkWidget*, GdkEvent*, void* ));
83  gulong connectSignal(char* event, gint(*signal)(GtkWidget*, Widget* ));
84  gulong connectSignal(char* event, void* extObj, gint(*signal)(GtkWidget*, GdkEvent*, void* ));
85  gulong connectSignal(char* event, void* extObj, gint(*signal)(GtkWidget*, void* ));
86  gulong connectSignal(char* event, void* extObj, gint(*signal)(GtkWidget*, GdkEventKey*, void* ));
87  void disconnectSignal(gulong signalID);
88  // Signals
89  static gint doNothingSignal(GtkWidget* widget, GdkEvent* event, void* nothing);
[4046]90#else /* HAVE_GTK2 */
91  // Connection - Functions
92  unsigned long connectSignal(char* event, int(*signal)(void*, void*, void* )){};
93  unsigned long connectSignal(char* event, int(*signal)(void*, Widget* )){};
94  unsigned long connectSignal(char* event, void* extObj, int(*signal)(void*, void*, void* )){};
95  unsigned long connectSignal(char* event, void* extObj, int(*signal)(void*, void* )){};
96  void disconnectSignal(unsigned long signalID);
97  // Signals
98  static int doNothingSignal(void* widget, void* event, void* nothing);
[3165]99#endif /* HAVE_GTK2 */
[3423]100
[4046]101
[3423]102  Widget* next;                     //!< next always points to the next Widget in the list. Every Widget has a next one, or has NULL as next
[3165]103#ifdef HAVE_GTK2
[3423]104  GtkWidget* widget;                //!< widget is the gtk_widget that the specific Object Contains.
[4046]105#else /* HAVE_GTK2 */
106  void* widget;
[3165]107#endif /* HAVE_GTK2 */
[4046]108
[4071]109  GUI_OPTION optionType;            //!< The Type of the Widget.
[3423]110  char* title;                      //!< The name of the Widget. Some do display it, Options need it to save;
[3144]111};
112
113//! This is a Packer Object, which has the ability to Pack other Widgets into itself.
114class Packer : public Widget
115{
116 public:
[3623]117  Packer(void);
118  virtual ~Packer(void);
119
[4046]120  Widget* down;                      //!< this points to the Widget below this.
121  char* groupName;                   //!< For each Packer you can specify a Groupname under which the lowerWidgets will be saved.
[3144]122
[4046]123  void setGroupName(const char* name);
124  /** \returns the GroupName if existent NULL otherwise */
125  inline const char* getGroupName(void) const {return this->groupName;}
[3423]126
[4046]127
[3423]128  virtual void fill(Widget* lowerWidget) = 0; //!< An abstract function, that fills Packers.
[3144]129};
130
131//! This is a Container Class, it can contain one sub-Widget: down.
132/**
133 * A Container is a Widget that can hold a subWidget in addition to a next-Widget.
134 * The Container can by itself not be displayed created or used.
135 * The derived classes of Container can be displayed
136*/
137class Container : public Packer
138{
139 private:
[3423]140  int borderwidth;          //!< The width of The Container Boarder.
141  int policy;               //!< The Update Policy of a Container.
[3144]142 
143 public:
[3623]144  Container(void);
145  virtual ~Container(void);
[4071]146
[4046]147  void setBorderWidth(int borderwidth);
[3423]148  void fill(Widget* lowerWidget);
[3144]149};
150
151//! Window is the class that creates new Windows, and handels them
152/**
153 * A Window is a class derived from Container that contains a window-widget.
154 * It has the ability to hold one sub-object
155 */
156class Window : public Container
157{
158 private:
[3423]159  bool isOpen;                      //!< A bool Variable that checks if a Window is already open.
[3144]160 public:
[3423]161  static Window* mainWindow;        //!< Pointer to the First Window that was opened. By default this should be the GUI's main-Window.
[3148]162  static void addWindow(Window* windowToAdd);
163
[4046]164  Window(const char* windowName = NULL);
[3623]165  virtual ~Window(void);
[3144]166 
[4046]167  virtual void setTitle(const char* title);
[3423]168  void showall(void);
169  void open(void);
170  void close(void);
[3153]171
[3165]172#ifdef HAVE_GTK2
[3423]173  // Signals
174  static gint windowOpen(GtkWidget* widget, GdkEvent* event, void* window);
175  static gint windowClose(GtkWidget* widget, GdkEvent* event, void* window);
[4046]176#else /* HAVE_GTK2 */
177  int Window::windowOpen(void* widget, void* event, void* window);
178  int Window::windowClose(void* widget, void* event, void* window);
[3165]179#endif /* HAVE_GTK2 */
[3144]180};
181
182//! Frame is the class that handles frames
183/**
184 * A Frame is an object, that has a border and if you like a name on it.
185 * It can contain a Widget, which means that you can insert anything you like inside of a frame
186 */
187class Frame :public Container
188{
189 public:
[4068]190  Frame(const char* frameName = NULL);
[3623]191  virtual ~Frame(void);
[3624]192
[4046]193  virtual void setTitle(const char* title);
[3144]194};
195
196//! EventBox is a Container that can Handle all Events happening inside of it.
197/**
198 * Example: if you have a picture, and you want it to catch mouse-clicks, you have to pack it inside a EventBox
199 */
200class EventBox : public Container
201{
202 public:
[4046]203  EventBox(const char* eventBoxName = NULL);
[3623]204  virtual ~EventBox(void);
[3144]205};
206
207//! A Box can contain multiple Widgets
208/**
[3187]209   A Box can Contain multiple Widgets, that are ordered either horizontally or vertically
210   I defined the standartbox to be horizontally.
[3423]211   A Box is always filled left->right(horizontally) or up->down(vertically)
[3187]212*/
[3144]213class Box : public Packer
214{
215 public:
[4046]216  Box(char boxtype = 'h');
[3623]217  virtual ~Box(void);
[3423]218 
[4046]219  virtual void fill(Widget* lowerWidget);
[3144]220};
221
222//! An Option is a Widget that contains something that may change its state.
223/**
224 * Options are the essence of a GUI, they: Configure, Start, Quit, Execute, and make it worth something
225 */
226class Option : public Widget
227{
[3423]228 protected:
[4046]229  bool saveable;              //!< Options can be Saved.
[3423]230 
[3144]231 public:
[3623]232  Option(void);
233  virtual ~Option(void);
[3144]234
[4046]235  int value;                  //!< every option has a value either true or false(0,1) or something else like 25 for 25% of the volume
236  char* flagName;             //!< options have a flag name that will be appendet if you start the Program from the GUI.
237  char* flagNameShort;        //!< like flag_name but shorter
238  int defaultValue;           //!< A default value is good, for hiding a option if it is not needed.(hidden if value == default_value)
[3144]239
[4046]240  char* shortDescription;      //!< A Text that describes this option in short
241  char* longDescription;      //!< A Longer Text describing this option in a full way
242
243  void saveability(bool isSaveable = true);
[3625]244  virtual char* save(void);
245  virtual void load(char* loadString);
246
[3423]247  bool isSaveable(void);
[4058]248  void setDefaultValue(int defaultValue);
[4046]249  void setFlagName(const char* flagname, int defaultvalue);
250  void setFlagName(const char* flagname, const char* flagnameshort, int defaultvalue);
251  void setDescription(const char* shortDescription, const char* longDescription = NULL);
252
253  virtual void redraw(void) = 0;       //!< A Option must be able to redraw itself.
[3423]254  virtual void changeOption(void) = 0; //!< What to do, if an Option is Changed. eacht option decides for itself.
255#ifdef HAVE_GTK2
256    // Signals 
257  static gint OptionChange(GtkWidget* widget, Widget* option); //!< Signal for Options that change.
258#endif /* HAVE_GTK2 */
[3144]259};
260
261//! Buttons can be pressed, and released.
262/**
263 * Buttons are mainly there for executing some action like Starting the Programm, or Quiting it.
264 */
265class Button : public Option
266{
267 public:
[4089]268  Button(const char* buttonName = NULL);
[3623]269  virtual ~Button(void);
[3144]270
[4046]271  virtual void setTitle(const char* title);
272  virtual void redraw(void);
273  virtual void changeOption(void);
[3144]274};
275
276//! CheckButtons are a key in configuring bool Variables
277/** CheckButtons can configure bool Variables like wireframe on/off, enable_sound etc.
278 */
279class CheckButton : public Option
280{
281 public:
[4046]282  CheckButton(const char* buttonName = NULL);
[3623]283  virtual ~CheckButton(void);
[3423]284
[4046]285  bool isActive(void);
286
287  virtual void setTitle(const char* title);
288  virtual void redraw(void);
289  virtual void changeOption(void);
[3144]290};
291
292//! Sliders are Options that can be modified in their value
293/**
294 * good for volume, brightness, etc.
295 */
296class Slider : public Option
297{
[3423]298 private:
[4338]299  float start;                            //!< The beginning of the Slider-range.
300  float end;                              //!< The end of the Slider-range.
301  float fValue;                           //!< a value for the slider
[3144]302 public:
[4338]303  Slider(const char* slidername, float start, float end);
[3623]304  virtual ~Slider(void);
[3144]305
[4338]306  void setExactness(int exactness);
307  void setValue(float value);
[4046]308  virtual void redraw(void);
309  virtual void changeOption(void);
[4338]310
311  virtual char* save(void);
312  virtual void load(char* loadString);
[3144]313};
314
315//! A Menu is an Option that has a dropdown menu, where you can chose between different Items
316class Menu : public Option
317{
318 private:
[3165]319#ifdef HAVE_GTK2
[3423]320  GtkWidget* menu;                      //!< The menu That will hold the Options.
[3165]321#endif /* HAVE_GTK2 */
[3625]322
[3624]323  //! A struct to handle the MenuItems
324  struct MenuItem
325  {
[3625]326    char* name;                         //!< The name of this entry.
327    int itemNumber;                     //!< The n'th entry of this menu;
[3624]328#ifdef HAVE_GTK2
329    GtkWidget* item;                    //!< One Item From a Menu.
330#endif /* HAVE_GTK2 */
[4046]331
[3624]332    MenuItem* next;                     //!< Pointer to the next MenuItem.
333  };
334  MenuItem* firstItem;                  //!< Pointer to the first Item.
335  MenuItem* currItem;                   //!< Pointer to the current Item.
336 
[3144]337 public:
[3624]338  Menu(const char* menuName);
[3423]339  Menu(char* menuname, ...);
[3623]340  virtual ~Menu(void);
[3144]341  void init(void);
[3625]342
343  virtual char* save(void);
344  virtual void load(char* loadString);
[3423]345 
[3144]346  void addItem(char* itemName);
[4046]347  virtual void redraw(void);
348  virtual void changeOption(void);
[3144]349};
350
[3423]351//! A OptionLabel is a simple Label, that holds a char*, and will be updated, if changed.
[3156]352class OptionLabel : public Option
353{
354 public:
[4046]355  OptionLabel(const char* label, const char* value);
[3623]356  virtual ~OptionLabel(void);
[3161]357 
[4046]358  void setValue(const char* newValue);
[3625]359
360  virtual char* save(void);
361  virtual void load(char* loadString);
362
[4046]363  virtual void redraw(void);
364  virtual void changeOption(void);
[3423]365
366  char* cValue;                          //!< The Value the Label will have. \todo make private
[3156]367};
368
[4064]369//! A EntryField is a TextEntry field, for putting some text into.
370class EntryField : public Option
371{
372 public:
373  EntryField(const char* name = NULL);
374  virtual ~EntryField(void);
375 
376  void setValue(const char* newValue);
377  virtual char* save(void);
378  virtual void load(char* loadString);
379 
380  virtual void redraw(void);
381  virtual void changeOption(void);
382};
383
[3144]384//! A label is a Widget, that displays a text
385class Label : public Widget
386{
387 public:
[4046]388  Label(const char* text = NULL);
[3623]389  virtual ~Label(void);
[3144]390 
[4046]391  virtual void setTitle(const char* text);
[3423]392  void ereaseText(void);
393  void appendText(char* textToAppend);
394  void appendInt(int intToAppend);
[4046]395  const char* getText(void);
[3144]396};
397
[3423]398//! A ProgressBar is a Widget, that can display a Progress
399class ProgressBar : public Widget
400{
401 public:
[4046]402  ProgressBar(const char* label = NULL);
[3623]403  virtual ~ProgressBar(void);
[3156]404
[3423]405  void setProgress(double progress);
406  void setTotalSize(double totalSize);
407  double getProgress(void);
[3144]408
[3423]409 private:
410  double totalSize;         //!< The total Size of a download Bar
411  double progress;          //!< The progress of a Bar.
412#ifdef HAVE_GTK2
413  GtkAdjustment* adjustment;
414#endif /* HAVE_GTK2 */
415};
416
417//! Image is the keeper of one Image
418/**
419 * Images are mighty cool.
420 * Images can help you lighten up the Programming process, and will give everyone a better impression of the Software.
421 */
422class Image : public Widget
423{
424 public:
[4030]425  Image(const char* imgaeName);
426  Image(char** imageData);
[3623]427  virtual ~Image(void);
[4030]428  void init(const char* name);
[3423]429};
430
[4068]431//! A FileDialog is a window with wich one can select a File
432class FileDialog : public Widget
433{
434 private:
435  OptionLabel* changeOption;
436  Button* openUpButton;
437  bool isOpen;
[4083]438  bool (*okFunc)(const char* , void*);
439  void* okObject;
440
[4068]441 public:
442  FileDialog(const char* fileDialogName);
443  virtual ~FileDialog(void);
[3423]444
[4068]445  void setChangeOption(OptionLabel* changeOption);
[4083]446  void setOKFunc(void* okObject, bool(*function)(const char* , void*));
[4068]447  void setOpenUpButton(Button* openUpButton);
448  void setDefaultFileName(const char* defaultFileName);
449  void setMask(const char* mask);
[4083]450  void disableFileOpts(void);
[4068]451
452  void okEvent();
453  void open();
454  void close();
455
456#ifdef HAVE_GTK2
457  static gint dialogOK(GtkWidget* widget, GdkEvent* event, void* dialog);
458  static gint dialogOpen(GtkWidget* widget, GdkEvent* event, void* dialog);
459  static gint dialogClose(GtkWidget* widget, GdkEvent* event, void* dialog);
460#else /* HAVE_GTK2 */
461  static int dialogOK(void* widget, void* event, void* dialog);
462  static int dialogOpen(void* widget, void* event, void* dialog);
463  static int dialogClose(void* widget, void* event, void* dialog);
464#endif /* HAVE_GTK2 */
465};
466
[4048]467#endif /* _GUI_GTK_H */
Note: See TracBrowser for help on using the repository browser.