Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk/gui: new isOption-tag of Widgets: optionType

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