Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/gui/gtk_gui/gui_gtk.h @ 6335

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

orxonox/trunk: icon and name get displayed correctly again

File size: 14.1 KB
Line 
1/*!
2 * @file gui_gtk.h
3 * Contains all th different Widgets.
4 */
5#ifndef _GUI_GTK_H
6#define _GUI_GTK_H
7
8#if HAVE_CONFIG_H
9#include <config.h>
10#endif
11
12#include "debug.h"
13#include "globals.h"
14
15#ifdef HAVE_GTK2
16#include <gtk/gtkmain.h>
17#include <gtk/gtkwindow.h>
18#include <gtk/gtkframe.h>
19#include <gtk/gtkhbox.h>
20#include <gtk/gtkvbox.h>
21#include <gtk/gtkbutton.h>
22#include <gtk/gtkcheckbutton.h>
23#include <gtk/gtkhscale.h>
24#include <gtk/gtkoptionmenu.h>
25#include <gtk/gtkmenu.h>
26#include <gtk/gtkmenuitem.h>
27#include <gtk/gtklabel.h>
28#include <gtk/gtkimage.h>
29#include <gtk/gtkeventbox.h>
30#include <gtk/gtkprogressbar.h>
31#include <gtk/gtkfilesel.h>
32#endif /* HAVE_GTK2 */
33
34// enumerator for different GuiOption-Types
35enum GUI_OPTION
36{
37  GUI_BOX = -2,
38  GUI_CONTAINER = -1,
39  GUI_NOTHING = 0,
40  GUI_BOOL = 1,
41  GUI_INT = 2,
42  GUI_FLOAT = 3,
43  GUI_CHAR = 4,
44  GUI_CHAR_ARRAY = 5
45};
46
47extern char* executable;
48
49bool initGUI(int argc, char* argv[]);
50bool mainloopGUI();
51
52//! This is the topmost object that can be displayed all others are derived from it.
53class Widget
54{
55 private:
56
57 public:
58  Widget();
59  virtual ~Widget();
60
61  void show();
62  void hide();
63  void setSize(int width, int height);
64
65  virtual void setTitle(const char* title);  //!< An abstract Function, that sets the title of Widgets.
66  virtual const char* getTitle() const { return this->title; };
67
68  Widget* findWidgetByName(char* name, unsigned int depth);
69  void walkThrough(void(*function)(Widget*), unsigned int depth);
70  void walkThrough(void(*function)(Widget*, void*), void* data, unsigned int depth);
71   static void listOptionsAndGroups(Widget* widget);
72   static void listOptions(Widget* widget);
73   static void listOptions(Widget* widget, void* data);
74   Widget* findOptionByNumber(int* number, unsigned int depth);
75   static void listGroups(Widget* widget);
76   static void listGroups(Widget* widget, void* data);
77   static void printHelp(Widget* widget);
78   Widget* findGroupByNumber(int* number, unsigned int depth);
79   static void setOptions(Widget* widget);
80   static void redrawOptions(Widget* widget);
81   static void flagCheck(Widget* widget, void* flagName);
82
83#ifdef HAVE_GTK2
84  // Connection - Functions
85  gulong connectSignal(char* event, gint(*signal)(GtkWidget*, GdkEvent*, void* ));
86  gulong connectSignal(char* event, gint(*signal)(GtkWidget*, Widget* ));
87  gulong connectSignal(char* event, void* extObj, gint(*signal)(GtkWidget*, GdkEvent*, void* ));
88  gulong connectSignal(char* event, void* extObj, gint(*signal)(GtkWidget*, void* ));
89  gulong connectSignal(char* event, void* extObj, gint(*signal)(GtkWidget*, GdkEventKey*, void* ));
90  void disconnectSignal(gulong signalID);
91  // Signals
92  static gint doNothingSignal(GtkWidget* widget, GdkEvent* event, void* nothing);
93#else /* HAVE_GTK2 */
94  // Connection - Functions
95  unsigned long connectSignal(char* event, int(*signal)(void*, void*, void* )){};
96  unsigned long connectSignal(char* event, int(*signal)(void*, Widget* )){};
97  unsigned long connectSignal(char* event, void* extObj, int(*signal)(void*, void*, void* )){};
98  unsigned long connectSignal(char* event, void* extObj, int(*signal)(void*, void* )){};
99  void disconnectSignal(unsigned long signalID);
100  // Signals
101  static int doNothingSignal(void* widget, void* event, void* nothing);
102#endif /* HAVE_GTK2 */
103
104
105  Widget* next;                     //!< next always points to the next Widget in the list. Every Widget has a next one, or has NULL as next
106#ifdef HAVE_GTK2
107  GtkWidget* widget;                //!< widget is the gtk_widget that the specific Object Contains.
108#else /* HAVE_GTK2 */
109  void* widget;
110#endif /* HAVE_GTK2 */
111
112  GUI_OPTION optionType;            //!< The Type of the Widget.
113  char* title;                      //!< The name of the Widget. Some do display it, Options need it to save;
114};
115
116//! This is a Packer Object, which has the ability to Pack other Widgets into itself.
117class Packer : public Widget
118{
119 public:
120  Packer();
121  virtual ~Packer();
122
123  Widget* down;                      //!< this points to the Widget below this.
124  char* groupName;                   //!< For each Packer you can specify a Groupname under which the lowerWidgets will be saved.
125
126  void setGroupName(const char* name);
127  /** @returns the GroupName if existent NULL otherwise */
128  inline const char* getGroupName() const {return this->groupName;}
129
130
131  virtual void fill(Widget* lowerWidget) = 0; //!< An abstract function, that fills Packers.
132};
133
134//! This is a Container Class, it can contain one sub-Widget: down.
135/**
136 * A Container is a Widget that can hold a subWidget in addition to a next-Widget.
137 * The Container can by itself not be displayed created or used.
138 * The derived classes of Container can be displayed
139*/
140class Container : public Packer
141{
142 private:
143  int borderwidth;          //!< The width of The Container Boarder.
144  int policy;               //!< The Update Policy of a Container.
145
146 public:
147  Container();
148  virtual ~Container();
149
150  void setBorderWidth(int borderwidth);
151  void fill(Widget* lowerWidget);
152};
153
154//! Window is the class that creates new Windows, and handels them
155/**
156 * A Window is a class derived from Container that contains a window-widget.
157 * It has the ability to hold one sub-object
158 */
159class Window : public Container
160{
161 private:
162  bool isOpen;                      //!< A bool Variable that checks if a Window is already open.
163 public:
164  static Window* mainWindow;        //!< Pointer to the First Window that was opened. By default this should be the GUI's main-Window.
165  static void addWindow(Window* windowToAdd);
166
167  Window(const char* windowName = NULL);
168  virtual ~Window();
169
170  virtual void setTitle(const char* title);
171  void showall();
172  void open();
173  void close();
174
175#ifdef HAVE_GTK2
176  // Signals
177  static gint windowOpen(GtkWidget* widget, GdkEvent* event, void* window);
178  static gint windowClose(GtkWidget* widget, GdkEvent* event, void* window);
179#else /* HAVE_GTK2 */
180  int Window::windowOpen(void* widget, void* event, void* window);
181  int Window::windowClose(void* widget, void* event, void* window);
182#endif /* HAVE_GTK2 */
183};
184
185//! Frame is the class that handles frames
186/**
187 * A Frame is an object, that has a border and if you like a name on it.
188 * It can contain a Widget, which means that you can insert anything you like inside of a frame
189 */
190class Frame :public Container
191{
192 public:
193  Frame(const char* frameName = NULL);
194  virtual ~Frame();
195
196  virtual void setTitle(const char* title);
197};
198
199//! EventBox is a Container that can Handle all Events happening inside of it.
200/**
201 * Example: if you have a picture, and you want it to catch mouse-clicks, you have to pack it inside a EventBox
202 */
203class EventBox : public Container
204{
205 public:
206  EventBox(const char* eventBoxName = NULL);
207  virtual ~EventBox();
208};
209
210//! A Box can contain multiple Widgets
211/**
212   A Box can Contain multiple Widgets, that are ordered either horizontally or vertically
213   I defined the standartbox to be horizontally.
214   A Box is always filled left->right(horizontally) or up->down(vertically)
215*/
216class Box : public Packer
217{
218 public:
219  Box(char boxtype = 'h');
220  virtual ~Box();
221
222  virtual void fill(Widget* lowerWidget);
223};
224
225//! An Option is a Widget that contains something that may change its state.
226/**
227 * Options are the essence of a GUI, they: Configure, Start, Quit, Execute, and make it worth something
228 */
229class Option : public Widget
230{
231 protected:
232  bool saveable;              //!< Options can be Saved.
233
234 public:
235  Option();
236  virtual ~Option();
237
238  int value;                  //!< every option has a value either true or false(0,1) or something else like 25 for 25% of the volume
239  char* flagName;             //!< options have a flag name that will be appendet if you start the Program from the GUI.
240  char* flagNameShort;        //!< like flag_name but shorter
241  int defaultValue;           //!< A default value is good, for hiding a option if it is not needed.(hidden if value == default_value)
242
243  char* shortDescription;      //!< A Text that describes this option in short
244  char* longDescription;      //!< A Longer Text describing this option in a full way
245
246  void saveability(bool isSaveable = true);
247  virtual char* save();
248  virtual void load(const char* loadString);
249
250  bool isSaveable();
251  void setDefaultValue(int defaultValue);
252  void setFlagName(const char* flagname, int defaultvalue);
253  void setFlagName(const char* flagname, const char* flagnameshort, int defaultvalue);
254  void setDescription(const char* shortDescription, const char* longDescription = NULL);
255
256  virtual void redraw() = 0;       //!< A Option must be able to redraw itself.
257  virtual void changeOption() = 0; //!< What to do, if an Option is Changed. eacht option decides for itself.
258#ifdef HAVE_GTK2
259    // Signals
260  static gint OptionChange(GtkWidget* widget, Widget* option); //!< Signal for Options that change.
261#endif /* HAVE_GTK2 */
262};
263
264//! Buttons can be pressed, and released.
265/**
266 * Buttons are mainly there for executing some action like Starting the Programm, or Quiting it.
267 */
268class Button : public Option
269{
270 public:
271  Button(const char* buttonName = NULL);
272  virtual ~Button();
273
274  virtual void setTitle(const char* title);
275  virtual void redraw();
276  virtual void changeOption();
277};
278
279//! CheckButtons are a key in configuring bool Variables
280/** CheckButtons can configure bool Variables like wireframe on/off, enable_sound etc.
281 */
282class CheckButton : public Option
283{
284 public:
285  CheckButton(const char* buttonName = NULL);
286  virtual ~CheckButton();
287
288  bool isActive();
289
290  virtual void setTitle(const char* title);
291  virtual void redraw();
292  virtual void changeOption();
293};
294
295//! Sliders are Options that can be modified in their value
296/**
297 * good for volume, brightness, etc.
298 */
299class Slider : public Option
300{
301 private:
302  float start;                            //!< The beginning of the Slider-range.
303  float end;                              //!< The end of the Slider-range.
304  float fValue;                           //!< a value for the slider
305 public:
306  Slider(const char* slidername, float start, float end);
307  virtual ~Slider();
308
309  void setExactness(int exactness);
310  void setValue(float value);
311  virtual void redraw();
312  virtual void changeOption();
313
314  virtual char* save();
315  virtual void load(const char* loadString);
316};
317
318//! A Menu is an Option that has a dropdown menu, where you can chose between different Items
319class Menu : public Option
320{
321 private:
322#ifdef HAVE_GTK2
323  GtkWidget* menu;                      //!< The menu That will hold the Options.
324#endif /* HAVE_GTK2 */
325
326  //! A struct to handle the MenuItems
327  struct MenuItem
328  {
329    char* name;                         //!< The name of this entry.
330    int itemNumber;                     //!< The n'th entry of this menu;
331#ifdef HAVE_GTK2
332    GtkWidget* item;                    //!< One Item From a Menu.
333#endif /* HAVE_GTK2 */
334
335    MenuItem* next;                     //!< Pointer to the next MenuItem.
336  };
337  MenuItem* firstItem;                  //!< Pointer to the first Item.
338  MenuItem* currItem;                   //!< Pointer to the current Item.
339
340 public:
341  Menu(const char* menuName);
342  Menu(char* menuname, ...);
343  virtual ~Menu();
344  void init();
345
346  virtual char* save();
347  virtual void load(const char* loadString);
348
349  void addItem(char* itemName);
350  virtual void redraw();
351  virtual void changeOption();
352};
353
354//! A OptionLabel is a simple Label, that holds a char*, and will be updated, if changed.
355class OptionLabel : public Option
356{
357 public:
358  OptionLabel(const char* label, const char* value);
359  virtual ~OptionLabel();
360
361  void setValue(const char* newValue);
362
363  virtual char* save();
364  virtual void load(const char* loadString);
365
366  virtual void redraw();
367  virtual void changeOption();
368
369  char* cValue;                          //!< The Value the Label will have. @todo make private
370};
371
372//! A EntryField is a TextEntry field, for putting some text into.
373class EntryField : public Option
374{
375 public:
376  EntryField(const char* name = NULL);
377  virtual ~EntryField();
378
379  void setValue(const char* newValue);
380  virtual char* save();
381  virtual void load(const char* loadString);
382
383  virtual void redraw();
384  virtual void changeOption();
385};
386
387//! A label is a Widget, that displays a text
388class Label : public Widget
389{
390 public:
391  Label(const char* text = NULL);
392  virtual ~Label();
393
394  virtual void setTitle(const char* text);
395  void ereaseText();
396  void appendText(char* textToAppend);
397  void appendInt(int intToAppend);
398  const char* getText();
399};
400
401//! A ProgressBar is a Widget, that can display a Progress
402class ProgressBar : public Widget
403{
404 public:
405  ProgressBar(const char* label = NULL);
406  virtual ~ProgressBar();
407
408  void setProgress(double progress);
409  void setTotalSize(double totalSize);
410  double getProgress();
411
412 private:
413  double totalSize;         //!< The total Size of a download Bar
414  double progress;          //!< The progress of a Bar.
415#ifdef HAVE_GTK2
416  GtkAdjustment* adjustment;
417#endif /* HAVE_GTK2 */
418};
419
420//! Image is the keeper of one Image
421/**
422 * Images are mighty cool.
423 * Images can help you lighten up the Programming process, and will give everyone a better impression of the Software.
424 */
425class Image : public Widget
426{
427 public:
428  Image(const char* imgaeName);
429  Image(char** imageData);
430  virtual ~Image();
431  void init(const char* name);
432};
433
434//! A FileDialog is a window with wich one can select a File
435class FileDialog : public Widget
436{
437 private:
438  OptionLabel* changeOption;
439  Button* openUpButton;
440  bool isOpen;
441  bool (*okFunc)(const char* , void*);
442  void* okObject;
443
444 public:
445  FileDialog(const char* fileDialogName);
446  virtual ~FileDialog();
447
448  void setChangeOption(OptionLabel* changeOption);
449  void setOKFunc(void* okObject, bool(*function)(const char* , void*));
450  void setOpenUpButton(Button* openUpButton);
451  void setDefaultFileName(const char* defaultFileName);
452  void setMask(const char* mask);
453  void disableFileOpts();
454
455  void okEvent();
456  void open();
457  void close();
458
459#ifdef HAVE_GTK2
460  static gint dialogOK(GtkWidget* widget, GdkEvent* event, void* dialog);
461  static gint dialogOpen(GtkWidget* widget, GdkEvent* event, void* dialog);
462  static gint dialogClose(GtkWidget* widget, GdkEvent* event, void* dialog);
463#else /* HAVE_GTK2 */
464  static int dialogOK(void* widget, void* event, void* dialog);
465  static int dialogOpen(void* widget, void* event, void* dialog);
466  static int dialogClose(void* widget, void* event, void* dialog);
467#endif /* HAVE_GTK2 */
468};
469
470#endif /* _GUI_GTK_H */
Note: See TracBrowser for help on using the repository browser.