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