Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/branches/updater: Now in non-gtk-mode, the Gui will ask questions for what Option to change… it is kind of sexy, but you can not change the Option yet. but this will follow.
I am now going into holydays till 1.1.2005: I hope you all have a good 'rutsch' into the new year.
cheers bensch

PS: I do not believe that anyone reads this, but anyways it was fun writing it :)

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