Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/gui/gtk/gui_gtk.h @ 8727

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

trunk: merged the gui back
merged with command:
svn merge -r8114:HEAD https://svn.orxonox.net/orxonox/branches/gui .
→ no conflicts

File size: 14.1 KB
RevLine 
[3156]1/*!
[5024]2 * @file gui_gtk.h
3 * Contains all th different Widgets.
4 */
[4048]5#ifndef _GUI_GTK_H
6#define _GUI_GTK_H
[3147]7
[5015]8#if HAVE_CONFIG_H
9#include <config.h>
[3164]10#endif
11
[3493]12#include "debug.h"
[4091]13#include "globals.h"
[3423]14
[3165]15#ifdef HAVE_GTK2
[3144]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>
[3423]30#include <gtk/gtkprogressbar.h>
[4068]31#include <gtk/gtkfilesel.h>
[3165]32#endif /* HAVE_GTK2 */
[3144]33
[4046]34// enumerator for different GuiOption-Types
[5024]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};
[4046]46
[4052]47extern char* executable;
[4039]48
[3423]49bool initGUI(int argc, char* argv[]);
[4746]50bool mainloopGUI();
[3164]51
[3144]52//! This is the topmost object that can be displayed all others are derived from it.
53class Widget
54{
55 private:
[3187]56
[3144]57 public:
[4746]58  Widget();
59  virtual ~Widget();
[3144]60
[4746]61  void show();
62  void hide();
[3423]63  void setSize(int width, int height);
[4046]64
[3624]65  virtual void setTitle(const char* title);  //!< An abstract Function, that sets the title of Widgets.
[4746]66  virtual const char* getTitle() const { return this->title; };
[3423]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);
[4071]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);
[4132]77   static void printHelp(Widget* widget);
[4071]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);
[5015]82
[3165]83#ifdef HAVE_GTK2
[3423]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);
[4046]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);
[3165]102#endif /* HAVE_GTK2 */
[3423]103
[4046]104
[3423]105  Widget* next;                     //!< next always points to the next Widget in the list. Every Widget has a next one, or has NULL as next
[3165]106#ifdef HAVE_GTK2
[3423]107  GtkWidget* widget;                //!< widget is the gtk_widget that the specific Object Contains.
[4046]108#else /* HAVE_GTK2 */
109  void* widget;
[3165]110#endif /* HAVE_GTK2 */
[4046]111
[4071]112  GUI_OPTION optionType;            //!< The Type of the Widget.
[3423]113  char* title;                      //!< The name of the Widget. Some do display it, Options need it to save;
[3144]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:
[4746]120  Packer();
121  virtual ~Packer();
[3623]122
[4046]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.
[3144]125
[4046]126  void setGroupName(const char* name);
[4836]127  /** @returns the GroupName if existent NULL otherwise */
[4746]128  inline const char* getGroupName() const {return this->groupName;}
[3423]129
[4046]130
[3423]131  virtual void fill(Widget* lowerWidget) = 0; //!< An abstract function, that fills Packers.
[3144]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:
[3423]143  int borderwidth;          //!< The width of The Container Boarder.
144  int policy;               //!< The Update Policy of a Container.
[5015]145
[3144]146 public:
[4746]147  Container();
148  virtual ~Container();
[4071]149
[4046]150  void setBorderWidth(int borderwidth);
[3423]151  void fill(Widget* lowerWidget);
[3144]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:
[3423]162  bool isOpen;                      //!< A bool Variable that checks if a Window is already open.
[3144]163 public:
[3423]164  static Window* mainWindow;        //!< Pointer to the First Window that was opened. By default this should be the GUI's main-Window.
[3148]165  static void addWindow(Window* windowToAdd);
166
[4046]167  Window(const char* windowName = NULL);
[4746]168  virtual ~Window();
[5015]169
[4046]170  virtual void setTitle(const char* title);
[4746]171  void showall();
172  void open();
173  void close();
[3153]174
[3165]175#ifdef HAVE_GTK2
[3423]176  // Signals
177  static gint windowOpen(GtkWidget* widget, GdkEvent* event, void* window);
178  static gint windowClose(GtkWidget* widget, GdkEvent* event, void* window);
[4046]179#else /* HAVE_GTK2 */
180  int Window::windowOpen(void* widget, void* event, void* window);
181  int Window::windowClose(void* widget, void* event, void* window);
[3165]182#endif /* HAVE_GTK2 */
[3144]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:
[4068]193  Frame(const char* frameName = NULL);
[4746]194  virtual ~Frame();
[3624]195
[4046]196  virtual void setTitle(const char* title);
[3144]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:
[4046]206  EventBox(const char* eventBoxName = NULL);
[4746]207  virtual ~EventBox();
[3144]208};
209
210//! A Box can contain multiple Widgets
211/**
[3187]212   A Box can Contain multiple Widgets, that are ordered either horizontally or vertically
213   I defined the standartbox to be horizontally.
[3423]214   A Box is always filled left->right(horizontally) or up->down(vertically)
[3187]215*/
[3144]216class Box : public Packer
217{
218 public:
[4046]219  Box(char boxtype = 'h');
[4746]220  virtual ~Box();
[5015]221
[4046]222  virtual void fill(Widget* lowerWidget);
[3144]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{
[3423]231 protected:
[4046]232  bool saveable;              //!< Options can be Saved.
[5015]233
[3144]234 public:
[4746]235  Option();
236  virtual ~Option();
[3144]237
[4046]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)
[3144]242
[4046]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);
[4746]247  virtual char* save();
[5015]248  virtual void load(const char* loadString);
[3625]249
[4746]250  bool isSaveable();
[4058]251  void setDefaultValue(int defaultValue);
[4046]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
[4746]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.
[3423]258#ifdef HAVE_GTK2
[5015]259    // Signals
[3423]260  static gint OptionChange(GtkWidget* widget, Widget* option); //!< Signal for Options that change.
261#endif /* HAVE_GTK2 */
[3144]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 */
[5015]268class Button : public Option
[3144]269{
270 public:
[4089]271  Button(const char* buttonName = NULL);
[4746]272  virtual ~Button();
[3144]273
[4046]274  virtual void setTitle(const char* title);
[4746]275  virtual void redraw();
276  virtual void changeOption();
[3144]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:
[4046]285  CheckButton(const char* buttonName = NULL);
[4746]286  virtual ~CheckButton();
[3423]287
[4746]288  bool isActive();
[4046]289
290  virtual void setTitle(const char* title);
[4746]291  virtual void redraw();
292  virtual void changeOption();
[3144]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{
[3423]301 private:
[4338]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
[3144]305 public:
[4338]306  Slider(const char* slidername, float start, float end);
[4746]307  virtual ~Slider();
[3144]308
[4338]309  void setExactness(int exactness);
310  void setValue(float value);
[4746]311  virtual void redraw();
312  virtual void changeOption();
[4338]313
[4746]314  virtual char* save();
[5015]315  virtual void load(const char* loadString);
[3144]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:
[3165]322#ifdef HAVE_GTK2
[3423]323  GtkWidget* menu;                      //!< The menu That will hold the Options.
[3165]324#endif /* HAVE_GTK2 */
[3625]325
[3624]326  //! A struct to handle the MenuItems
327  struct MenuItem
328  {
[3625]329    char* name;                         //!< The name of this entry.
330    int itemNumber;                     //!< The n'th entry of this menu;
[3624]331#ifdef HAVE_GTK2
332    GtkWidget* item;                    //!< One Item From a Menu.
333#endif /* HAVE_GTK2 */
[4046]334
[3624]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.
[5015]339
[3144]340 public:
[3624]341  Menu(const char* menuName);
[3423]342  Menu(char* menuname, ...);
[4746]343  virtual ~Menu();
344  void init();
[3625]345
[4746]346  virtual char* save();
[5015]347  virtual void load(const char* loadString);
348
[3144]349  void addItem(char* itemName);
[4746]350  virtual void redraw();
351  virtual void changeOption();
[3144]352};
353
[3423]354//! A OptionLabel is a simple Label, that holds a char*, and will be updated, if changed.
[3156]355class OptionLabel : public Option
356{
357 public:
[4046]358  OptionLabel(const char* label, const char* value);
[4746]359  virtual ~OptionLabel();
[5015]360
[4046]361  void setValue(const char* newValue);
[3625]362
[4746]363  virtual char* save();
[5015]364  virtual void load(const char* loadString);
[3625]365
[4746]366  virtual void redraw();
367  virtual void changeOption();
[3423]368
[4836]369  char* cValue;                          //!< The Value the Label will have. @todo make private
[3156]370};
371
[4064]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);
[4746]377  virtual ~EntryField();
[5015]378
[4064]379  void setValue(const char* newValue);
[4746]380  virtual char* save();
[5015]381  virtual void load(const char* loadString);
382
[4746]383  virtual void redraw();
384  virtual void changeOption();
[4064]385};
386
[3144]387//! A label is a Widget, that displays a text
388class Label : public Widget
389{
390 public:
[4046]391  Label(const char* text = NULL);
[4746]392  virtual ~Label();
[5015]393
[4046]394  virtual void setTitle(const char* text);
[4746]395  void ereaseText();
[3423]396  void appendText(char* textToAppend);
397  void appendInt(int intToAppend);
[4746]398  const char* getText();
[3144]399};
400
[3423]401//! A ProgressBar is a Widget, that can display a Progress
402class ProgressBar : public Widget
403{
404 public:
[4046]405  ProgressBar(const char* label = NULL);
[4746]406  virtual ~ProgressBar();
[3156]407
[3423]408  void setProgress(double progress);
409  void setTotalSize(double totalSize);
[4746]410  double getProgress();
[3144]411
[3423]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
[5015]420//! Image is the keeper of one Image
421/**
[3423]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:
[4030]428  Image(const char* imgaeName);
429  Image(char** imageData);
[4746]430  virtual ~Image();
[4030]431  void init(const char* name);
[3423]432};
433
[4068]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;
[4083]441  bool (*okFunc)(const char* , void*);
442  void* okObject;
443
[4068]444 public:
445  FileDialog(const char* fileDialogName);
[4746]446  virtual ~FileDialog();
[3423]447
[4068]448  void setChangeOption(OptionLabel* changeOption);
[4083]449  void setOKFunc(void* okObject, bool(*function)(const char* , void*));
[4068]450  void setOpenUpButton(Button* openUpButton);
451  void setDefaultFileName(const char* defaultFileName);
452  void setMask(const char* mask);
[4746]453  void disableFileOpts();
[4068]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
[4048]470#endif /* _GUI_GTK_H */
Note: See TracBrowser for help on using the repository browser.