Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/branches/updater: implemented class ProgressBar.

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