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