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