Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: gui: now the resolution is integrated from SDL. I hope this works on Windows too.
also fixed some virtual-function-stuff
also added better ability for menu→addItem, so now it should also work in non-GTK mode (after addaption).

File size: 11.3 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  bool isSaveable(void);
220  void setFlagName(char* flagname, int defaultvalue);
221  void setFlagName(char* flagname, char* flagnameshort, int defaultvalue);
222  virtual void redraw(void) = 0; //!< A Option must be able to redraw itself.
223  virtual void changeOption(void) = 0; //!< What to do, if an Option is Changed. eacht option decides for itself.
224#ifdef HAVE_GTK2
225    // Signals 
226  static gint OptionChange(GtkWidget* widget, Widget* option); //!< Signal for Options that change.
227#endif /* HAVE_GTK2 */
228};
229
230//! Buttons can be pressed, and released.
231/**
232 * Buttons are mainly there for executing some action like Starting the Programm, or Quiting it.
233 */
234class Button : public Option
235{
236 public:
237  Button(char* buttonname);
238  virtual ~Button(void);
239  void init(void);
240
241  void setTitle(const char* title);
242  void redraw(void);
243  void changeOption(void);
244};
245
246//! CheckButtons are a key in configuring bool Variables
247/** CheckButtons can configure bool Variables like wireframe on/off, enable_sound etc.
248 */
249class CheckButton : public Option
250{
251 public:
252  CheckButton(char* buttonname);
253  virtual ~CheckButton(void);
254  void init(void);
255
256  void setTitle(const char* title);
257  bool isActive(void);           //!< a Bool value to see, if this CheckButton is active.
258  void redraw(void);
259  void changeOption(void);
260};
261
262//! Sliders are Options that can be modified in their value
263/**
264 * good for volume, brightness, etc.
265 */
266class Slider : public Option
267{
268 private:
269  int start;                            //!< The beginning of the Slider-range.
270  int end;                              //!< The end of the Slider-range.
271 public:
272  Slider(char* slidername, int start, int end);
273  virtual ~Slider(void);
274  void init(int start, int end);
275
276  void setValue(int value);
277  void redraw(void);
278  void changeOption(void);
279};
280
281//! A Menu is an Option that has a dropdown menu, where you can chose between different Items
282class Menu : public Option
283{
284 private:
285#ifdef HAVE_GTK2
286  GtkWidget* menu;                      //!< The menu That will hold the Options.
287#endif /* HAVE_GTK2 */
288  va_list itemlist;                     //!< The list to readin multiple Options.
289 
290  //! A struct to handle the MenuItems
291  struct MenuItem
292  {
293    char* name;                         //!< The name of this entry.
294#ifdef HAVE_GTK2
295    GtkWidget* item;                    //!< One Item From a Menu.
296#endif /* HAVE_GTK2 */
297    MenuItem* next;                     //!< Pointer to the next MenuItem.
298  };
299  MenuItem* firstItem;                  //!< Pointer to the first Item.
300  MenuItem* currItem;                   //!< Pointer to the current Item.
301 
302 public:
303  Menu(const char* menuName);
304  Menu(char* menuname, ...);
305  virtual ~Menu(void);
306  void init(void);
307 
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  virtual ~OptionLabel(void);
321  void init(void);
322 
323  void setValue(char* newValue);
324  void redraw(void);
325  void changeOption(void);
326
327  char* cValue;                          //!< The Value the Label will have. \todo make private
328
329};
330
331//! A label is a Widget, that displays a text
332class Label : public Widget
333{
334 public:
335  Label(void);
336  Label(char* text);
337  virtual ~Label(void);
338  void init(void);
339 
340  void setTitle(char* text);
341  void ereaseText(void);
342  void appendText(char* textToAppend);
343  void appendInt(int intToAppend);
344  char* getText(void);
345};
346
347//! A ProgressBar is a Widget, that can display a Progress
348class ProgressBar : public Widget
349{
350 public:
351  ProgressBar(void);
352  ProgressBar(char* label);
353  virtual ~ProgressBar(void);
354  void init(void);
355
356  void setProgress(double progress);
357  void setTotalSize(double totalSize);
358  double getProgress(void);
359
360 private:
361  double totalSize;         //!< The total Size of a download Bar
362  double progress;          //!< The progress of a Bar.
363#ifdef HAVE_GTK2
364  GtkAdjustment* adjustment;
365#endif /* HAVE_GTK2 */
366};
367
368//! Image is the keeper of one Image
369/**
370 * Images are mighty cool.
371 * Images can help you lighten up the Programming process, and will give everyone a better impression of the Software.
372 */
373class Image : public Widget
374{
375 public:
376  Image(char* imgaename);
377  virtual ~Image(void);
378  void init(void);
379};
380
381//gint orxonox_gui_quit(GtkWidget* widget, GdkEvent* event, gpointer data);
382
383#endif /* _ORXONOX_GUI_GTK_H */
Note: See TracBrowser for help on using the repository browser.