1 | #include <iostream.h> |
---|
2 | |
---|
3 | #include "orxonox_gui.h" |
---|
4 | #include "orxonox_gui_video.h" |
---|
5 | #include "orxonox_gui_audio.h" |
---|
6 | #include "orxonox_gui_exec.h" |
---|
7 | #include "orxonox_gui_flags.h" |
---|
8 | |
---|
9 | Window* orxonoxGUI; |
---|
10 | OrxonoxGuiVideo* video; |
---|
11 | OrxonoxGuiAudio* audio; |
---|
12 | OrxonoxGuiExec* exec; |
---|
13 | OrxonoxGuiFlags* flags; |
---|
14 | |
---|
15 | int main( int argc, char *argv[] ) |
---|
16 | { |
---|
17 | OrxonoxGui* orxonoxgui = new OrxonoxGui(argc, argv); |
---|
18 | return 0; |
---|
19 | } |
---|
20 | |
---|
21 | /* ORXONOXGUI */ |
---|
22 | |
---|
23 | OrxonoxGui::OrxonoxGui (int argc, char *argv[]) |
---|
24 | { |
---|
25 | /** |
---|
26 | * Initializes the Gui |
---|
27 | */ |
---|
28 | gtk_init (&argc, &argv); |
---|
29 | gtk_rc_parse( "rc" ); |
---|
30 | |
---|
31 | orxonoxGUI = new Window("Graphical Orxonox Launcher"); |
---|
32 | orxonoxGUI->connectSignal ("destroy", orxonoxGUI->orxonox_gui_quit); |
---|
33 | orxonoxGUI->connectSignal ("delete_event", orxonoxGUI->orxonox_gui_quit); |
---|
34 | |
---|
35 | Box* windowBox = new Box ('v'); |
---|
36 | |
---|
37 | Box* avBox = new Box ('h'); |
---|
38 | |
---|
39 | video = new OrxonoxGuiVideo (); |
---|
40 | avBox->fill (video->getFrame ()); |
---|
41 | audio = new OrxonoxGuiAudio (); |
---|
42 | avBox->fill (audio->getFrame ()); |
---|
43 | |
---|
44 | windowBox->fill (avBox); |
---|
45 | |
---|
46 | exec = new OrxonoxGuiExec (orxonoxGUI); |
---|
47 | windowBox->fill (exec->getFrame ()); |
---|
48 | |
---|
49 | flags = new OrxonoxGuiFlags (orxonoxGUI); |
---|
50 | windowBox->fill (flags->getFrame ()); |
---|
51 | |
---|
52 | orxonoxGUI->fill (windowBox); |
---|
53 | flags->setTextFromFlags (orxonoxGUI); |
---|
54 | |
---|
55 | exec->setFilename ("~/.orxonox.conf"); |
---|
56 | exec->readFromFile (orxonoxGUI); |
---|
57 | orxonoxGUI->listOptions(); |
---|
58 | |
---|
59 | orxonoxGUI->showall (); |
---|
60 | |
---|
61 | |
---|
62 | gtk_main(); |
---|
63 | } |
---|
64 | |
---|
65 | /* WIDGET */ |
---|
66 | |
---|
67 | void Widget::connectSignal (char* event, gint (*signal)(GtkWidget*, GdkEvent*, void *)) |
---|
68 | { |
---|
69 | /** |
---|
70 | * Connect any signal to any given Sub-widget |
---|
71 | */ |
---|
72 | g_signal_connect (G_OBJECT (this->widget), event, G_CALLBACK (signal), NULL); |
---|
73 | } |
---|
74 | |
---|
75 | void Widget::connectSignal (char* event, gint (*signal)( GtkWidget*, Widget *)) |
---|
76 | { |
---|
77 | /** |
---|
78 | * Connect a signal with additionally passing the whole Object |
---|
79 | */ |
---|
80 | g_signal_connect (G_OBJECT (this->widget), event, G_CALLBACK (signal), this); |
---|
81 | } |
---|
82 | |
---|
83 | void Widget::show() |
---|
84 | { |
---|
85 | /** |
---|
86 | * Function to Show any Widget |
---|
87 | */ |
---|
88 | gtk_widget_show (widget); |
---|
89 | } |
---|
90 | |
---|
91 | void Widget::listOptions () |
---|
92 | { |
---|
93 | /** |
---|
94 | * This is For listing all the Options witch are located beneath this Widget. |
---|
95 | */ |
---|
96 | if (this->is_option >= 1) |
---|
97 | cout << static_cast<Option*>(this)->option_name <<" is : " << static_cast<Option*>(this)->value <<endl; |
---|
98 | |
---|
99 | switch (this->is_option) |
---|
100 | { |
---|
101 | case -1: |
---|
102 | static_cast<Container*>(this)->down->listOptions (); |
---|
103 | break; |
---|
104 | case -2: |
---|
105 | static_cast<Box*>(this)->down->listOptions (); |
---|
106 | break; |
---|
107 | } |
---|
108 | |
---|
109 | if (this->next != NULL) |
---|
110 | this->next->listOptions (); |
---|
111 | |
---|
112 | |
---|
113 | } |
---|
114 | |
---|
115 | /* CONTAINERS*/ |
---|
116 | |
---|
117 | void Container::fill (Widget *lowerWidget) |
---|
118 | { |
---|
119 | /** |
---|
120 | * fill any given Container with a lowerwidet |
---|
121 | */ |
---|
122 | if (this->down == NULL) |
---|
123 | { |
---|
124 | gtk_container_add (GTK_CONTAINER (this->widget), lowerWidget->widget); |
---|
125 | this->down = lowerWidget; |
---|
126 | } |
---|
127 | else |
---|
128 | cout << "!!error!! You try to put more than one Widget into a container.\nnot including this item."<<endl; |
---|
129 | } |
---|
130 | |
---|
131 | // gtk_container_set_border_width (GTK_CONTAINER (widget), 5); |
---|
132 | |
---|
133 | /* WINDOW */ |
---|
134 | |
---|
135 | Window::Window (void) |
---|
136 | { |
---|
137 | /** |
---|
138 | * Creating a Window |
---|
139 | */ |
---|
140 | is_option = -1; |
---|
141 | next = NULL; |
---|
142 | down = NULL; |
---|
143 | widget = gtk_window_new (GTK_WINDOW_TOPLEVEL); |
---|
144 | gtk_window_set_policy (GTK_WINDOW(widget), TRUE, TRUE, TRUE); |
---|
145 | gtk_container_set_border_width (GTK_CONTAINER (widget), 3); |
---|
146 | } |
---|
147 | |
---|
148 | Window::Window (char* windowName) |
---|
149 | { |
---|
150 | /** |
---|
151 | * Creating a Window with passing a name |
---|
152 | */ |
---|
153 | is_option = -1; |
---|
154 | next = NULL; |
---|
155 | down = NULL; |
---|
156 | widget = gtk_window_new (GTK_WINDOW_TOPLEVEL); |
---|
157 | gtk_window_set_policy (GTK_WINDOW (widget), TRUE, TRUE, TRUE); |
---|
158 | gtk_container_set_border_width (GTK_CONTAINER (widget), 3); |
---|
159 | this->setTitle (windowName); |
---|
160 | } |
---|
161 | |
---|
162 | Window::~Window () |
---|
163 | { |
---|
164 | /** |
---|
165 | * Destoying a Window (not implemented) |
---|
166 | */ |
---|
167 | } |
---|
168 | |
---|
169 | void Window::showall () |
---|
170 | { |
---|
171 | /** |
---|
172 | * Shows all Widgets that are included within this Widget |
---|
173 | */ |
---|
174 | gtk_widget_show_all (widget); |
---|
175 | } |
---|
176 | |
---|
177 | void Window::setTitle (char* title) |
---|
178 | { |
---|
179 | /** |
---|
180 | * Set The Window title to title |
---|
181 | */ |
---|
182 | gtk_window_set_title (GTK_WINDOW (widget), title); |
---|
183 | } |
---|
184 | |
---|
185 | |
---|
186 | gint Window::orxonox_gui_quit (GtkWidget *widget, GdkEvent *event, gpointer data) |
---|
187 | { |
---|
188 | /** |
---|
189 | * Quits the orxonox_GUI |
---|
190 | */ |
---|
191 | exec->writeToFile (orxonoxGUI); |
---|
192 | |
---|
193 | gtk_main_quit(); |
---|
194 | return FALSE; |
---|
195 | } |
---|
196 | |
---|
197 | |
---|
198 | /* FRAME */ |
---|
199 | |
---|
200 | Frame::Frame (void) |
---|
201 | { |
---|
202 | /** |
---|
203 | * Creates a new Frame without a name |
---|
204 | */ |
---|
205 | is_option = -1; |
---|
206 | next = NULL; |
---|
207 | down = NULL; |
---|
208 | widget = gtk_frame_new (""); |
---|
209 | gtk_container_set_border_width (GTK_CONTAINER (widget), 3); |
---|
210 | } |
---|
211 | Frame::Frame (char* title) |
---|
212 | { |
---|
213 | /** |
---|
214 | * Creates a new Frame with name title |
---|
215 | */ |
---|
216 | is_option = -1; |
---|
217 | next = NULL; |
---|
218 | down = NULL; |
---|
219 | widget = gtk_frame_new (title); |
---|
220 | gtk_container_set_border_width (GTK_CONTAINER (widget), 3); |
---|
221 | } |
---|
222 | Frame::~Frame () |
---|
223 | { |
---|
224 | /** |
---|
225 | * Destroys given Frame (not implemented yet) |
---|
226 | */ |
---|
227 | } |
---|
228 | |
---|
229 | void Frame::setTitle (char* title) |
---|
230 | { |
---|
231 | /** |
---|
232 | * Sets the Frames name to title |
---|
233 | */ |
---|
234 | gtk_frame_set_label (GTK_FRAME (widget), title); |
---|
235 | } |
---|
236 | |
---|
237 | |
---|
238 | |
---|
239 | /* BOX */ |
---|
240 | |
---|
241 | Box::Box (void) |
---|
242 | { |
---|
243 | /** |
---|
244 | * Creates a new horizontal Box |
---|
245 | */ |
---|
246 | is_option = -2; |
---|
247 | next = NULL; |
---|
248 | down = NULL; |
---|
249 | widget = gtk_hbox_new(FALSE, 0); |
---|
250 | } |
---|
251 | Box::Box (char boxtype) |
---|
252 | { |
---|
253 | /** |
---|
254 | * Creates a new Box if boxtype is 'v' it will be vertically, if 'h' it will be horizontally |
---|
255 | */ |
---|
256 | is_option = -2; |
---|
257 | next = NULL; |
---|
258 | down = NULL; |
---|
259 | if (boxtype == 'v') |
---|
260 | { |
---|
261 | widget = gtk_vbox_new (FALSE, 0); |
---|
262 | } |
---|
263 | else |
---|
264 | { |
---|
265 | widget = gtk_hbox_new (FALSE, 0); |
---|
266 | } |
---|
267 | } |
---|
268 | |
---|
269 | Box::~Box () |
---|
270 | { |
---|
271 | /** |
---|
272 | * Destroys given Frame (not implemented yet) |
---|
273 | */ |
---|
274 | } |
---|
275 | |
---|
276 | void Box::fill (Widget *lowerWidget) |
---|
277 | { |
---|
278 | /** |
---|
279 | * Fill a Box with its lowerwidgets |
---|
280 | */ |
---|
281 | gtk_box_pack_start (GTK_BOX (this->widget), lowerWidget->widget, TRUE, TRUE, 0); |
---|
282 | if (this->down == NULL) |
---|
283 | this->down = lowerWidget; |
---|
284 | else |
---|
285 | { |
---|
286 | Widget* tmp; |
---|
287 | tmp = this->down; |
---|
288 | while (tmp->next != NULL) |
---|
289 | { |
---|
290 | tmp = tmp->next; |
---|
291 | } |
---|
292 | tmp->next = lowerWidget; |
---|
293 | } |
---|
294 | } |
---|
295 | |
---|
296 | |
---|
297 | /* OPTION */ |
---|
298 | |
---|
299 | void Option::setFlagName (char* flagname, int defaultvalue) |
---|
300 | { |
---|
301 | flag_name = flagname; |
---|
302 | default_value = defaultvalue; |
---|
303 | cout << "Set Flagname of " << option_name << " to " << flagname << endl; |
---|
304 | } |
---|
305 | |
---|
306 | void Option::setFlagName (char* flagname, char* flagnameshort, int defaultvalue) |
---|
307 | { |
---|
308 | /** |
---|
309 | * \brief Sets the Flagname of an Option. If it is set different then "" this Option will be saved to the Configurationfile |
---|
310 | */ |
---|
311 | flag_name = flagname; |
---|
312 | flag_name_short = flagnameshort; |
---|
313 | default_value = defaultvalue; |
---|
314 | cout << "Set Flagname of " << option_name << " to " << flagname << endl; |
---|
315 | } |
---|
316 | |
---|
317 | |
---|
318 | /* BUTTON */ |
---|
319 | Button::Button(char* buttonname) |
---|
320 | { |
---|
321 | /** |
---|
322 | * Creates a new Button with name buttonname |
---|
323 | */ |
---|
324 | is_option = 0; |
---|
325 | value = 0; |
---|
326 | next = NULL; |
---|
327 | option_name = buttonname; |
---|
328 | flag_name = ""; |
---|
329 | flag_name_short = ""; |
---|
330 | default_value = 0; |
---|
331 | widget = gtk_button_new_with_label (buttonname); |
---|
332 | } |
---|
333 | |
---|
334 | /* CHECKBUTTON */ |
---|
335 | CheckButton::CheckButton (char* buttonname) |
---|
336 | { |
---|
337 | /** |
---|
338 | * Creates a new CheckButton with name buttonname |
---|
339 | */ |
---|
340 | is_option = 1; |
---|
341 | value = 0; |
---|
342 | next = NULL; |
---|
343 | option_name = buttonname; |
---|
344 | flag_name = ""; |
---|
345 | flag_name_short = ""; |
---|
346 | default_value = 0; |
---|
347 | widget = gtk_check_button_new_with_label (buttonname); |
---|
348 | |
---|
349 | this->connectSignal ("clicked", this->OptionChange); |
---|
350 | } |
---|
351 | |
---|
352 | gint CheckButton::OptionChange (GtkWidget *widget, Widget* checkbutton) |
---|
353 | { |
---|
354 | /** |
---|
355 | * Writes value, if changed on the checkbutton, to the object. |
---|
356 | */ |
---|
357 | static_cast<CheckButton*>(checkbutton)->value = (int)gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON ((CheckButton*)checkbutton->widget)); |
---|
358 | flags->setTextFromFlags(orxonoxGUI); |
---|
359 | cout << static_cast<CheckButton*>(checkbutton)->option_name << " set to: " << static_cast<CheckButton*>(checkbutton)->value << endl; |
---|
360 | } |
---|
361 | |
---|
362 | /* SLIDER */ |
---|
363 | Slider::Slider (char* slidername, int start, int end) |
---|
364 | { |
---|
365 | /** |
---|
366 | * Creates a new Slider with name slidername a beginning value of start and an end value of end. |
---|
367 | */ |
---|
368 | is_option = 2; |
---|
369 | value = 0; |
---|
370 | next = NULL; |
---|
371 | option_name = slidername; |
---|
372 | flag_name = ""; |
---|
373 | flag_name_short = ""; |
---|
374 | default_value = 0; |
---|
375 | widget = gtk_hscale_new_with_range (start, end, 5); |
---|
376 | value = start; |
---|
377 | |
---|
378 | this->connectSignal ("value_changed", this->OptionChange); |
---|
379 | } |
---|
380 | |
---|
381 | gint Slider::OptionChange (GtkWidget *widget, Widget* slider) |
---|
382 | { |
---|
383 | /** |
---|
384 | * Writes value, if changed on the slider, to the object. |
---|
385 | */ |
---|
386 | static_cast<Slider*>(slider)->value = (int)gtk_range_get_value (GTK_RANGE ((Slider*)slider->widget)); |
---|
387 | flags->setTextFromFlags(orxonoxGUI); |
---|
388 | cout << static_cast<Slider*>(slider)->option_name << " set to: "<< static_cast<Slider*>(slider)->value << endl; |
---|
389 | } |
---|
390 | |
---|
391 | Menu::Menu (char* menuname, ...) |
---|
392 | { |
---|
393 | /** |
---|
394 | * Creates an Menu-Item-list out of multiple input. Consider, that the last input argument has to be "lastItem" for this to work. |
---|
395 | */ |
---|
396 | is_option = 2; |
---|
397 | value = 0; |
---|
398 | next = NULL; |
---|
399 | option_name = menuname; |
---|
400 | flag_name = ""; |
---|
401 | flag_name_short = ""; |
---|
402 | default_value = 0; |
---|
403 | char *tmp; |
---|
404 | va_list itemlist; |
---|
405 | widget = gtk_option_menu_new (); |
---|
406 | GtkWidget* menu = gtk_menu_new (); |
---|
407 | GtkWidget* item; |
---|
408 | |
---|
409 | va_start (itemlist, menuname); |
---|
410 | while (strcmp (tmp = va_arg (itemlist, char*), "lastItem")) |
---|
411 | { |
---|
412 | item = gtk_menu_item_new_with_label (tmp); |
---|
413 | gtk_menu_shell_append(GTK_MENU_SHELL (menu), item); |
---|
414 | } |
---|
415 | va_end(itemlist); |
---|
416 | |
---|
417 | gtk_option_menu_set_menu (GTK_OPTION_MENU (widget), menu); |
---|
418 | this->connectSignal ("changed", this->OptionChange); |
---|
419 | } |
---|
420 | |
---|
421 | gint Menu::OptionChange (GtkWidget *widget, Widget* menu) |
---|
422 | { |
---|
423 | /** |
---|
424 | * Writes value, if changed on the Menu, to the object. |
---|
425 | */ |
---|
426 | static_cast<Menu*>(menu)->value = (int)gtk_option_menu_get_history (GTK_OPTION_MENU (menu->widget)); |
---|
427 | flags->setTextFromFlags(orxonoxGUI); |
---|
428 | cout << static_cast<Menu*>(menu)->option_name << " changed to : " << static_cast<Menu*>(menu)->value << endl; |
---|
429 | } |
---|
430 | |
---|
431 | Label:: Label () |
---|
432 | { |
---|
433 | is_option = 0; |
---|
434 | next = NULL; |
---|
435 | widget = gtk_label_new (""); |
---|
436 | gtk_widget_set_usize (widget, 260, 60); |
---|
437 | gtk_label_set_line_wrap (GTK_LABEL(widget), TRUE); |
---|
438 | } |
---|
439 | |
---|
440 | Label:: Label (char* text) |
---|
441 | { |
---|
442 | is_option = 0; |
---|
443 | next = NULL; |
---|
444 | widget = gtk_label_new (text); |
---|
445 | gtk_label_set_line_wrap (GTK_LABEL(widget), TRUE); |
---|
446 | } |
---|
447 | |
---|
448 | Label::~Label () |
---|
449 | {} |
---|
450 | |
---|
451 | void Label::setText (char * text) |
---|
452 | { |
---|
453 | gtk_label_set_text (GTK_LABEL (this->widget), text); |
---|
454 | } |
---|
455 | |
---|
456 | char* Label::getText () |
---|
457 | { |
---|
458 | return ((char*)gtk_label_get_text (GTK_LABEL (this->widget))); |
---|
459 | } |
---|