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
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
14#ifdef HAVE_GTK2
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>
29#include <gtk/gtkprogressbar.h>
30#include <gtk/gtkfilesel.h>
31#endif /* HAVE_GTK2 */
32
33// enumerator for different GuiOption-Types
34enum GUI_OPTION {GUI_BOX = -2,
35                 GUI_CONTAINER = -1,
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
43extern char* executable;
44
45bool initGUI(int argc, char* argv[]);
46bool mainloopGUI(void);
47
48//! This is the topmost object that can be displayed all others are derived from it.
49class Widget
50{
51 private:
52
53 public:
54  Widget(void);
55  virtual ~Widget(void);
56
57  void show(void);
58  void hide(void);
59  void setSize(int width, int height);
60
61  virtual void setTitle(const char* title);  //!< An abstract Function, that sets the title of Widgets.
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);
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);
76 
77#ifdef HAVE_GTK2
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);
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);
96#endif /* HAVE_GTK2 */
97
98
99  Widget* next;                     //!< next always points to the next Widget in the list. Every Widget has a next one, or has NULL as next
100#ifdef HAVE_GTK2
101  GtkWidget* widget;                //!< widget is the gtk_widget that the specific Object Contains.
102#else /* HAVE_GTK2 */
103  void* widget;
104#endif /* HAVE_GTK2 */
105
106  GUI_OPTION optionType;            //!< The Type of the Widget.
107  char* title;                      //!< The name of the Widget. Some do display it, Options need it to save;
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:
114  Packer(void);
115  virtual ~Packer(void);
116
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.
119
120  void setGroupName(const char* name);
121  /** \returns the GroupName if existent NULL otherwise */
122  inline const char* getGroupName(void) const {return this->groupName;}
123
124
125  virtual void fill(Widget* lowerWidget) = 0; //!< An abstract function, that fills Packers.
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:
137  int borderwidth;          //!< The width of The Container Boarder.
138  int policy;               //!< The Update Policy of a Container.
139 
140 public:
141  Container(void);
142  virtual ~Container(void);
143
144  void setBorderWidth(int borderwidth);
145  void fill(Widget* lowerWidget);
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:
156  bool isOpen;                      //!< A bool Variable that checks if a Window is already open.
157 public:
158  static Window* mainWindow;        //!< Pointer to the First Window that was opened. By default this should be the GUI's main-Window.
159  static void addWindow(Window* windowToAdd);
160
161  Window(const char* windowName = NULL);
162  virtual ~Window(void);
163 
164  virtual void setTitle(const char* title);
165  void showall(void);
166  void open(void);
167  void close(void);
168
169#ifdef HAVE_GTK2
170  // Signals
171  static gint windowOpen(GtkWidget* widget, GdkEvent* event, void* window);
172  static gint windowClose(GtkWidget* widget, GdkEvent* event, void* window);
173#else /* HAVE_GTK2 */
174  int Window::windowOpen(void* widget, void* event, void* window);
175  int Window::windowClose(void* widget, void* event, void* window);
176#endif /* HAVE_GTK2 */
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:
187  Frame(const char* frameName = NULL);
188  virtual ~Frame(void);
189
190  virtual void setTitle(const char* title);
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:
200  EventBox(const char* eventBoxName = NULL);
201  virtual ~EventBox(void);
202};
203
204//! A Box can contain multiple Widgets
205/**
206   A Box can Contain multiple Widgets, that are ordered either horizontally or vertically
207   I defined the standartbox to be horizontally.
208   A Box is always filled left->right(horizontally) or up->down(vertically)
209*/
210class Box : public Packer
211{
212 public:
213  Box(char boxtype = 'h');
214  virtual ~Box(void);
215 
216  virtual void fill(Widget* lowerWidget);
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{
225 protected:
226  bool saveable;              //!< Options can be Saved.
227 
228 public:
229  Option(void);
230  virtual ~Option(void);
231
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)
236
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);
241  virtual char* save(void);
242  virtual void load(char* loadString);
243
244  bool isSaveable(void);
245  void setDefaultValue(int defaultValue);
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.
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 */
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:
265  Button(char* buttonName = NULL);
266  virtual ~Button(void);
267
268  virtual void setTitle(const char* title);
269  virtual void redraw(void);
270  virtual void changeOption(void);
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:
279  CheckButton(const char* buttonName = NULL);
280  virtual ~CheckButton(void);
281
282  bool isActive(void);
283
284  virtual void setTitle(const char* title);
285  virtual void redraw(void);
286  virtual void changeOption(void);
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{
295 private:
296  int start;                            //!< The beginning of the Slider-range.
297  int end;                              //!< The end of the Slider-range.
298 public:
299  Slider(const char* slidername, int start, int end);
300  virtual ~Slider(void);
301
302  void setValue(int value);
303  virtual void redraw(void);
304  virtual void changeOption(void);
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:
311#ifdef HAVE_GTK2
312  GtkWidget* menu;                      //!< The menu That will hold the Options.
313#endif /* HAVE_GTK2 */
314
315  //! A struct to handle the MenuItems
316  struct MenuItem
317  {
318    char* name;                         //!< The name of this entry.
319    int itemNumber;                     //!< The n'th entry of this menu;
320#ifdef HAVE_GTK2
321    GtkWidget* item;                    //!< One Item From a Menu.
322#endif /* HAVE_GTK2 */
323
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 
329 public:
330  Menu(const char* menuName);
331  Menu(char* menuname, ...);
332  virtual ~Menu(void);
333  void init(void);
334
335  virtual char* save(void);
336  virtual void load(char* loadString);
337 
338  void addItem(char* itemName);
339  virtual void redraw(void);
340  virtual void changeOption(void);
341};
342
343//! A OptionLabel is a simple Label, that holds a char*, and will be updated, if changed.
344class OptionLabel : public Option
345{
346 public:
347  OptionLabel(const char* label, const char* value);
348  virtual ~OptionLabel(void);
349 
350  void setValue(const char* newValue);
351
352  virtual char* save(void);
353  virtual void load(char* loadString);
354
355  virtual void redraw(void);
356  virtual void changeOption(void);
357
358  char* cValue;                          //!< The Value the Label will have. \todo make private
359};
360
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
376//! A label is a Widget, that displays a text
377class Label : public Widget
378{
379 public:
380  Label(const char* text = NULL);
381  virtual ~Label(void);
382 
383  virtual void setTitle(const char* text);
384  void ereaseText(void);
385  void appendText(char* textToAppend);
386  void appendInt(int intToAppend);
387  const char* getText(void);
388};
389
390//! A ProgressBar is a Widget, that can display a Progress
391class ProgressBar : public Widget
392{
393 public:
394  ProgressBar(const char* label = NULL);
395  virtual ~ProgressBar(void);
396
397  void setProgress(double progress);
398  void setTotalSize(double totalSize);
399  double getProgress(void);
400
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:
417  Image(const char* imgaeName);
418  Image(char** imageData);
419  virtual ~Image(void);
420  void init(const char* name);
421};
422
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);
433
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
454#endif /* _GUI_GTK_H */
Note: See TracBrowser for help on using the repository browser.