Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/branches/updater/src/gui/orxonox_gui_gtk.h @ 3296

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

orxonox/branches/updater: now the GUI just opens the first time, and the seccond time only if requested by —gui.

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