[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 | |
---|
[3493] | 12 | #include "debug.h" |
---|
[3423] | 13 | |
---|
[3165] | 14 | #ifdef HAVE_GTK2 |
---|
[3144] | 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> |
---|
[3423] | 29 | #include <gtk/gtkprogressbar.h> |
---|
[3165] | 30 | #endif /* HAVE_GTK2 */ |
---|
[3144] | 31 | |
---|
[3423] | 32 | bool initGUI(int argc, char* argv[]); |
---|
| 33 | bool mainloopGUI(void); |
---|
[3164] | 34 | |
---|
[3144] | 35 | //! This is the topmost object that can be displayed all others are derived from it. |
---|
| 36 | class Widget |
---|
| 37 | { |
---|
| 38 | private: |
---|
[3187] | 39 | |
---|
[3144] | 40 | public: |
---|
[3623] | 41 | Widget(void); |
---|
[3423] | 42 | virtual ~Widget(void); |
---|
[3144] | 43 | |
---|
[3423] | 44 | void show(void); |
---|
| 45 | void hide(void); |
---|
| 46 | void setSize(int width, int height); |
---|
[3624] | 47 | virtual void setTitle(const char* title); //!< An abstract Function, that sets the title of Widgets. |
---|
[3423] | 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 | |
---|
[3165] | 62 | #ifdef HAVE_GTK2 |
---|
[3423] | 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); |
---|
[3165] | 74 | #endif /* HAVE_GTK2 */ |
---|
[3423] | 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 |
---|
[3165] | 77 | #ifdef HAVE_GTK2 |
---|
[3423] | 78 | GtkWidget* widget; //!< widget is the gtk_widget that the specific Object Contains. |
---|
[3165] | 79 | #endif /* HAVE_GTK2 */ |
---|
[3423] | 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 |
---|
[3144] | 81 | |
---|
[3423] | 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; |
---|
[3144] | 85 | }; |
---|
| 86 | |
---|
| 87 | //! This is a Packer Object, which has the ability to Pack other Widgets into itself. |
---|
| 88 | class Packer : public Widget |
---|
| 89 | { |
---|
| 90 | public: |
---|
[3623] | 91 | Packer(void); |
---|
| 92 | virtual ~Packer(void); |
---|
| 93 | |
---|
[3144] | 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 | |
---|
[3423] | 97 | void setGroupName(char* name); |
---|
| 98 | char* getGroupName(void); |
---|
| 99 | |
---|
| 100 | virtual void fill(Widget* lowerWidget) = 0; //!< An abstract function, that fills Packers. |
---|
[3144] | 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 | */ |
---|
| 109 | class Container : public Packer |
---|
| 110 | { |
---|
| 111 | private: |
---|
[3423] | 112 | int borderwidth; //!< The width of The Container Boarder. |
---|
| 113 | int policy; //!< The Update Policy of a Container. |
---|
[3144] | 114 | |
---|
| 115 | public: |
---|
[3623] | 116 | Container(void); |
---|
| 117 | virtual ~Container(void); |
---|
[3423] | 118 | // void setBorderWidth(int borderwidth); |
---|
| 119 | void fill(Widget* lowerWidget); |
---|
[3144] | 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 | */ |
---|
| 127 | class Window : public Container |
---|
| 128 | { |
---|
| 129 | private: |
---|
[3423] | 130 | bool isOpen; //!< A bool Variable that checks if a Window is already open. |
---|
[3144] | 131 | public: |
---|
[3423] | 132 | static Window* mainWindow; //!< Pointer to the First Window that was opened. By default this should be the GUI's main-Window. |
---|
[3148] | 133 | static void addWindow(Window* windowToAdd); |
---|
| 134 | |
---|
[3423] | 135 | Window(void); |
---|
| 136 | Window(char* windowName); |
---|
[3623] | 137 | virtual ~Window(void); |
---|
[3423] | 138 | void init(void); |
---|
[3144] | 139 | |
---|
[3624] | 140 | void setTitle(const char* title); |
---|
[3423] | 141 | void showall(void); |
---|
| 142 | void open(void); |
---|
| 143 | void close(void); |
---|
[3153] | 144 | |
---|
[3165] | 145 | #ifdef HAVE_GTK2 |
---|
[3423] | 146 | // Signals |
---|
| 147 | static gint windowOpen(GtkWidget* widget, GdkEvent* event, void* window); |
---|
| 148 | static gint windowClose(GtkWidget* widget, GdkEvent* event, void* window); |
---|
[3165] | 149 | #endif /* HAVE_GTK2 */ |
---|
[3144] | 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 | */ |
---|
| 157 | class Frame :public Container |
---|
| 158 | { |
---|
| 159 | public: |
---|
[3423] | 160 | Frame(void); |
---|
| 161 | Frame(char* frameName); |
---|
[3623] | 162 | virtual ~Frame(void); |
---|
[3144] | 163 | void init(void); |
---|
[3624] | 164 | |
---|
| 165 | void setTitle(const char* title); |
---|
[3144] | 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 | */ |
---|
| 172 | class EventBox : public Container |
---|
| 173 | { |
---|
| 174 | public: |
---|
[3423] | 175 | EventBox(void); |
---|
| 176 | EventBox(char* eventBoxName); |
---|
[3623] | 177 | virtual ~EventBox(void); |
---|
[3144] | 178 | void init(void); |
---|
| 179 | }; |
---|
| 180 | |
---|
| 181 | //! A Box can contain multiple Widgets |
---|
| 182 | /** |
---|
[3187] | 183 | A Box can Contain multiple Widgets, that are ordered either horizontally or vertically |
---|
| 184 | I defined the standartbox to be horizontally. |
---|
[3423] | 185 | A Box is always filled left->right(horizontally) or up->down(vertically) |
---|
[3187] | 186 | */ |
---|
[3144] | 187 | class Box : public Packer |
---|
| 188 | { |
---|
| 189 | public: |
---|
[3423] | 190 | Box(void); |
---|
| 191 | Box(char boxtype); |
---|
[3623] | 192 | virtual ~Box(void); |
---|
[3144] | 193 | void init(char boxtype); |
---|
[3423] | 194 | |
---|
| 195 | void fill(Widget* lowerWidget); |
---|
[3144] | 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 | */ |
---|
| 202 | class Option : public Widget |
---|
| 203 | { |
---|
[3423] | 204 | protected: |
---|
| 205 | bool saveable; //!< Options can be Saved. |
---|
| 206 | |
---|
[3144] | 207 | public: |
---|
[3623] | 208 | Option(void); |
---|
| 209 | virtual ~Option(void); |
---|
[3144] | 210 | void init(void); |
---|
| 211 | |
---|
[3423] | 212 | int value; //!< every option has a value either true or false(0,1) or something else like 25 for 25% of the volume |
---|
[3158] | 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 |
---|
[3423] | 215 | int defaultValue; //!< A default value is good, for hiding a option if it is not needed.(hidden if value == default_value) |
---|
[3144] | 216 | |
---|
[3423] | 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 */ |
---|
[3144] | 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 | */ |
---|
| 234 | class Button : public Option |
---|
| 235 | { |
---|
| 236 | public: |
---|
[3423] | 237 | Button(char* buttonname); |
---|
[3623] | 238 | virtual ~Button(void); |
---|
[3144] | 239 | void init(void); |
---|
| 240 | |
---|
[3624] | 241 | void setTitle(const char* title); |
---|
[3423] | 242 | void redraw(void); |
---|
| 243 | void changeOption(void); |
---|
[3144] | 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 | */ |
---|
| 249 | class CheckButton : public Option |
---|
| 250 | { |
---|
| 251 | public: |
---|
[3423] | 252 | CheckButton(char* buttonname); |
---|
[3623] | 253 | virtual ~CheckButton(void); |
---|
[3144] | 254 | void init(void); |
---|
[3423] | 255 | |
---|
[3624] | 256 | void setTitle(const char* title); |
---|
[3423] | 257 | bool isActive(void); //!< a Bool value to see, if this CheckButton is active. |
---|
| 258 | void redraw(void); |
---|
| 259 | void changeOption(void); |
---|
[3144] | 260 | }; |
---|
| 261 | |
---|
| 262 | //! Sliders are Options that can be modified in their value |
---|
| 263 | /** |
---|
| 264 | * good for volume, brightness, etc. |
---|
| 265 | */ |
---|
| 266 | class Slider : public Option |
---|
| 267 | { |
---|
[3423] | 268 | private: |
---|
| 269 | int start; //!< The beginning of the Slider-range. |
---|
| 270 | int end; //!< The end of the Slider-range. |
---|
[3144] | 271 | public: |
---|
[3423] | 272 | Slider(char* slidername, int start, int end); |
---|
[3623] | 273 | virtual ~Slider(void); |
---|
[3144] | 274 | void init(int start, int end); |
---|
| 275 | |
---|
| 276 | void setValue(int value); |
---|
[3423] | 277 | void redraw(void); |
---|
| 278 | void changeOption(void); |
---|
[3144] | 279 | }; |
---|
| 280 | |
---|
| 281 | //! A Menu is an Option that has a dropdown menu, where you can chose between different Items |
---|
| 282 | class Menu : public Option |
---|
| 283 | { |
---|
| 284 | private: |
---|
[3165] | 285 | #ifdef HAVE_GTK2 |
---|
[3423] | 286 | GtkWidget* menu; //!< The menu That will hold the Options. |
---|
[3165] | 287 | #endif /* HAVE_GTK2 */ |
---|
[3423] | 288 | va_list itemlist; //!< The list to readin multiple Options. |
---|
[3144] | 289 | |
---|
[3624] | 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 | |
---|
[3144] | 302 | public: |
---|
[3624] | 303 | Menu(const char* menuName); |
---|
[3423] | 304 | Menu(char* menuname, ...); |
---|
[3623] | 305 | virtual ~Menu(void); |
---|
[3144] | 306 | void init(void); |
---|
[3423] | 307 | |
---|
[3144] | 308 | void addItem(char* itemName); |
---|
[3423] | 309 | void redraw(void); |
---|
| 310 | void changeOption(void); |
---|
[3144] | 311 | }; |
---|
| 312 | |
---|
[3423] | 313 | //! A OptionLabel is a simple Label, that holds a char*, and will be updated, if changed. |
---|
[3156] | 314 | class OptionLabel : public Option |
---|
| 315 | { |
---|
[3423] | 316 | private: |
---|
| 317 | |
---|
[3156] | 318 | public: |
---|
[3161] | 319 | OptionLabel(char* label, char* value); |
---|
[3623] | 320 | virtual ~OptionLabel(void); |
---|
[3156] | 321 | void init(void); |
---|
[3161] | 322 | |
---|
| 323 | void setValue(char* newValue); |
---|
[3423] | 324 | void redraw(void); |
---|
| 325 | void changeOption(void); |
---|
| 326 | |
---|
| 327 | char* cValue; //!< The Value the Label will have. \todo make private |
---|
| 328 | |
---|
[3156] | 329 | }; |
---|
| 330 | |
---|
[3144] | 331 | //! A label is a Widget, that displays a text |
---|
| 332 | class Label : public Widget |
---|
| 333 | { |
---|
| 334 | public: |
---|
[3423] | 335 | Label(void); |
---|
| 336 | Label(char* text); |
---|
[3623] | 337 | virtual ~Label(void); |
---|
[3144] | 338 | void init(void); |
---|
| 339 | |
---|
[3423] | 340 | void setTitle(char* text); |
---|
| 341 | void ereaseText(void); |
---|
| 342 | void appendText(char* textToAppend); |
---|
| 343 | void appendInt(int intToAppend); |
---|
| 344 | char* getText(void); |
---|
[3144] | 345 | }; |
---|
| 346 | |
---|
[3423] | 347 | //! A ProgressBar is a Widget, that can display a Progress |
---|
| 348 | class ProgressBar : public Widget |
---|
| 349 | { |
---|
| 350 | public: |
---|
| 351 | ProgressBar(void); |
---|
| 352 | ProgressBar(char* label); |
---|
[3623] | 353 | virtual ~ProgressBar(void); |
---|
[3423] | 354 | void init(void); |
---|
[3156] | 355 | |
---|
[3423] | 356 | void setProgress(double progress); |
---|
| 357 | void setTotalSize(double totalSize); |
---|
| 358 | double getProgress(void); |
---|
[3144] | 359 | |
---|
[3423] | 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 | */ |
---|
| 373 | class Image : public Widget |
---|
| 374 | { |
---|
| 375 | public: |
---|
| 376 | Image(char* imgaename); |
---|
[3623] | 377 | virtual ~Image(void); |
---|
[3423] | 378 | void init(void); |
---|
| 379 | }; |
---|
| 380 | |
---|
| 381 | //gint orxonox_gui_quit(GtkWidget* widget, GdkEvent* event, gpointer data); |
---|
| 382 | |
---|
[3144] | 383 | #endif /* _ORXONOX_GUI_GTK_H */ |
---|