Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/trunk/src/lib/gui/gui/orxonox_gui_gtk.h @ 3625

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

orxonox/trunk: merged the branches/updater back to the trunk.
merged with command
svn merge -r 3423:HEAD branches/updater/src/gui trunk/src/lib/graphics/gui/gui.

I do not wish to make such jokes again, because it is even worse than copy-pasting. All Files had to be eddited manually, and many diffs where a little bit strange (artifacts).

File size: 11.5 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#include "debug.h"
13
14#ifdef HAVE_GTK2
15#include <gtk/gtkmain.h>
16#include <gtk/gtkwindow.h>
17#include <gtk/gtkframe.h>
18#include <gtk/gtkhbox.h>
19#include <gtk/gtkvbox.h>
20#include <gtk/gtkbutton.h>
21#include <gtk/gtkcheckbutton.h>
22#include <gtk/gtkhscale.h>
23#include <gtk/gtkoptionmenu.h>
24#include <gtk/gtkmenu.h>
25#include <gtk/gtkmenuitem.h>
26#include <gtk/gtklabel.h>
27#include <gtk/gtkimage.h>
28#include <gtk/gtkeventbox.h>
29#include <gtk/gtkprogressbar.h>
30#endif /* HAVE_GTK2 */
31
32bool initGUI(int argc, char* argv[]);
33bool mainloopGUI(void);
34
35//! This is the topmost object that can be displayed all others are derived from it.
36class Widget
37{
38 private:
39
40 public:
41  Widget(void);
42  virtual ~Widget(void);
43
44  void show(void);
45  void hide(void);
46  void setSize(int width, int height);
47  virtual void setTitle(const char* title);  //!< An abstract Function, that sets the title of Widgets.
48
49  Widget* findWidgetByName(char* name, unsigned int depth);
50  void walkThrough(void(*function)(Widget*), unsigned int depth);
51  void walkThrough(void(*function)(Widget*, void*), void* data, unsigned int depth);
52  static void listOptionsAndGroups(Widget* widget);
53  static void listOptions(Widget* widget);
54  static void listOptions(Widget* widget, void* data);
55  Widget* findOptionByNumber(int* number, unsigned int depth);
56  static void listGroups(Widget* widget);
57  static void listGroups(Widget* widget, void* data);
58  Widget* findGroupByNumber(int* number, unsigned int depth);
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  Packer(void);
92  virtual ~Packer(void);
93
94  Widget* down; //!< this points to the Widget below this.
95  char* groupName; //!< For each Packer you can specify a Groupname under which the lowerWidgets will be saved.
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  Container(void);
117  virtual ~Container(void);
118  //  void setBorderWidth(int borderwidth);
119  void fill(Widget* lowerWidget);
120};
121
122//! Window is the class that creates new Windows, and handels them
123/**
124 * A Window is a class derived from Container that contains a window-widget.
125 * It has the ability to hold one sub-object
126 */
127class Window : public Container
128{
129 private:
130  bool isOpen;                      //!< A bool Variable that checks if a Window is already open.
131 public:
132  static Window* mainWindow;        //!< Pointer to the First Window that was opened. By default this should be the GUI's main-Window.
133  static void addWindow(Window* windowToAdd);
134
135  Window(void);
136  Window(char* windowName);
137  virtual ~Window(void);
138  void init(void);
139 
140  void setTitle(const char* title);
141  void showall(void);
142  void open(void);
143  void close(void);
144
145#ifdef HAVE_GTK2
146  // Signals
147  static gint windowOpen(GtkWidget* widget, GdkEvent* event, void* window);
148  static gint windowClose(GtkWidget* widget, GdkEvent* event, void* window);
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  virtual ~Frame(void);
163  void init(void);
164
165  void setTitle(const char* title);
166};
167
168//! EventBox is a Container that can Handle all Events happening inside of it.
169/**
170 * Example: if you have a picture, and you want it to catch mouse-clicks, you have to pack it inside a EventBox
171 */
172class EventBox : public Container
173{
174 public:
175  EventBox(void);
176  EventBox(char* eventBoxName);
177  virtual ~EventBox(void);
178  void init(void);
179};
180
181//! A Box can contain multiple Widgets
182/**
183   A Box can Contain multiple Widgets, that are ordered either horizontally or vertically
184   I defined the standartbox to be horizontally.
185   A Box is always filled left->right(horizontally) or up->down(vertically)
186*/
187class Box : public Packer
188{
189 public:
190  Box(void);
191  Box(char boxtype);
192  virtual ~Box(void);
193  void init(char boxtype);
194 
195  void fill(Widget* lowerWidget);
196};
197
198//! An Option is a Widget that contains something that may change its state.
199/**
200 * Options are the essence of a GUI, they: Configure, Start, Quit, Execute, and make it worth something
201 */
202class Option : public Widget
203{
204 protected:
205  bool saveable;  //!< Options can be Saved.
206 
207 public:
208  Option(void);
209  virtual ~Option(void);
210  void init(void);
211
212  int value; //!< every option has a value either true or false(0,1) or something else like 25 for 25% of the volume
213  char* flagName; //!< options have a flag name that will be appendet if you start the Program from the GUI.
214  char* flagNameShort; //!< like flag_name but shorter
215  int defaultValue; //!< A default value is good, for hiding a option if it is not needed.(hidden if value == default_value)
216
217  void saveability(void);
218  void saveability(bool isSaveable);
219  virtual char* save(void);
220  virtual void load(char* loadString);
221
222  bool isSaveable(void);
223  void setFlagName(char* flagname, int defaultvalue);
224  void setFlagName(char* flagname, char* flagnameshort, int defaultvalue);
225  virtual void redraw(void) = 0; //!< A Option must be able to redraw itself.
226  virtual void changeOption(void) = 0; //!< What to do, if an Option is Changed. eacht option decides for itself.
227#ifdef HAVE_GTK2
228    // Signals 
229  static gint OptionChange(GtkWidget* widget, Widget* option); //!< Signal for Options that change.
230#endif /* HAVE_GTK2 */
231};
232
233//! Buttons can be pressed, and released.
234/**
235 * Buttons are mainly there for executing some action like Starting the Programm, or Quiting it.
236 */
237class Button : public Option
238{
239 public:
240  Button(char* buttonname);
241  virtual ~Button(void);
242  void init(void);
243
244  void setTitle(const char* title);
245  void redraw(void);
246  void changeOption(void);
247};
248
249//! CheckButtons are a key in configuring bool Variables
250/** CheckButtons can configure bool Variables like wireframe on/off, enable_sound etc.
251 */
252class CheckButton : public Option
253{
254 public:
255  CheckButton(char* buttonname);
256  virtual ~CheckButton(void);
257  void init(void);
258
259  void setTitle(const char* title);
260  bool isActive(void);           //!< a Bool value to see, if this CheckButton is active.
261  void redraw(void);
262  void changeOption(void);
263};
264
265//! Sliders are Options that can be modified in their value
266/**
267 * good for volume, brightness, etc.
268 */
269class Slider : public Option
270{
271 private:
272  int start;                            //!< The beginning of the Slider-range.
273  int end;                              //!< The end of the Slider-range.
274 public:
275  Slider(char* slidername, int start, int end);
276  virtual ~Slider(void);
277  void init(int start, int end);
278
279  void setValue(int value);
280  void redraw(void);
281  void changeOption(void);
282};
283
284//! A Menu is an Option that has a dropdown menu, where you can chose between different Items
285class Menu : public Option
286{
287 private:
288#ifdef HAVE_GTK2
289  GtkWidget* menu;                      //!< The menu That will hold the Options.
290#endif /* HAVE_GTK2 */
291
292  //! A struct to handle the MenuItems
293  struct MenuItem
294  {
295    char* name;                         //!< The name of this entry.
296    int itemNumber;                     //!< The n'th entry of this menu;
297#ifdef HAVE_GTK2
298    GtkWidget* item;                    //!< One Item From a Menu.
299#endif /* HAVE_GTK2 */
300    MenuItem* next;                     //!< Pointer to the next MenuItem.
301  };
302  MenuItem* firstItem;                  //!< Pointer to the first Item.
303  MenuItem* currItem;                   //!< Pointer to the current Item.
304 
305 public:
306  Menu(const char* menuName);
307  Menu(char* menuname, ...);
308  virtual ~Menu(void);
309  void init(void);
310
311  virtual char* save(void);
312  virtual void load(char* loadString);
313 
314  void addItem(char* itemName);
315  void redraw(void);
316  void changeOption(void);
317};
318
319//! A OptionLabel is a simple Label, that holds a char*, and will be updated, if changed.
320class OptionLabel : public Option
321{
322 private:
323
324 public:
325  OptionLabel(char* label, char* value);
326  virtual ~OptionLabel(void);
327  void init(void);
328 
329  void setValue(char* newValue);
330
331  virtual char* save(void);
332  virtual void load(char* loadString);
333
334  void redraw(void);
335  void changeOption(void);
336
337  char* cValue;                          //!< The Value the Label will have. \todo make private
338
339};
340
341//! A label is a Widget, that displays a text
342class Label : public Widget
343{
344 public:
345  Label(void);
346  Label(char* text);
347  virtual ~Label(void);
348  void init(void);
349 
350  void setTitle(char* text);
351  void ereaseText(void);
352  void appendText(char* textToAppend);
353  void appendInt(int intToAppend);
354  char* getText(void);
355};
356
357//! A ProgressBar is a Widget, that can display a Progress
358class ProgressBar : public Widget
359{
360 public:
361  ProgressBar(void);
362  ProgressBar(char* label);
363  virtual ~ProgressBar(void);
364  void init(void);
365
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  virtual ~Image(void);
388  void init(void);
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.