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