Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/branches/updater: nicer optionChange-Function

File size: 11.0 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*, void* ));
69  gulong connectSignal (char* event, void* extObj, gint (*signal)(GtkWidget*, GdkEventKey*, void* ));
70  void disconnectSignal (gulong signalID);
71
72  // Signals
73  static gint doNothingSignal (GtkWidget* widget, GdkEvent* event, void* nothing);
74#endif /* HAVE_GTK2 */
75
76  Widget* next;                     //!< next always points to the next Widget in the list. Every Widget has a next one, or has NULL as next
77#ifdef HAVE_GTK2
78  GtkWidget* widget;                //!< widget is the gtk_widget that the specific Object Contains.
79#endif /* HAVE_GTK2 */
80  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
81
82  //! defines isOption states
83  enum option { containerType = -2, boxType = -1, nothingType = 0, boolType = 1, intType = 2}; 
84  char* title;                      //!< The name of the Widget. Some do display it, Options need it to save;
85};
86
87//! This is a Packer Object, which has the ability to Pack other Widgets into itself.
88class Packer : public Widget
89{
90 public:
91  Widget* down; //!< this points to the Widget below this.
92  char* groupName; //!< For each Packer you can specify a Groupname under which the lowerWidgets will be saved.
93
94  void init(void);
95  void destroy(void);
96
97  void setGroupName (char* name);
98  char* getGroupName (void);
99
100  virtual void fill (Widget* lowerWidget) = 0; //!< An abstract function, that fills Packers.
101};
102
103//! This is a Container Class, it can contain one sub-Widget: down.
104/**
105 * A Container is a Widget that can hold a subWidget in addition to a next-Widget.
106 * The Container can by itself not be displayed created or used.
107 * The derived classes of Container can be displayed
108*/
109class Container : public Packer
110{
111 private:
112  int borderwidth;          //!< The width of The Container Boarder.
113  int policy;               //!< The Update Policy of a Container.
114 
115 public:
116  void init(void);
117  void destroy(void);
118
119  //  void setBorderWidth (int borderwidth);
120  //  virtual void setTitle (char* title) = 0;
121  void fill (Widget* lowerWidget);
122};
123
124//! Window is the class that creates new Windows, and handels them
125/**
126 * A Window is a class derived from Container that contains a window-widget.
127 * It has the ability to hold one sub-object
128 */
129class Window : public Container
130{
131 private:
132  bool isOpen;                      //!< A bool Variable that checks if a Window is already open.
133 public:
134  static Window* mainWindow;        //!< Pointer to the First Window that was opened. By default this should be the GUI's main-Window.
135  static void addWindow(Window* windowToAdd);
136
137  Window(void);
138  Window(char* windowName);
139  ~Window(void);
140  void init();
141  void destroy(void);
142 
143  void setTitle(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  ~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  void init(void);
219  void destroy(void);
220
221  int value; //!< every option has a value either true or false (0,1) or something else like 25 for 25% of the volume
222  char* flagName; //!< options have a flag name that will be appendet if you start the Program from the GUI.
223  char* flagNameShort; //!< like flag_name but shorter
224  int defaultValue; //!< A default value is good, for hiding a option if it is not needed. (hidden if value == default_value)
225
226  void saveability(void);
227  void saveability(bool isSaveable);
228  bool isSaveable(void);
229  void setFlagName (char* flagname, int defaultvalue);
230  void setFlagName (char* flagname, char* flagnameshort, int defaultvalue);
231  virtual void redraw (void) = 0; //!< A Option must be able to redraw itself.
232  virtual void changeOption(void) = 0; //!< What to do, if an Option is Changed. eacht option decides for itself.
233#ifdef HAVE_GTK2
234    // Signals 
235  static gint OptionChange (GtkWidget* widget, Widget* option); //!< Signal for Options that change.
236#endif /* HAVE_GTK2 */
237};
238
239//! Buttons can be pressed, and released.
240/**
241 * Buttons are mainly there for executing some action like Starting the Programm, or Quiting it.
242 */
243class Button : public Option
244{
245 public:
246  Button (char* buttonname);
247  ~Button(void);
248  void init(void);
249  void destroy(void);
250
251  void setTitle(char* title);
252  void redraw();
253  void changeOption(void);
254};
255
256//! CheckButtons are a key in configuring bool Variables
257/** CheckButtons can configure bool Variables like wireframe on/off, enable_sound etc.
258 */
259class CheckButton : public Option
260{
261 public:
262  CheckButton (char* buttonname);
263  ~CheckButton(void);
264  void init(void);
265  void destroy(void);
266
267  void setTitle(char* title);
268  bool isActive();           //!< a Bool value to see, if this CheckButton is active.
269  void redraw ();
270  void changeOption(void);
271};
272
273//! Sliders are Options that can be modified in their value
274/**
275 * good for volume, brightness, etc.
276 */
277class Slider : public Option
278{
279 public:
280  Slider(char* slidername,int start, int end);
281  ~Slider(void);
282  void init(int start, int end);
283  void destroy(void);
284
285  void setTitle(char* title);
286  void setValue(int value);
287  void redraw(void);
288  void changeOption(void);
289};
290
291//! A Menu is an Option that has a dropdown menu, where you can chose between different Items
292class Menu : public Option
293{
294 private:
295#ifdef HAVE_GTK2
296  GtkWidget* menu;                      //!< The menu That will hold the Options.
297  GtkWidget* item;                      //!< One Item From a Menu.
298#endif /* HAVE_GTK2 */
299  va_list itemlist;                     //!< The list to readin multiple Options.
300 
301 public:
302  Menu (char* menuname, ...);
303  ~Menu(void);
304  void init(void);
305  void destroy(void);
306 
307  void setTitle(char* title);
308  void addItem(char* itemName);
309  void redraw(void);
310  void changeOption(void);
311};
312
313//! A OptionLabel is a simple Label, that holds a char*, and will be updated, if changed.
314class OptionLabel : public Option
315{
316 private:
317
318 public:
319  OptionLabel(char* label, char* value);
320  ~OptionLabel(void);
321  void init(void);
322  void destroy(void);
323 
324 
325  void setValue(char* newValue);
326  void setTitle(char* title);
327  void redraw();
328  void changeOption();
329
330  char* cValue;                          //!< The Value the Label will have. \todo make private
331
332};
333
334//! A label is a Widget, that displays a text
335class Label : public Widget
336{
337 public:
338  Label (void);
339  Label (char* text);
340  ~Label(void);
341  void init(void);
342  void destroy(void);
343 
344  void setTitle(char* text);
345  void ereaseText(void);
346  void appendText(char* textToAppend);
347  void appendInt(int intToAppend);
348  char* getText ();
349};
350
351//! A ProgressBar is a Widget, that can display a Progress
352class ProgressBar : public Widget
353{
354 public:
355  ProgressBar (void);
356  ProgressBar (char* label);
357  ~ProgressBar (void);
358  void init(void);
359  void destroy(void);
360
361  void setTitle(char* title);
362  void setProgress (double progress);
363  void setTotalSize (double totalSize);
364  double getProgress (void);
365
366 private:
367  double totalSize;         //!< The total Size of a download Bar
368  double progress;          //!< The progress of a Bar.
369#ifdef HAVE_GTK2
370  GtkAdjustment* adjustment;
371#endif /* HAVE_GTK2 */
372};
373
374//! Image is the keeper of one Image
375/**
376 * Images are mighty cool.
377 * Images can help you lighten up the Programming process, and will give everyone a better impression of the Software.
378 */
379class Image : public Widget
380{
381 public:
382  Image (char* imgaename);
383  ~Image(void);
384  void init(void);
385  void destroy(void);
386
387  void setTitle(char* title);
388};
389
390//gint orxonox_gui_quit (GtkWidget* widget, GdkEvent* event, gpointer data);
391
392#endif /* _ORXONOX_GUI_GTK_H */
Note: See TracBrowser for help on using the repository browser.