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
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  virtual const char* getTitle(void) const { return this->title; };
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);
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);
74   static void printHelp(Widget* widget);
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);
79 
80#ifdef HAVE_GTK2
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);
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);
99#endif /* HAVE_GTK2 */
100
101
102  Widget* next;                     //!< next always points to the next Widget in the list. Every Widget has a next one, or has NULL as next
103#ifdef HAVE_GTK2
104  GtkWidget* widget;                //!< widget is the gtk_widget that the specific Object Contains.
105#else /* HAVE_GTK2 */
106  void* widget;
107#endif /* HAVE_GTK2 */
108
109  GUI_OPTION optionType;            //!< The Type of the Widget.
110  char* title;                      //!< The name of the Widget. Some do display it, Options need it to save;
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:
117  Packer(void);
118  virtual ~Packer(void);
119
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.
122
123  void setGroupName(const char* name);
124  /** \returns the GroupName if existent NULL otherwise */
125  inline const char* getGroupName(void) const {return this->groupName;}
126
127
128  virtual void fill(Widget* lowerWidget) = 0; //!< An abstract function, that fills Packers.
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:
140  int borderwidth;          //!< The width of The Container Boarder.
141  int policy;               //!< The Update Policy of a Container.
142 
143 public:
144  Container(void);
145  virtual ~Container(void);
146
147  void setBorderWidth(int borderwidth);
148  void fill(Widget* lowerWidget);
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:
159  bool isOpen;                      //!< A bool Variable that checks if a Window is already open.
160 public:
161  static Window* mainWindow;        //!< Pointer to the First Window that was opened. By default this should be the GUI's main-Window.
162  static void addWindow(Window* windowToAdd);
163
164  Window(const char* windowName = NULL);
165  virtual ~Window(void);
166 
167  virtual void setTitle(const char* title);
168  void showall(void);
169  void open(void);
170  void close(void);
171
172#ifdef HAVE_GTK2
173  // Signals
174  static gint windowOpen(GtkWidget* widget, GdkEvent* event, void* window);
175  static gint windowClose(GtkWidget* widget, GdkEvent* event, void* window);
176#else /* HAVE_GTK2 */
177  int Window::windowOpen(void* widget, void* event, void* window);
178  int Window::windowClose(void* widget, void* event, void* window);
179#endif /* HAVE_GTK2 */
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:
190  Frame(const char* frameName = NULL);
191  virtual ~Frame(void);
192
193  virtual void setTitle(const char* title);
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:
203  EventBox(const char* eventBoxName = NULL);
204  virtual ~EventBox(void);
205};
206
207//! A Box can contain multiple Widgets
208/**
209   A Box can Contain multiple Widgets, that are ordered either horizontally or vertically
210   I defined the standartbox to be horizontally.
211   A Box is always filled left->right(horizontally) or up->down(vertically)
212*/
213class Box : public Packer
214{
215 public:
216  Box(char boxtype = 'h');
217  virtual ~Box(void);
218 
219  virtual void fill(Widget* lowerWidget);
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{
228 protected:
229  bool saveable;              //!< Options can be Saved.
230 
231 public:
232  Option(void);
233  virtual ~Option(void);
234
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)
239
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);
244  virtual char* save(void);
245  virtual void load(char* loadString);
246
247  bool isSaveable(void);
248  void setDefaultValue(int defaultValue);
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.
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 */
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:
268  Button(const char* buttonName = NULL);
269  virtual ~Button(void);
270
271  virtual void setTitle(const char* title);
272  virtual void redraw(void);
273  virtual void changeOption(void);
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:
282  CheckButton(const char* buttonName = NULL);
283  virtual ~CheckButton(void);
284
285  bool isActive(void);
286
287  virtual void setTitle(const char* title);
288  virtual void redraw(void);
289  virtual void changeOption(void);
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{
298 private:
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
302 public:
303  Slider(const char* slidername, float start, float end);
304  virtual ~Slider(void);
305
306  void setExactness(int exactness);
307  void setValue(float value);
308  virtual void redraw(void);
309  virtual void changeOption(void);
310
311  virtual char* save(void);
312  virtual void load(char* loadString);
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:
319#ifdef HAVE_GTK2
320  GtkWidget* menu;                      //!< The menu That will hold the Options.
321#endif /* HAVE_GTK2 */
322
323  //! A struct to handle the MenuItems
324  struct MenuItem
325  {
326    char* name;                         //!< The name of this entry.
327    int itemNumber;                     //!< The n'th entry of this menu;
328#ifdef HAVE_GTK2
329    GtkWidget* item;                    //!< One Item From a Menu.
330#endif /* HAVE_GTK2 */
331
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 
337 public:
338  Menu(const char* menuName);
339  Menu(char* menuname, ...);
340  virtual ~Menu(void);
341  void init(void);
342
343  virtual char* save(void);
344  virtual void load(char* loadString);
345 
346  void addItem(char* itemName);
347  virtual void redraw(void);
348  virtual void changeOption(void);
349};
350
351//! A OptionLabel is a simple Label, that holds a char*, and will be updated, if changed.
352class OptionLabel : public Option
353{
354 public:
355  OptionLabel(const char* label, const char* value);
356  virtual ~OptionLabel(void);
357 
358  void setValue(const char* newValue);
359
360  virtual char* save(void);
361  virtual void load(char* loadString);
362
363  virtual void redraw(void);
364  virtual void changeOption(void);
365
366  char* cValue;                          //!< The Value the Label will have. \todo make private
367};
368
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
384//! A label is a Widget, that displays a text
385class Label : public Widget
386{
387 public:
388  Label(const char* text = NULL);
389  virtual ~Label(void);
390 
391  virtual void setTitle(const char* text);
392  void ereaseText(void);
393  void appendText(char* textToAppend);
394  void appendInt(int intToAppend);
395  const char* getText(void);
396};
397
398//! A ProgressBar is a Widget, that can display a Progress
399class ProgressBar : public Widget
400{
401 public:
402  ProgressBar(const char* label = NULL);
403  virtual ~ProgressBar(void);
404
405  void setProgress(double progress);
406  void setTotalSize(double totalSize);
407  double getProgress(void);
408
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:
425  Image(const char* imgaeName);
426  Image(char** imageData);
427  virtual ~Image(void);
428  void init(const char* name);
429};
430
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;
438  bool (*okFunc)(const char* , void*);
439  void* okObject;
440
441 public:
442  FileDialog(const char* fileDialogName);
443  virtual ~FileDialog(void);
444
445  void setChangeOption(OptionLabel* changeOption);
446  void setOKFunc(void* okObject, bool(*function)(const char* , void*));
447  void setOpenUpButton(Button* openUpButton);
448  void setDefaultFileName(const char* defaultFileName);
449  void setMask(const char* mask);
450  void disableFileOpts(void);
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
467#endif /* _GUI_GTK_H */
Note: See TracBrowser for help on using the repository browser.