Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8605 in orxonox.OLD for branches/gui/src/lib/gui/gl/glgui_widget.cc


Ignore:
Timestamp:
Jun 20, 2006, 9:59:53 AM (18 years ago)
Author:
bensch
Message:

orxonox/gui: fading works again

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/gui/src/lib/gui/gl/glgui_widget.cc

    r8604 r8605  
    1414*/
    1515
    16 #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_GUI
     16#define DEBUG_SPECIAL_MODULE 4//DEBUG_MODULE_GUI
    1717
    1818#include "glgui_widget.h"
     
    4141
    4242  /**
     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  /**
    4370   * @brief standard deconstructor
    4471   */
     
    4774    if (this == GLGuiWidget::_focused)
    4875      GLGuiWidget::_focused = NULL;
    49 
    50     if (this->_toFrontColor)
    51       delete this->_toFrontColor;
    5276  }
    5377
     
    6993    this->_pushed = false;
    7094    this->_state = OrxGui::Normal;
    71     this->_toFrontColor = NULL;
    7295
    7396
     
    7598    this->resetStyle();
    7699
    77     this->_animationCycle = -1.0;
     100    this->_animating = false;
     101    this->_animationCycle = 0.0;
    78102    this->_animationDuration = 1.0;
    79103
    80104
    81105    this->setBackgroundColor(Color(0, 0, 0, 1));
     106    this->_style[0]._background.setBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
     107    this->_style[1]._background.setBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
     108    this->_style[2]._background.setBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
     109    this->_style[3]._background.setBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    82110
    83111    this->setForegroundColor(Color(1, 0, 0, 1), OrxGui::Normal);
     
    136164  void GLGuiWidget::setFrontColor(const Color& frontColor, bool instantaniously)
    137165  {
    138     if (instantaniously)
     166/*    if (instantaniously)
    139167    {
    140168      this->setForegroundColor(frontColor);
     
    150178      *this->_toFrontColor = frontColor;
    151179    //this->_frontColor = frontColor;
    152     //this->updateFrontColor();
     180    //this->updateFrontColor();*/
    153181  };
    154182
     
    265293    this->setFont(NULL);
    266294
    267     this->setAnimated(true);
    268295    this->setAnimatedStateChanges(true);
    269296  }
    270297
    271   /**
    272    * @brief loads Parameters for a Style from XML
    273    * @param root the XML-Element to load from.
    274    */
    275   void GLGuiWidget::loadParams(const TiXmlElement* root)
    276   {
    277     LoadParam(root, "border-left", this, GLGuiWidget, setBorderLeft);
    278     LoadParam(root, "border-right", this, GLGuiWidget, setBorderRight);
    279     LoadParam(root, "border-top", this, GLGuiWidget, setBorderTop);
    280     LoadParam(root, "border-bottom", this, GLGuiWidget, setBorderBottom);
    281 
    282     LoadParam(root, "text-size", this, GLGuiWidget, setTextSize);
    283     LoadParam(root, "background-color", this, GLGuiWidget, setBackgroundColorS);
    284     LoadParam(root, "foreground-color", this, GLGuiWidget, setForegroundColorS);
    285 
    286     //    LoadParamXML(root, "backmat", this, GLGuiWidget, loadBackgroundMaterial);
    287     //    LoadParamXML(root, "frontmat", this, GLGuiWidget, loadForegroundMaterial);
    288 
    289     LoadParam(root, "feature-position", this, GLGuiWidget, setFeaturePositionS);
    290     LoadParam(root, "Font", this, GLGuiWidget, setFont);
    291 
    292     LoadParam(root, "animated", this, GLGuiWidget, setAnimated);
    293     LoadParam(root, "animated-state-changes", this, GLGuiWidget, setAnimatedStateChanges);
    294   }
    295298
    296299  /**
     
    674677
    675678  /**
    676    * @brief if Animation should be turned on.
    677    * @param animated true if on, false otherwise.
    678    */
    679   void GLGuiWidget::setAnimated(bool animated)
    680   {
    681     this->_animated = animated;
    682   }
    683 
    684   /**
    685679   * @brief sets the AnimatedState.
    686680   * @param animated: it states-changes should animate true, otherwise false.
     
    694688  void GLGuiWidget::switchState(OrxGui::State state)
    695689  {
    696     this->_currentStyle = this->_style[state];
     690    //this->_currentStyle = this->_style[state];
    697691    this->_state = state;
    698     printf("Switching to state %s\n", OrxGui::StateString[state].c_str());
     692    PRINTF(3)("Switching to state %s\n", OrxGui::StateString[state].c_str());
     693
     694    this->animateBack();
    699695  }
    700696
     
    716712  }
    717713
     714  void GLGuiWidget::animateBack()
     715  {
     716    this->_animating = true;
     717    this->_animationCycle = 0.0f;
     718  }
     719
    718720
    719721  void GLGuiWidget::tick(float dt)
    720722  {
    721     if (this->_toFrontColor)
     723    if (this->_animating)
    722724    {
    723       this->foregroundColor(_state).slerp(*_toFrontColor, dt*3.0);
     725      this->foregroundColor();
     726
     727      _animationCycle += dt / _animationDuration;
     728      if (_animationCycle >= 1.0)
     729      {
     730        _currentStyle._foreground.diffuseColor() = this->foregroundColor(_state);
     731        _animating = false;
     732      }
     733      else
     734        _currentStyle._foreground.diffuseColor().slerp(this->foregroundColor(_state), _animationCycle);
     735
    724736      this->updateFrontColor();
    725       if (this->foregroundColor(_state).dist(*_toFrontColor) < .1)
    726       {
    727         delete _toFrontColor;
    728         _toFrontColor = NULL;
    729       }
    730737    }
    731738  }
     
    779786    /// TODO    PRINT(0)("");    Font*               _font;                 //!< The Font used in the current Widget.
    780787
    781     if (_animated)
    782       PRINT(0)("- Animated ");
    783788    if (_animatedStateChanges)
    784789      PRINT(0)("- AnimatedStateChanges");
     
    786791
    787792    /*
     793    if (_animating)
     794      PRINT(0)("- Animated ");
     795
     796    //
    788797    float               _animationCycle;
    789798    float               _animationDuration;
Note: See TracChangeset for help on using the changeset viewer.