Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/branches/updater: label → this→title (now setTitle makes at least some sense)

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