Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/gui/gl/glgui_widget.cc @ 8760

Last change on this file since 8760 was 8717, checked in by bensch, 18 years ago

merged the gui back

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