[4744] | 1 | /* |
---|
[1853] | 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. |
---|
[1855] | 10 | |
---|
| 11 | ### File Specific: |
---|
[5359] | 12 | main-programmer: Benjamin Grauer |
---|
[1855] | 13 | co-programmer: ... |
---|
[1853] | 14 | */ |
---|
| 15 | |
---|
[8989] | 16 | #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_GUI |
---|
[1853] | 17 | |
---|
[5362] | 18 | #include "glgui_widget.h" |
---|
[1853] | 19 | |
---|
[7919] | 20 | #include "glgui_cursor.h" |
---|
| 21 | |
---|
[6287] | 22 | #include "material.h" |
---|
| 23 | |
---|
[5392] | 24 | #include "debug.h" |
---|
| 25 | |
---|
[8619] | 26 | #include "loading/load_param.h" |
---|
| 27 | |
---|
[8982] | 28 | /// TODO TAKE THIS OUT OF HERE |
---|
| 29 | #include "loading/resource_manager.h" |
---|
| 30 | |
---|
[7779] | 31 | namespace OrxGui |
---|
[3365] | 32 | { |
---|
[1853] | 33 | |
---|
[7779] | 34 | /** |
---|
[8035] | 35 | * @brief standard constructor |
---|
[7779] | 36 | */ |
---|
[8035] | 37 | GLGuiWidget::GLGuiWidget (GLGuiWidget* parent) |
---|
[7779] | 38 | { |
---|
| 39 | this->init(); |
---|
[8035] | 40 | |
---|
| 41 | this->setParentWidget(parent); |
---|
[7779] | 42 | } |
---|
[1853] | 43 | |
---|
[5359] | 44 | |
---|
[7779] | 45 | /** |
---|
[8619] | 46 | * @brief loads Parameters for a Style from XML |
---|
| 47 | * @param root the XML-Element to load from. |
---|
| 48 | */ |
---|
| 49 | void GLGuiWidget::loadParams(const TiXmlElement* root) |
---|
| 50 | { |
---|
| 51 | |
---|
| 52 | /// STYLE |
---|
| 53 | LoadParam(root, "border-left", this, GLGuiWidget, setBorderLeft); |
---|
| 54 | LoadParam(root, "border-right", this, GLGuiWidget, setBorderRight); |
---|
| 55 | LoadParam(root, "border-top", this, GLGuiWidget, setBorderTop); |
---|
| 56 | LoadParam(root, "border-bottom", this, GLGuiWidget, setBorderBottom); |
---|
| 57 | |
---|
| 58 | LoadParam(root, "text-size", this, GLGuiWidget, setTextSize); |
---|
| 59 | LoadParam(root, "background-color", this, GLGuiWidget, setBackgroundColorS); |
---|
| 60 | LoadParam(root, "foreground-color", this, GLGuiWidget, setForegroundColorS); |
---|
| 61 | |
---|
| 62 | // LoadParamXML(root, "backmat", this, GLGuiWidget, loadBackgroundMaterial); |
---|
| 63 | // LoadParamXML(root, "frontmat", this, GLGuiWidget, loadForegroundMaterial); |
---|
| 64 | |
---|
| 65 | LoadParam(root, "feature-position", this, GLGuiWidget, setFeaturePositionS); |
---|
| 66 | LoadParam(root, "Font", this, GLGuiWidget, setFont); |
---|
| 67 | |
---|
| 68 | LoadParam(root, "animated-state-changes", this, GLGuiWidget, setAnimatedStateChanges); |
---|
| 69 | } |
---|
| 70 | |
---|
| 71 | |
---|
| 72 | /** |
---|
[8035] | 73 | * @brief standard deconstructor |
---|
[7779] | 74 | */ |
---|
| 75 | GLGuiWidget::~GLGuiWidget() |
---|
| 76 | { |
---|
[8717] | 77 | if (this == GLGuiWidget::_mouseFocused) |
---|
| 78 | GLGuiWidget::_mouseFocused = NULL; |
---|
| 79 | if (this == GLGuiWidget::selected()) |
---|
| 80 | this->unselect(); |
---|
[7779] | 81 | } |
---|
[5359] | 82 | |
---|
[8035] | 83 | GLGuiWidget* GLGuiWidget::_selected = NULL; |
---|
[8717] | 84 | GLGuiWidget* GLGuiWidget::_mouseFocused = NULL; |
---|
[7919] | 85 | GLGuiWidget* GLGuiWidget::_inputGrabber = NULL; |
---|
[5362] | 86 | |
---|
[7919] | 87 | |
---|
| 88 | |
---|
[7779] | 89 | /** |
---|
| 90 | * initializes the GUI-element |
---|
| 91 | */ |
---|
| 92 | void GLGuiWidget::init() |
---|
| 93 | { |
---|
| 94 | this->setClassID(CL_GLGUI_WIDGET, "GLGuiWidget"); |
---|
[5392] | 95 | |
---|
[7919] | 96 | this->_focusable = false; |
---|
| 97 | this->_clickable = false; |
---|
[8717] | 98 | this->_selectable = false; |
---|
[7919] | 99 | this->_pushed = false; |
---|
[8619] | 100 | this->_state = OrxGui::Normal; |
---|
[7919] | 101 | |
---|
[8619] | 102 | |
---|
[8982] | 103 | this->_font = Font(ResourceManager::getInstance()->getDataDir() + "/fonts/final_frontier.ttf", 20); |
---|
[8619] | 104 | this->resetStyle(); |
---|
| 105 | |
---|
| 106 | this->_animating = false; |
---|
| 107 | this->_animationCycle = 0.0; |
---|
| 108 | this->_animationDuration = 1.0; |
---|
| 109 | |
---|
| 110 | |
---|
| 111 | this->setBackgroundColor(Color(.51, .3, .3, .5)); |
---|
| 112 | this->setBackgroundColor(Color(.3, .5, .3, 1), OrxGui::Selected); |
---|
| 113 | this->_style[0]._background.setBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
---|
| 114 | this->_style[1]._background.setBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
---|
| 115 | this->_style[2]._background.setBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
---|
| 116 | this->_style[3]._background.setBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
---|
| 117 | |
---|
[9019] | 118 | this->setForegroundColor(Color(.8, .8, 1, 1), OrxGui::Normal); |
---|
| 119 | this->setForegroundColor(Color(0, .4, 1.0, 1), OrxGui::Selected); |
---|
| 120 | this->setForegroundColor(Color(0, .0, 1.0, 1), OrxGui::Focused); |
---|
[8619] | 121 | this->setForegroundColor(Color(.1, .1, .1, 1), OrxGui::Insensitive); |
---|
| 122 | |
---|
[7779] | 123 | this->setVisibility(GLGUI_WIDGET_DEFAULT_VISIBLE); |
---|
[5392] | 124 | |
---|
[8619] | 125 | this->setBorderLeft(15); |
---|
| 126 | this->setBackgroundTexture("gui_element_background.png"); |
---|
[8115] | 127 | |
---|
[8619] | 128 | this->switchState(_state); |
---|
| 129 | this->_currentStyle = this->_style[_state]; |
---|
[8035] | 130 | } |
---|
[6287] | 131 | |
---|
[8035] | 132 | |
---|
| 133 | void GLGuiWidget::setParentWidget(GLGuiWidget* parent) |
---|
| 134 | { |
---|
| 135 | this->_parent = parent; |
---|
| 136 | |
---|
| 137 | if (parent != NULL) |
---|
| 138 | parent->addChild2D(this); |
---|
[7779] | 139 | } |
---|
[5392] | 140 | |
---|
[7919] | 141 | |
---|
[8717] | 142 | void GLGuiWidget::setFrontColor(const Color& frontColor, bool instantaniously) |
---|
[7919] | 143 | { |
---|
[8717] | 144 | this->_currentStyle._foreground.setDiffuseColor(frontColor); |
---|
| 145 | this->animateBack(); |
---|
[7919] | 146 | }; |
---|
| 147 | |
---|
| 148 | |
---|
| 149 | bool GLGuiWidget::focusOverWidget(const Vector2D& position) const |
---|
| 150 | { |
---|
| 151 | return (this->getAbsCoor2D().x < position.x && this->getAbsCoor2D().x + this->getSizeX2D() > position.x && |
---|
[8717] | 152 | this->getAbsCoor2D().y < position.y && this->getAbsCoor2D().y + this->getSizeY2D() > position.y); |
---|
[7779] | 153 | } |
---|
[5391] | 154 | |
---|
[7919] | 155 | bool GLGuiWidget::focusOverWidget(const GLGuiCursor* const cursor) const |
---|
| 156 | { |
---|
| 157 | return this->focusOverWidget(cursor->getAbsCoor2D()); |
---|
| 158 | } |
---|
| 159 | |
---|
[8619] | 160 | |
---|
| 161 | |
---|
[8717] | 162 | /** @brief gives focus to this widget */ |
---|
| 163 | void GLGuiWidget::giveMouseFocus() |
---|
[8448] | 164 | { |
---|
[8717] | 165 | if (this->_state == OrxGui::Insensitive) |
---|
| 166 | return ; |
---|
| 167 | |
---|
| 168 | if (GLGuiWidget::mouseFocused() != NULL) |
---|
| 169 | GLGuiWidget::mouseFocused()->breakMouseFocus(); |
---|
| 170 | GLGuiWidget::_mouseFocused = this; |
---|
| 171 | |
---|
| 172 | this->switchState(OrxGui::Focused); |
---|
| 173 | |
---|
| 174 | this->receivedFocus(); |
---|
[8448] | 175 | }; |
---|
[8035] | 176 | |
---|
[8717] | 177 | void GLGuiWidget::breakMouseFocus() |
---|
| 178 | { |
---|
| 179 | if (GLGuiWidget::_mouseFocused == this) |
---|
| 180 | { |
---|
| 181 | GLGuiWidget::_mouseFocused = NULL; |
---|
[8448] | 182 | |
---|
[8717] | 183 | if (GLGuiWidget::_selected != this) |
---|
| 184 | this->switchState(OrxGui::Normal); |
---|
| 185 | else |
---|
| 186 | this->switchState(OrxGui::Selected); |
---|
| 187 | |
---|
| 188 | this->removedFocus(); |
---|
| 189 | } |
---|
| 190 | }; |
---|
| 191 | |
---|
| 192 | /** |
---|
| 193 | * @brief selects the Widget, unselecting the old one (if existing) |
---|
| 194 | */ |
---|
| 195 | void GLGuiWidget::select() |
---|
| 196 | { |
---|
| 197 | if (GLGuiWidget::_selected != NULL) |
---|
| 198 | GLGuiWidget::selected()->unselect(); |
---|
| 199 | GLGuiWidget::_selected = this; |
---|
| 200 | |
---|
| 201 | this->switchState(OrxGui::Selected); |
---|
| 202 | } |
---|
| 203 | |
---|
| 204 | /** |
---|
| 205 | * @brief unselects the current Widget. |
---|
| 206 | * |
---|
| 207 | * if the current Widget is not selected, nothing is done here. |
---|
| 208 | */ |
---|
| 209 | void GLGuiWidget::unselect() |
---|
| 210 | { |
---|
| 211 | if (GLGuiWidget::_selected != this) |
---|
| 212 | return; |
---|
| 213 | |
---|
| 214 | if (GLGuiWidget::_mouseFocused == this) |
---|
| 215 | this->switchState(OrxGui::Focused); |
---|
| 216 | else |
---|
| 217 | this->switchState(OrxGui::Normal); |
---|
| 218 | |
---|
| 219 | GLGuiWidget::_selected = NULL; |
---|
| 220 | } |
---|
| 221 | |
---|
| 222 | |
---|
[8035] | 223 | void GLGuiWidget::resize() |
---|
| 224 | { |
---|
| 225 | this->backRect().setSize(this->getSize2D()); |
---|
| 226 | if (this->parent() != NULL) |
---|
| 227 | this->parent()->resize(); |
---|
| 228 | } |
---|
| 229 | |
---|
| 230 | |
---|
| 231 | void GLGuiWidget::click(const Vector2D& pos) |
---|
| 232 | { |
---|
[7919] | 233 | assert (!this->_pushed); |
---|
| 234 | this->_pushed = true; |
---|
| 235 | |
---|
[8035] | 236 | this->clicking(pos); |
---|
[7919] | 237 | } |
---|
| 238 | |
---|
[8035] | 239 | void GLGuiWidget::release(const Vector2D& pos) |
---|
[7919] | 240 | { |
---|
| 241 | if (this->_pushed) |
---|
| 242 | { |
---|
[8717] | 243 | this->releasing(pos, GLGuiWidget::_mouseFocused == this); |
---|
[7919] | 244 | this->_pushed = false; |
---|
| 245 | } |
---|
| 246 | } |
---|
| 247 | |
---|
| 248 | |
---|
[8035] | 249 | void GLGuiWidget::clicking(const Vector2D& pos) |
---|
[8717] | 250 | {} |
---|
| 251 | |
---|
| 252 | void GLGuiWidget::releasing(const Vector2D& pos, bool focused) |
---|
| 253 | {} |
---|
| 254 | |
---|
| 255 | void GLGuiWidget::receivedFocus() |
---|
[7919] | 256 | { |
---|
| 257 | } |
---|
| 258 | |
---|
[8717] | 259 | void GLGuiWidget::removedFocus() |
---|
[7919] | 260 | { |
---|
[8717] | 261 | |
---|
[7919] | 262 | } |
---|
| 263 | |
---|
[8717] | 264 | void GLGuiWidget::selecting() |
---|
[7919] | 265 | { |
---|
| 266 | } |
---|
| 267 | |
---|
[8717] | 268 | void GLGuiWidget::unselecting() |
---|
[7919] | 269 | { |
---|
[8717] | 270 | } |
---|
[7919] | 271 | |
---|
[8717] | 272 | |
---|
| 273 | void GLGuiWidget::destroying() |
---|
| 274 | { |
---|
[7919] | 275 | } |
---|
| 276 | |
---|
[8035] | 277 | |
---|
| 278 | void GLGuiWidget::setWidgetSize(const Vector2D& size) |
---|
[7919] | 279 | { |
---|
[8035] | 280 | this->setSize2D(size); |
---|
| 281 | this->resize(); |
---|
[7919] | 282 | |
---|
[8035] | 283 | } |
---|
[7919] | 284 | |
---|
| 285 | |
---|
[8035] | 286 | void GLGuiWidget::setWidgetSize(float x, float y) |
---|
[7779] | 287 | { |
---|
[8035] | 288 | this->setWidgetSize(Vector2D(x, y)); |
---|
| 289 | } |
---|
[5391] | 290 | |
---|
[7779] | 291 | void GLGuiWidget::show() |
---|
| 292 | { |
---|
| 293 | this->setVisibility(true); |
---|
[8115] | 294 | this->showing(); |
---|
[7779] | 295 | } |
---|
[6287] | 296 | |
---|
[8035] | 297 | |
---|
[8312] | 298 | |
---|
[7779] | 299 | void GLGuiWidget::hide() |
---|
| 300 | { |
---|
| 301 | this->setVisibility(false); |
---|
[8115] | 302 | this->hiding(); |
---|
[7779] | 303 | } |
---|
[6287] | 304 | |
---|
[8619] | 305 | |
---|
| 306 | /** |
---|
| 307 | * @brief resets the Style to the default Settings. |
---|
| 308 | */ |
---|
| 309 | void GLGuiWidget::resetStyle() |
---|
| 310 | { |
---|
| 311 | this->setBorderLeft(1.0); |
---|
| 312 | this->setBorderRight(1.0); |
---|
| 313 | this->setBorderTop(1.0); |
---|
| 314 | this->setBorderBottom(1.0); |
---|
| 315 | |
---|
| 316 | this->setTextSize(20.0); |
---|
| 317 | this->setBackgroundColor(1.0); |
---|
| 318 | this->setForegroundColor(1.0); |
---|
| 319 | |
---|
| 320 | this->setFeaturePosition(FeatureLeft); |
---|
| 321 | |
---|
| 322 | this->setAnimatedStateChanges(true); |
---|
| 323 | } |
---|
| 324 | |
---|
| 325 | |
---|
| 326 | /** |
---|
| 327 | * @brief sets the Width of the left border for all States |
---|
| 328 | * @param value the borderWidth |
---|
| 329 | */ |
---|
| 330 | void GLGuiWidget::setBorderLeft(float value) |
---|
| 331 | { |
---|
| 332 | for (unsigned int i = 0; i < GLGUI_STATE_COUNT; ++i) |
---|
| 333 | setBorderLeft(value, (OrxGui::State)i); |
---|
| 334 | } |
---|
| 335 | |
---|
| 336 | /** |
---|
| 337 | * @brief sets the Width of the left border. |
---|
| 338 | * @param value the borderWidth |
---|
| 339 | * @param state the State to set the borderwidth to |
---|
| 340 | */ |
---|
| 341 | void GLGuiWidget::setBorderLeft(float value, OrxGui::State state) |
---|
| 342 | { |
---|
| 343 | _style[state]._borderLeft = value; |
---|
| 344 | if (state == _state) |
---|
| 345 | _currentStyle._borderLeft = value; |
---|
| 346 | } |
---|
| 347 | |
---|
| 348 | /** |
---|
| 349 | * @brief sets the Width of the left border. |
---|
| 350 | * @param value the borderWidth |
---|
| 351 | * @param stateName the State to set the borderwidth to |
---|
| 352 | */ |
---|
| 353 | void GLGuiWidget::setBorderLeftS(float value, const std::string& stateName) |
---|
| 354 | { |
---|
| 355 | OrxGui::State state; |
---|
| 356 | if (getState(stateName, &state)) |
---|
| 357 | this->setBorderLeft(value, state); |
---|
| 358 | else |
---|
| 359 | this->setBorderLeft(value); |
---|
| 360 | } |
---|
| 361 | |
---|
| 362 | /** |
---|
| 363 | * @brief sets the Width of the right border for all states. |
---|
| 364 | * @param value the borderWidth |
---|
| 365 | */ |
---|
| 366 | void GLGuiWidget::setBorderRight(float value) |
---|
| 367 | { |
---|
| 368 | for (unsigned int i = 0; i < GLGUI_STATE_COUNT; ++i) |
---|
| 369 | setBorderRight(value, (OrxGui::State)i); |
---|
| 370 | } |
---|
| 371 | |
---|
| 372 | /** |
---|
| 373 | * @brief sets the Width of the right border. |
---|
| 374 | * @param value the borderWidth |
---|
| 375 | * @param state the State to setup. |
---|
| 376 | */ |
---|
| 377 | void GLGuiWidget::setBorderRight(float value, OrxGui::State state) |
---|
| 378 | { |
---|
| 379 | _style[state]._borderRight = value; |
---|
| 380 | if (state == _state) |
---|
| 381 | _currentStyle._borderRight = value; |
---|
| 382 | } |
---|
| 383 | |
---|
| 384 | /** |
---|
| 385 | * @brief sets the Width of the right border. |
---|
| 386 | * @param value the borderWidth |
---|
| 387 | * @param stateName the State to setup. |
---|
| 388 | */ |
---|
| 389 | void GLGuiWidget::setBorderRightS(float value, const std::string& stateName) |
---|
| 390 | { |
---|
| 391 | OrxGui::State state; |
---|
| 392 | if (getState(stateName, &state)) |
---|
| 393 | this->setBorderRight(value, state); |
---|
| 394 | else |
---|
| 395 | this->setBorderRight(value); |
---|
| 396 | } |
---|
| 397 | |
---|
| 398 | |
---|
| 399 | /** |
---|
| 400 | * @brief sets the Width of the top border for all states. |
---|
| 401 | * @param value the borderWidth |
---|
| 402 | */ |
---|
| 403 | void GLGuiWidget::setBorderTop(float value) |
---|
| 404 | { |
---|
| 405 | for (unsigned int i = 0; i < GLGUI_STATE_COUNT; ++i) |
---|
| 406 | setBorderTop(value, (OrxGui::State)i); |
---|
| 407 | } |
---|
| 408 | |
---|
| 409 | /** |
---|
| 410 | * @brief sets the Width of the top border. |
---|
| 411 | * @param value the borderWidth |
---|
| 412 | * @param state the State to setup. |
---|
| 413 | */ |
---|
| 414 | void GLGuiWidget::setBorderTop(float value, OrxGui::State state) |
---|
| 415 | { |
---|
| 416 | _style[state]._borderTop = value; |
---|
| 417 | if (state == _state) |
---|
| 418 | _currentStyle._borderTop = value; |
---|
| 419 | } |
---|
| 420 | |
---|
| 421 | /** |
---|
| 422 | * @brief sets the Width of the top border. |
---|
| 423 | * @param value the borderWidth |
---|
| 424 | * @param stateName the State to setup. |
---|
| 425 | */ |
---|
| 426 | void GLGuiWidget::setBorderTopS(float value, const std::string& stateName) |
---|
| 427 | { |
---|
| 428 | OrxGui::State state; |
---|
| 429 | if (getState(stateName, &state)) |
---|
| 430 | this->setBorderTop(value, state); |
---|
| 431 | else |
---|
| 432 | this->setBorderTop(value); |
---|
| 433 | } |
---|
| 434 | |
---|
| 435 | |
---|
| 436 | /** |
---|
| 437 | * @brief sets the Width of the bottom border for all states. |
---|
| 438 | * @param value the borderWidth |
---|
| 439 | */ |
---|
| 440 | void GLGuiWidget::setBorderBottom(float value) |
---|
| 441 | { |
---|
| 442 | for (unsigned int i = 0; i < GLGUI_STATE_COUNT; ++i) |
---|
| 443 | setBorderBottom(value, (OrxGui::State)i); |
---|
| 444 | } |
---|
| 445 | |
---|
| 446 | /** |
---|
| 447 | * @brief sets the Width of the bottom border. |
---|
| 448 | * @param value the borderWidth |
---|
| 449 | * @param state the State to setup. |
---|
| 450 | */ |
---|
| 451 | void GLGuiWidget::setBorderBottom(float value, OrxGui::State state) |
---|
| 452 | { |
---|
| 453 | _style[state]._borderBottom = value; |
---|
| 454 | if (state == _state) |
---|
| 455 | _currentStyle._borderBottom = value; |
---|
| 456 | |
---|
| 457 | } |
---|
| 458 | |
---|
| 459 | /** |
---|
| 460 | * @brief sets the Width of the bottom border for all states. |
---|
| 461 | * @param value the borderWidth |
---|
| 462 | * @param stateName the State to setup. |
---|
| 463 | */ |
---|
| 464 | void GLGuiWidget::setBorderBottomS(float value, const std::string& stateName) |
---|
| 465 | { |
---|
| 466 | OrxGui::State state; |
---|
| 467 | if (getState(stateName, &state)) |
---|
| 468 | this->setBorderBottom(value, state); |
---|
| 469 | else |
---|
| 470 | this->setBorderBottom(value); |
---|
| 471 | } |
---|
| 472 | |
---|
| 473 | |
---|
| 474 | /** |
---|
| 475 | * @brief sets the TextSize for all states. |
---|
| 476 | * @param value the TextSize |
---|
| 477 | */ |
---|
| 478 | void GLGuiWidget::setTextSize(float value) |
---|
| 479 | { |
---|
| 480 | for (unsigned int i = 0; i < GLGUI_STATE_COUNT; ++i) |
---|
| 481 | setTextSize(value, (OrxGui::State)i); |
---|
| 482 | } |
---|
| 483 | |
---|
| 484 | /** |
---|
| 485 | * @brief sets the TextSize. |
---|
| 486 | * @param value the TextSize. |
---|
| 487 | * @param state: the State to setup |
---|
| 488 | */ |
---|
| 489 | void GLGuiWidget::setTextSize(float value, OrxGui::State state) |
---|
| 490 | { |
---|
| 491 | _style[state]._textSize = value; |
---|
| 492 | if (state == _state) |
---|
| 493 | _currentStyle._textSize = value; |
---|
| 494 | } |
---|
| 495 | |
---|
| 496 | /** |
---|
| 497 | * @brief sets the TextSize. |
---|
| 498 | * @param value the TextSize. |
---|
| 499 | * @param stateName: the State to setup |
---|
| 500 | */ |
---|
| 501 | void GLGuiWidget::setTextSizeS(float value, const std::string& stateName) |
---|
| 502 | { |
---|
| 503 | OrxGui::State state; |
---|
| 504 | if (getState(stateName, &state)) |
---|
| 505 | this->setTextSize(value, state); |
---|
| 506 | else |
---|
| 507 | this->setTextSize(value); |
---|
| 508 | } |
---|
| 509 | |
---|
| 510 | |
---|
| 511 | /** |
---|
| 512 | * @brief sets the Background Color for all States. |
---|
| 513 | * @param color the Color. |
---|
| 514 | */ |
---|
| 515 | void GLGuiWidget::setBackgroundColor(const Color& color) |
---|
| 516 | { |
---|
| 517 | for (unsigned int i = 0; i < GLGUI_STATE_COUNT; ++i) |
---|
| 518 | setBackgroundColor(color, (OrxGui::State)i); |
---|
| 519 | } |
---|
| 520 | |
---|
| 521 | /** |
---|
| 522 | * @brief sets the Background Color. |
---|
| 523 | * @param color the Color. |
---|
| 524 | * @param state: the State to setup |
---|
| 525 | */ |
---|
| 526 | void GLGuiWidget::setBackgroundColor(const Color& color, OrxGui::State state) |
---|
| 527 | { |
---|
| 528 | _style[state]._background.setDiffuseColor(color); |
---|
| 529 | if (state == _state) |
---|
| 530 | _currentStyle._background.setDiffuseColor(color); |
---|
| 531 | |
---|
| 532 | } |
---|
| 533 | |
---|
| 534 | /** |
---|
| 535 | * @brief sets the Background Color. |
---|
| 536 | * @param r the Color's red part. |
---|
| 537 | * @param g the Color's green part. |
---|
| 538 | * @param b the Color's blue part. |
---|
| 539 | * @param a the Color's alpha part. |
---|
| 540 | * @param stateName: the State to setup |
---|
| 541 | */ |
---|
| 542 | void GLGuiWidget::setBackgroundColorS(float r, float g, float b, float a, const std::string& stateName) |
---|
| 543 | { |
---|
| 544 | OrxGui::State state; |
---|
| 545 | if (getState(stateName, &state)) |
---|
| 546 | this->setBackgroundColor(Color(r,g,b,a), state); |
---|
| 547 | else |
---|
| 548 | this->setBackgroundColor(Color(r,g,b,a)); |
---|
| 549 | } |
---|
| 550 | |
---|
| 551 | |
---|
| 552 | /** |
---|
| 553 | * @brief sets the Background Texture for all States. |
---|
| 554 | * @param texture the Texture. |
---|
| 555 | */ |
---|
| 556 | void GLGuiWidget::setBackgroundTexture(const Texture& texture) |
---|
| 557 | { |
---|
| 558 | for (unsigned int i = 0; i < GLGUI_STATE_COUNT; ++i) |
---|
| 559 | setBackgroundTexture(texture, (OrxGui::State)i); |
---|
| 560 | } |
---|
| 561 | |
---|
| 562 | /** |
---|
| 563 | * @brief sets the Background Texture to all States. |
---|
| 564 | * @param textureName the Texture's fileName. |
---|
| 565 | */ |
---|
| 566 | void GLGuiWidget::setBackgroundTexture(const std::string& textureName) |
---|
| 567 | { |
---|
| 568 | for (unsigned int i = 0; i < GLGUI_STATE_COUNT; ++i) |
---|
| 569 | _style[i]._background.setDiffuseMap(textureName); |
---|
| 570 | this->_currentStyle._background.setDiffuseMap(textureName); |
---|
| 571 | } |
---|
| 572 | |
---|
| 573 | /** |
---|
| 574 | * @brief sets the Background Texture. |
---|
| 575 | * @param texture the Texture. |
---|
| 576 | * @param state the State to setup. |
---|
| 577 | */ |
---|
| 578 | void GLGuiWidget::setBackgroundTexture(const Texture& texture, OrxGui::State state) |
---|
| 579 | { |
---|
| 580 | _style[state]._background.setDiffuseMap(texture); |
---|
| 581 | if (state == _state) |
---|
| 582 | _currentStyle._background.setDiffuseMap(texture); |
---|
| 583 | } |
---|
| 584 | |
---|
| 585 | |
---|
| 586 | |
---|
| 587 | /** |
---|
| 588 | * @brief sets the Background Texture. |
---|
| 589 | * @param texture the Texture. |
---|
| 590 | * @param stateName the State to setup. |
---|
| 591 | */ |
---|
| 592 | void GLGuiWidget::setBackgroundTexture(const std::string& textureName, const std::string& stateName) |
---|
| 593 | { |
---|
| 594 | OrxGui::State state; |
---|
| 595 | if (getState(stateName, &state)) |
---|
| 596 | ; /// FIXME this->setBackgroundTexture(textureName, state); |
---|
| 597 | else |
---|
| 598 | ; /// this->setBackgroundTexture(textureName); |
---|
| 599 | } |
---|
| 600 | |
---|
| 601 | |
---|
| 602 | /** |
---|
| 603 | * @brief sets the Foreground Color for all States. |
---|
| 604 | * @param color the Color. |
---|
| 605 | */ |
---|
| 606 | void GLGuiWidget::setForegroundColor(const Color& color) |
---|
| 607 | { |
---|
| 608 | for (unsigned int i = 0; i < GLGUI_STATE_COUNT; ++i) |
---|
| 609 | setForegroundColor(color, (OrxGui::State)i); |
---|
| 610 | } |
---|
| 611 | |
---|
| 612 | /** |
---|
| 613 | * @brief sets the Foreground Color. |
---|
| 614 | * @param color the Color. |
---|
| 615 | * @param state the State to setup |
---|
| 616 | */ |
---|
| 617 | void GLGuiWidget::setForegroundColor(const Color& color, OrxGui::State state) |
---|
| 618 | { |
---|
| 619 | _style[state]._foreground.setDiffuseColor(color); |
---|
| 620 | if (state == _state) |
---|
| 621 | _currentStyle._foreground.setDiffuseColor(color); |
---|
| 622 | |
---|
| 623 | } |
---|
| 624 | |
---|
| 625 | /** |
---|
| 626 | * @brief sets the Foreground Color. |
---|
| 627 | * @param r the Color's red part. |
---|
| 628 | * @param g the Color's green part. |
---|
| 629 | * @param b the Color's blue part. |
---|
| 630 | * @param a the Color's alpha part. |
---|
| 631 | * @param stateName: the State to setup |
---|
| 632 | */ |
---|
| 633 | void GLGuiWidget::setForegroundColorS(float r, float g, float b, float a, const std::string& stateName) |
---|
| 634 | { |
---|
| 635 | OrxGui::State state; |
---|
| 636 | if (getState(stateName, &state)) |
---|
| 637 | this->setForegroundColor(Color(r,g,b,a), state); |
---|
| 638 | else |
---|
| 639 | this->setForegroundColor(Color(r,g,b,a)); |
---|
| 640 | } |
---|
| 641 | |
---|
| 642 | |
---|
[8990] | 643 | /** |
---|
| 644 | * @brief sets the Foreground Texture for all States. |
---|
| 645 | * @param texture the Texture. |
---|
| 646 | */ |
---|
| 647 | void GLGuiWidget::setForegroundTexture(const Texture& texture) |
---|
| 648 | { |
---|
| 649 | for (unsigned int i = 0; i < GLGUI_STATE_COUNT; ++i) |
---|
| 650 | setForegroundTexture(texture, (OrxGui::State)i); |
---|
| 651 | } |
---|
| 652 | |
---|
| 653 | /** |
---|
| 654 | * @brief sets the Foreground Texture to all States. |
---|
| 655 | * @param textureName the Texture's fileName. |
---|
| 656 | */ |
---|
| 657 | void GLGuiWidget::setForegroundTexture(const std::string& textureName) |
---|
| 658 | { |
---|
| 659 | for (unsigned int i = 0; i < GLGUI_STATE_COUNT; ++i) |
---|
| 660 | _style[i]._foreground.setDiffuseMap(textureName); |
---|
| 661 | this->_currentStyle._foreground.setDiffuseMap(textureName); |
---|
| 662 | } |
---|
| 663 | |
---|
| 664 | /** |
---|
| 665 | * @brief sets the Foreground Texture. |
---|
| 666 | * @param texture the Texture. |
---|
| 667 | * @param state the State to setup. |
---|
| 668 | */ |
---|
| 669 | void GLGuiWidget::setForegroundTexture(const Texture& texture, OrxGui::State state) |
---|
| 670 | { |
---|
| 671 | _style[state]._background.setDiffuseMap(texture); |
---|
| 672 | if (state == _state) |
---|
| 673 | _currentStyle._background.setDiffuseMap(texture); |
---|
| 674 | } |
---|
| 675 | |
---|
| 676 | |
---|
| 677 | |
---|
| 678 | /** |
---|
| 679 | * @brief sets the Foreground Texture. |
---|
| 680 | * @param texture the Texture. |
---|
| 681 | * @param stateName the State to setup. |
---|
| 682 | */ |
---|
| 683 | void GLGuiWidget::setForegroundTexture(const std::string& textureName, const std::string& stateName) |
---|
| 684 | { |
---|
| 685 | OrxGui::State state; |
---|
| 686 | if (getState(stateName, &state)) |
---|
| 687 | ; /// FIXME this->setForegroundTexture(textureName, state); |
---|
| 688 | else |
---|
| 689 | ; /// this->setForegroundTexture(textureName); |
---|
| 690 | } |
---|
| 691 | |
---|
| 692 | |
---|
[8619] | 693 | void GLGuiWidget::loadBackgroundMaterial(const Material& material) |
---|
| 694 | { |
---|
| 695 | for (unsigned int i = 0; i < GLGUI_STATE_COUNT; ++i) |
---|
| 696 | this->loadForegroundMaterial(material, (OrxGui::State)i); |
---|
| 697 | } |
---|
| 698 | |
---|
| 699 | void GLGuiWidget::loadBackgroundMaterial(const Material& material, OrxGui::State state) |
---|
| 700 | { |
---|
| 701 | this->_style[state]._background = material; |
---|
| 702 | if (state == _state) |
---|
| 703 | _currentStyle._background = material; |
---|
| 704 | |
---|
| 705 | } |
---|
| 706 | |
---|
| 707 | void GLGuiWidget::loadBackgroundMaterial(const TiXmlElement* element) |
---|
| 708 | { |
---|
| 709 | for (unsigned int i = 0; i < GLGUI_STATE_COUNT; ++i) |
---|
| 710 | this->loadBackgroundMaterial(element, (OrxGui::State)i); |
---|
| 711 | } |
---|
| 712 | |
---|
| 713 | void GLGuiWidget::loadBackgroundMaterial(const TiXmlElement* element, OrxGui::State state) |
---|
| 714 | { |
---|
| 715 | this->_style[state]._background.loadParams(element); |
---|
| 716 | if (state == _state) |
---|
| 717 | this->_currentStyle._background = _style[state]._background; |
---|
| 718 | } |
---|
| 719 | |
---|
| 720 | void GLGuiWidget::loadBackgroundMaterialS(const TiXmlElement* element, const std::string& stateName) |
---|
| 721 | { |
---|
| 722 | OrxGui::State state; |
---|
| 723 | if (getState(stateName, &state)) |
---|
| 724 | this->loadBackgroundMaterial(element, state); |
---|
| 725 | else |
---|
| 726 | this->loadBackgroundMaterial(element); |
---|
| 727 | } |
---|
| 728 | |
---|
| 729 | void GLGuiWidget::loadForegroundMaterial(const Material& material) |
---|
| 730 | {} |
---|
| 731 | void GLGuiWidget::loadForegroundMaterial(const Material& material, OrxGui::State state) |
---|
| 732 | {} |
---|
| 733 | void GLGuiWidget::loadForegroundMaterial(const TiXmlElement* element, OrxGui::State state) |
---|
| 734 | {} |
---|
| 735 | void GLGuiWidget::loadForegroundMaterialS(const TiXmlElement* element, const std::string& stateName) |
---|
| 736 | {} |
---|
| 737 | |
---|
| 738 | |
---|
| 739 | /** |
---|
| 740 | * @brief sets the Feature-Position. |
---|
| 741 | * @param featurePosition the Feature-Position. |
---|
| 742 | */ |
---|
| 743 | void GLGuiWidget::setFeaturePosition(FeaturePosition featurePosition) |
---|
| 744 | { |
---|
| 745 | this->_featurePosition = featurePosition; |
---|
| 746 | } |
---|
| 747 | |
---|
| 748 | /** |
---|
| 749 | * @brief sets the Feature-Position by converting from a String. |
---|
| 750 | * @param featurePosition the Feature-Position. |
---|
| 751 | */ |
---|
| 752 | void GLGuiWidget::setFeaturePositionS(const std::string& featurePosition) |
---|
| 753 | { |
---|
| 754 | for (unsigned int i = 0; i < 4; ++i) |
---|
| 755 | { |
---|
| 756 | if (featurePosition == FeaturePositionString[i]) |
---|
| 757 | { |
---|
| 758 | this->setFeaturePosition((FeaturePosition)i); |
---|
| 759 | } |
---|
| 760 | } |
---|
| 761 | } |
---|
| 762 | |
---|
| 763 | /** |
---|
| 764 | * @brief sets the Font. |
---|
| 765 | * @param font the Font. |
---|
| 766 | */ |
---|
[8769] | 767 | void GLGuiWidget::setFont(const Font& font) |
---|
[8619] | 768 | { |
---|
| 769 | this->_font = font; |
---|
| 770 | } |
---|
| 771 | |
---|
| 772 | /** |
---|
| 773 | * @brief sets the font from a Font-Name. |
---|
| 774 | * @param fontName the FileName of the Font. |
---|
| 775 | */ |
---|
[8769] | 776 | void GLGuiWidget::setFont(const std::string& fontName, unsigned int renderSize) |
---|
[8619] | 777 | { |
---|
[8769] | 778 | this->_font = Font(fontName, renderSize); |
---|
[8619] | 779 | } |
---|
| 780 | |
---|
| 781 | /** |
---|
| 782 | * @brief sets the AnimatedState. |
---|
| 783 | * @param animated: it states-changes should animate true, otherwise false. |
---|
| 784 | */ |
---|
| 785 | void GLGuiWidget::setAnimatedStateChanges(bool animated) |
---|
| 786 | { |
---|
| 787 | this->_animatedStateChanges = animated; |
---|
| 788 | } |
---|
| 789 | |
---|
| 790 | |
---|
| 791 | void GLGuiWidget::switchState(OrxGui::State state) |
---|
| 792 | { |
---|
| 793 | //this->_currentStyle = this->_style[state]; |
---|
| 794 | this->_state = state; |
---|
[9406] | 795 | PRINTF(4)("%s::%s Switches to state %s\n", this->getClassCName(), this->getCName(), OrxGui::StateString[state].c_str()); |
---|
[8619] | 796 | |
---|
| 797 | this->animateBack(); |
---|
| 798 | } |
---|
| 799 | |
---|
| 800 | |
---|
| 801 | void GLGuiWidget::animateBack() |
---|
| 802 | { |
---|
| 803 | this->_animating = true; |
---|
| 804 | this->_animationCycle = 0.0f; |
---|
| 805 | } |
---|
| 806 | |
---|
| 807 | |
---|
[8448] | 808 | void GLGuiWidget::tick(float dt) |
---|
| 809 | { |
---|
[8619] | 810 | if (this->_animating) |
---|
[8448] | 811 | { |
---|
[8619] | 812 | this->foregroundColor(); |
---|
| 813 | |
---|
| 814 | _animationCycle += dt / _animationDuration; |
---|
| 815 | if (_animationCycle >= 1.0) |
---|
[8448] | 816 | { |
---|
[8619] | 817 | _currentStyle._foreground.diffuseColor() = this->foregroundColor(_state); |
---|
| 818 | _currentStyle._background.diffuseColor() = this->backgroundColor(_state); |
---|
| 819 | _animating = false; |
---|
[8448] | 820 | } |
---|
[8619] | 821 | else |
---|
| 822 | { |
---|
| 823 | _currentStyle._foreground.diffuseColor().slerp(this->foregroundColor(_state), _animationCycle); |
---|
| 824 | _currentStyle._background.diffuseColor().slerp(this->backgroundColor(_state), _animationCycle); |
---|
| 825 | } |
---|
| 826 | this->updateFrontColor(); |
---|
[8448] | 827 | } |
---|
| 828 | } |
---|
[6431] | 829 | |
---|
[8448] | 830 | |
---|
[8035] | 831 | /** |
---|
| 832 | * USE THIS FUNCTION ONLY FROM DERIVED CLASS |
---|
| 833 | */ |
---|
[7779] | 834 | void GLGuiWidget::draw() const |
---|
| 835 | { |
---|
[8619] | 836 | this->background().select(); |
---|
[8035] | 837 | this->drawRect(this->backRect()); |
---|
[8619] | 838 | this->background().unselect(); |
---|
[7779] | 839 | } |
---|
| 840 | |
---|
[8619] | 841 | |
---|
| 842 | /** |
---|
| 843 | * @param stateName the Name of a State. |
---|
| 844 | * @param state the found State is returned here if found. |
---|
| 845 | * @returns true if String is found, false otherwise. |
---|
| 846 | */ |
---|
| 847 | bool GLGuiWidget::getState(const std::string& stateName, OrxGui::State* state) |
---|
| 848 | { |
---|
| 849 | for (unsigned int i = 0; i < GLGUI_STATE_COUNT; ++i) |
---|
| 850 | if (stateName == OrxGui::StateString[i]) |
---|
[8717] | 851 | { |
---|
| 852 | *state = (OrxGui::State)i; |
---|
| 853 | return true; |
---|
| 854 | } |
---|
[8619] | 855 | return false; |
---|
| 856 | } |
---|
| 857 | |
---|
| 858 | /** |
---|
| 859 | * @brief print out some nice debug output about the Widget. |
---|
| 860 | */ |
---|
[8717] | 861 | void GLGuiWidget::debug(unsigned int level) const |
---|
[8619] | 862 | { |
---|
[9406] | 863 | PRINT(0)("Debug of %s::%s - WidgetPart ", this->getClassCName(), this->getCName()); |
---|
[8619] | 864 | if (_parent != NULL) |
---|
[9406] | 865 | PRINT(0)("- Parent %s::%s ", _parent->getClassCName(), _parent->getCName()); |
---|
[8619] | 866 | PRINT(0)("- State: %s", StateString[_state].c_str()); |
---|
| 867 | |
---|
| 868 | if (_focusable) |
---|
| 869 | PRINT(0)("- focusable "); |
---|
| 870 | if (_clickable) |
---|
| 871 | PRINT(0)("- Clickable "); |
---|
| 872 | if (_pushed) |
---|
| 873 | PRINT(0)("- Pushed "); |
---|
| 874 | PRINT(0)("\n"); |
---|
| 875 | |
---|
| 876 | |
---|
| 877 | PRINT(0)("Minimum Size %0.2f %0.2f ", _minSize.x, _minSize.y); |
---|
| 878 | PRINT(0)("Back Rect: "); |
---|
| 879 | _backRect.debug(); |
---|
| 880 | PRINT(0)("Style:\n"); |
---|
| 881 | |
---|
| 882 | for (unsigned int i = 0; i < GLGUI_STATE_COUNT; ++i) |
---|
| 883 | { |
---|
| 884 | PRINT(0)("In State %s: \n", StateString[i].c_str()); |
---|
| 885 | |
---|
| 886 | PRINT(0)(" Borders: Left: %0.2f, Right: %0.2f, Top: %0.2f, Bottom %0.2f\n", |
---|
| 887 | _style[i]._borderLeft, _style[i]._borderRight, _style[i]._borderTop, _style[i]._borderBottom); |
---|
| 888 | PRINT(0)(" TextSize %0.2f\n", _style[i]._textSize); |
---|
| 889 | PRINT(0)(" BackgroundColor: "); _style[i]._background.diffuseColor().debug(); |
---|
| 890 | PRINT(0)(" ForegroundColor: "); _style[i]._foreground.diffuseColor().debug(); |
---|
| 891 | PRINT(0)("\n"); |
---|
| 892 | } |
---|
| 893 | |
---|
| 894 | |
---|
| 895 | PRINT(0)(" Feature at %s ", FeaturePositionString[_featurePosition].c_str()); |
---|
| 896 | /// TODO PRINT(0)(""); Font* _font; //!< The Font used in the current Widget. |
---|
| 897 | |
---|
| 898 | if (_animatedStateChanges) |
---|
| 899 | PRINT(0)("- AnimatedStateChanges"); |
---|
| 900 | PRINT(0)("\n"); |
---|
| 901 | |
---|
| 902 | /* |
---|
| 903 | if (_animating) |
---|
| 904 | PRINT(0)("- Animated "); |
---|
| 905 | |
---|
| 906 | // |
---|
| 907 | float _animationCycle; |
---|
| 908 | float _animationDuration; |
---|
| 909 | StatedStyle _currentStyle; |
---|
| 910 | OrxGui::State _currentState; |
---|
| 911 | */ |
---|
| 912 | } |
---|
| 913 | |
---|
| 914 | |
---|
[6287] | 915 | } |
---|