Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/branches/movie_player/src/lib/gui/gui/gui_gtk.h @ 4217

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

orxonox/branches/movie_player: merged the trunk back into the movie_player
merged with command:
svn merge -r 4014:HEAD ../trunk/ movie_player/
no conflicts

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