Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/trunk/src/lib/gui/gui/orxonox_gui_gtk.h @ 4039

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

orxonox/trunk/gui: minor change

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