Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/branches/md2_loader/src/lib/gui/gui/gui_gtk.h @ 4063

Last change on this file since 4063 was 4063, checked in by patrick, 19 years ago

orxonox/branche/md2_loader: merged trunk into my branche

File size: 12.7 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 redrawOptions(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 setDefaultValue(int defaultValue);
245  void setFlagName(const char* flagname, int defaultvalue);
246  void setFlagName(const char* flagname, const char* flagnameshort, int defaultvalue);
247  void setDescription(const char* shortDescription, const char* longDescription = NULL);
248
249  virtual void redraw(void) = 0;       //!< A Option must be able to redraw itself.
250  virtual void changeOption(void) = 0; //!< What to do, if an Option is Changed. eacht option decides for itself.
251#ifdef HAVE_GTK2
252    // Signals 
253  static gint OptionChange(GtkWidget* widget, Widget* option); //!< Signal for Options that change.
254#endif /* HAVE_GTK2 */
255};
256
257//! Buttons can be pressed, and released.
258/**
259 * Buttons are mainly there for executing some action like Starting the Programm, or Quiting it.
260 */
261class Button : public Option
262{
263 public:
264  Button(char* buttonName = NULL);
265  virtual ~Button(void);
266
267  virtual void setTitle(const char* title);
268  virtual void redraw(void);
269  virtual void changeOption(void);
270};
271
272//! CheckButtons are a key in configuring bool Variables
273/** CheckButtons can configure bool Variables like wireframe on/off, enable_sound etc.
274 */
275class CheckButton : public Option
276{
277 public:
278  CheckButton(const char* buttonName = NULL);
279  virtual ~CheckButton(void);
280
281  bool isActive(void);
282
283  virtual void setTitle(const char* title);
284  virtual void redraw(void);
285  virtual void changeOption(void);
286};
287
288//! Sliders are Options that can be modified in their value
289/**
290 * good for volume, brightness, etc.
291 */
292class Slider : public Option
293{
294 private:
295  int start;                            //!< The beginning of the Slider-range.
296  int end;                              //!< The end of the Slider-range.
297 public:
298  Slider(const char* slidername, int start, int end);
299  virtual ~Slider(void);
300
301  void setValue(int value);
302  virtual void redraw(void);
303  virtual void changeOption(void);
304};
305
306//! A Menu is an Option that has a dropdown menu, where you can chose between different Items
307class Menu : public Option
308{
309 private:
310#ifdef HAVE_GTK2
311  GtkWidget* menu;                      //!< The menu That will hold the Options.
312#endif /* HAVE_GTK2 */
313
314  //! A struct to handle the MenuItems
315  struct MenuItem
316  {
317    char* name;                         //!< The name of this entry.
318    int itemNumber;                     //!< The n'th entry of this menu;
319#ifdef HAVE_GTK2
320    GtkWidget* item;                    //!< One Item From a Menu.
321#endif /* HAVE_GTK2 */
322
323    MenuItem* next;                     //!< Pointer to the next MenuItem.
324  };
325  MenuItem* firstItem;                  //!< Pointer to the first Item.
326  MenuItem* currItem;                   //!< Pointer to the current Item.
327 
328 public:
329  Menu(const char* menuName);
330  Menu(char* menuname, ...);
331  virtual ~Menu(void);
332  void init(void);
333
334  virtual char* save(void);
335  virtual void load(char* loadString);
336 
337  void addItem(char* itemName);
338  virtual void redraw(void);
339  virtual void changeOption(void);
340};
341
342//! A OptionLabel is a simple Label, that holds a char*, and will be updated, if changed.
343class OptionLabel : public Option
344{
345 public:
346  OptionLabel(const char* label, const char* value);
347  virtual ~OptionLabel(void);
348 
349  void setValue(const char* newValue);
350
351  virtual char* save(void);
352  virtual void load(char* loadString);
353
354  virtual void redraw(void);
355  virtual void changeOption(void);
356
357  char* cValue;                          //!< The Value the Label will have. \todo make private
358};
359
360//! A label is a Widget, that displays a text
361class Label : public Widget
362{
363 public:
364  Label(const char* text = NULL);
365  virtual ~Label(void);
366 
367  virtual void setTitle(const char* text);
368  void ereaseText(void);
369  void appendText(char* textToAppend);
370  void appendInt(int intToAppend);
371  const char* getText(void);
372};
373
374//! A ProgressBar is a Widget, that can display a Progress
375class ProgressBar : public Widget
376{
377 public:
378  ProgressBar(const char* label = NULL);
379  virtual ~ProgressBar(void);
380
381  void setProgress(double progress);
382  void setTotalSize(double totalSize);
383  double getProgress(void);
384
385 private:
386  double totalSize;         //!< The total Size of a download Bar
387  double progress;          //!< The progress of a Bar.
388#ifdef HAVE_GTK2
389  GtkAdjustment* adjustment;
390#endif /* HAVE_GTK2 */
391};
392
393//! Image is the keeper of one Image
394/**
395 * Images are mighty cool.
396 * Images can help you lighten up the Programming process, and will give everyone a better impression of the Software.
397 */
398class Image : public Widget
399{
400 public:
401  Image(const char* imgaeName);
402  Image(char** imageData);
403  virtual ~Image(void);
404  void init(const char* name);
405};
406
407//gint orxonox_gui_quit(GtkWidget* widget, GdkEvent* event, gpointer data);
408
409#endif /* _GUI_GTK_H */
Note: See TracBrowser for help on using the repository browser.