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