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