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