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