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