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