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