[3156] | 1 | /*! |
---|
| 2 | \file orxonox_gui_gtk.h |
---|
| 3 | \brief Contains all th different Widgets. |
---|
| 4 | */ |
---|
[3144] | 5 | |
---|
| 6 | #ifndef _ORXONOX_GUI_GTK_H |
---|
| 7 | #define _ORXONOX_GUI_GTK_H |
---|
[3147] | 8 | |
---|
[3164] | 9 | #if HAVE_CONFIG_H |
---|
| 10 | #include <config.h> |
---|
| 11 | #endif |
---|
| 12 | |
---|
[3263] | 13 | extern int verbose; // soon obsolete here |
---|
| 14 | |
---|
[3254] | 15 | #include "../debug.h" |
---|
| 16 | |
---|
[3165] | 17 | #ifdef HAVE_GTK2 |
---|
[3144] | 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> |
---|
[3244] | 32 | #include <gtk/gtkprogressbar.h> |
---|
[3165] | 33 | #endif /* HAVE_GTK2 */ |
---|
[3144] | 34 | |
---|
[3165] | 35 | #ifdef HAVE_GTK2 |
---|
[3164] | 36 | bool initGTK(int argc, char *argv[]); |
---|
| 37 | bool mainloopGTK(void); |
---|
[3165] | 38 | #endif /* HAVE_GTK2 */ |
---|
[3164] | 39 | |
---|
[3144] | 40 | //! This is the topmost object that can be displayed all others are derived from it. |
---|
| 41 | class Widget |
---|
| 42 | { |
---|
| 43 | private: |
---|
[3187] | 44 | |
---|
[3144] | 45 | public: |
---|
| 46 | ~Widget (); |
---|
| 47 | |
---|
| 48 | Widget* next; //!< next always points to the next Widget in the list. Every Widget has a next one, or has NULL as next |
---|
[3165] | 49 | #ifdef HAVE_GTK2 |
---|
[3144] | 50 | GtkWidget* widget; //!< widget is the gtk_widget that the specific Object Contains. |
---|
[3165] | 51 | #endif /* HAVE_GTK2 */ |
---|
[3144] | 52 | void init(void); |
---|
[3161] | 53 | 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 |
---|
[3144] | 54 | /** |
---|
[3147] | 55 | \briefdefines isOption states |
---|
[3144] | 56 | */ |
---|
| 57 | enum option { containerType = -2, boxType = -1, nothingType = 0, boolType = 1, intType = 2}; |
---|
| 58 | char* label; //!< The name of the Widget. Some do display it, Options need it to save; |
---|
[3165] | 59 | #ifdef HAVE_GTK2 |
---|
[3156] | 60 | gulong connectSignal (char* event, gint (*signal)(GtkWidget*, GdkEvent*, void *)); |
---|
| 61 | gulong connectSignal (char* event, gint (*signal)(GtkWidget*, Widget *)); |
---|
| 62 | gulong connectSignal (char* event, void* extObj, gint (*signal)(GtkWidget*, GdkEvent*, void *)); |
---|
| 63 | gulong connectSignal (char* event, void* extObj, gint (*signal)(GtkWidget*, GdkEventKey*, void *)); |
---|
| 64 | void disconnectSignal (gulong signalID); |
---|
[3165] | 65 | #endif /* HAVE_GTK2 */ |
---|
[3144] | 66 | void show (); |
---|
| 67 | void hide (); |
---|
| 68 | void setSize(int width, int height); |
---|
| 69 | |
---|
| 70 | void walkThrough (void (*function)(Widget*)); |
---|
| 71 | static void listOptions (Widget* widget); |
---|
| 72 | static void setOptions (Widget* widget); |
---|
[3157] | 73 | |
---|
[3165] | 74 | #ifdef HAVE_GTK2 |
---|
[3157] | 75 | static gint doNothingSignal (GtkWidget *widget, GdkEvent* event, void* nothing); |
---|
[3165] | 76 | #endif /* HAVE_GTK2 */ |
---|
[3144] | 77 | }; |
---|
| 78 | |
---|
| 79 | //! This is a Packer Object, which has the ability to Pack other Widgets into itself. |
---|
| 80 | class Packer : public Widget |
---|
| 81 | { |
---|
| 82 | public: |
---|
| 83 | Widget* down; //!< this points to the Widget below this. |
---|
| 84 | char* groupName; //!< For each Packer you can specify a Groupname under which the lowerWidgets will be saved. |
---|
| 85 | |
---|
| 86 | void init(void); |
---|
| 87 | void setGroupName (char* name); |
---|
| 88 | char* getGroupName (void); |
---|
| 89 | }; |
---|
| 90 | |
---|
| 91 | //! This is a Container Class, it can contain one sub-Widget: down. |
---|
| 92 | /** |
---|
| 93 | * A Container is a Widget that can hold a subWidget in addition to a next-Widget. |
---|
| 94 | * The Container can by itself not be displayed created or used. |
---|
| 95 | * The derived classes of Container can be displayed |
---|
| 96 | */ |
---|
| 97 | class Container : public Packer |
---|
| 98 | { |
---|
| 99 | private: |
---|
| 100 | int borderwidth; |
---|
| 101 | int policy; |
---|
| 102 | |
---|
| 103 | public: |
---|
| 104 | void init(void); |
---|
| 105 | // void setBorderWidth (int borderwidth); |
---|
| 106 | // virtual void setTitle (char* title) = 0; |
---|
| 107 | void fill (Widget *lowerWidget); |
---|
| 108 | }; |
---|
| 109 | |
---|
| 110 | //! Window is the class that creates new Windows, and handels them |
---|
| 111 | /** |
---|
| 112 | * A Window is a class derived from Container that contains a window-widget. |
---|
| 113 | * It has the ability to hold one sub-object |
---|
| 114 | */ |
---|
| 115 | class Window : public Container |
---|
| 116 | { |
---|
| 117 | private: |
---|
[3187] | 118 | bool isOpen; //!< A bool Variable that checks if a Window is already open. |
---|
[3144] | 119 | public: |
---|
[3187] | 120 | static Window* mainWindow; //!< Pointer to the First Window that was opened. By default this should be the GUI's main-Window. |
---|
[3148] | 121 | static void addWindow(Window* windowToAdd); |
---|
| 122 | |
---|
[3144] | 123 | Window (void); |
---|
| 124 | Window (char* windowName); |
---|
| 125 | void init (); |
---|
| 126 | |
---|
| 127 | void setTitle (char* title); |
---|
[3153] | 128 | void showall (); |
---|
[3147] | 129 | void open(); |
---|
| 130 | void close(); |
---|
[3153] | 131 | |
---|
[3165] | 132 | #ifdef HAVE_GTK2 |
---|
[3153] | 133 | static gint windowOpen (GtkWidget *widget, GdkEvent* event, void* window); |
---|
| 134 | static gint windowClose (GtkWidget *widget, GdkEvent* event, void* window); |
---|
[3144] | 135 | static gint orxonox_gui_quit (GtkWidget *widget, GdkEvent *event, gpointer data); |
---|
[3165] | 136 | #endif /* HAVE_GTK2 */ |
---|
[3144] | 137 | }; |
---|
| 138 | |
---|
| 139 | //! Frame is the class that handles frames |
---|
| 140 | /** |
---|
| 141 | * A Frame is an object, that has a border and if you like a name on it. |
---|
| 142 | * It can contain a Widget, which means that you can insert anything you like inside of a frame |
---|
| 143 | */ |
---|
| 144 | class Frame :public Container |
---|
| 145 | { |
---|
| 146 | public: |
---|
| 147 | Frame (char* frameName); |
---|
| 148 | Frame (void); |
---|
| 149 | void init(void); |
---|
| 150 | |
---|
| 151 | void setTitle (char* title); |
---|
| 152 | }; |
---|
| 153 | |
---|
| 154 | //! EventBox is a Container that can Handle all Events happening inside of it. |
---|
| 155 | /** |
---|
| 156 | * Example: if you have a picture, and you want it to catch mouse-clicks, you have to pack it inside a EventBox |
---|
| 157 | */ |
---|
| 158 | class EventBox : public Container |
---|
| 159 | { |
---|
| 160 | public: |
---|
| 161 | EventBox (char* eventBoxName); |
---|
| 162 | EventBox (void); |
---|
| 163 | void init(void); |
---|
| 164 | |
---|
| 165 | void setTitle (char* title); |
---|
| 166 | }; |
---|
| 167 | |
---|
| 168 | //! A Box can contain multiple Widgets |
---|
| 169 | /** |
---|
[3187] | 170 | A Box can Contain multiple Widgets, that are ordered either horizontally or vertically |
---|
| 171 | I defined the standartbox to be horizontally. |
---|
| 172 | A Box is always filled left->right (horizontally) or up->down (vertically) |
---|
| 173 | */ |
---|
[3144] | 174 | class Box : public Packer |
---|
| 175 | { |
---|
| 176 | public: |
---|
| 177 | Box (void); |
---|
| 178 | Box (char boxtype); |
---|
| 179 | void init(char boxtype); |
---|
| 180 | |
---|
| 181 | void fill (Widget* lowerWidget); |
---|
| 182 | |
---|
| 183 | }; |
---|
| 184 | |
---|
| 185 | //! Image is the keeper of one Image |
---|
| 186 | /** |
---|
| 187 | * Images are mighty cool. |
---|
| 188 | * Images can help you lighten up the Programming process, and will give everyone a better impression of the Software. |
---|
| 189 | */ |
---|
| 190 | class Image : public Widget |
---|
| 191 | { |
---|
| 192 | public: |
---|
| 193 | Image (char* imgaename); |
---|
| 194 | void init(void); |
---|
| 195 | }; |
---|
| 196 | |
---|
| 197 | //! An Option is a Widget that contains something that may change its state. |
---|
| 198 | /** |
---|
| 199 | * Options are the essence of a GUI, they: Configure, Start, Quit, Execute, and make it worth something |
---|
| 200 | */ |
---|
| 201 | class Option : public Widget |
---|
| 202 | { |
---|
| 203 | public: |
---|
| 204 | //virtual gint OptionChange (GtkWidget *widget, GdkEvent *event, gpointer data); |
---|
| 205 | void init(void); |
---|
| 206 | |
---|
| 207 | int value; //!< every option has a value either true or false (0,1) or something else like 25 for 25% of the volume |
---|
[3158] | 208 | char* flagName; //!< options have a flag name that will be appendet if you start the Program from the GUI. |
---|
| 209 | char* flagNameShort; //!< like flag_name but shorter |
---|
| 210 | int defaultValue; //!< A default value is good, for hiding a option if it is not needed. (hidden if value == default_value) |
---|
[3187] | 211 | bool saveable; //!< Options can be Saved. |
---|
[3144] | 212 | |
---|
| 213 | void setFlagName (char* flagname, int defaultvalue); |
---|
| 214 | void setFlagName (char* flagname, char* flagnameshort, int defaultvalue); |
---|
| 215 | virtual void redraw () = 0; //!< A Option must be able to redraw itself. |
---|
| 216 | }; |
---|
| 217 | |
---|
| 218 | //! Buttons can be pressed, and released. |
---|
| 219 | /** |
---|
| 220 | * Buttons are mainly there for executing some action like Starting the Programm, or Quiting it. |
---|
| 221 | */ |
---|
| 222 | class Button : public Option |
---|
| 223 | { |
---|
| 224 | public: |
---|
| 225 | Button (char* buttonname); |
---|
| 226 | void init(void); |
---|
| 227 | |
---|
| 228 | void setTitle(char* title); |
---|
| 229 | |
---|
| 230 | void redraw(); |
---|
| 231 | }; |
---|
| 232 | |
---|
| 233 | //! CheckButtons are a key in configuring bool Variables |
---|
| 234 | /** CheckButtons can configure bool Variables like wireframe on/off, enable_sound etc. |
---|
| 235 | */ |
---|
| 236 | class CheckButton : public Option |
---|
| 237 | { |
---|
| 238 | public: |
---|
| 239 | CheckButton (char* buttonname); |
---|
[3165] | 240 | #ifdef HAVE_GTK2 |
---|
[3144] | 241 | static gint OptionChange (GtkWidget* widget, Widget* checkbutton); |
---|
[3165] | 242 | #endif /* HAVE_GTK2 */ |
---|
[3144] | 243 | |
---|
| 244 | void init(void); |
---|
| 245 | void setTitle(char* title); |
---|
| 246 | |
---|
[3146] | 247 | bool isActive(); |
---|
[3144] | 248 | void redraw (); |
---|
| 249 | }; |
---|
| 250 | |
---|
| 251 | //! Sliders are Options that can be modified in their value |
---|
| 252 | /** |
---|
| 253 | * good for volume, brightness, etc. |
---|
| 254 | */ |
---|
| 255 | class Slider : public Option |
---|
| 256 | { |
---|
| 257 | public: |
---|
| 258 | Slider (char* slidername,int start, int end); |
---|
| 259 | void init(int start, int end); |
---|
| 260 | |
---|
| 261 | void setTitle(char* title); |
---|
| 262 | void setValue(int value); |
---|
| 263 | |
---|
[3165] | 264 | #ifdef HAVE_GTK2 |
---|
[3144] | 265 | static gint OptionChange (GtkWidget* widget, Widget* slider); |
---|
[3165] | 266 | #endif /* HAVE_GTK2 */ |
---|
[3144] | 267 | void redraw(); |
---|
| 268 | }; |
---|
| 269 | |
---|
| 270 | //! A Menu is an Option that has a dropdown menu, where you can chose between different Items |
---|
| 271 | class Menu : public Option |
---|
| 272 | { |
---|
| 273 | private: |
---|
[3165] | 274 | #ifdef HAVE_GTK2 |
---|
[3187] | 275 | GtkWidget* menu; //!< The menu That will hold the Options. |
---|
| 276 | GtkWidget* item; //!< One Item From a Menu. |
---|
[3165] | 277 | #endif /* HAVE_GTK2 */ |
---|
[3187] | 278 | va_list itemlist; //!> The list to readin multiple Options. |
---|
[3144] | 279 | |
---|
| 280 | public: |
---|
| 281 | Menu (char* menuname, ...); |
---|
| 282 | void init(void); |
---|
| 283 | |
---|
| 284 | void setTitle(char* title); |
---|
| 285 | |
---|
| 286 | void addItem(char* itemName); |
---|
[3165] | 287 | #ifdef HAVE_GTK2 |
---|
[3144] | 288 | static gint OptionChange (GtkWidget* widget, Widget* menu); |
---|
[3165] | 289 | #endif /* HAVE_GTK2 */ |
---|
[3144] | 290 | void redraw(); |
---|
| 291 | }; |
---|
| 292 | |
---|
[3156] | 293 | //! A CharLabel is a simple Label, that holds a char*, and will be updated, if changed. |
---|
| 294 | class OptionLabel : public Option |
---|
| 295 | { |
---|
| 296 | public: |
---|
[3161] | 297 | OptionLabel(char* label, char* value); |
---|
[3156] | 298 | void init(void); |
---|
[3161] | 299 | |
---|
[3187] | 300 | char* cValue; //!< The Value the Label will have. |
---|
[3161] | 301 | |
---|
| 302 | void setValue(char* newValue); |
---|
[3156] | 303 | void setTitle(char* title); |
---|
| 304 | void redraw(); |
---|
| 305 | }; |
---|
| 306 | |
---|
[3144] | 307 | //! A label is a Widget, that displays a text |
---|
| 308 | class Label : public Widget |
---|
| 309 | { |
---|
| 310 | public: |
---|
| 311 | Label (); |
---|
| 312 | Label (char* text); |
---|
| 313 | void init(void); |
---|
| 314 | |
---|
| 315 | void setText (char* text); |
---|
| 316 | char* getText (); |
---|
| 317 | }; |
---|
| 318 | |
---|
[3244] | 319 | //! A ProgressBar is a Widget, that can display a Progress |
---|
| 320 | class ProgressBar : public Widget |
---|
| 321 | { |
---|
| 322 | public: |
---|
| 323 | ProgressBar (void); |
---|
| 324 | ProgressBar (char* label); |
---|
| 325 | ~ProgressBar (); |
---|
| 326 | void init (void); |
---|
| 327 | |
---|
| 328 | void setProgress (double progress); |
---|
| 329 | void setTotalSize (double totalSize); |
---|
| 330 | double getProgress (void); |
---|
[3156] | 331 | |
---|
[3244] | 332 | private: |
---|
| 333 | double totalSize; |
---|
| 334 | double progress; |
---|
| 335 | #ifdef HAVE_GTK2 |
---|
| 336 | GtkAdjustment* adjustment; |
---|
| 337 | #endif /* HAVE_GTK2 */ |
---|
| 338 | }; |
---|
| 339 | |
---|
[3144] | 340 | //gint orxonox_gui_quit (GtkWidget *widget, GdkEvent *event, gpointer data); |
---|
| 341 | |
---|
| 342 | #endif /* _ORXONOX_GUI_GTK_H */ |
---|