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