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
Line 
1/*!
2 \file gui_gtk.h
3 \brief Contains all th different Widgets.
4*/
5#ifndef _GUI_GTK_H
6#define _GUI_GTK_H
7
8#if HAVE_CONFIG_H
9#include <config.h> 
10#endif
11
12#include "debug.h"
13#include "globals.h"
14
15#ifdef HAVE_GTK2
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>
30#include <gtk/gtkprogressbar.h>
31#include <gtk/gtkfilesel.h>
32#endif /* HAVE_GTK2 */
33
34// enumerator for different GuiOption-Types
35enum GUI_OPTION {GUI_BOX = -2,
36                 GUI_CONTAINER = -1,
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
44extern char* executable;
45
46bool initGUI(int argc, char* argv[]);
47bool mainloopGUI(void);
48
49//! This is the topmost object that can be displayed all others are derived from it.
50class Widget
51{
52 private:
53
54 public:
55  Widget(void);
56  virtual ~Widget(void);
57
58  void show(void);
59  void hide(void);
60  void setSize(int width, int height);
61
62  virtual void setTitle(const char* title);  //!< An abstract Function, that sets the title of Widgets.
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);
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);
73   static void printHelp(Widget* widget);
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);
78 
79#ifdef HAVE_GTK2
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);
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);
98#endif /* HAVE_GTK2 */
99
100
101  Widget* next;                     //!< next always points to the next Widget in the list. Every Widget has a next one, or has NULL as next
102#ifdef HAVE_GTK2
103  GtkWidget* widget;                //!< widget is the gtk_widget that the specific Object Contains.
104#else /* HAVE_GTK2 */
105  void* widget;
106#endif /* HAVE_GTK2 */
107
108  GUI_OPTION optionType;            //!< The Type of the Widget.
109  char* title;                      //!< The name of the Widget. Some do display it, Options need it to save;
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:
116  Packer(void);
117  virtual ~Packer(void);
118
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.
121
122  void setGroupName(const char* name);
123  /** \returns the GroupName if existent NULL otherwise */
124  inline const char* getGroupName(void) const {return this->groupName;}
125
126
127  virtual void fill(Widget* lowerWidget) = 0; //!< An abstract function, that fills Packers.
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:
139  int borderwidth;          //!< The width of The Container Boarder.
140  int policy;               //!< The Update Policy of a Container.
141 
142 public:
143  Container(void);
144  virtual ~Container(void);
145
146  void setBorderWidth(int borderwidth);
147  void fill(Widget* lowerWidget);
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:
158  bool isOpen;                      //!< A bool Variable that checks if a Window is already open.
159 public:
160  static Window* mainWindow;        //!< Pointer to the First Window that was opened. By default this should be the GUI's main-Window.
161  static void addWindow(Window* windowToAdd);
162
163  Window(const char* windowName = NULL);
164  virtual ~Window(void);
165 
166  virtual void setTitle(const char* title);
167  void showall(void);
168  void open(void);
169  void close(void);
170
171#ifdef HAVE_GTK2
172  // Signals
173  static gint windowOpen(GtkWidget* widget, GdkEvent* event, void* window);
174  static gint windowClose(GtkWidget* widget, GdkEvent* event, void* window);
175#else /* HAVE_GTK2 */
176  int Window::windowOpen(void* widget, void* event, void* window);
177  int Window::windowClose(void* widget, void* event, void* window);
178#endif /* HAVE_GTK2 */
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:
189  Frame(const char* frameName = NULL);
190  virtual ~Frame(void);
191
192  virtual void setTitle(const char* title);
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:
202  EventBox(const char* eventBoxName = NULL);
203  virtual ~EventBox(void);
204};
205
206//! A Box can contain multiple Widgets
207/**
208   A Box can Contain multiple Widgets, that are ordered either horizontally or vertically
209   I defined the standartbox to be horizontally.
210   A Box is always filled left->right(horizontally) or up->down(vertically)
211*/
212class Box : public Packer
213{
214 public:
215  Box(char boxtype = 'h');
216  virtual ~Box(void);
217 
218  virtual void fill(Widget* lowerWidget);
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{
227 protected:
228  bool saveable;              //!< Options can be Saved.
229 
230 public:
231  Option(void);
232  virtual ~Option(void);
233
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)
238
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);
243  virtual char* save(void);
244  virtual void load(char* loadString);
245
246  bool isSaveable(void);
247  void setDefaultValue(int defaultValue);
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.
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 */
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:
267  Button(const char* buttonName = NULL);
268  virtual ~Button(void);
269
270  virtual void setTitle(const char* title);
271  virtual void redraw(void);
272  virtual void changeOption(void);
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:
281  CheckButton(const char* buttonName = NULL);
282  virtual ~CheckButton(void);
283
284  bool isActive(void);
285
286  virtual void setTitle(const char* title);
287  virtual void redraw(void);
288  virtual void changeOption(void);
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{
297 private:
298  int start;                            //!< The beginning of the Slider-range.
299  int end;                              //!< The end of the Slider-range.
300 public:
301  Slider(const char* slidername, int start, int end);
302  virtual ~Slider(void);
303
304  void setValue(int value);
305  virtual void redraw(void);
306  virtual void changeOption(void);
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:
313#ifdef HAVE_GTK2
314  GtkWidget* menu;                      //!< The menu That will hold the Options.
315#endif /* HAVE_GTK2 */
316
317  //! A struct to handle the MenuItems
318  struct MenuItem
319  {
320    char* name;                         //!< The name of this entry.
321    int itemNumber;                     //!< The n'th entry of this menu;
322#ifdef HAVE_GTK2
323    GtkWidget* item;                    //!< One Item From a Menu.
324#endif /* HAVE_GTK2 */
325
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 
331 public:
332  Menu(const char* menuName);
333  Menu(char* menuname, ...);
334  virtual ~Menu(void);
335  void init(void);
336
337  virtual char* save(void);
338  virtual void load(char* loadString);
339 
340  void addItem(char* itemName);
341  virtual void redraw(void);
342  virtual void changeOption(void);
343};
344
345//! A OptionLabel is a simple Label, that holds a char*, and will be updated, if changed.
346class OptionLabel : public Option
347{
348 public:
349  OptionLabel(const char* label, const char* value);
350  virtual ~OptionLabel(void);
351 
352  void setValue(const char* newValue);
353
354  virtual char* save(void);
355  virtual void load(char* loadString);
356
357  virtual void redraw(void);
358  virtual void changeOption(void);
359
360  char* cValue;                          //!< The Value the Label will have. \todo make private
361};
362
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
378//! A label is a Widget, that displays a text
379class Label : public Widget
380{
381 public:
382  Label(const char* text = NULL);
383  virtual ~Label(void);
384 
385  virtual void setTitle(const char* text);
386  void ereaseText(void);
387  void appendText(char* textToAppend);
388  void appendInt(int intToAppend);
389  const char* getText(void);
390};
391
392//! A ProgressBar is a Widget, that can display a Progress
393class ProgressBar : public Widget
394{
395 public:
396  ProgressBar(const char* label = NULL);
397  virtual ~ProgressBar(void);
398
399  void setProgress(double progress);
400  void setTotalSize(double totalSize);
401  double getProgress(void);
402
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:
419  Image(const char* imgaeName);
420  Image(char** imageData);
421  virtual ~Image(void);
422  void init(const char* name);
423};
424
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;
432  bool (*okFunc)(const char* , void*);
433  void* okObject;
434
435 public:
436  FileDialog(const char* fileDialogName);
437  virtual ~FileDialog(void);
438
439  void setChangeOption(OptionLabel* changeOption);
440  void setOKFunc(void* okObject, bool(*function)(const char* , void*));
441  void setOpenUpButton(Button* openUpButton);
442  void setDefaultFileName(const char* defaultFileName);
443  void setMask(const char* mask);
444  void disableFileOpts(void);
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
461#endif /* _GUI_GTK_H */
Note: See TracBrowser for help on using the repository browser.