[2581] | 1 | /* |
---|
| 2 | orxonox - the future of 3D-vertical-scrollers |
---|
| 3 | |
---|
| 4 | Copyright (C) 2004 orx |
---|
| 5 | |
---|
| 6 | This program is free software; you can redistribute it and/or modify |
---|
| 7 | it under the terms of the GNU General Public License as published by |
---|
| 8 | the Free Software Foundation; either version 2, or (at your option) |
---|
| 9 | any later version. |
---|
| 10 | |
---|
| 11 | This program is distributed in the hope that it will be useful, |
---|
| 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 14 | GNU General Public License for more details. |
---|
| 15 | |
---|
| 16 | You should have received a copy of the GNU General Public License |
---|
| 17 | along with this program; if not, write to the Free Software Foundation, |
---|
| 18 | Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
---|
| 19 | |
---|
| 20 | |
---|
| 21 | ### File Specific: |
---|
| 22 | main-programmer: Benjamin Grauer |
---|
| 23 | |
---|
| 24 | */ |
---|
| 25 | |
---|
[2018] | 26 | #include <iostream.h> |
---|
| 27 | |
---|
| 28 | #include "orxonox_gui.h" |
---|
| 29 | #include "orxonox_gui_video.h" |
---|
| 30 | #include "orxonox_gui_audio.h" |
---|
| 31 | #include "orxonox_gui_exec.h" |
---|
| 32 | #include "orxonox_gui_flags.h" |
---|
[2580] | 33 | #include "orxonox_gui_banner.h" |
---|
[2018] | 34 | |
---|
| 35 | Window* orxonoxGUI; |
---|
| 36 | OrxonoxGuiVideo* video; |
---|
| 37 | OrxonoxGuiAudio* audio; |
---|
| 38 | OrxonoxGuiExec* exec; |
---|
[2580] | 39 | OrxonoxGuiFlags* flags; |
---|
| 40 | OrxonoxGuiBanner* banner; |
---|
[2018] | 41 | |
---|
| 42 | int main( int argc, char *argv[] ) |
---|
| 43 | { |
---|
| 44 | OrxonoxGui* orxonoxgui = new OrxonoxGui(argc, argv); |
---|
| 45 | return 0; |
---|
| 46 | } |
---|
| 47 | |
---|
| 48 | /* ORXONOXGUI */ |
---|
| 49 | |
---|
[2588] | 50 | /** |
---|
| 51 | * Initializes the Gui |
---|
| 52 | */ |
---|
[2018] | 53 | OrxonoxGui::OrxonoxGui (int argc, char *argv[]) |
---|
| 54 | { |
---|
| 55 | gtk_init (&argc, &argv); |
---|
| 56 | gtk_rc_parse( "rc" ); |
---|
| 57 | |
---|
| 58 | orxonoxGUI = new Window("Graphical Orxonox Launcher"); |
---|
| 59 | orxonoxGUI->connectSignal ("destroy", orxonoxGUI->orxonox_gui_quit); |
---|
| 60 | orxonoxGUI->connectSignal ("delete_event", orxonoxGUI->orxonox_gui_quit); |
---|
| 61 | |
---|
[2024] | 62 | Box* windowBox = new Box ('h'); |
---|
| 63 | |
---|
[2580] | 64 | banner = new OrxonoxGuiBanner(); |
---|
| 65 | windowBox->fill (banner->getEventBox()); |
---|
| 66 | |
---|
[2024] | 67 | Box* optionBox = new Box ('v'); |
---|
[2018] | 68 | |
---|
| 69 | Box* avBox = new Box ('h'); |
---|
| 70 | |
---|
| 71 | video = new OrxonoxGuiVideo (); |
---|
| 72 | avBox->fill (video->getFrame ()); |
---|
| 73 | audio = new OrxonoxGuiAudio (); |
---|
| 74 | avBox->fill (audio->getFrame ()); |
---|
| 75 | |
---|
[2024] | 76 | optionBox->fill (avBox); |
---|
[2018] | 77 | |
---|
| 78 | exec = new OrxonoxGuiExec (orxonoxGUI); |
---|
[2024] | 79 | optionBox->fill (exec->getFrame ()); |
---|
[2018] | 80 | |
---|
| 81 | flags = new OrxonoxGuiFlags (orxonoxGUI); |
---|
[2024] | 82 | |
---|
| 83 | |
---|
| 84 | optionBox->fill (flags->getFrame ()); |
---|
| 85 | windowBox->fill (optionBox); |
---|
[2018] | 86 | |
---|
| 87 | orxonoxGUI->fill (windowBox); |
---|
| 88 | flags->setTextFromFlags (orxonoxGUI); |
---|
| 89 | |
---|
| 90 | exec->setFilename ("~/.orxonox.conf"); |
---|
| 91 | exec->readFromFile (orxonoxGUI); |
---|
[2584] | 92 | orxonoxGUI->walkThrough(orxonoxGUI->listOptions); |
---|
[2018] | 93 | |
---|
| 94 | orxonoxGUI->showall (); |
---|
| 95 | |
---|
| 96 | |
---|
| 97 | gtk_main(); |
---|
| 98 | } |
---|
| 99 | |
---|
| 100 | /* WIDGET */ |
---|
[2588] | 101 | /** |
---|
| 102 | * Initializes a widget. |
---|
| 103 | * Nothing to do here. |
---|
| 104 | */ |
---|
[2586] | 105 | void Widget::init() |
---|
| 106 | { |
---|
| 107 | return; |
---|
| 108 | } |
---|
| 109 | |
---|
[2588] | 110 | /** |
---|
| 111 | * Connect any signal to any given Sub-widget |
---|
| 112 | */ |
---|
[2018] | 113 | void Widget::connectSignal (char* event, gint (*signal)(GtkWidget*, GdkEvent*, void *)) |
---|
| 114 | { |
---|
| 115 | g_signal_connect (G_OBJECT (this->widget), event, G_CALLBACK (signal), NULL); |
---|
| 116 | } |
---|
| 117 | |
---|
[2588] | 118 | /** |
---|
| 119 | * Connect a signal with additionally passing the whole Object |
---|
| 120 | */ |
---|
[2018] | 121 | void Widget::connectSignal (char* event, gint (*signal)( GtkWidget*, Widget *)) |
---|
| 122 | { |
---|
[2581] | 123 | g_signal_connect (G_OBJECT (this->widget), event, G_CALLBACK (signal), this); |
---|
[2018] | 124 | } |
---|
| 125 | |
---|
[2588] | 126 | /** |
---|
| 127 | * Connect a signal with additionally passing a whole external Object |
---|
| 128 | */ |
---|
[2581] | 129 | void Widget::connectSignal (char* event, void* extObj, gint (*signal)(GtkWidget*, GdkEvent*, void *)) |
---|
| 130 | { |
---|
| 131 | g_signal_connect (G_OBJECT (this->widget), event, G_CALLBACK (signal), extObj); |
---|
| 132 | } |
---|
[2588] | 133 | |
---|
| 134 | |
---|
| 135 | /** |
---|
| 136 | * Function to Shows a specific widget. |
---|
| 137 | */ |
---|
[2018] | 138 | void Widget::show() |
---|
| 139 | { |
---|
[2588] | 140 | gtk_widget_show (this->widget); |
---|
[2018] | 141 | } |
---|
| 142 | |
---|
[2588] | 143 | /** |
---|
| 144 | * Moves through all the Widgets downwards from this and executes the function on them. |
---|
| 145 | \param function must be of type void and takes a Widget* as an Input. |
---|
| 146 | |
---|
| 147 | */ |
---|
[2584] | 148 | void Widget::walkThrough (void (*function)(Widget*)) |
---|
[2018] | 149 | { |
---|
[2584] | 150 | function(this); |
---|
[2018] | 151 | switch (this->is_option) |
---|
| 152 | { |
---|
| 153 | case -1: |
---|
[2584] | 154 | static_cast<Container*>(this)->down->walkThrough (function); |
---|
[2018] | 155 | break; |
---|
| 156 | case -2: |
---|
[2584] | 157 | static_cast<Box*>(this)->down->walkThrough (function); |
---|
[2018] | 158 | break; |
---|
| 159 | } |
---|
| 160 | |
---|
| 161 | if (this->next != NULL) |
---|
[2584] | 162 | this->next->walkThrough(function); |
---|
[2018] | 163 | } |
---|
| 164 | |
---|
[2584] | 165 | |
---|
[2588] | 166 | /** |
---|
| 167 | * This is for listing the option of "widget" |
---|
| 168 | \param widget specifies the widget that should be listed |
---|
| 169 | */ |
---|
[2584] | 170 | void Widget::listOptions (Widget* widget) |
---|
[2018] | 171 | { |
---|
[2584] | 172 | if (widget->is_option >= 1) |
---|
| 173 | cout << static_cast<Option*>(widget)->option_name <<" is : " << static_cast<Option*>(widget)->value <<endl; |
---|
| 174 | } |
---|
[2018] | 175 | |
---|
[2588] | 176 | /** |
---|
| 177 | * This is for setting the option of "widget" |
---|
| 178 | \param widget specifies the widget that should be set. |
---|
| 179 | */ |
---|
[2584] | 180 | void Widget::setOptions (Widget* widget) |
---|
| 181 | { |
---|
| 182 | if (widget->is_option >= 1) |
---|
| 183 | static_cast<Option*>(widget)->redraw();// <<" is : " << static_cast<Option*>(this)->value <<endl; |
---|
[2018] | 184 | } |
---|
| 185 | |
---|
| 186 | /* CONTAINERS*/ |
---|
[2588] | 187 | |
---|
| 188 | /** |
---|
| 189 | * Initializes a Container. |
---|
| 190 | * nothing to do here |
---|
| 191 | */ |
---|
[2586] | 192 | void Container::init (void) |
---|
| 193 | { |
---|
| 194 | return; |
---|
| 195 | } |
---|
[2588] | 196 | |
---|
| 197 | /** |
---|
| 198 | * Fills a Container with lowerWidget. |
---|
| 199 | * It does this by filling up the down pointer only if down points to NULL. |
---|
| 200 | \param lowerWidget the Widget that should be filled into the Container. |
---|
| 201 | */ |
---|
[2018] | 202 | void Container::fill (Widget *lowerWidget) |
---|
| 203 | { |
---|
| 204 | if (this->down == NULL) |
---|
| 205 | { |
---|
| 206 | gtk_container_add (GTK_CONTAINER (this->widget), lowerWidget->widget); |
---|
| 207 | this->down = lowerWidget; |
---|
| 208 | } |
---|
| 209 | else |
---|
| 210 | cout << "!!error!! You try to put more than one Widget into a container.\nnot including this item."<<endl; |
---|
| 211 | } |
---|
| 212 | |
---|
| 213 | // gtk_container_set_border_width (GTK_CONTAINER (widget), 5); |
---|
| 214 | |
---|
| 215 | /* WINDOW */ |
---|
| 216 | |
---|
[2588] | 217 | /** |
---|
| 218 | * Creating a new Window without a Name |
---|
| 219 | */ |
---|
[2018] | 220 | Window::Window (void) |
---|
| 221 | { |
---|
[2586] | 222 | this->init(); |
---|
[2018] | 223 | } |
---|
| 224 | |
---|
[2588] | 225 | /** |
---|
| 226 | * Creating a Window with a name |
---|
| 227 | \param windowName the name the window should get. |
---|
| 228 | */ |
---|
[2018] | 229 | Window::Window (char* windowName) |
---|
| 230 | { |
---|
[2586] | 231 | this->init(); |
---|
[2018] | 232 | this->setTitle (windowName); |
---|
| 233 | } |
---|
| 234 | |
---|
[2588] | 235 | /** |
---|
| 236 | * Destoying a Window (very BAD implemented). |
---|
| 237 | * For now it just hides the window. |
---|
| 238 | */ |
---|
[2018] | 239 | Window::~Window () |
---|
| 240 | { |
---|
[2581] | 241 | gtk_widget_hide (widget); |
---|
[2018] | 242 | } |
---|
| 243 | |
---|
[2588] | 244 | /** |
---|
| 245 | *initializes a new Window |
---|
| 246 | */ |
---|
[2586] | 247 | void Window::init() |
---|
| 248 | { |
---|
| 249 | is_option = -1; |
---|
| 250 | next = NULL; |
---|
| 251 | down = NULL; |
---|
| 252 | widget = gtk_window_new (GTK_WINDOW_TOPLEVEL); |
---|
| 253 | gtk_window_set_policy (GTK_WINDOW(widget), TRUE, TRUE, TRUE); |
---|
| 254 | #if !defined(__WIN32__) |
---|
| 255 | gtk_window_set_decorated (GTK_WINDOW (widget), FALSE); |
---|
| 256 | #endif |
---|
| 257 | gtk_container_set_border_width (GTK_CONTAINER (widget), 3); |
---|
| 258 | } |
---|
| 259 | |
---|
[2588] | 260 | /** |
---|
| 261 | * Shows all Widgets that are included within this->widget. |
---|
| 262 | */ |
---|
[2018] | 263 | void Window::showall () |
---|
| 264 | { |
---|
| 265 | gtk_widget_show_all (widget); |
---|
| 266 | } |
---|
| 267 | |
---|
[2588] | 268 | /** |
---|
| 269 | * Set The Window-title to title |
---|
| 270 | \param title title the Window should get. |
---|
| 271 | */ |
---|
[2018] | 272 | void Window::setTitle (char* title) |
---|
| 273 | { |
---|
| 274 | gtk_window_set_title (GTK_WINDOW (widget), title); |
---|
| 275 | } |
---|
| 276 | |
---|
[2588] | 277 | /** |
---|
| 278 | * Quits the orxonox_GUI. |
---|
| 279 | * This can be called as a Signal and is therefor static |
---|
| 280 | \param widget The widget that called this function |
---|
| 281 | \param event the event that happened to execute this function |
---|
| 282 | \param data some data passed with the Signal |
---|
| 283 | */ |
---|
[2018] | 284 | gint Window::orxonox_gui_quit (GtkWidget *widget, GdkEvent *event, gpointer data) |
---|
| 285 | { |
---|
| 286 | if (exec->shouldsave()) |
---|
| 287 | exec->writeToFile (orxonoxGUI); |
---|
| 288 | |
---|
| 289 | gtk_main_quit(); |
---|
| 290 | return FALSE; |
---|
| 291 | } |
---|
| 292 | |
---|
| 293 | |
---|
| 294 | /* FRAME */ |
---|
| 295 | |
---|
[2588] | 296 | /** |
---|
| 297 | * Creates a new Frame without a name |
---|
| 298 | */ |
---|
[2018] | 299 | Frame::Frame (void) |
---|
| 300 | { |
---|
[2586] | 301 | this->init(); |
---|
[2018] | 302 | } |
---|
[2588] | 303 | |
---|
| 304 | /** |
---|
| 305 | * Creates a new Frame with name title |
---|
| 306 | */ |
---|
[2018] | 307 | Frame::Frame (char* title) |
---|
| 308 | { |
---|
[2586] | 309 | this->init(); |
---|
| 310 | this->setTitle(title); |
---|
[2018] | 311 | } |
---|
[2588] | 312 | |
---|
| 313 | /** |
---|
| 314 | * Destroys given Frame (not implemented yet) |
---|
| 315 | */ |
---|
[2018] | 316 | Frame::~Frame () |
---|
| 317 | { |
---|
| 318 | } |
---|
| 319 | |
---|
[2588] | 320 | /** |
---|
| 321 | * Initializes a new Frame with default settings |
---|
| 322 | */ |
---|
[2586] | 323 | void Frame::init() |
---|
| 324 | { |
---|
| 325 | is_option = -1; |
---|
| 326 | next = NULL; |
---|
| 327 | down = NULL; |
---|
| 328 | widget = gtk_frame_new (""); |
---|
| 329 | gtk_container_set_border_width (GTK_CONTAINER (widget), 3); |
---|
| 330 | } |
---|
| 331 | |
---|
[2588] | 332 | /** |
---|
| 333 | * Sets the Frames name to title |
---|
| 334 | \param title The title the Frame should get. |
---|
| 335 | */ |
---|
[2018] | 336 | void Frame::setTitle (char* title) |
---|
| 337 | { |
---|
| 338 | gtk_frame_set_label (GTK_FRAME (widget), title); |
---|
| 339 | } |
---|
| 340 | |
---|
[2580] | 341 | // EVENTBOX // |
---|
[2588] | 342 | |
---|
| 343 | /** |
---|
| 344 | * Creates a new EventBox with default settings. |
---|
| 345 | */ |
---|
[2580] | 346 | EventBox::EventBox () |
---|
| 347 | { |
---|
[2586] | 348 | this->init(); |
---|
[2580] | 349 | } |
---|
[2588] | 350 | /** |
---|
| 351 | * Creates a new EventBox with name title |
---|
| 352 | \param title title the Eventbox should get (only data-structure-internal) |
---|
| 353 | */ |
---|
[2580] | 354 | EventBox::EventBox (char* title) |
---|
| 355 | { |
---|
[2586] | 356 | this->init(); |
---|
| 357 | this->setTitle(title); |
---|
| 358 | |
---|
| 359 | } |
---|
[2588] | 360 | |
---|
| 361 | /** |
---|
| 362 | * Initializes a new EventBox |
---|
| 363 | */ |
---|
[2586] | 364 | void EventBox::init(void) |
---|
| 365 | { |
---|
[2580] | 366 | is_option = -1; |
---|
| 367 | next = NULL; |
---|
| 368 | down = NULL; |
---|
| 369 | widget = gtk_event_box_new (); |
---|
| 370 | gtk_container_set_border_width (GTK_CONTAINER (widget), 3); |
---|
[2586] | 371 | |
---|
| 372 | } |
---|
[2018] | 373 | |
---|
[2588] | 374 | /** |
---|
| 375 | * Sets the Title of the EventBox (not implemented) |
---|
| 376 | \param title Name the EventBox should get (only datastructure-internal). |
---|
| 377 | */ |
---|
[2580] | 378 | void EventBox::setTitle (char* title) |
---|
| 379 | { |
---|
[2588] | 380 | |
---|
[2580] | 381 | } |
---|
[2588] | 382 | |
---|
| 383 | /** |
---|
| 384 | * Destructs an EventBox (not Implemented) |
---|
| 385 | */ |
---|
[2580] | 386 | EventBox::~EventBox () |
---|
| 387 | { |
---|
| 388 | } |
---|
| 389 | |
---|
| 390 | |
---|
[2018] | 391 | /* BOX */ |
---|
| 392 | |
---|
[2588] | 393 | /** |
---|
| 394 | * Creates a new horizontal Box |
---|
| 395 | */ |
---|
[2018] | 396 | Box::Box (void) |
---|
| 397 | { |
---|
[2586] | 398 | this->init('h'); |
---|
[2018] | 399 | } |
---|
[2588] | 400 | |
---|
| 401 | /** |
---|
| 402 | * Creates a new Box of type boxtype |
---|
| 403 | \param boxtype if 'v' the Box will be vertically, if 'h' the Box will be horizontally |
---|
| 404 | */ |
---|
[2018] | 405 | Box::Box (char boxtype) |
---|
| 406 | { |
---|
[2586] | 407 | this->init(boxtype); |
---|
| 408 | } |
---|
[2588] | 409 | |
---|
| 410 | /** |
---|
| 411 | * Destroys given Box (not implemented yet) |
---|
| 412 | */ |
---|
[2586] | 413 | Box::~Box () |
---|
| 414 | { |
---|
| 415 | } |
---|
| 416 | |
---|
[2588] | 417 | /** |
---|
| 418 | * Initializes a new Box with type boxtype |
---|
| 419 | \param boxtype see Box(char boxtype) |
---|
| 420 | */ |
---|
[2586] | 421 | void Box::init(char boxtype) |
---|
| 422 | { |
---|
[2018] | 423 | is_option = -2; |
---|
| 424 | next = NULL; |
---|
| 425 | down = NULL; |
---|
| 426 | if (boxtype == 'v') |
---|
| 427 | { |
---|
| 428 | widget = gtk_vbox_new (FALSE, 0); |
---|
| 429 | } |
---|
| 430 | else |
---|
| 431 | { |
---|
| 432 | widget = gtk_hbox_new (FALSE, 0); |
---|
| 433 | } |
---|
| 434 | } |
---|
| 435 | |
---|
[2588] | 436 | /** |
---|
| 437 | * Fills a box with a given Widget. |
---|
| 438 | * It does this by apending the first one to its down-pointer and all its following ones to the preceding next-pointer. The last one will receive a NULL pointer as Next |
---|
| 439 | \param lowerWidget the next Widget that should be appendet to this Box |
---|
| 440 | */ |
---|
[2018] | 441 | void Box::fill (Widget *lowerWidget) |
---|
| 442 | { |
---|
| 443 | /** |
---|
| 444 | * Fill a Box with its lowerwidgets |
---|
| 445 | */ |
---|
| 446 | gtk_box_pack_start (GTK_BOX (this->widget), lowerWidget->widget, TRUE, TRUE, 0); |
---|
| 447 | if (this->down == NULL) |
---|
| 448 | this->down = lowerWidget; |
---|
| 449 | else |
---|
| 450 | { |
---|
| 451 | Widget* tmp; |
---|
| 452 | tmp = this->down; |
---|
| 453 | while (tmp->next != NULL) |
---|
| 454 | { |
---|
| 455 | tmp = tmp->next; |
---|
| 456 | } |
---|
| 457 | tmp->next = lowerWidget; |
---|
| 458 | } |
---|
| 459 | } |
---|
| 460 | |
---|
[2024] | 461 | /* IMAGE */ |
---|
[2018] | 462 | |
---|
[2588] | 463 | /** |
---|
| 464 | * Creates a new Image |
---|
| 465 | \param imagename the location of the Image on the Hard Disc |
---|
| 466 | */ |
---|
[2024] | 467 | Image::Image (char* imagename) |
---|
| 468 | { |
---|
[2588] | 469 | this->init(); |
---|
[2024] | 470 | widget = gtk_image_new_from_file (imagename); |
---|
| 471 | } |
---|
[2588] | 472 | |
---|
| 473 | /** |
---|
| 474 | * Initializes a new Image |
---|
| 475 | */ |
---|
[2586] | 476 | void Image::init() |
---|
| 477 | { |
---|
[2588] | 478 | is_option = 0; |
---|
| 479 | next = NULL; |
---|
[2586] | 480 | } |
---|
[2024] | 481 | |
---|
| 482 | |
---|
[2018] | 483 | /* OPTION */ |
---|
[2588] | 484 | |
---|
| 485 | /** |
---|
| 486 | * Initializes a new Option: nothing to do here |
---|
| 487 | */ |
---|
[2586] | 488 | void Option::init() |
---|
| 489 | { |
---|
| 490 | return; |
---|
| 491 | } |
---|
[2588] | 492 | |
---|
| 493 | /** |
---|
| 494 | * This sets The FlagName of an Option and defines its default Values |
---|
| 495 | !! Options will be saved if flagname is different from "" !! |
---|
| 496 | \param flagname the Name that will be displayed in the output |
---|
| 497 | \param defaultvalue the default Value for this Option (see definition of defaultvalue |
---|
| 498 | */ |
---|
[2018] | 499 | void Option::setFlagName (char* flagname, int defaultvalue) |
---|
| 500 | { |
---|
| 501 | flag_name = flagname; |
---|
| 502 | default_value = defaultvalue; |
---|
| 503 | cout << "Set Flagname of " << option_name << " to " << flagname << endl; |
---|
| 504 | } |
---|
| 505 | |
---|
[2588] | 506 | /** |
---|
| 507 | * see Option::setFlagName (char* flagname, int defaultvalue) |
---|
| 508 | \param flagname the Name that will be displayed in the output |
---|
| 509 | \param defaultvalue the default Value for this Option (see definition of defaultvalue |
---|
| 510 | \param flagnameshort a short flagname to be displayed in the output |
---|
| 511 | */ |
---|
[2018] | 512 | void Option::setFlagName (char* flagname, char* flagnameshort, int defaultvalue) |
---|
| 513 | { |
---|
| 514 | flag_name = flagname; |
---|
| 515 | flag_name_short = flagnameshort; |
---|
| 516 | default_value = defaultvalue; |
---|
| 517 | cout << "Set Flagname of " << option_name << " to " << flagname << endl; |
---|
| 518 | } |
---|
| 519 | |
---|
| 520 | |
---|
| 521 | /* BUTTON */ |
---|
[2588] | 522 | |
---|
| 523 | /** |
---|
| 524 | * Creates a new Button with a buttonname |
---|
| 525 | \param buttonname sets the Name of the Button |
---|
| 526 | */ |
---|
[2018] | 527 | Button::Button(char* buttonname) |
---|
| 528 | { |
---|
[2586] | 529 | this->init(); |
---|
| 530 | this->setTitle(buttonname); |
---|
| 531 | } |
---|
| 532 | |
---|
[2588] | 533 | /** |
---|
| 534 | * Initializes a new Button |
---|
| 535 | */ |
---|
[2586] | 536 | void Button::init(void) |
---|
| 537 | { |
---|
[2018] | 538 | is_option = 0; |
---|
| 539 | value = 0; |
---|
| 540 | next = NULL; |
---|
[2586] | 541 | option_name =""; |
---|
[2018] | 542 | flag_name = ""; |
---|
| 543 | flag_name_short = ""; |
---|
| 544 | default_value = 0; |
---|
[2586] | 545 | widget = gtk_button_new_with_label (""); |
---|
[2018] | 546 | } |
---|
| 547 | |
---|
[2588] | 548 | /** |
---|
| 549 | * Sets a new name to the Button |
---|
| 550 | \param title The name the Button should get |
---|
| 551 | */ |
---|
[2586] | 552 | void Button::setTitle (char *title) |
---|
| 553 | { |
---|
| 554 | option_name = title; |
---|
| 555 | gtk_button_set_label (GTK_BUTTON(widget), title); |
---|
| 556 | } |
---|
| 557 | |
---|
[2588] | 558 | /** |
---|
| 559 | * redraws the Button |
---|
| 560 | * not implemented yet |
---|
| 561 | */ |
---|
[2018] | 562 | void Button::redraw () |
---|
| 563 | { |
---|
| 564 | } |
---|
| 565 | |
---|
| 566 | /* CHECKBUTTON */ |
---|
[2588] | 567 | |
---|
| 568 | /** |
---|
| 569 | * Creates a new CheckButton with an ame |
---|
| 570 | \param buttonname The name the CheckButton should display. |
---|
| 571 | */ |
---|
[2018] | 572 | CheckButton::CheckButton (char* buttonname) |
---|
| 573 | { |
---|
[2586] | 574 | this->init(); |
---|
| 575 | this->setTitle(buttonname); |
---|
| 576 | |
---|
| 577 | this->connectSignal ("clicked", this->OptionChange); |
---|
| 578 | } |
---|
[2588] | 579 | |
---|
| 580 | /** |
---|
| 581 | * Destructs a CheckButton (not Implemented yet). |
---|
| 582 | */ |
---|
[2586] | 583 | CheckButton::~CheckButton() |
---|
| 584 | { |
---|
| 585 | } |
---|
| 586 | |
---|
[2588] | 587 | /** |
---|
| 588 | * Initiali a new CheckButton with default settings |
---|
| 589 | */ |
---|
[2586] | 590 | void CheckButton::init(void) |
---|
| 591 | { |
---|
[2018] | 592 | is_option = 1; |
---|
| 593 | value = 0; |
---|
| 594 | next = NULL; |
---|
[2586] | 595 | option_name = ""; |
---|
[2018] | 596 | flag_name = ""; |
---|
| 597 | flag_name_short = ""; |
---|
| 598 | default_value = 0; |
---|
[2586] | 599 | widget = gtk_check_button_new_with_label (""); |
---|
[2018] | 600 | } |
---|
[2588] | 601 | |
---|
| 602 | /** |
---|
| 603 | * Sets a new Title to a CheckButton |
---|
| 604 | \param title The new Name the CheckButton should display. |
---|
| 605 | */ |
---|
[2586] | 606 | void CheckButton::setTitle(char* title) |
---|
| 607 | { |
---|
| 608 | option_name = title; |
---|
| 609 | gtk_button_set_label(GTK_BUTTON(widget), title); |
---|
| 610 | } |
---|
[2018] | 611 | |
---|
[2588] | 612 | |
---|
| 613 | /** |
---|
| 614 | * Signal OptionChange writes the Value from the CheckButton to its Object-Database. |
---|
| 615 | \param widget The widget(CheckButton) that has a changed Value |
---|
| 616 | \param checkbutton the CheckButton-Object that should receive the change. |
---|
| 617 | */ |
---|
[2018] | 618 | gint CheckButton::OptionChange (GtkWidget *widget, Widget* checkbutton) |
---|
| 619 | { |
---|
| 620 | static_cast<CheckButton*>(checkbutton)->value = (int)gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON ((CheckButton*)checkbutton->widget)); |
---|
| 621 | flags->setTextFromFlags(orxonoxGUI); |
---|
| 622 | cout << static_cast<CheckButton*>(checkbutton)->option_name << " set to: " << static_cast<CheckButton*>(checkbutton)->value << endl; |
---|
| 623 | } |
---|
| 624 | |
---|
[2588] | 625 | /** |
---|
| 626 | * Redraws the CheckButton (if option has changed). |
---|
| 627 | * Example: if new settings are loaded the Button must be redrawn for the GUI to display that Change |
---|
| 628 | */ |
---|
[2018] | 629 | void CheckButton::redraw () |
---|
| 630 | { |
---|
| 631 | gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), value); |
---|
| 632 | } |
---|
| 633 | |
---|
| 634 | /* SLIDER */ |
---|
[2588] | 635 | |
---|
| 636 | /** |
---|
| 637 | * Creates a new Slider |
---|
| 638 | \param slidername The data-structure-name of the slider. |
---|
| 639 | \param start The minimal Value of the slider. |
---|
| 640 | \param end The maximal Value of the slider. |
---|
| 641 | */ |
---|
[2018] | 642 | Slider::Slider (char* slidername, int start, int end) |
---|
| 643 | { |
---|
[2586] | 644 | this->init(start, end); |
---|
| 645 | this->setValue(start); |
---|
| 646 | this->setTitle(slidername); |
---|
| 647 | this->connectSignal ("value_changed", this->OptionChange); |
---|
| 648 | } |
---|
| 649 | |
---|
[2588] | 650 | /** |
---|
| 651 | * Destructs a Slider (not implemented yet) |
---|
| 652 | */ |
---|
[2586] | 653 | Slider::~Slider() |
---|
| 654 | { |
---|
| 655 | } |
---|
| 656 | |
---|
[2588] | 657 | /** |
---|
| 658 | * Initializes a Slider with start and end Values |
---|
| 659 | * params: see Slider::Slider (char* slidername, int start, int end) |
---|
| 660 | */ |
---|
[2586] | 661 | void Slider::init(int start, int end) |
---|
| 662 | { |
---|
[2018] | 663 | is_option = 2; |
---|
| 664 | value = 0; |
---|
| 665 | next = NULL; |
---|
[2586] | 666 | option_name = ""; |
---|
[2018] | 667 | flag_name = ""; |
---|
| 668 | flag_name_short = ""; |
---|
| 669 | default_value = 0; |
---|
| 670 | widget = gtk_hscale_new_with_range (start, end, 5); |
---|
| 671 | } |
---|
[2588] | 672 | |
---|
| 673 | /** |
---|
| 674 | * Sets a new Title to the Slider |
---|
| 675 | \param title The new Name of the slider |
---|
| 676 | */ |
---|
[2586] | 677 | void Slider::setTitle(char* title) |
---|
| 678 | { |
---|
| 679 | option_name = title; |
---|
| 680 | } |
---|
[2588] | 681 | |
---|
| 682 | /** |
---|
| 683 | * Setting a new value to the Slider. |
---|
| 684 | * Maybe you also require a Slider::redraw() for this to display |
---|
| 685 | */ |
---|
[2586] | 686 | void Slider::setValue(int value) |
---|
| 687 | { |
---|
| 688 | this->value = value; |
---|
| 689 | } |
---|
[2018] | 690 | |
---|
[2588] | 691 | /** |
---|
| 692 | * Signal OptionChange writes the Value from the Slider to its Object-Database. |
---|
| 693 | \param widget The widget(Slider) that has a changed Value |
---|
| 694 | \param slider the Slider-Object that should receive the change. |
---|
| 695 | */ |
---|
[2018] | 696 | gint Slider::OptionChange (GtkWidget *widget, Widget* slider) |
---|
| 697 | { |
---|
| 698 | static_cast<Slider*>(slider)->value = (int)gtk_range_get_value (GTK_RANGE ((Slider*)slider->widget)); |
---|
| 699 | flags->setTextFromFlags(orxonoxGUI); |
---|
| 700 | cout << static_cast<Slider*>(slider)->option_name << " set to: "<< static_cast<Slider*>(slider)->value << endl; |
---|
| 701 | } |
---|
| 702 | |
---|
[2588] | 703 | /** |
---|
| 704 | * Redraws the widget |
---|
| 705 | * Example: see void CheckButton::redraw () |
---|
| 706 | */ |
---|
[2018] | 707 | void Slider::redraw () |
---|
| 708 | { |
---|
| 709 | gtk_range_set_value (GTK_RANGE (widget), value); |
---|
| 710 | } |
---|
| 711 | |
---|
[2588] | 712 | /* MENU */ |
---|
| 713 | |
---|
| 714 | /** |
---|
| 715 | * Creates a Menu-Item-list out of multiple input. |
---|
| 716 | * !! Consider, that the last input argument has to be "lastItem" for this to work!! |
---|
| 717 | \param menuname The Database-Name of this Menu |
---|
| 718 | \param ... items to be added to this Menu. !! Consider, that the last input argument has to be "lastItem" for this to work!! |
---|
| 719 | */ |
---|
[2018] | 720 | Menu::Menu (char* menuname, ...) |
---|
| 721 | { |
---|
[2587] | 722 | this->init(); |
---|
| 723 | this->setTitle(menuname); |
---|
| 724 | |
---|
| 725 | char *itemName; |
---|
| 726 | |
---|
| 727 | va_start (itemlist, menuname); |
---|
| 728 | while (strcmp (itemName = va_arg (itemlist, char*), "lastItem")) |
---|
| 729 | { |
---|
| 730 | this->addItem(itemName); |
---|
| 731 | } |
---|
| 732 | va_end(itemlist); |
---|
| 733 | |
---|
| 734 | gtk_option_menu_set_menu (GTK_OPTION_MENU (widget), menu); |
---|
| 735 | this->connectSignal ("changed", this->OptionChange); |
---|
| 736 | } |
---|
| 737 | |
---|
[2588] | 738 | /** |
---|
| 739 | * Initializes a new Menu with no items |
---|
| 740 | */ |
---|
[2587] | 741 | void Menu::init(void) |
---|
| 742 | { |
---|
[2018] | 743 | is_option = 2; |
---|
| 744 | value = 0; |
---|
| 745 | next = NULL; |
---|
| 746 | flag_name = ""; |
---|
| 747 | flag_name_short = ""; |
---|
| 748 | default_value = 0; |
---|
| 749 | widget = gtk_option_menu_new (); |
---|
[2587] | 750 | menu = gtk_menu_new (); |
---|
[2018] | 751 | |
---|
[2587] | 752 | } |
---|
[2018] | 753 | |
---|
[2588] | 754 | /** |
---|
| 755 | * Sets the Database-Name of this Menu |
---|
| 756 | \param title Database-Name to be set. |
---|
| 757 | */ |
---|
[2587] | 758 | void Menu::setTitle(char* title) |
---|
| 759 | { |
---|
| 760 | option_name = title; |
---|
[2018] | 761 | } |
---|
| 762 | |
---|
[2588] | 763 | /** |
---|
| 764 | * appends a new Item to the Menu-List. |
---|
| 765 | \param itemName the itemName to be appendet. |
---|
| 766 | */ |
---|
[2587] | 767 | void Menu::addItem (char* itemName) |
---|
[2586] | 768 | { |
---|
[2587] | 769 | item = gtk_menu_item_new_with_label (itemName); |
---|
| 770 | gtk_menu_shell_append(GTK_MENU_SHELL (menu), item); |
---|
[2586] | 771 | } |
---|
| 772 | |
---|
[2588] | 773 | /** |
---|
| 774 | * Signal OptionChange writes the Value from the Menu to its Object-Database. |
---|
| 775 | \param widget The widget(Menu) that has a changed Value |
---|
| 776 | \param menu the Menu-Object that should receive the change. |
---|
| 777 | */gint Menu::OptionChange (GtkWidget *widget, Widget* menu) |
---|
[2018] | 778 | { |
---|
| 779 | static_cast<Menu*>(menu)->value = (int)gtk_option_menu_get_history (GTK_OPTION_MENU (menu->widget)); |
---|
| 780 | flags->setTextFromFlags(orxonoxGUI); |
---|
| 781 | cout << static_cast<Menu*>(menu)->option_name << " changed to : " << static_cast<Menu*>(menu)->value << endl; |
---|
| 782 | } |
---|
| 783 | |
---|
[2588] | 784 | /** |
---|
| 785 | * Redraws the widget |
---|
| 786 | * Example: see void CheckButton::redraw () |
---|
| 787 | */ |
---|
[2018] | 788 | void Menu::redraw () |
---|
| 789 | { |
---|
| 790 | gtk_option_menu_set_history (GTK_OPTION_MENU (widget), value); |
---|
| 791 | } |
---|
| 792 | |
---|
[2588] | 793 | /** |
---|
| 794 | * Creates a new default Label with no Text. |
---|
| 795 | * You migth consider adding Label::setTitle with this. |
---|
| 796 | */ |
---|
[2018] | 797 | Label:: Label () |
---|
| 798 | { |
---|
[2586] | 799 | this->init(); |
---|
[2018] | 800 | } |
---|
| 801 | |
---|
[2588] | 802 | /** |
---|
| 803 | * Creates a new Label with a Text. |
---|
| 804 | \param text The text to be displayed. |
---|
| 805 | */ |
---|
[2018] | 806 | Label:: Label (char* text) |
---|
| 807 | { |
---|
| 808 | is_option = 0; |
---|
| 809 | next = NULL; |
---|
| 810 | widget = gtk_label_new (text); |
---|
| 811 | gtk_label_set_line_wrap (GTK_LABEL(widget), TRUE); |
---|
| 812 | } |
---|
| 813 | |
---|
[2588] | 814 | /** |
---|
| 815 | * Destructs a Label |
---|
| 816 | */ |
---|
[2018] | 817 | Label::~Label () |
---|
| 818 | {} |
---|
[2586] | 819 | |
---|
[2588] | 820 | /** |
---|
| 821 | * initializes a new Label |
---|
| 822 | */ |
---|
[2586] | 823 | void Label::init(void) |
---|
| 824 | { |
---|
| 825 | is_option = 0; |
---|
| 826 | next = NULL; |
---|
| 827 | widget = gtk_label_new (""); |
---|
| 828 | gtk_widget_set_usize (widget, 260, 60); |
---|
| 829 | gtk_label_set_line_wrap (GTK_LABEL(widget), TRUE); |
---|
| 830 | } |
---|
[2588] | 831 | |
---|
| 832 | /** |
---|
| 833 | * Sets a new Text to a Label. |
---|
| 834 | \param text The text to be inserted into the Label. |
---|
| 835 | */ |
---|
[2018] | 836 | void Label::setText (char * text) |
---|
| 837 | { |
---|
| 838 | gtk_label_set_text (GTK_LABEL (this->widget), text); |
---|
| 839 | } |
---|
| 840 | |
---|
[2588] | 841 | /** |
---|
| 842 | * get the Text of a Label |
---|
| 843 | \return The Text the Label holds. |
---|
| 844 | */ |
---|
[2018] | 845 | char* Label::getText () |
---|
| 846 | { |
---|
| 847 | return ((char*)gtk_label_get_text (GTK_LABEL (this->widget))); |
---|
| 848 | } |
---|