[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 | |
---|
[3165] | 41 | #ifdef HAVE_GTK2 |
---|
[3187] | 42 | /** |
---|
| 43 | \brief Initializes the Guis GTK-stuff. |
---|
| 44 | \param argc the argument count. |
---|
| 45 | \param argv The Argument strings. |
---|
| 46 | */ |
---|
[3164] | 47 | bool initGTK(int argc, char *argv[]) |
---|
| 48 | { |
---|
[3271] | 49 | #ifdef HAVE_GTHREAD |
---|
| 50 | PRINTF(3)("Initializing the ThreadSystem of the GUI\n"); |
---|
| 51 | g_thread_init(NULL); |
---|
| 52 | gdk_threads_init(); |
---|
| 53 | #endif /* HAVE_GTHREAD */ |
---|
[3164] | 54 | gtk_init (&argc, &argv); |
---|
| 55 | gtk_rc_parse( "rc" ); |
---|
| 56 | } |
---|
[3187] | 57 | |
---|
| 58 | /** |
---|
| 59 | \brief enters the GTK-main-loop |
---|
| 60 | */ |
---|
[3164] | 61 | bool mainloopGTK(void) |
---|
| 62 | { |
---|
[3271] | 63 | gdk_threads_enter(); |
---|
[3164] | 64 | gtk_main(); |
---|
[3271] | 65 | gdk_threads_leave(); |
---|
[3289] | 66 | delete Window::mainWindow; |
---|
[3164] | 67 | } |
---|
[3165] | 68 | #endif /* HAVE_GTK2 */ |
---|
| 69 | |
---|
[3289] | 70 | |
---|
| 71 | ////////////////////////////// |
---|
| 72 | /// DEFINING WIDGET-CLASES /// |
---|
| 73 | ////////////////////////////// |
---|
| 74 | |
---|
[3144] | 75 | /* WIDGET */ |
---|
| 76 | |
---|
| 77 | /** |
---|
| 78 | \brief deletes any given Widget |
---|
| 79 | This is still pretty crappy. |
---|
| 80 | */ |
---|
| 81 | Widget::~Widget() |
---|
| 82 | { |
---|
[3289] | 83 | this->destroy(); |
---|
[3144] | 84 | } |
---|
| 85 | |
---|
| 86 | /** |
---|
| 87 | \brief Initializes a widget. |
---|
| 88 | Initializes the next Pointer and the other Widget-specific Defaults. |
---|
| 89 | */ |
---|
| 90 | void Widget::init() |
---|
| 91 | { |
---|
| 92 | next = NULL; |
---|
[3290] | 93 | this->title = NULL; |
---|
[3144] | 94 | return; |
---|
| 95 | } |
---|
| 96 | |
---|
| 97 | /** |
---|
[3289] | 98 | \brief Destroys a Widget |
---|
| 99 | */ |
---|
| 100 | void Widget::destroy(void) |
---|
| 101 | { |
---|
[3290] | 102 | if (this->title) |
---|
[3289] | 103 | { |
---|
[3290] | 104 | delete []this->title; |
---|
[3289] | 105 | } |
---|
| 106 | |
---|
| 107 | PRINTF(4)("deleting the Widget part.\n"); |
---|
| 108 | |
---|
| 109 | PRINTF(4)("deleting recursively\n"); |
---|
| 110 | |
---|
| 111 | // deleting next item if existent |
---|
| 112 | if (this->next) |
---|
| 113 | delete this->next; |
---|
| 114 | this->next = NULL; |
---|
| 115 | |
---|
| 116 | //! \todo not hiding widget, deleting. |
---|
| 117 | // this->hide(); |
---|
[3291] | 118 | // delete this->widget; |
---|
[3289] | 119 | } |
---|
| 120 | |
---|
| 121 | /** |
---|
[3144] | 122 | \brief makes the widget visible. |
---|
| 123 | */ |
---|
| 124 | void Widget::show() |
---|
| 125 | { |
---|
[3165] | 126 | #ifdef HAVE_GTK2 |
---|
[3144] | 127 | gtk_widget_show (this->widget); |
---|
[3165] | 128 | #endif /* HAVE_GTK2 */ |
---|
[3144] | 129 | } |
---|
| 130 | |
---|
| 131 | /** |
---|
| 132 | \brief hides the widget. |
---|
| 133 | */ |
---|
| 134 | void Widget::hide() |
---|
| 135 | { |
---|
[3165] | 136 | #ifdef HAVE_GTK2 |
---|
[3144] | 137 | gtk_widget_hide (this->widget); |
---|
[3165] | 138 | #endif /* HAVE_GTK2 */ |
---|
[3144] | 139 | } |
---|
| 140 | |
---|
| 141 | /** |
---|
| 142 | \brief Sets the resolution of a specific widget to the given size. |
---|
| 143 | \param width the width of the widget to set. |
---|
| 144 | \param height the height of the widget to set. |
---|
| 145 | */ |
---|
| 146 | void Widget::setSize(int width, int height) |
---|
| 147 | { |
---|
[3165] | 148 | #ifdef HAVE_GTK2 |
---|
[3144] | 149 | gtk_widget_set_usize (this->widget, width, height); |
---|
[3165] | 150 | #endif /* HAVE_GTK2 */ |
---|
[3144] | 151 | } |
---|
| 152 | |
---|
| 153 | /** |
---|
| 154 | \brief Moves through all the Widgets downwards from this and executes the function on them. |
---|
[3275] | 155 | \param function must be of type void and takes a Widget* as an Input. |
---|
[3144] | 156 | */ |
---|
[3292] | 157 | void Widget::walkThrough (void (*function)(Widget*), unsigned int depth) |
---|
[3144] | 158 | { |
---|
| 159 | function(this); |
---|
[3147] | 160 | if (this->isOption < 0) |
---|
[3144] | 161 | { |
---|
[3292] | 162 | static_cast<Packer*>(this)->down->walkThrough (function, depth+1); |
---|
[3144] | 163 | } |
---|
| 164 | |
---|
[3292] | 165 | if (this->next && depth != 0) |
---|
| 166 | this->next->walkThrough(function, depth); |
---|
[3144] | 167 | } |
---|
| 168 | |
---|
[3292] | 169 | /** |
---|
| 170 | \brief Moves through all the Widgets downwards from this and executes the function on them. |
---|
| 171 | \param function must be of type void and takes a Widget* as an Input. |
---|
| 172 | \param data Additional Data you want to pass to the function. |
---|
| 173 | */ |
---|
| 174 | void Widget::walkThrough (void (*function)(Widget*, void*), void* data, unsigned int depth) |
---|
| 175 | { |
---|
| 176 | function(this, data); |
---|
| 177 | if (this->isOption < 0) |
---|
| 178 | { |
---|
| 179 | static_cast<Packer*>(this)->down->walkThrough(function, data, depth+1); |
---|
| 180 | } |
---|
| 181 | if (this->next && depth != 0) |
---|
| 182 | this->next->walkThrough(function, data, depth); |
---|
| 183 | } |
---|
| 184 | |
---|
[3144] | 185 | /** |
---|
| 186 | \brief This is for listing the option of "widget" |
---|
| 187 | \param widget specifies the widget that should be listed |
---|
| 188 | */ |
---|
| 189 | void Widget::listOptions (Widget* widget) |
---|
| 190 | { |
---|
[3166] | 191 | if (widget->isOption < 0 && static_cast<Packer*>(widget)->groupName) |
---|
| 192 | cout << "[" << static_cast<Packer*>(widget)->groupName << "]\n"; |
---|
| 193 | if (widget->isOption >= 1 && widget->isOption <= 3) |
---|
[3290] | 194 | cout << " " << static_cast<Option*>(widget)->title <<" is : " << static_cast<Option*>(widget)->value <<endl; |
---|
[3166] | 195 | else if (widget->isOption == 5) |
---|
[3290] | 196 | cout << " " << static_cast<Option*>(widget)->title <<" is : " << static_cast<OptionLabel*>(widget)->cValue <<endl; |
---|
[3144] | 197 | } |
---|
| 198 | |
---|
| 199 | /** |
---|
| 200 | \brief This is for setting the option of "widget" |
---|
| 201 | \param widget specifies the widget that should be set. |
---|
| 202 | */ |
---|
| 203 | void Widget::setOptions (Widget* widget) |
---|
| 204 | { |
---|
[3147] | 205 | if (widget->isOption >= 1) |
---|
[3292] | 206 | static_cast<Option*>(widget)->redraw(); |
---|
[3144] | 207 | } |
---|
| 208 | |
---|
[3165] | 209 | #ifdef HAVE_GTK2 |
---|
[3289] | 210 | /** |
---|
| 211 | \brief Connect any signal to any given Sub-widget |
---|
| 212 | */ |
---|
| 213 | gulong Widget::connectSignal (char* event, gint (*signal)(GtkWidget*, GdkEvent*, void *)) |
---|
| 214 | { |
---|
| 215 | return g_signal_connect (G_OBJECT (this->widget), event, G_CALLBACK (signal), NULL); |
---|
| 216 | } |
---|
[3187] | 217 | |
---|
| 218 | /** |
---|
[3289] | 219 | \brief Connect a signal with additionally passing the whole Object |
---|
| 220 | */ |
---|
| 221 | gulong Widget::connectSignal (char* event, gint (*signal)( GtkWidget*, Widget *)) |
---|
| 222 | { |
---|
| 223 | return g_signal_connect (G_OBJECT (this->widget), event, G_CALLBACK (signal), this); |
---|
| 224 | } |
---|
| 225 | |
---|
| 226 | /** |
---|
| 227 | \brief Connect a signal with additionally passing a whole external Object |
---|
| 228 | */ |
---|
| 229 | gulong Widget::connectSignal (char* event, void* extObj, gint (*signal)(GtkWidget*, GdkEvent*, void *)) |
---|
| 230 | { |
---|
| 231 | return g_signal_connect (G_OBJECT (this->widget), event, G_CALLBACK (signal), extObj); |
---|
| 232 | } |
---|
| 233 | |
---|
| 234 | /** |
---|
| 235 | \brief Connect a signal with additionally passing a whole external Object |
---|
| 236 | */ |
---|
| 237 | gulong Widget::connectSignal (char* event, void* extObj, gint (*signal)(GtkWidget*, GdkEventKey*, void *)) |
---|
| 238 | { |
---|
| 239 | return g_signal_connect (G_OBJECT (this->widget), event, G_CALLBACK (signal), extObj); |
---|
| 240 | } |
---|
| 241 | |
---|
| 242 | void Widget::disconnectSignal (gulong signalID) |
---|
| 243 | { |
---|
| 244 | g_signal_handler_disconnect (G_OBJECT (this->widget), signalID); |
---|
| 245 | } |
---|
| 246 | |
---|
| 247 | /** |
---|
[3187] | 248 | \brief Signal that does absolutely nothing |
---|
| 249 | \param widget The widget that initiated the Signal |
---|
| 250 | \param event The event-type. |
---|
| 251 | \param nothing nothin. |
---|
| 252 | */ |
---|
[3157] | 253 | gint Widget::doNothingSignal (GtkWidget *widget, GdkEvent* event, void* nothing) |
---|
| 254 | { |
---|
| 255 | } |
---|
[3165] | 256 | #endif /* HAVE_GTK2 */ |
---|
[3157] | 257 | |
---|
[3144] | 258 | //void deleteWidget(Widget* lastWidget) |
---|
| 259 | |
---|
| 260 | |
---|
| 261 | /* PACKERS */ |
---|
| 262 | |
---|
| 263 | /** |
---|
| 264 | \brief Initializes a Packer. |
---|
[3187] | 265 | |
---|
[3144] | 266 | Sets the down-pinter to NULL and other PackerSpecific-values to their defaults. |
---|
| 267 | */ |
---|
| 268 | void Packer::init (void) |
---|
| 269 | { |
---|
| 270 | down = NULL; |
---|
[3161] | 271 | groupName = NULL; |
---|
[3144] | 272 | |
---|
| 273 | |
---|
| 274 | static_cast<Widget*>(this)->init(); |
---|
| 275 | return; |
---|
| 276 | } |
---|
| 277 | |
---|
| 278 | /** |
---|
[3289] | 279 | \brief Destroys a Packer. |
---|
| 280 | */ |
---|
| 281 | void Packer::destroy(void) |
---|
| 282 | { |
---|
| 283 | PRINTF(4)("deleting the Packer part.\n"); |
---|
| 284 | |
---|
| 285 | if (groupName) |
---|
| 286 | delete []groupName; |
---|
| 287 | |
---|
| 288 | //deleting recursively. |
---|
| 289 | if (this->down) |
---|
| 290 | delete this->down; |
---|
| 291 | this->down = NULL; |
---|
| 292 | |
---|
| 293 | static_cast<Widget*>(this)->destroy(); |
---|
| 294 | } |
---|
| 295 | |
---|
| 296 | /** |
---|
[3144] | 297 | \brief Sets the group name under which all the lower widgets of this will be saved. |
---|
| 298 | \param name The name of the group. |
---|
| 299 | */ |
---|
| 300 | void Packer::setGroupName (char* name) |
---|
| 301 | { |
---|
[3161] | 302 | if (groupName) |
---|
| 303 | delete groupName; |
---|
| 304 | groupName = new char [strlen(name)+1]; |
---|
| 305 | strcpy(groupName, name); |
---|
[3144] | 306 | } |
---|
| 307 | |
---|
| 308 | /** |
---|
| 309 | \brief Retrieves the group name under which all the lower widgets of this will be saved. |
---|
| 310 | \returns name The name of the group. |
---|
| 311 | */ |
---|
| 312 | char* Packer::getGroupName (void) |
---|
| 313 | { |
---|
| 314 | return groupName; |
---|
| 315 | } |
---|
| 316 | |
---|
| 317 | /* CONTAINERS */ |
---|
| 318 | |
---|
| 319 | /** |
---|
| 320 | \brief Initializes a Container. |
---|
[3187] | 321 | |
---|
[3144] | 322 | sets the Container-Specific defaults. |
---|
| 323 | */ |
---|
| 324 | void Container::init (void) |
---|
| 325 | { |
---|
[3147] | 326 | isOption = -1; |
---|
[3144] | 327 | |
---|
| 328 | static_cast<Packer*>(this)->init(); |
---|
| 329 | |
---|
| 330 | return; |
---|
| 331 | } |
---|
| 332 | |
---|
| 333 | /** |
---|
[3289] | 334 | \brief Destroys a Container. |
---|
| 335 | */ |
---|
| 336 | void Container::destroy(void) |
---|
| 337 | { |
---|
| 338 | PRINTF(4)("deleting the Container part.\n"); |
---|
| 339 | |
---|
| 340 | static_cast<Packer*>(this)->destroy(); |
---|
| 341 | } |
---|
| 342 | |
---|
| 343 | /** |
---|
[3144] | 344 | \briefFills a Container with lowerWidget. |
---|
[3187] | 345 | \param lowerWidget the Widget that should be filled into the Container. |
---|
| 346 | |
---|
[3144] | 347 | It does this by filling up the down pointer only if down points to NULL. |
---|
| 348 | */ |
---|
| 349 | void Container::fill (Widget *lowerWidget) |
---|
| 350 | { |
---|
| 351 | if (this->down == NULL) |
---|
| 352 | { |
---|
[3165] | 353 | #ifdef HAVE_GTK2 |
---|
[3144] | 354 | gtk_container_add (GTK_CONTAINER (this->widget), lowerWidget->widget); |
---|
[3165] | 355 | #endif /* HAVE_GTK2 */ |
---|
[3144] | 356 | this->down = lowerWidget; |
---|
| 357 | } |
---|
| 358 | else |
---|
[3289] | 359 | PRINTF(1)("!!error!! You try to put more than one Widget into a Container. \nNot including this item.\nThis is only possible with Boxes.\n"); |
---|
[3144] | 360 | } |
---|
| 361 | |
---|
| 362 | // gtk_container_set_border_width (GTK_CONTAINER (widget), 5); |
---|
| 363 | |
---|
| 364 | /* WINDOW */ |
---|
| 365 | |
---|
[3148] | 366 | Window* Window::mainWindow = NULL; |
---|
| 367 | |
---|
[3187] | 368 | /** |
---|
| 369 | \brief Adds a new Window Windows to the List of Windows. |
---|
| 370 | \param windowToAdd The Windows that should be added to the List |
---|
| 371 | \todo this instead of windowToAdd (possibly) |
---|
| 372 | */ |
---|
[3148] | 373 | void Window::addWindow(Window* windowToAdd) |
---|
| 374 | { |
---|
| 375 | if (!mainWindow) |
---|
| 376 | { |
---|
| 377 | mainWindow = windowToAdd; |
---|
| 378 | return; |
---|
| 379 | } |
---|
| 380 | |
---|
| 381 | Widget* tmpWindow = mainWindow; |
---|
| 382 | while (tmpWindow->next) |
---|
| 383 | tmpWindow = tmpWindow->next; |
---|
| 384 | tmpWindow->next = windowToAdd; |
---|
| 385 | |
---|
| 386 | return; |
---|
| 387 | } |
---|
| 388 | |
---|
| 389 | |
---|
[3144] | 390 | /** |
---|
| 391 | \brief Creating a new Window without a Name |
---|
| 392 | */ |
---|
| 393 | Window::Window (void) |
---|
| 394 | { |
---|
| 395 | this->init(); |
---|
| 396 | } |
---|
| 397 | |
---|
| 398 | /** |
---|
| 399 | \brief Creating a Window with a name |
---|
| 400 | \param windowName the name the window should get. |
---|
| 401 | */ |
---|
[3289] | 402 | |
---|
[3144] | 403 | Window::Window (char* windowName) |
---|
| 404 | { |
---|
| 405 | this->init(); |
---|
| 406 | this->setTitle (windowName); |
---|
| 407 | } |
---|
| 408 | |
---|
| 409 | /** |
---|
[3289] | 410 | \brief Destructs a Window. |
---|
| 411 | */ |
---|
| 412 | Window::~Window(void) |
---|
| 413 | { |
---|
| 414 | this->destroy(); |
---|
| 415 | } |
---|
| 416 | |
---|
| 417 | /** |
---|
[3144] | 418 | \brief initializes a new Window |
---|
| 419 | */ |
---|
| 420 | void Window::init() |
---|
| 421 | { |
---|
[3148] | 422 | if (!mainWindow) |
---|
| 423 | mainWindow = this; |
---|
[3152] | 424 | |
---|
[3144] | 425 | isOpen = false; |
---|
| 426 | |
---|
| 427 | static_cast<Container*>(this)->init(); |
---|
| 428 | |
---|
[3165] | 429 | #ifdef HAVE_GTK2 |
---|
[3144] | 430 | widget = gtk_window_new (GTK_WINDOW_TOPLEVEL); |
---|
| 431 | gtk_window_set_policy (GTK_WINDOW(widget), TRUE, TRUE, TRUE); |
---|
| 432 | #if !defined(__WIN32__) |
---|
[3154] | 433 | // gtk_window_set_decorated (GTK_WINDOW (widget), FALSE); |
---|
[3144] | 434 | #endif |
---|
| 435 | gtk_container_set_border_width (GTK_CONTAINER (widget), 3); |
---|
[3165] | 436 | #endif /* HAVE_GTK2 */ |
---|
[3144] | 437 | } |
---|
| 438 | |
---|
| 439 | /** |
---|
[3289] | 440 | \brief Destroys a Window. |
---|
| 441 | */ |
---|
| 442 | void Window::destroy(void) |
---|
| 443 | { |
---|
[3290] | 444 | if (this->title) |
---|
| 445 | PRINTF(3)("deleting the Window: %s\n", this->title); |
---|
[3289] | 446 | else |
---|
| 447 | PRINTF(3)("deleting the Window.\n"); |
---|
| 448 | |
---|
[3291] | 449 | this->hide(); |
---|
[3289] | 450 | static_cast<Container*>(this)->destroy(); |
---|
| 451 | |
---|
| 452 | } |
---|
| 453 | |
---|
| 454 | /** |
---|
[3144] | 455 | \brief Shows all Widgets that are included within this->widget. |
---|
| 456 | */ |
---|
| 457 | void Window::showall () |
---|
| 458 | { |
---|
| 459 | if (!isOpen) |
---|
| 460 | { |
---|
[3166] | 461 | // printf ("showall\n"); |
---|
[3165] | 462 | #ifdef HAVE_GTK2 |
---|
[3144] | 463 | gtk_widget_show_all (widget); |
---|
[3165] | 464 | #endif /* HAVE_GTK2 */ |
---|
| 465 | isOpen = true; |
---|
[3144] | 466 | } |
---|
| 467 | else |
---|
| 468 | { |
---|
[3166] | 469 | // printf ("showone\n"); |
---|
[3165] | 470 | #ifdef HAVE_GTK2 |
---|
[3144] | 471 | gtk_widget_show (widget); |
---|
[3165] | 472 | #endif /* HAVE_GTK2 */ |
---|
[3144] | 473 | } |
---|
| 474 | } |
---|
| 475 | |
---|
| 476 | /** |
---|
| 477 | \brief Set The Window-title to title |
---|
| 478 | \param title title the Window should get. |
---|
| 479 | */ |
---|
| 480 | void Window::setTitle (char* title) |
---|
| 481 | { |
---|
[3290] | 482 | if (this->title) |
---|
| 483 | delete []this->title; |
---|
| 484 | this->title = new char[strlen(title)+1]; |
---|
| 485 | strcpy(this->title, title); |
---|
[3165] | 486 | #ifdef HAVE_GTK2 |
---|
[3144] | 487 | gtk_window_set_title (GTK_WINDOW (widget), title); |
---|
[3165] | 488 | #endif /* HAVE_GTK2 */ |
---|
[3144] | 489 | } |
---|
| 490 | |
---|
| 491 | /** |
---|
[3147] | 492 | \brief opens up a Window and fixes the Focus to it |
---|
| 493 | */ |
---|
| 494 | void Window::open() |
---|
| 495 | { |
---|
[3148] | 496 | if (this != mainWindow) |
---|
| 497 | { |
---|
| 498 | isOpen = true; |
---|
[3165] | 499 | #ifdef HAVE_GTK2 |
---|
[3148] | 500 | gtk_widget_show_all(widget); |
---|
| 501 | gtk_grab_add(widget); |
---|
[3165] | 502 | #endif /* HAVE_GTK2 */ |
---|
[3148] | 503 | } |
---|
[3147] | 504 | } |
---|
| 505 | |
---|
| 506 | /** |
---|
| 507 | \brief closes up a Window and removes the Focus from it |
---|
| 508 | */ |
---|
| 509 | void Window::close() |
---|
| 510 | { |
---|
[3148] | 511 | if (this != mainWindow) |
---|
| 512 | { |
---|
| 513 | isOpen = false; |
---|
[3165] | 514 | #ifdef HAVE_GTK2 |
---|
[3148] | 515 | gtk_grab_remove(widget); |
---|
| 516 | gtk_widget_hide (widget); |
---|
[3165] | 517 | #endif /* HAVE_GTK2 */ |
---|
[3148] | 518 | } |
---|
[3147] | 519 | } |
---|
| 520 | |
---|
[3165] | 521 | #ifdef HAVE_GTK2 |
---|
[3147] | 522 | /** |
---|
[3153] | 523 | \brief opens up a window (not topmost Window). |
---|
| 524 | this is the Signal that does it. !!SIGNALS ARE STATIC!! |
---|
[3187] | 525 | \param widget the widget that did it. |
---|
| 526 | \param event the event that did it. |
---|
[3153] | 527 | \param window the Window that should be opened |
---|
| 528 | */ |
---|
| 529 | gint Window::windowOpen (GtkWidget *widget, GdkEvent* event, void* window) |
---|
| 530 | { |
---|
| 531 | static_cast<Window*>(window)->open(); |
---|
| 532 | } |
---|
| 533 | |
---|
| 534 | /** |
---|
| 535 | \brief closes a window (not topmost Window). |
---|
| 536 | this is the Signal that does it. !!SIGNALS ARE STATIC!! |
---|
| 537 | \param widget the widget that did it! |
---|
| 538 | \param event the event that did it! |
---|
| 539 | \param window the Window that should be closed |
---|
| 540 | */ |
---|
| 541 | gint Window::windowClose (GtkWidget *widget, GdkEvent* event, void* window) |
---|
| 542 | { |
---|
| 543 | static_cast<Window*>(window)->close(); |
---|
| 544 | } |
---|
[3156] | 545 | |
---|
[3153] | 546 | /** |
---|
[3144] | 547 | * Quits the orxonox_GUI. |
---|
| 548 | * This can be called as a Signal and is therefor static |
---|
| 549 | \param widget The widget that called this function |
---|
| 550 | \param event the event that happened to execute this function |
---|
| 551 | \param data some data passed with the Signal |
---|
| 552 | */ |
---|
| 553 | gint Window::orxonox_gui_quit (GtkWidget *widget, GdkEvent *event, gpointer data) |
---|
| 554 | { |
---|
| 555 | if (exec->shouldsave()) |
---|
[3161] | 556 | exec->writeToFile (Window::mainWindow); |
---|
[3144] | 557 | |
---|
| 558 | gtk_main_quit(); |
---|
| 559 | return FALSE; |
---|
| 560 | } |
---|
[3165] | 561 | #endif /* HAVE_GTK2 */ |
---|
[3144] | 562 | |
---|
| 563 | |
---|
| 564 | /* FRAME */ |
---|
| 565 | |
---|
| 566 | /** |
---|
| 567 | \brief Creates a new Frame without a name |
---|
| 568 | */ |
---|
| 569 | Frame::Frame (void) |
---|
| 570 | { |
---|
| 571 | this->init(); |
---|
| 572 | } |
---|
| 573 | |
---|
| 574 | /** |
---|
| 575 | \brief Creates a new Frame with name title |
---|
| 576 | */ |
---|
| 577 | Frame::Frame (char* title) |
---|
| 578 | { |
---|
| 579 | this->init(); |
---|
| 580 | this->setTitle(title); |
---|
| 581 | } |
---|
| 582 | |
---|
[3289] | 583 | /** |
---|
| 584 | \brief destrcucts a Frame |
---|
| 585 | */ |
---|
| 586 | Frame::~Frame() |
---|
| 587 | { |
---|
| 588 | this->destroy(); |
---|
| 589 | } |
---|
| 590 | |
---|
[3144] | 591 | /** |
---|
| 592 | \brief Initializes a new Frame with default settings |
---|
| 593 | */ |
---|
| 594 | void Frame::init() |
---|
| 595 | { |
---|
| 596 | static_cast<Container*>(this)->init(); |
---|
[3165] | 597 | |
---|
| 598 | #ifdef HAVE_GTK2 |
---|
[3144] | 599 | widget = gtk_frame_new (""); |
---|
| 600 | gtk_container_set_border_width (GTK_CONTAINER (widget), 3); |
---|
[3165] | 601 | #endif /* HAVE_GTK2 */ |
---|
[3144] | 602 | } |
---|
| 603 | |
---|
| 604 | /** |
---|
[3289] | 605 | \brief Destroys a Frame. |
---|
| 606 | */ |
---|
| 607 | void Frame::destroy(void) |
---|
| 608 | { |
---|
[3290] | 609 | if (this->title) |
---|
| 610 | PRINTF(3)("deleting the Frame: %s\n", this->title); |
---|
[3289] | 611 | else |
---|
| 612 | PRINTF(3)("deleting the Frame.\n"); |
---|
| 613 | |
---|
| 614 | static_cast<Container*>(this)->destroy(); |
---|
| 615 | } |
---|
| 616 | |
---|
| 617 | /** |
---|
[3144] | 618 | \brief Sets the Frames name to title |
---|
| 619 | \param title The title the Frame should get. |
---|
| 620 | */ |
---|
| 621 | void Frame::setTitle (char* title) |
---|
| 622 | { |
---|
[3290] | 623 | if (this->title) |
---|
| 624 | delete []this->title; |
---|
| 625 | this->title = new char[strlen(title)+1]; |
---|
| 626 | strcpy(this->title, title); |
---|
[3165] | 627 | #ifdef HAVE_GTK2 |
---|
[3144] | 628 | gtk_frame_set_label (GTK_FRAME (widget), title); |
---|
[3165] | 629 | #endif /* HAVE_GTK2 */ |
---|
[3144] | 630 | } |
---|
| 631 | |
---|
| 632 | // EVENTBOX // |
---|
| 633 | |
---|
| 634 | /** |
---|
| 635 | \brief Creates a new EventBox with default settings. |
---|
| 636 | */ |
---|
[3289] | 637 | EventBox::EventBox (void) |
---|
[3144] | 638 | { |
---|
| 639 | this->init(); |
---|
| 640 | } |
---|
[3263] | 641 | |
---|
[3144] | 642 | /** |
---|
| 643 | \brief Creates a new EventBox with name title |
---|
| 644 | \param title title the Eventbox should get (only data-structure-internal) |
---|
| 645 | */ |
---|
| 646 | EventBox::EventBox (char* title) |
---|
| 647 | { |
---|
| 648 | this->init(); |
---|
| 649 | this->setTitle(title); |
---|
| 650 | } |
---|
| 651 | |
---|
| 652 | /** |
---|
[3292] | 653 | \brief destructs an EventBox. |
---|
[3289] | 654 | */ |
---|
| 655 | EventBox::~EventBox(void) |
---|
| 656 | { |
---|
| 657 | this->destroy(); |
---|
| 658 | |
---|
| 659 | } |
---|
| 660 | |
---|
| 661 | /** |
---|
[3144] | 662 | \brief Initializes a new EventBox |
---|
| 663 | */ |
---|
| 664 | void EventBox::init(void) |
---|
| 665 | { |
---|
[3147] | 666 | isOption = -1; |
---|
[3144] | 667 | |
---|
| 668 | static_cast<Container*>(this)->init(); |
---|
| 669 | |
---|
[3165] | 670 | #ifdef HAVE_GTK2 |
---|
[3144] | 671 | widget = gtk_event_box_new (); |
---|
| 672 | gtk_container_set_border_width (GTK_CONTAINER (widget), 3); |
---|
[3165] | 673 | #endif /* HAVE_GTK2 */ |
---|
[3144] | 674 | } |
---|
| 675 | |
---|
| 676 | /** |
---|
[3289] | 677 | \brief Destroys an EventBox. |
---|
| 678 | */ |
---|
| 679 | void EventBox::destroy(void) |
---|
| 680 | { |
---|
[3290] | 681 | if (this->title) |
---|
| 682 | PRINTF(3)("deleting the EventBox: %s\n", this->title); |
---|
[3289] | 683 | else |
---|
| 684 | PRINTF(3)("deleting the EventBox.\n"); |
---|
| 685 | |
---|
| 686 | static_cast<Container*>(this)->destroy(); |
---|
| 687 | } |
---|
| 688 | |
---|
| 689 | /** |
---|
[3144] | 690 | \brief Sets the Title of the EventBox (not implemented) |
---|
| 691 | \param title Name the EventBox should get (only datastructure-internal). |
---|
| 692 | */ |
---|
| 693 | void EventBox::setTitle (char* title) |
---|
| 694 | { |
---|
[3290] | 695 | if (this->title) |
---|
| 696 | delete []this->title; |
---|
| 697 | this->title = new char[strlen(title)+1]; |
---|
| 698 | strcpy(this->title, title); |
---|
[3144] | 699 | } |
---|
| 700 | |
---|
| 701 | /* BOX */ |
---|
| 702 | |
---|
| 703 | /** |
---|
| 704 | \brief Creates a new horizontal Box |
---|
| 705 | */ |
---|
| 706 | Box::Box (void) |
---|
| 707 | { |
---|
| 708 | this->init('h'); |
---|
| 709 | } |
---|
| 710 | |
---|
| 711 | /** |
---|
| 712 | \brief Creates a new Box of type boxtype |
---|
| 713 | \param boxtype if 'v' the Box will be vertically, if 'h' the Box will be horizontally |
---|
| 714 | */ |
---|
| 715 | Box::Box (char boxtype) |
---|
| 716 | { |
---|
| 717 | this->init(boxtype); |
---|
| 718 | } |
---|
| 719 | |
---|
| 720 | /** |
---|
[3292] | 721 | \brief destructs a Box. |
---|
[3289] | 722 | */ |
---|
| 723 | Box::~Box(void) |
---|
| 724 | { |
---|
| 725 | this->destroy(); |
---|
| 726 | } |
---|
| 727 | |
---|
| 728 | /** |
---|
[3144] | 729 | \brief Initializes a new Box with type boxtype |
---|
| 730 | \param boxtype see Box(char boxtype) |
---|
| 731 | */ |
---|
| 732 | void Box::init(char boxtype) |
---|
| 733 | { |
---|
[3147] | 734 | isOption = -2; |
---|
[3144] | 735 | |
---|
| 736 | static_cast<Packer*>(this)->init(); |
---|
[3165] | 737 | #ifdef HAVE_GTK2 |
---|
[3144] | 738 | if (boxtype == 'v') |
---|
| 739 | { |
---|
| 740 | widget = gtk_vbox_new (FALSE, 0); |
---|
| 741 | } |
---|
| 742 | else |
---|
| 743 | { |
---|
| 744 | widget = gtk_hbox_new (FALSE, 0); |
---|
| 745 | } |
---|
[3165] | 746 | #endif /* HAVE_GTK2 */ |
---|
[3144] | 747 | } |
---|
| 748 | |
---|
[3289] | 749 | /** |
---|
| 750 | \brief Destroys a Box. |
---|
| 751 | */ |
---|
| 752 | void Box::destroy(void) |
---|
| 753 | { |
---|
[3290] | 754 | if (this->title) |
---|
| 755 | PRINTF(3)("deleting the Box: %s\n", this->title); |
---|
[3289] | 756 | else |
---|
| 757 | PRINTF(3)("deleting the Box.\n"); |
---|
| 758 | |
---|
| 759 | static_cast<Packer*>(this)->destroy(); |
---|
| 760 | } |
---|
| 761 | |
---|
[3144] | 762 | /** |
---|
| 763 | \brief Fills a box with a given Widget. |
---|
[3187] | 764 | \param lowerWidget the next Widget that should be appendet to this Box |
---|
| 765 | |
---|
[3144] | 766 | 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 |
---|
| 767 | */ |
---|
| 768 | void Box::fill (Widget *lowerWidget) |
---|
| 769 | { |
---|
[3165] | 770 | #ifdef HAVE_GTK2 |
---|
[3144] | 771 | gtk_box_pack_start (GTK_BOX (this->widget), lowerWidget->widget, TRUE, TRUE, 0); |
---|
[3165] | 772 | #endif /* HAVE_GTK2 */ |
---|
[3144] | 773 | if (this->down == NULL) |
---|
| 774 | this->down = lowerWidget; |
---|
| 775 | else |
---|
| 776 | { |
---|
| 777 | Widget* tmp; |
---|
| 778 | tmp = this->down; |
---|
| 779 | while (tmp->next != NULL) |
---|
| 780 | { |
---|
| 781 | tmp = tmp->next; |
---|
| 782 | } |
---|
| 783 | tmp->next = lowerWidget; |
---|
| 784 | } |
---|
| 785 | } |
---|
| 786 | |
---|
| 787 | /** |
---|
[3287] | 788 | \brief Sets the Title of a Box. |
---|
[3289] | 789 | \param title the new Title to set. |
---|
[3144] | 790 | */ |
---|
[3287] | 791 | void Box::setTitle(char* title) |
---|
[3144] | 792 | { |
---|
[3290] | 793 | if (this->title) |
---|
| 794 | delete []this->title; |
---|
| 795 | this->title = new char[strlen(title)+1]; |
---|
| 796 | strcpy(this->title, title); |
---|
[3144] | 797 | } |
---|
| 798 | |
---|
| 799 | /* OPTION */ |
---|
| 800 | |
---|
| 801 | /** |
---|
| 802 | \brief Initializes a new Option. |
---|
| 803 | sets all Option-Specific-Values to their defaults. |
---|
| 804 | */ |
---|
| 805 | void Option::init() |
---|
| 806 | { |
---|
| 807 | value = 0; |
---|
[3158] | 808 | flagName = NULL; |
---|
| 809 | flagNameShort = NULL; |
---|
[3144] | 810 | saveable = false; |
---|
[3158] | 811 | defaultValue = 0; |
---|
[3144] | 812 | |
---|
| 813 | static_cast<Widget*>(this)->init(); |
---|
| 814 | |
---|
| 815 | return; |
---|
| 816 | } |
---|
| 817 | |
---|
| 818 | /** |
---|
[3289] | 819 | \brief Destroys an Option. |
---|
| 820 | */ |
---|
| 821 | void Option::destroy(void) |
---|
| 822 | { |
---|
| 823 | PRINTF(4)("deleting the Option Part.\n"); |
---|
| 824 | if (flagName) |
---|
| 825 | delete []flagName; |
---|
| 826 | if (flagNameShort) |
---|
| 827 | delete []flagNameShort; |
---|
| 828 | |
---|
| 829 | static_cast<Widget*>(this)->destroy(); |
---|
| 830 | } |
---|
| 831 | |
---|
| 832 | /** |
---|
[3144] | 833 | \brief This sets The FlagName of an Option and defines its default Values |
---|
[3187] | 834 | !! Options will be saved if flagname is different from NULL !! |
---|
[3144] | 835 | \param flagname the Name that will be displayed in the output |
---|
| 836 | \param defaultvalue the default Value for this Option (see definition of defaultvalue |
---|
| 837 | */ |
---|
| 838 | void Option::setFlagName (char* flagname, int defaultvalue) |
---|
| 839 | { |
---|
[3158] | 840 | if (flagName) |
---|
| 841 | delete flagName; |
---|
| 842 | flagName = new char [strlen(flagname)+1]; |
---|
| 843 | strcpy(flagName, flagname); |
---|
| 844 | defaultValue = defaultvalue; |
---|
[3166] | 845 | |
---|
[3290] | 846 | // cout << "Set Flagname of " << this->title << " to " << flagname << endl; |
---|
[3144] | 847 | } |
---|
| 848 | |
---|
| 849 | /** |
---|
| 850 | \brief see Option::setFlagName (char* flagname, int defaultvalue) |
---|
| 851 | \param flagname the Name that will be displayed in the output |
---|
| 852 | \param defaultvalue the default Value for this Option (see definition of defaultvalue |
---|
| 853 | \param flagnameshort a short flagname to be displayed in the output |
---|
| 854 | */ |
---|
| 855 | void Option::setFlagName (char* flagname, char* flagnameshort, int defaultvalue) |
---|
| 856 | { |
---|
[3158] | 857 | if (flagName) |
---|
| 858 | delete flagName; |
---|
| 859 | flagName = new char [strlen(flagname)+1]; |
---|
| 860 | strcpy(flagName, flagname); |
---|
| 861 | |
---|
| 862 | if (flagNameShort) |
---|
| 863 | delete flagNameShort; |
---|
| 864 | flagNameShort = new char [strlen(flagnameshort)+1]; |
---|
[3159] | 865 | strcpy(flagNameShort, flagnameshort); |
---|
[3158] | 866 | defaultValue = defaultvalue; |
---|
[3290] | 867 | // cout << "Set Flagname of " << this->title << " to " << flagname << endl; |
---|
[3144] | 868 | } |
---|
| 869 | |
---|
[3288] | 870 | /** |
---|
| 871 | \brief Sets the saveable-state of the option to true. |
---|
| 872 | */ |
---|
| 873 | void Option::saveability(void) |
---|
| 874 | { |
---|
| 875 | this->saveable = true; |
---|
| 876 | } |
---|
[3144] | 877 | |
---|
[3288] | 878 | /** |
---|
| 879 | \brief Sets the saveable-state of the option. |
---|
| 880 | \param isSaveable the saveable-state to set. |
---|
| 881 | */ |
---|
| 882 | void Option::saveability(bool isSaveable) |
---|
| 883 | { |
---|
| 884 | this->saveable = isSaveable; |
---|
| 885 | } |
---|
| 886 | |
---|
| 887 | /** |
---|
| 888 | \returns The saveable-state. |
---|
| 889 | */ |
---|
| 890 | bool Option::isSaveable(void) |
---|
| 891 | { |
---|
| 892 | return this->saveable; |
---|
| 893 | } |
---|
| 894 | |
---|
[3144] | 895 | /* BUTTON */ |
---|
| 896 | |
---|
| 897 | /** |
---|
| 898 | \brief Creates a new Button with a buttonname |
---|
| 899 | \param buttonname sets the Name of the Button |
---|
| 900 | */ |
---|
| 901 | Button::Button(char* buttonname) |
---|
| 902 | { |
---|
| 903 | this->init(); |
---|
| 904 | this->setTitle(buttonname); |
---|
| 905 | } |
---|
| 906 | |
---|
| 907 | /** |
---|
[3292] | 908 | \brief destructs a Button. |
---|
[3289] | 909 | */ |
---|
| 910 | Button::~Button(void) |
---|
| 911 | { |
---|
| 912 | this->destroy(); |
---|
| 913 | } |
---|
| 914 | |
---|
| 915 | /** |
---|
[3144] | 916 | \brief Initializes a new Button |
---|
| 917 | */ |
---|
| 918 | void Button::init(void) |
---|
| 919 | { |
---|
[3147] | 920 | isOption = 0; |
---|
[3144] | 921 | |
---|
| 922 | static_cast<Option*>(this)->init(); |
---|
| 923 | |
---|
[3165] | 924 | #ifdef HAVE_GTK2 |
---|
[3144] | 925 | widget = gtk_button_new_with_label (""); |
---|
[3165] | 926 | #endif /* HAVE_GTK2 */ |
---|
[3144] | 927 | } |
---|
| 928 | |
---|
| 929 | /** |
---|
[3289] | 930 | \brief Destroys a Button. |
---|
| 931 | */ |
---|
| 932 | void Button::destroy(void) |
---|
| 933 | { |
---|
[3290] | 934 | if (this->title) |
---|
| 935 | PRINTF(3)("deleting the Label: %s\n", this->title); |
---|
[3289] | 936 | else |
---|
| 937 | PRINTF(3)("deleting the Label.\n"); |
---|
| 938 | |
---|
| 939 | static_cast<Option*>(this)->destroy(); |
---|
| 940 | } |
---|
| 941 | |
---|
| 942 | /** |
---|
[3144] | 943 | \brief Sets a new name to the Button |
---|
| 944 | \param title The name the Button should get |
---|
| 945 | */ |
---|
| 946 | void Button::setTitle (char *title) |
---|
| 947 | { |
---|
[3290] | 948 | if (this->title) |
---|
| 949 | delete []this->title; |
---|
| 950 | this->title = new char[strlen(title)+1]; |
---|
| 951 | strcpy(this->title, title); |
---|
[3165] | 952 | #ifdef HAVE_GTK2 |
---|
[3144] | 953 | gtk_button_set_label (GTK_BUTTON(widget), title); |
---|
[3165] | 954 | #endif /* HAVE_GTK2 */ |
---|
[3144] | 955 | } |
---|
| 956 | |
---|
| 957 | /** |
---|
| 958 | \brief redraws the Button |
---|
| 959 | not implemented yet |
---|
| 960 | */ |
---|
| 961 | void Button::redraw () |
---|
| 962 | { |
---|
| 963 | } |
---|
| 964 | |
---|
| 965 | /* CHECKBUTTON */ |
---|
| 966 | |
---|
| 967 | /** |
---|
| 968 | \brief Creates a new CheckButton with an ame |
---|
| 969 | \param buttonname The name the CheckButton should display. |
---|
| 970 | */ |
---|
| 971 | CheckButton::CheckButton (char* buttonname) |
---|
| 972 | { |
---|
| 973 | this->init(); |
---|
| 974 | this->setTitle(buttonname); |
---|
| 975 | |
---|
[3165] | 976 | #ifdef HAVE_GTK2 |
---|
[3144] | 977 | this->connectSignal ("clicked", this->OptionChange); |
---|
[3165] | 978 | #endif /* HAVE_GTK2 */ |
---|
[3144] | 979 | } |
---|
| 980 | |
---|
| 981 | /** |
---|
[3292] | 982 | \brief destructs a CheckButton. |
---|
[3289] | 983 | */ |
---|
| 984 | CheckButton::~CheckButton(void) |
---|
| 985 | { |
---|
| 986 | this->destroy(); |
---|
| 987 | } |
---|
| 988 | |
---|
| 989 | /** |
---|
[3144] | 990 | \brief Initialize a new CheckButton with default settings |
---|
| 991 | */ |
---|
| 992 | void CheckButton::init(void) |
---|
| 993 | { |
---|
[3147] | 994 | isOption = 1; |
---|
[3144] | 995 | |
---|
| 996 | static_cast<Option*>(this)->init(); |
---|
| 997 | |
---|
[3165] | 998 | #ifdef HAVE_GTK2 |
---|
[3144] | 999 | widget = gtk_check_button_new_with_label (""); |
---|
[3165] | 1000 | #endif /* HAVE_GTK2 */ |
---|
[3144] | 1001 | } |
---|
| 1002 | |
---|
| 1003 | /** |
---|
[3289] | 1004 | \brief Destroys a CheckButton. |
---|
| 1005 | */ |
---|
| 1006 | void CheckButton::destroy(void) |
---|
| 1007 | { |
---|
[3290] | 1008 | if (this->title) |
---|
| 1009 | PRINTF(3)("deleting the CheckButton: %s\n", this->title); |
---|
[3289] | 1010 | else |
---|
| 1011 | PRINTF(3)("deleting the CheckButton.\n"); |
---|
| 1012 | |
---|
| 1013 | static_cast<Option*>(this)->destroy(); |
---|
| 1014 | } |
---|
| 1015 | |
---|
| 1016 | /** |
---|
[3144] | 1017 | \brief Sets a new Title to a CheckButton |
---|
| 1018 | \param title The new Name the CheckButton should display. |
---|
| 1019 | */ |
---|
| 1020 | void CheckButton::setTitle(char* title) |
---|
| 1021 | { |
---|
[3290] | 1022 | if (this->title) |
---|
| 1023 | delete []this->title; |
---|
| 1024 | this->title = new char[strlen(title)+1]; |
---|
| 1025 | strcpy(this->title, title); |
---|
[3165] | 1026 | #ifdef HAVE_GTK2 |
---|
[3144] | 1027 | gtk_button_set_label(GTK_BUTTON(widget), title); |
---|
[3165] | 1028 | #endif /* HAVE_GTK2 */ |
---|
[3144] | 1029 | } |
---|
| 1030 | |
---|
[3146] | 1031 | bool CheckButton::isActive() |
---|
| 1032 | { |
---|
[3165] | 1033 | #ifdef HAVE_GTK2 |
---|
[3146] | 1034 | return gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)); |
---|
[3165] | 1035 | #endif /* HAVE_GTK2 */ |
---|
[3146] | 1036 | } |
---|
[3144] | 1037 | |
---|
[3165] | 1038 | #ifdef HAVE_GTK2 |
---|
[3144] | 1039 | /** |
---|
| 1040 | \brief Signal OptionChange writes the Value from the CheckButton to its Object-Database. |
---|
| 1041 | \param widget The widget(CheckButton) that has a changed Value |
---|
| 1042 | \param checkbutton the CheckButton-Object that should receive the change. |
---|
| 1043 | */ |
---|
| 1044 | gint CheckButton::OptionChange (GtkWidget *widget, Widget* checkbutton) |
---|
| 1045 | { |
---|
| 1046 | static_cast<CheckButton*>(checkbutton)->value = (int)gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON ((CheckButton*)checkbutton->widget)); |
---|
| 1047 | flags->setTextFromFlags(orxonoxGUI); ////// must be different!!! |
---|
[3290] | 1048 | cout << static_cast<CheckButton*>(checkbutton)->title << " set to: " << static_cast<CheckButton*>(checkbutton)->value << endl; |
---|
[3144] | 1049 | } |
---|
[3165] | 1050 | #endif /* HAVE_GTK2 */ |
---|
[3144] | 1051 | |
---|
| 1052 | /** |
---|
| 1053 | \brief Redraws the CheckButton (if option has changed). |
---|
| 1054 | Example: if new settings are loaded the Button must be redrawn for the GUI to display that Change |
---|
| 1055 | */ |
---|
| 1056 | void CheckButton::redraw () |
---|
| 1057 | { |
---|
[3165] | 1058 | #ifdef HAVE_GTK2 |
---|
[3144] | 1059 | gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), value); |
---|
[3165] | 1060 | #endif /* HAVE_GTK2 */ |
---|
[3144] | 1061 | } |
---|
| 1062 | |
---|
| 1063 | /* SLIDER */ |
---|
| 1064 | |
---|
| 1065 | /** |
---|
| 1066 | \brief Creates a new Slider |
---|
| 1067 | \param slidername The data-structure-name of the slider. |
---|
| 1068 | \param start The minimal Value of the slider. |
---|
| 1069 | \param end The maximal Value of the slider. |
---|
| 1070 | */ |
---|
| 1071 | Slider::Slider (char* slidername, int start, int end) |
---|
| 1072 | { |
---|
| 1073 | this->init(start, end); |
---|
| 1074 | this->setValue(start); |
---|
| 1075 | this->setTitle(slidername); |
---|
[3165] | 1076 | #ifdef HAVE_GTK2 |
---|
[3144] | 1077 | this->connectSignal ("value_changed", this->OptionChange); |
---|
[3165] | 1078 | #endif /* HAVE_GTK2 */ |
---|
[3144] | 1079 | } |
---|
| 1080 | |
---|
| 1081 | /** |
---|
[3292] | 1082 | \brief destructs a Slider. |
---|
[3289] | 1083 | */ |
---|
| 1084 | Slider::~Slider(void) |
---|
| 1085 | { |
---|
| 1086 | this->destroy(); |
---|
| 1087 | } |
---|
| 1088 | |
---|
| 1089 | /** |
---|
[3144] | 1090 | \brief Initializes a Slider with start and end Values |
---|
| 1091 | params: see Slider::Slider (char* slidername, int start, int end) |
---|
| 1092 | */ |
---|
| 1093 | void Slider::init(int start, int end) |
---|
| 1094 | { |
---|
[3147] | 1095 | isOption = 2; |
---|
[3144] | 1096 | |
---|
| 1097 | static_cast<Option*>(this)->init(); |
---|
| 1098 | |
---|
[3165] | 1099 | #ifdef HAVE_GTK2 |
---|
| 1100 | widget = gtk_hscale_new_with_range (start, end, 5); |
---|
| 1101 | #endif /* HAVE_GTK2 */ |
---|
[3144] | 1102 | } |
---|
| 1103 | |
---|
| 1104 | /** |
---|
[3289] | 1105 | \brief Destroys a Slider. |
---|
| 1106 | */ |
---|
| 1107 | void Slider::destroy(void) |
---|
| 1108 | { |
---|
[3290] | 1109 | if (this->title) |
---|
| 1110 | PRINTF(3)("deleting the Slider: %s\n", this->title); |
---|
[3289] | 1111 | else |
---|
| 1112 | PRINTF(3)("deleting the Slider.\n"); |
---|
| 1113 | |
---|
| 1114 | static_cast<Option*>(this)->destroy(); |
---|
| 1115 | |
---|
| 1116 | } |
---|
| 1117 | |
---|
| 1118 | /** |
---|
[3144] | 1119 | \brief Sets a new Title to the Slider |
---|
| 1120 | \param title The new Name of the slider |
---|
| 1121 | */ |
---|
| 1122 | void Slider::setTitle(char* title) |
---|
| 1123 | { |
---|
[3290] | 1124 | if (this->title) |
---|
| 1125 | delete []this->title; |
---|
| 1126 | this->title = new char[strlen(title)+1]; |
---|
| 1127 | strcpy(this->title, title); |
---|
[3144] | 1128 | } |
---|
| 1129 | |
---|
| 1130 | /** |
---|
| 1131 | \brief Setting a new value to the Slider. |
---|
| 1132 | Maybe you also require a Slider::redraw() for this to display |
---|
| 1133 | */ |
---|
| 1134 | void Slider::setValue(int value) |
---|
| 1135 | { |
---|
| 1136 | this->value = value; |
---|
| 1137 | } |
---|
| 1138 | |
---|
[3289] | 1139 | /** |
---|
| 1140 | \brief Redraws the widget |
---|
| 1141 | Example: see void CheckButton::redraw () |
---|
| 1142 | */ |
---|
| 1143 | void Slider::redraw () |
---|
| 1144 | { |
---|
[3165] | 1145 | #ifdef HAVE_GTK2 |
---|
[3289] | 1146 | gtk_range_set_value (GTK_RANGE (widget), value); |
---|
| 1147 | #endif /* HAVE_GTK2 */ |
---|
| 1148 | } |
---|
| 1149 | |
---|
| 1150 | #ifdef HAVE_GTK2 |
---|
[3144] | 1151 | /** |
---|
| 1152 | \brief Signal OptionChange writes the Value from the Slider to its Object-Database. |
---|
| 1153 | \param widget The widget(Slider) that has a changed Value |
---|
| 1154 | \param slider the Slider-Object that should receive the change. |
---|
| 1155 | */ |
---|
| 1156 | gint Slider::OptionChange (GtkWidget *widget, Widget* slider) |
---|
| 1157 | { |
---|
| 1158 | static_cast<Slider*>(slider)->value = (int)gtk_range_get_value (GTK_RANGE ((Slider*)slider->widget)); |
---|
| 1159 | flags->setTextFromFlags(orxonoxGUI); //// must be different !!! |
---|
[3290] | 1160 | cout << static_cast<Slider*>(slider)->title << " set to: "<< static_cast<Slider*>(slider)->value << endl; |
---|
[3144] | 1161 | } |
---|
[3165] | 1162 | #endif /* HAVE_GTK2 */ |
---|
[3144] | 1163 | |
---|
| 1164 | |
---|
| 1165 | /* MENU */ |
---|
| 1166 | |
---|
| 1167 | /** |
---|
| 1168 | \brief Creates a Menu-Item-list out of multiple input. |
---|
| 1169 | !! Consider, that the last input argument has to be "lastItem" for this to work!! |
---|
| 1170 | \param menuname The Database-Name of this Menu |
---|
| 1171 | \param ... items to be added to this Menu. !! Consider, that the last input argument has to be "lastItem" for this to work!! |
---|
| 1172 | */ |
---|
| 1173 | Menu::Menu (char* menuname, ...) |
---|
| 1174 | { |
---|
| 1175 | this->init(); |
---|
| 1176 | this->setTitle(menuname); |
---|
| 1177 | |
---|
| 1178 | char *itemName; |
---|
[3165] | 1179 | |
---|
| 1180 | #ifdef HAVE_GTK2 /////////////////////// REINPLEMENT |
---|
[3144] | 1181 | va_start (itemlist, menuname); |
---|
| 1182 | while (strcmp (itemName = va_arg (itemlist, char*), "lastItem")) |
---|
| 1183 | { |
---|
| 1184 | this->addItem(itemName); |
---|
| 1185 | } |
---|
| 1186 | va_end(itemlist); |
---|
[3165] | 1187 | #endif /* HAVE_GTK2 */ |
---|
[3144] | 1188 | |
---|
[3165] | 1189 | #ifdef HAVE_GTK2 |
---|
[3144] | 1190 | gtk_option_menu_set_menu (GTK_OPTION_MENU (widget), menu); |
---|
| 1191 | this->connectSignal ("changed", this->OptionChange); |
---|
[3165] | 1192 | #endif /* HAVE_GTK2 */ |
---|
[3144] | 1193 | } |
---|
| 1194 | |
---|
| 1195 | /** |
---|
[3292] | 1196 | \brief destructs a Menu. |
---|
[3289] | 1197 | */ |
---|
| 1198 | Menu::~Menu(void) |
---|
| 1199 | { |
---|
| 1200 | this->destroy(); |
---|
| 1201 | } |
---|
| 1202 | |
---|
| 1203 | /** |
---|
[3144] | 1204 | \brief Initializes a new Menu with no items |
---|
| 1205 | */ |
---|
| 1206 | void Menu::init(void) |
---|
| 1207 | { |
---|
[3147] | 1208 | isOption = 2; |
---|
[3144] | 1209 | |
---|
| 1210 | static_cast<Option*>(this)->init(); |
---|
| 1211 | |
---|
[3165] | 1212 | #ifdef HAVE_GTK2 |
---|
[3144] | 1213 | widget = gtk_option_menu_new (); |
---|
| 1214 | menu = gtk_menu_new (); |
---|
[3165] | 1215 | #endif /* HAVE_GTK2 */ |
---|
[3144] | 1216 | |
---|
| 1217 | } |
---|
| 1218 | |
---|
| 1219 | /** |
---|
[3289] | 1220 | \brief Destroys a Menu. |
---|
| 1221 | */ |
---|
| 1222 | void Menu::destroy(void) |
---|
| 1223 | { |
---|
[3290] | 1224 | if (this->title) |
---|
| 1225 | PRINTF(3)("deleting the Menu: %s\n", this->title); |
---|
[3289] | 1226 | else |
---|
| 1227 | PRINTF(3)("deleting the Menu.\n"); |
---|
| 1228 | //! \todo destroy menu |
---|
| 1229 | |
---|
| 1230 | static_cast<Option*>(this)->destroy(); |
---|
| 1231 | } |
---|
| 1232 | |
---|
| 1233 | |
---|
| 1234 | /** |
---|
[3144] | 1235 | * Sets the Database-Name of this Menu |
---|
| 1236 | \param title Database-Name to be set. |
---|
| 1237 | */ |
---|
| 1238 | void Menu::setTitle(char* title) |
---|
| 1239 | { |
---|
[3290] | 1240 | if (this->title) |
---|
| 1241 | delete []this->title; |
---|
| 1242 | this->title = new char[strlen(title)+1]; |
---|
| 1243 | strcpy(this->title, title); |
---|
[3144] | 1244 | } |
---|
| 1245 | |
---|
| 1246 | /** |
---|
| 1247 | \brief appends a new Item to the Menu-List. |
---|
| 1248 | \param itemName the itemName to be appendet. |
---|
| 1249 | */ |
---|
| 1250 | void Menu::addItem (char* itemName) |
---|
| 1251 | { |
---|
[3165] | 1252 | #ifdef HAVE_GTK2 |
---|
[3144] | 1253 | item = gtk_menu_item_new_with_label (itemName); |
---|
| 1254 | gtk_menu_shell_append(GTK_MENU_SHELL (menu), item); |
---|
[3165] | 1255 | #endif /* HAVE_GTK2 */ |
---|
[3144] | 1256 | } |
---|
| 1257 | |
---|
[3289] | 1258 | /** |
---|
| 1259 | \brief Redraws the widget |
---|
| 1260 | Example: see void CheckButton::redraw () |
---|
| 1261 | */ |
---|
| 1262 | void Menu::redraw () |
---|
| 1263 | { |
---|
[3165] | 1264 | #ifdef HAVE_GTK2 |
---|
[3289] | 1265 | gtk_option_menu_set_history (GTK_OPTION_MENU (widget), value); |
---|
| 1266 | #endif /* HAVE_GTK2 */ |
---|
| 1267 | } |
---|
| 1268 | |
---|
| 1269 | #ifdef HAVE_GTK2 |
---|
[3144] | 1270 | /** |
---|
| 1271 | \brief Signal OptionChange writes the Value from the Menu to its Object-Database. |
---|
| 1272 | \param widget The widget(Menu) that has a changed Value |
---|
| 1273 | \param menu the Menu-Object that should receive the change. |
---|
| 1274 | */ |
---|
| 1275 | gint Menu::OptionChange (GtkWidget *widget, Widget* menu) |
---|
| 1276 | { |
---|
| 1277 | static_cast<Menu*>(menu)->value = (int)gtk_option_menu_get_history (GTK_OPTION_MENU (menu->widget)); |
---|
| 1278 | flags->setTextFromFlags(orxonoxGUI); //// must be different !!! |
---|
[3290] | 1279 | cout << static_cast<Menu*>(menu)->title << " changed to : " << static_cast<Menu*>(menu)->value << endl; |
---|
[3144] | 1280 | } |
---|
[3165] | 1281 | #endif /* HAVE_GTK2 */ |
---|
[3144] | 1282 | |
---|
[3289] | 1283 | /* OPTION LABEL */ |
---|
[3144] | 1284 | |
---|
[3187] | 1285 | /** |
---|
| 1286 | \brief Creates a new OptionLabel with a LabelName and a Value. |
---|
| 1287 | \param label The name of the OptionLabel. |
---|
| 1288 | \param value The Value of the OptionLabel (what will be displayed). |
---|
| 1289 | */ |
---|
[3161] | 1290 | OptionLabel::OptionLabel(char* label, char* value) |
---|
[3156] | 1291 | { |
---|
| 1292 | init(); |
---|
[3161] | 1293 | setTitle(label); |
---|
| 1294 | setValue(value); |
---|
[3156] | 1295 | } |
---|
| 1296 | |
---|
[3187] | 1297 | /** |
---|
[3292] | 1298 | \brief destructs an OptionLabel. |
---|
[3289] | 1299 | */ |
---|
| 1300 | OptionLabel::~OptionLabel(void) |
---|
| 1301 | { |
---|
| 1302 | this->destroy(); |
---|
| 1303 | } |
---|
| 1304 | |
---|
| 1305 | /** |
---|
[3187] | 1306 | \brief Initializes an OptionLabel |
---|
| 1307 | */ |
---|
[3156] | 1308 | void OptionLabel::init(void) |
---|
| 1309 | { |
---|
| 1310 | static_cast<Option*>(this)->init(); |
---|
[3161] | 1311 | isOption = 5; |
---|
| 1312 | cValue = NULL; |
---|
[3156] | 1313 | |
---|
[3165] | 1314 | #ifdef HAVE_GTK2 |
---|
[3156] | 1315 | widget = gtk_label_new (""); |
---|
[3165] | 1316 | #endif /* HAVE_GTK2 */ |
---|
[3156] | 1317 | } |
---|
[3165] | 1318 | |
---|
[3187] | 1319 | /** |
---|
[3289] | 1320 | \brief Destroys a OptionLabel. |
---|
| 1321 | */ |
---|
| 1322 | void OptionLabel::destroy(void) |
---|
| 1323 | { |
---|
[3290] | 1324 | if (this->title) |
---|
| 1325 | PRINTF(3)("deleting the OptionLabel: %s\n", this->title); |
---|
[3289] | 1326 | else |
---|
| 1327 | PRINTF(3)("deleting the OptionLabel.\n"); |
---|
| 1328 | if (cValue) |
---|
| 1329 | delete []cValue; |
---|
| 1330 | |
---|
| 1331 | static_cast<Option*>(this)->destroy(); |
---|
| 1332 | } |
---|
| 1333 | |
---|
| 1334 | |
---|
| 1335 | /** |
---|
[3187] | 1336 | \brief Updates the value of an OptionLabel |
---|
| 1337 | \param newValue The new Name that should be displayed. |
---|
| 1338 | */ |
---|
[3161] | 1339 | void OptionLabel::setValue(char* newValue) |
---|
| 1340 | { |
---|
| 1341 | if (cValue) |
---|
| 1342 | delete cValue; |
---|
| 1343 | cValue = new char [strlen(newValue)+1]; |
---|
| 1344 | strcpy(cValue, newValue); |
---|
[3165] | 1345 | #ifdef HAVE_GTK2 |
---|
[3161] | 1346 | gtk_label_set_text (GTK_LABEL (widget), cValue); |
---|
[3165] | 1347 | #endif /* HAVE_GTK2 */ |
---|
[3161] | 1348 | } |
---|
[3156] | 1349 | |
---|
[3187] | 1350 | /** |
---|
| 1351 | \brief Sets a ned Title to the OptionLabel. |
---|
| 1352 | \param title The now title of the OptionLabel. |
---|
| 1353 | */ |
---|
[3156] | 1354 | void OptionLabel::setTitle(char* title) |
---|
| 1355 | { |
---|
[3290] | 1356 | if (this->title) |
---|
| 1357 | delete []this->title; |
---|
| 1358 | this->title = new char [strlen(title)+1]; |
---|
| 1359 | strcpy(this->title, title); |
---|
[3165] | 1360 | #ifdef HAVE_GTK2 |
---|
[3156] | 1361 | gtk_label_set_text (GTK_LABEL (widget), title); |
---|
[3165] | 1362 | #endif /* HAVE_GTK2 */ |
---|
[3156] | 1363 | } |
---|
| 1364 | |
---|
[3187] | 1365 | /** |
---|
| 1366 | \brief Redraws an OptionLabel (not implemented yet, but it works). |
---|
| 1367 | */ |
---|
[3156] | 1368 | void OptionLabel::redraw(void) |
---|
| 1369 | { |
---|
| 1370 | |
---|
| 1371 | } |
---|
| 1372 | |
---|
[3144] | 1373 | /** |
---|
| 1374 | \brief Creates a new default Label with no Text. |
---|
| 1375 | You migth consider adding Label::setTitle with this. |
---|
| 1376 | */ |
---|
[3156] | 1377 | Label::Label () |
---|
[3144] | 1378 | { |
---|
| 1379 | this->init(); |
---|
| 1380 | } |
---|
| 1381 | |
---|
| 1382 | /** |
---|
| 1383 | \brief Creates a new Label with a Text. |
---|
| 1384 | \param text The text to be displayed. |
---|
| 1385 | */ |
---|
| 1386 | Label:: Label (char* text) |
---|
| 1387 | { |
---|
| 1388 | this->init(); |
---|
[3287] | 1389 | this->setTitle(text); |
---|
[3144] | 1390 | } |
---|
| 1391 | |
---|
| 1392 | /** |
---|
[3292] | 1393 | \brief destructs a Label. |
---|
[3289] | 1394 | */ |
---|
| 1395 | Label::~Label(void) |
---|
| 1396 | { |
---|
| 1397 | this->destroy(); |
---|
| 1398 | } |
---|
| 1399 | |
---|
| 1400 | /** |
---|
[3144] | 1401 | \brief initializes a new Label |
---|
| 1402 | */ |
---|
| 1403 | void Label::init(void) |
---|
| 1404 | { |
---|
[3147] | 1405 | isOption = 0; |
---|
[3144] | 1406 | |
---|
| 1407 | static_cast<Widget*>(this)->init(); |
---|
| 1408 | |
---|
[3165] | 1409 | #ifdef HAVE_GTK2 |
---|
[3144] | 1410 | widget = gtk_label_new (""); |
---|
| 1411 | gtk_label_set_line_wrap (GTK_LABEL(widget), TRUE); |
---|
[3165] | 1412 | #endif /* HAVE_GTK2 */ |
---|
[3144] | 1413 | } |
---|
| 1414 | |
---|
| 1415 | /** |
---|
[3289] | 1416 | \brief Destroys a Label. |
---|
| 1417 | */ |
---|
| 1418 | void Label::destroy(void) |
---|
| 1419 | { |
---|
[3290] | 1420 | if (this->title) |
---|
| 1421 | PRINTF(3)("deleting the Label: %s\n", this->title); |
---|
[3289] | 1422 | else |
---|
| 1423 | PRINTF(3)("deleting the Label.\n"); |
---|
| 1424 | |
---|
| 1425 | static_cast<Widget*>(this)->destroy(); |
---|
| 1426 | } |
---|
| 1427 | |
---|
| 1428 | /** |
---|
[3144] | 1429 | \brief Sets a new Text to a Label. |
---|
| 1430 | \param text The text to be inserted into the Label. |
---|
| 1431 | */ |
---|
[3287] | 1432 | void Label::setTitle(char* text) |
---|
[3144] | 1433 | { |
---|
[3290] | 1434 | if (this->title) |
---|
| 1435 | delete []this->title; |
---|
| 1436 | this->title = new char[strlen(text)+1]; |
---|
| 1437 | strcpy(this->title, text); |
---|
[3165] | 1438 | #ifdef HAVE_GTK2 |
---|
[3144] | 1439 | gtk_label_set_text (GTK_LABEL (this->widget), text); |
---|
[3165] | 1440 | #endif /* HAVE_GTK2 */ |
---|
[3144] | 1441 | } |
---|
| 1442 | |
---|
| 1443 | /** |
---|
| 1444 | \brief get the Text of a Label |
---|
| 1445 | \return The Text the Label holds. |
---|
| 1446 | */ |
---|
| 1447 | char* Label::getText () |
---|
| 1448 | { |
---|
[3290] | 1449 | return this->title; |
---|
[3144] | 1450 | } |
---|
[3244] | 1451 | |
---|
| 1452 | /** |
---|
[3275] | 1453 | \brief Creates a new ProgressBar. |
---|
[3244] | 1454 | */ |
---|
| 1455 | ProgressBar::ProgressBar (void) |
---|
| 1456 | { |
---|
| 1457 | this->init (); |
---|
| 1458 | } |
---|
| 1459 | |
---|
| 1460 | /** |
---|
[3275] | 1461 | \brief Creates a new ProgressBar. |
---|
[3244] | 1462 | \param label The name you want to get the ProgressBar. |
---|
| 1463 | */ |
---|
| 1464 | ProgressBar::ProgressBar (char* label) |
---|
| 1465 | { |
---|
| 1466 | this->init(); |
---|
[3287] | 1467 | this->setTitle (label); |
---|
[3244] | 1468 | } |
---|
| 1469 | |
---|
| 1470 | /** |
---|
[3275] | 1471 | \brief destructs a ProgressBar |
---|
[3244] | 1472 | */ |
---|
| 1473 | ProgressBar::~ProgressBar () |
---|
| 1474 | { |
---|
[3289] | 1475 | this->destroy(); |
---|
[3244] | 1476 | } |
---|
| 1477 | |
---|
| 1478 | /** |
---|
| 1479 | \brief Initializes a ProgressBar |
---|
| 1480 | */ |
---|
| 1481 | void ProgressBar::init (void) |
---|
| 1482 | { |
---|
| 1483 | isOption = 0; |
---|
| 1484 | progress = 0.0; |
---|
| 1485 | totalSize = 0.0; |
---|
| 1486 | |
---|
| 1487 | static_cast<Widget*>(this)->init(); |
---|
| 1488 | #ifdef HAVE_GTK2 |
---|
| 1489 | adjustment = (GtkAdjustment*)gtk_adjustment_new(0, 0, 100, 0, 0, 0); |
---|
| 1490 | widget = gtk_progress_bar_new_with_adjustment(adjustment); |
---|
| 1491 | #endif /* HAVE_GTK2 */ |
---|
| 1492 | } |
---|
| 1493 | |
---|
| 1494 | /** |
---|
[3289] | 1495 | \brief Destroys a ProgressBar. |
---|
| 1496 | */ |
---|
| 1497 | void ProgressBar::destroy(void) |
---|
| 1498 | { |
---|
[3290] | 1499 | if (this->title) |
---|
| 1500 | PRINTF(3)("deleting the ProgressBar: %s\n", this->title); |
---|
[3289] | 1501 | else |
---|
| 1502 | PRINTF(3)("deleting the ProgressBar.\n"); |
---|
| 1503 | |
---|
| 1504 | static_cast<Widget*>(this)->destroy(); |
---|
| 1505 | } |
---|
| 1506 | |
---|
| 1507 | /** |
---|
[3287] | 1508 | \brief Sets a ned Title to the ProgressBar. |
---|
| 1509 | \param title The now title of the ProgressBar. |
---|
| 1510 | */ |
---|
| 1511 | void ProgressBar::setTitle(char* title) |
---|
| 1512 | { |
---|
[3290] | 1513 | if (this->title) |
---|
| 1514 | delete []this->title; |
---|
| 1515 | this->title = new char [strlen(title)+1]; |
---|
| 1516 | strcpy(this->title, title); |
---|
[3287] | 1517 | } |
---|
| 1518 | |
---|
| 1519 | /** |
---|
[3244] | 1520 | \brief Sets the Total size of the Bar. (ex. The maximum one can download) |
---|
| 1521 | */ |
---|
[3259] | 1522 | void ProgressBar::setTotalSize (double totalSize) |
---|
[3244] | 1523 | { |
---|
[3259] | 1524 | this->totalSize = totalSize; |
---|
[3244] | 1525 | } |
---|
| 1526 | |
---|
| 1527 | /** |
---|
| 1528 | \brief Sets the progress maximum is this->totalSize |
---|
| 1529 | */ |
---|
| 1530 | void ProgressBar::setProgress (double progress) |
---|
| 1531 | { |
---|
| 1532 | this->progress = progress; |
---|
| 1533 | |
---|
| 1534 | if (this->progress > this->totalSize) |
---|
| 1535 | this->progress = this->totalSize; |
---|
| 1536 | |
---|
| 1537 | #ifdef HAVE_GTK2 |
---|
| 1538 | gtk_progress_set_value(GTK_PROGRESS(widget), this->progress*100.0/this->totalSize); |
---|
| 1539 | #endif /* HAVE_GTK2 */ |
---|
[3263] | 1540 | PRINTF(3)("Progress: %f\n", progress*100.0/totalSize); |
---|
[3244] | 1541 | } |
---|
| 1542 | |
---|
| 1543 | /** |
---|
| 1544 | \brief returns the Progress Status |
---|
| 1545 | */ |
---|
| 1546 | double ProgressBar::getProgress (void) |
---|
| 1547 | { |
---|
| 1548 | return this->progress; |
---|
| 1549 | } |
---|
[3287] | 1550 | |
---|
| 1551 | /* IMAGE */ |
---|
| 1552 | |
---|
| 1553 | /** |
---|
| 1554 | \brief Creates a new Image |
---|
| 1555 | \param imagename the location of the Image on the Hard Disc |
---|
| 1556 | */ |
---|
| 1557 | Image::Image (char* imagename) |
---|
| 1558 | { |
---|
| 1559 | this->init(); |
---|
[3290] | 1560 | if (this->title) |
---|
| 1561 | delete []this->title; |
---|
| 1562 | this->title = new char[strlen(imagename)+1]; |
---|
| 1563 | strcpy(this->title, imagename); |
---|
[3287] | 1564 | |
---|
| 1565 | #ifdef HAVE_GTK2 |
---|
| 1566 | widget = gtk_image_new_from_file (imagename); |
---|
| 1567 | #endif /* HAVE_GTK2 */ |
---|
| 1568 | } |
---|
| 1569 | |
---|
[3289] | 1570 | /** |
---|
[3292] | 1571 | \brief destructs an Image. |
---|
[3289] | 1572 | */ |
---|
| 1573 | Image::~Image(void) |
---|
| 1574 | { |
---|
| 1575 | this->destroy(); |
---|
| 1576 | } |
---|
| 1577 | |
---|
[3287] | 1578 | /** |
---|
| 1579 | \brief Initializes a new Image |
---|
| 1580 | */ |
---|
| 1581 | void Image::init() |
---|
| 1582 | { |
---|
| 1583 | isOption = 0; |
---|
| 1584 | |
---|
| 1585 | static_cast<Widget*>(this)->init(); |
---|
| 1586 | } |
---|
| 1587 | |
---|
| 1588 | /** |
---|
[3289] | 1589 | \brief Destroys a Image. |
---|
| 1590 | */ |
---|
| 1591 | void Image::destroy(void) |
---|
| 1592 | { |
---|
[3290] | 1593 | if (this->title) |
---|
| 1594 | PRINTF(3)("deleting the Image: %s\n", this->title); |
---|
[3289] | 1595 | else |
---|
| 1596 | PRINTF(3)("deleting the Image.\n"); |
---|
| 1597 | |
---|
| 1598 | static_cast<Widget*>(this)->destroy(); |
---|
| 1599 | } |
---|
| 1600 | |
---|
| 1601 | /** |
---|
[3287] | 1602 | \brief Sets a ned Title to the Image. |
---|
| 1603 | \param title The now title of the OptionLabel. |
---|
| 1604 | */ |
---|
| 1605 | void Image::setTitle(char* title) |
---|
| 1606 | { |
---|
[3290] | 1607 | if (this->title) |
---|
| 1608 | delete []this->title; |
---|
| 1609 | this->title = new char [strlen(title)+1]; |
---|
| 1610 | strcpy(this->title, title); |
---|
[3287] | 1611 | } |
---|