1 | #include "orxonox_gui.h" |
---|
2 | #include <iostream.h> |
---|
3 | |
---|
4 | |
---|
5 | int main( int argc, char *argv[] ) |
---|
6 | { |
---|
7 | gtk_init (&argc, &argv); |
---|
8 | Window* orxonoxGUI = new Window("Graphical Orxonox Launcher"); |
---|
9 | orxonoxGUI->connectSignal ("destroy", orxonoxGUI->orxonox_gui_quit); |
---|
10 | orxonoxGUI->connectSignal ("delete_event", orxonoxGUI->orxonox_gui_quit); |
---|
11 | |
---|
12 | Frame* Frametest = new Frame ("Test"); |
---|
13 | orxonoxGUI->fill((Frame*) Frametest); |
---|
14 | Box* box = new Box ('v'); |
---|
15 | Frametest->fill(box); |
---|
16 | |
---|
17 | CheckButton* button = new CheckButton("button"); |
---|
18 | button->connectSignal ("clicked", orxonoxGUI->orxonox_gui_quit); |
---|
19 | box->fill(button); |
---|
20 | Slider* slider = new Slider("slider", 0, 100); |
---|
21 | slider->connectSignal ("value_changed", slider->OptionChange); |
---|
22 | box->fill(slider); |
---|
23 | Menu* menu = new Menu("menu1", "no output", "verbose", "debug", "lastItem"); |
---|
24 | menu->connectSignal ("changed", menu->OptionChange); |
---|
25 | box->fill(menu); |
---|
26 | Menu* menu2 = new Menu("menu2", "no output", "verbose", "debug", "lastItem"); |
---|
27 | menu2->connectSignal ("changed", menu->OptionChange); |
---|
28 | box->fill(menu2); |
---|
29 | orxonoxGUI->listOptions(); |
---|
30 | orxonoxGUI->showall (); |
---|
31 | |
---|
32 | gtk_main(); |
---|
33 | return 0; |
---|
34 | } |
---|
35 | |
---|
36 | |
---|
37 | /* WIDGET */ |
---|
38 | |
---|
39 | void Widget::connectSignal (char* event, gint (*signal)(GtkWidget*, GdkEvent*, void *)) |
---|
40 | { |
---|
41 | /** |
---|
42 | * Connect any signal to any given Sub-widget |
---|
43 | */ |
---|
44 | g_signal_connect (G_OBJECT (this->widget), event, G_CALLBACK (signal), NULL); |
---|
45 | } |
---|
46 | |
---|
47 | void Widget::connectSignal (char* event, gint (*signal)( GtkWidget*, Widget *)) |
---|
48 | { |
---|
49 | /** |
---|
50 | * Connect a signal with additionally passing the whole Object |
---|
51 | */ |
---|
52 | g_signal_connect (G_OBJECT (this->widget), event, G_CALLBACK (signal), this); |
---|
53 | } |
---|
54 | |
---|
55 | void Widget::show() |
---|
56 | { |
---|
57 | /** |
---|
58 | * Function to Show any Widget |
---|
59 | */ |
---|
60 | gtk_widget_show (widget); |
---|
61 | } |
---|
62 | |
---|
63 | void Widget::listOptions () |
---|
64 | { |
---|
65 | /** |
---|
66 | * This is For listing all the Options witch are located beneath this Widget. |
---|
67 | */ |
---|
68 | if (this->is_option >= 1) |
---|
69 | cout << static_cast<Option*>(this)->option_name <<" is : " << static_cast<Option*>(this)->value <<endl; |
---|
70 | |
---|
71 | if (this->next != NULL) |
---|
72 | this->next->listOptions (); |
---|
73 | |
---|
74 | switch (this->is_option) |
---|
75 | { |
---|
76 | case -1: |
---|
77 | static_cast<Container*>(this)->down->listOptions (); |
---|
78 | break; |
---|
79 | case -2: |
---|
80 | static_cast<Box*>(this)->down->listOptions (); |
---|
81 | break; |
---|
82 | } |
---|
83 | } |
---|
84 | |
---|
85 | /* CONTAINERS*/ |
---|
86 | |
---|
87 | void Container::fill (Widget *lowerWidget) |
---|
88 | { |
---|
89 | /** |
---|
90 | * fill any given Container with a lowerwidet |
---|
91 | */ |
---|
92 | if (this->down == NULL) |
---|
93 | { |
---|
94 | gtk_container_add (GTK_CONTAINER (this->widget), lowerWidget->widget); |
---|
95 | this->down = lowerWidget; |
---|
96 | } |
---|
97 | else |
---|
98 | cout << "!!error!! You try to put more than one Widget into a container.\nnot including this item."<<endl; |
---|
99 | } |
---|
100 | |
---|
101 | // gtk_container_set_border_width (GTK_CONTAINER (widget), 5); |
---|
102 | |
---|
103 | /* WINDOW */ |
---|
104 | |
---|
105 | Window::Window (void) |
---|
106 | { |
---|
107 | /** |
---|
108 | * Creating a Window |
---|
109 | */ |
---|
110 | is_option = -1; |
---|
111 | widget = gtk_window_new (GTK_WINDOW_TOPLEVEL); |
---|
112 | gtk_window_set_policy (GTK_WINDOW(widget), TRUE, TRUE, TRUE); |
---|
113 | next = NULL; |
---|
114 | down = NULL; |
---|
115 | } |
---|
116 | |
---|
117 | Window::Window (char* windowName) |
---|
118 | { |
---|
119 | /** |
---|
120 | * Creating a Window with passing a name |
---|
121 | */ |
---|
122 | is_option = -1; |
---|
123 | widget = gtk_window_new (GTK_WINDOW_TOPLEVEL); |
---|
124 | gtk_window_set_policy (GTK_WINDOW (widget), TRUE, TRUE, TRUE); |
---|
125 | this->setTitle (windowName); |
---|
126 | } |
---|
127 | |
---|
128 | Window::~Window () |
---|
129 | { |
---|
130 | /** |
---|
131 | * Destoying a Window (not implemented) |
---|
132 | */ |
---|
133 | } |
---|
134 | |
---|
135 | void Window::showall () |
---|
136 | { |
---|
137 | /** |
---|
138 | * Shows all Widgets that are included within this Widget |
---|
139 | */ |
---|
140 | gtk_widget_show_all (widget); |
---|
141 | } |
---|
142 | |
---|
143 | void Window::setTitle (char* title) |
---|
144 | { |
---|
145 | /** |
---|
146 | * Set The Window title to title |
---|
147 | */ |
---|
148 | gtk_window_set_title (GTK_WINDOW (widget), title); |
---|
149 | } |
---|
150 | |
---|
151 | |
---|
152 | gint Window::orxonox_gui_quit (GtkWidget *widget, GdkEvent *event, gpointer data) |
---|
153 | { |
---|
154 | /** |
---|
155 | * Quits the orxonox_GUI |
---|
156 | */ |
---|
157 | gtk_main_quit(); |
---|
158 | return FALSE; |
---|
159 | } |
---|
160 | |
---|
161 | |
---|
162 | /* FRAME */ |
---|
163 | |
---|
164 | Frame::Frame (void) |
---|
165 | { |
---|
166 | /** |
---|
167 | * Creates a new Frame without a name |
---|
168 | */ |
---|
169 | is_option = -1; |
---|
170 | next = NULL; |
---|
171 | down = NULL; |
---|
172 | widget = gtk_frame_new (""); |
---|
173 | } |
---|
174 | Frame::Frame (char* title) |
---|
175 | { |
---|
176 | /** |
---|
177 | * Creates a new Frame with name title |
---|
178 | */ |
---|
179 | is_option = -1; |
---|
180 | next = NULL; |
---|
181 | down = NULL; |
---|
182 | widget = gtk_frame_new (title); |
---|
183 | } |
---|
184 | Frame::~Frame () |
---|
185 | { |
---|
186 | /** |
---|
187 | * Destroys given Frame (not implemented yet) |
---|
188 | */ |
---|
189 | } |
---|
190 | |
---|
191 | void Frame::setTitle (char* title) |
---|
192 | { |
---|
193 | /** |
---|
194 | * Sets the Frames name to title |
---|
195 | */ |
---|
196 | gtk_frame_set_label (GTK_FRAME (widget), title); |
---|
197 | } |
---|
198 | |
---|
199 | |
---|
200 | |
---|
201 | /* BOX */ |
---|
202 | |
---|
203 | Box::Box (void) |
---|
204 | { |
---|
205 | /** |
---|
206 | * Creates a new horizontal Box |
---|
207 | */ |
---|
208 | is_option = -2; |
---|
209 | next = NULL; |
---|
210 | down = NULL; |
---|
211 | widget = gtk_hbox_new(FALSE, 0); |
---|
212 | } |
---|
213 | Box::Box (char boxtype) |
---|
214 | { |
---|
215 | /** |
---|
216 | * Creates a new Box if boxtype is 'v' it will be vertically, if 'h' it will be horizontally |
---|
217 | */ |
---|
218 | is_option = -2; |
---|
219 | next = NULL; |
---|
220 | down = NULL; |
---|
221 | if (boxtype == 'v') |
---|
222 | { |
---|
223 | widget = gtk_vbox_new (FALSE, 0); |
---|
224 | } |
---|
225 | else |
---|
226 | { |
---|
227 | widget = gtk_hbox_new (FALSE, 0); |
---|
228 | } |
---|
229 | } |
---|
230 | |
---|
231 | Box::~Box () |
---|
232 | { |
---|
233 | /** |
---|
234 | * Destroys given Frame (not implemented yet) |
---|
235 | */ |
---|
236 | } |
---|
237 | |
---|
238 | void Box::fill (Widget *lowerWidget) |
---|
239 | { |
---|
240 | /** |
---|
241 | * Fill a Box with its lowerwidgets |
---|
242 | */ |
---|
243 | gtk_box_pack_start (GTK_BOX (this->widget), lowerWidget->widget, TRUE, TRUE, 0); |
---|
244 | if (this->down == NULL) |
---|
245 | this->down = lowerWidget; |
---|
246 | else |
---|
247 | { |
---|
248 | Widget* tmp; |
---|
249 | tmp = this->down; |
---|
250 | while (tmp->next != NULL) |
---|
251 | { |
---|
252 | tmp = tmp->next; |
---|
253 | } |
---|
254 | tmp->next = lowerWidget; |
---|
255 | } |
---|
256 | } |
---|
257 | |
---|
258 | |
---|
259 | /* OPTION */ |
---|
260 | |
---|
261 | /* BUTTON */ |
---|
262 | Button::Button(char* buttonname) |
---|
263 | { |
---|
264 | /** |
---|
265 | * Creates a new Button with name buttonname |
---|
266 | */ |
---|
267 | is_option = 0; |
---|
268 | next = NULL; |
---|
269 | option_name = buttonname; |
---|
270 | widget = gtk_button_new_with_label (buttonname); |
---|
271 | } |
---|
272 | |
---|
273 | /* CHECKBUTTON */ |
---|
274 | CheckButton::CheckButton (char* buttonname) |
---|
275 | { |
---|
276 | /** |
---|
277 | * Creates a new CheckButton with name buttonname |
---|
278 | */ |
---|
279 | is_option = 1; |
---|
280 | next = NULL; |
---|
281 | option_name = buttonname; |
---|
282 | widget = gtk_check_button_new_with_label (buttonname); |
---|
283 | } |
---|
284 | |
---|
285 | /* SLIDER */ |
---|
286 | Slider::Slider (char* slidername, int start, int end) |
---|
287 | { |
---|
288 | /** |
---|
289 | * Creates a new Slider with name slidername a beginning value of start and an end value of end. |
---|
290 | */ |
---|
291 | is_option = 1; |
---|
292 | next = NULL; |
---|
293 | option_name = slidername; |
---|
294 | widget = gtk_hscale_new_with_range (start, end, 5); |
---|
295 | value = start; |
---|
296 | } |
---|
297 | |
---|
298 | gint Slider::OptionChange (GtkWidget *widget, Widget* slider) |
---|
299 | { |
---|
300 | /** |
---|
301 | * Writes value, if changed on the slider, to the object. |
---|
302 | */ |
---|
303 | static_cast<Slider*>(slider)->value = (int)gtk_range_get_value (GTK_RANGE ((Slider*)slider->widget)); |
---|
304 | cout << static_cast<Slider*>(slider)->value << endl; |
---|
305 | } |
---|
306 | |
---|
307 | |
---|
308 | Menu::Menu (char* menuname, ...) |
---|
309 | { |
---|
310 | /** |
---|
311 | * Creates an Menu-Item-list out of multiple input. Consider, that the last input argument has to be "lastItem" for this to work. |
---|
312 | */ |
---|
313 | is_option = 1; |
---|
314 | next = NULL; |
---|
315 | option_name = menuname; |
---|
316 | char *tmp; |
---|
317 | va_list itemlist; |
---|
318 | widget = gtk_option_menu_new (); |
---|
319 | GtkWidget* menu = gtk_menu_new (); |
---|
320 | GtkWidget* item; |
---|
321 | |
---|
322 | va_start (itemlist, menuname); |
---|
323 | while (strcmp (tmp = va_arg (itemlist, char*), "lastItem")) |
---|
324 | { |
---|
325 | item = gtk_menu_item_new_with_label (tmp); |
---|
326 | gtk_menu_shell_append(GTK_MENU_SHELL (menu), item); |
---|
327 | } |
---|
328 | va_end(itemlist); |
---|
329 | |
---|
330 | gtk_option_menu_set_menu (GTK_OPTION_MENU (widget), menu); |
---|
331 | } |
---|
332 | |
---|
333 | gint Menu::OptionChange (GtkWidget *widget, Widget* menu) |
---|
334 | { |
---|
335 | /** |
---|
336 | * Writes value, if changed on the Menu, to the object. |
---|
337 | */ |
---|
338 | static_cast<Menu*>(menu)->value = (int)gtk_option_menu_get_history (GTK_OPTION_MENU (menu->widget)); |
---|
339 | cout << static_cast<Menu*>(menu)->option_name << " changed to : " << static_cast<Menu*>(menu)->value << endl; |
---|
340 | } |
---|