Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: merged the guiMerge-branche back into the trunk
merged with command:
svn merge -r 4043:HEAD guiMerge/ ../trunk/
no conflicts, only updates and moves :)

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