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