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