Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/branches/guiMerge/src/lib/gui/gui/orxonox_gui_gtk.h @ 4046

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

orxonox/branches/guiMerge: heavy clean-up of the gui

File size: 12.7 KB
Line 
1/*!
2 \file orxonox_gui_gtk.h
3 \brief Contains all th different Widgets.
4*/
5#ifndef _ORXONOX_GUI_GTK_H
6#define _ORXONOX_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#endif /* HAVE_GTK2 */
31
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
42extern char* guiExecutable;
43extern char* progExecutable;
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 flagCheck(Widget* widget, void* flagName);
75 
76#ifdef HAVE_GTK2
77  // Connection - Functions
78  gulong connectSignal(char* event, gint(*signal)(GtkWidget*, GdkEvent*, void* ));
79  gulong connectSignal(char* event, gint(*signal)(GtkWidget*, Widget* ));
80  gulong connectSignal(char* event, void* extObj, gint(*signal)(GtkWidget*, GdkEvent*, void* ));
81  gulong connectSignal(char* event, void* extObj, gint(*signal)(GtkWidget*, void* ));
82  gulong connectSignal(char* event, void* extObj, gint(*signal)(GtkWidget*, GdkEventKey*, void* ));
83  void disconnectSignal(gulong signalID);
84  // Signals
85  static gint doNothingSignal(GtkWidget* widget, GdkEvent* event, void* nothing);
86#else /* HAVE_GTK2 */
87  // Connection - Functions
88  unsigned long connectSignal(char* event, int(*signal)(void*, void*, void* )){};
89  unsigned long connectSignal(char* event, int(*signal)(void*, Widget* )){};
90  unsigned long connectSignal(char* event, void* extObj, int(*signal)(void*, void*, void* )){};
91  unsigned long connectSignal(char* event, void* extObj, int(*signal)(void*, void* )){};
92  void disconnectSignal(unsigned long signalID);
93  // Signals
94  static int doNothingSignal(void* widget, void* event, void* nothing);
95#endif /* HAVE_GTK2 */
96
97
98  Widget* next;                     //!< next always points to the next Widget in the list. Every Widget has a next one, or has NULL as next
99#ifdef HAVE_GTK2
100  GtkWidget* widget;                //!< widget is the gtk_widget that the specific Object Contains.
101#else /* HAVE_GTK2 */
102  void* widget;
103#endif /* HAVE_GTK2 */
104
105  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
106 
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  void setBorderWidth(int borderwidth);
144  void fill(Widget* lowerWidget);
145};
146
147//! Window is the class that creates new Windows, and handels them
148/**
149 * A Window is a class derived from Container that contains a window-widget.
150 * It has the ability to hold one sub-object
151 */
152class Window : public Container
153{
154 private:
155  bool isOpen;                      //!< A bool Variable that checks if a Window is already open.
156 public:
157  static Window* mainWindow;        //!< Pointer to the First Window that was opened. By default this should be the GUI's main-Window.
158  static void addWindow(Window* windowToAdd);
159
160  Window(const char* windowName = NULL);
161  virtual ~Window(void);
162 
163  virtual void setTitle(const char* title);
164  void showall(void);
165  void open(void);
166  void close(void);
167
168#ifdef HAVE_GTK2
169  // Signals
170  static gint windowOpen(GtkWidget* widget, GdkEvent* event, void* window);
171  static gint windowClose(GtkWidget* widget, GdkEvent* event, void* window);
172#else /* HAVE_GTK2 */
173  int Window::windowOpen(void* widget, void* event, void* window);
174  int Window::windowClose(void* widget, void* event, void* window);
175#endif /* HAVE_GTK2 */
176};
177
178//! Frame is the class that handles frames
179/**
180 * A Frame is an object, that has a border and if you like a name on it.
181 * It can contain a Widget, which means that you can insert anything you like inside of a frame
182 */
183class Frame :public Container
184{
185 public:
186  Frame(char* frameName = NULL);
187  virtual ~Frame(void);
188
189  virtual void setTitle(const char* title);
190};
191
192//! EventBox is a Container that can Handle all Events happening inside of it.
193/**
194 * Example: if you have a picture, and you want it to catch mouse-clicks, you have to pack it inside a EventBox
195 */
196class EventBox : public Container
197{
198 public:
199  EventBox(const char* eventBoxName = NULL);
200  virtual ~EventBox(void);
201};
202
203//! A Box can contain multiple Widgets
204/**
205   A Box can Contain multiple Widgets, that are ordered either horizontally or vertically
206   I defined the standartbox to be horizontally.
207   A Box is always filled left->right(horizontally) or up->down(vertically)
208*/
209class Box : public Packer
210{
211 public:
212  Box(char boxtype = 'h');
213  virtual ~Box(void);
214 
215  virtual void fill(Widget* lowerWidget);
216};
217
218//! An Option is a Widget that contains something that may change its state.
219/**
220 * Options are the essence of a GUI, they: Configure, Start, Quit, Execute, and make it worth something
221 */
222class Option : public Widget
223{
224 protected:
225  bool saveable;              //!< Options can be Saved.
226 
227 public:
228  Option(void);
229  virtual ~Option(void);
230
231  int value;                  //!< every option has a value either true or false(0,1) or something else like 25 for 25% of the volume
232  char* flagName;             //!< options have a flag name that will be appendet if you start the Program from the GUI.
233  char* flagNameShort;        //!< like flag_name but shorter
234  int defaultValue;           //!< A default value is good, for hiding a option if it is not needed.(hidden if value == default_value)
235
236  char* shortDescription;      //!< A Text that describes this option in short
237  char* longDescription;      //!< A Longer Text describing this option in a full way
238
239  void saveability(bool isSaveable = true);
240  virtual char* save(void);
241  virtual void load(char* loadString);
242
243  bool isSaveable(void);
244  void setFlagName(const char* flagname, int defaultvalue);
245  void setFlagName(const char* flagname, const char* flagnameshort, int defaultvalue);
246  void setDescription(const char* shortDescription, const char* longDescription = NULL);
247
248  virtual void redraw(void) = 0;       //!< A Option must be able to redraw itself.
249  virtual void changeOption(void) = 0; //!< What to do, if an Option is Changed. eacht option decides for itself.
250#ifdef HAVE_GTK2
251    // Signals 
252  static gint OptionChange(GtkWidget* widget, Widget* option); //!< Signal for Options that change.
253#endif /* HAVE_GTK2 */
254};
255
256//! Buttons can be pressed, and released.
257/**
258 * Buttons are mainly there for executing some action like Starting the Programm, or Quiting it.
259 */
260class Button : public Option
261{
262 public:
263  Button(char* buttonName = NULL);
264  virtual ~Button(void);
265
266  virtual void setTitle(const char* title);
267  virtual void redraw(void);
268  virtual void changeOption(void);
269};
270
271//! CheckButtons are a key in configuring bool Variables
272/** CheckButtons can configure bool Variables like wireframe on/off, enable_sound etc.
273 */
274class CheckButton : public Option
275{
276 public:
277  CheckButton(const char* buttonName = NULL);
278  virtual ~CheckButton(void);
279
280  bool isActive(void);
281
282  virtual void setTitle(const char* title);
283  virtual void redraw(void);
284  virtual void changeOption(void);
285};
286
287//! Sliders are Options that can be modified in their value
288/**
289 * good for volume, brightness, etc.
290 */
291class Slider : public Option
292{
293 private:
294  int start;                            //!< The beginning of the Slider-range.
295  int end;                              //!< The end of the Slider-range.
296 public:
297  Slider(const char* slidername, int start, int end);
298  virtual ~Slider(void);
299
300  void setValue(int value);
301  virtual void redraw(void);
302  virtual void changeOption(void);
303};
304
305//! A Menu is an Option that has a dropdown menu, where you can chose between different Items
306class Menu : public Option
307{
308 private:
309#ifdef HAVE_GTK2
310  GtkWidget* menu;                      //!< The menu That will hold the Options.
311#endif /* HAVE_GTK2 */
312
313  //! A struct to handle the MenuItems
314  struct MenuItem
315  {
316    char* name;                         //!< The name of this entry.
317    int itemNumber;                     //!< The n'th entry of this menu;
318#ifdef HAVE_GTK2
319    GtkWidget* item;                    //!< One Item From a Menu.
320#endif /* HAVE_GTK2 */
321
322    MenuItem* next;                     //!< Pointer to the next MenuItem.
323  };
324  MenuItem* firstItem;                  //!< Pointer to the first Item.
325  MenuItem* currItem;                   //!< Pointer to the current Item.
326 
327 public:
328  Menu(const char* menuName);
329  Menu(char* menuname, ...);
330  virtual ~Menu(void);
331  void init(void);
332
333  virtual char* save(void);
334  virtual void load(char* loadString);
335 
336  void addItem(char* itemName);
337  virtual void redraw(void);
338  virtual void changeOption(void);
339};
340
341//! A OptionLabel is a simple Label, that holds a char*, and will be updated, if changed.
342class OptionLabel : public Option
343{
344 public:
345  OptionLabel(const char* label, const char* value);
346  virtual ~OptionLabel(void);
347 
348  void setValue(const char* newValue);
349
350  virtual char* save(void);
351  virtual void load(char* loadString);
352
353  virtual void redraw(void);
354  virtual void changeOption(void);
355
356  char* cValue;                          //!< The Value the Label will have. \todo make private
357};
358
359//! A label is a Widget, that displays a text
360class Label : public Widget
361{
362 public:
363  Label(const char* text = NULL);
364  virtual ~Label(void);
365 
366  virtual void setTitle(const char* text);
367  void ereaseText(void);
368  void appendText(char* textToAppend);
369  void appendInt(int intToAppend);
370  const char* getText(void);
371};
372
373//! A ProgressBar is a Widget, that can display a Progress
374class ProgressBar : public Widget
375{
376 public:
377  ProgressBar(const char* label = NULL);
378  virtual ~ProgressBar(void);
379
380  void setProgress(double progress);
381  void setTotalSize(double totalSize);
382  double getProgress(void);
383
384 private:
385  double totalSize;         //!< The total Size of a download Bar
386  double progress;          //!< The progress of a Bar.
387#ifdef HAVE_GTK2
388  GtkAdjustment* adjustment;
389#endif /* HAVE_GTK2 */
390};
391
392//! Image is the keeper of one Image
393/**
394 * Images are mighty cool.
395 * Images can help you lighten up the Programming process, and will give everyone a better impression of the Software.
396 */
397class Image : public Widget
398{
399 public:
400  Image(const char* imgaeName);
401  Image(char** imageData);
402  virtual ~Image(void);
403  void init(const char* name);
404};
405
406//gint orxonox_gui_quit(GtkWidget* widget, GdkEvent* event, gpointer data);
407
408#endif /* _ORXONOX_GUI_GTK_H */
Note: See TracBrowser for help on using the repository browser.