Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/branches/guiMerge/src/lib/gui/gui/gui_gtk.h @ 4052

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

orxonox/branches/guiMerge: gui produces no more segFault right now … this will probably change again

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