Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8619 in orxonox.OLD for trunk/src/lib/gui/gl


Ignore:
Timestamp:
Jun 20, 2006, 1:24:11 PM (18 years ago)
Author:
bensch
Message:

trunk: merged the gui-branche back.
merged with command:
svn merge -r8520:HEAD https://svn.orxonox.net/orxonox/branches/gui
no conflicts

Location:
trunk/src/lib/gui/gl
Files:
2 deleted
17 edited
2 copied

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/gui/gl/Makefile.am

    r8518 r8619  
    1212                glmenu/glmenu_imagescreen.cc \
    1313                \
    14                 glgui_style.cc \
    1514                glgui_handler.cc \
    1615                signal_connector.cc \
     
    2726                glgui_inputline.cc \
    2827                glgui_textfield.cc \
     28                glgui_table.cc \
    2929                glgui_image.cc \
    3030                glgui_window.cc \
     
    3737                glmenu/glmenu_imagescreen.h \
    3838                \
    39                 glgui_style.h \
    4039                signal_connector.h \
    4140                glgui.h \
     
    5453                glgui_inputline.h \
    5554                glgui_textfield.h \
     55                glgui_table.h \
    5656                glgui_image.h \
    5757                glgui_window.h \
  • trunk/src/lib/gui/gl/glgui.h

    r8145 r8619  
    1616#include "glgui_button.h"
    1717#include "glgui_checkbutton.h"
    18 //#include "glgui_colorselector.h"
    1918#include "glgui_pushbutton.h"
    2019#include "glgui_slider.h"
     
    2221#include "glgui_inputline.h"
    2322#include "glgui_textfield.h"
     23#include "glgui_table.h"
    2424#include "glgui_image.h"
    2525
  • trunk/src/lib/gui/gl/glgui_box.cc

    r8450 r8619  
    110110    if (orientation() == OrxGui::Vertical)
    111111    {
    112       float height = this->borderTop();
     112      float height = borderTop();
    113113      float width = 0.0f;
    114114      std::vector<GLGuiWidget*>::iterator widget;
     
    117117      for (widget = this->children.begin(); widget != this->children.end(); ++widget)
    118118      {
    119         (*widget)->setRelCoor2D(this->borderLeft(), height);
     119        (*widget)->setRelCoor2D(borderLeft(), height);
    120120        height += (*widget)->getSizeY2D();
    121121        width = fmax(width, (*widget)->getSizeX2D());
    122122      }
    123123
    124       width += this->borderLeft() + this->borderRight();
    125       height += this->borderBottom(); /* *2 done further up */
     124      width += borderLeft() + borderRight();
     125      height += borderBottom(); /* *2 done further up */
    126126
    127127      printf("%f %f\n", width, height);
     
    130130    else
    131131    {
    132       float height = this->borderTop();
    133       float width = this->borderLeft();
     132      float height = borderTop();
     133      float width = borderLeft();
    134134      std::vector<GLGuiWidget*>::iterator widget;
    135135
     
    137137      for (widget = this->children.begin(); widget != this->children.end(); ++widget)
    138138      {
    139         (*widget)->setRelCoor2D(width, this->borderTop());
     139        (*widget)->setRelCoor2D(width, borderTop());
    140140        height = fmax(height, (*widget)->getSizeY2D());
    141141        width += (*widget)->getSizeX2D();
    142142      }
    143143
    144       width += this->borderRight() ;
    145       height += this->borderBottom(); /* *2 done further up */
     144      width += borderRight() ;
     145      height += borderBottom(); /* *2 done further up */
    146146
    147147      printf("%f %f\n", width, height);
  • trunk/src/lib/gui/gl/glgui_button.cc

    r8448 r8619  
    5555
    5656    this->_label.setFont("fonts/final_frontier.ttf", 20);
    57     this->_label.setColor(this->frontColor());
     57    this->_label.setColor(this->foregroundColor() );
    5858
    5959    this->_label.setParent2D(this);
     
    7171  void GLGuiButton::updateFrontColor()
    7272  {
    73     this->_label.setColor(this->frontColor());
     73    this->_label.setColor(this->foregroundColor());
    7474  }
    7575
  • trunk/src/lib/gui/gl/glgui_button.h

    r8448 r8619  
    3636      virtual ~GLGuiButton();
    3737
    38       const std::string& label() const { return this->_label.getText(); };
     38      const std::string& label() const { return this->_label.text(); };
    3939      void setLabel(const std::string& label);
    4040
  • trunk/src/lib/gui/gl/glgui_checkbutton.cc

    r8448 r8619  
    9696//     this->frontMaterial().select();
    9797//     this->drawRect(this->frontRect());
    98 
    9998    if (this->bActive)
    10099    {
    101       glColor3fv( &this->frontColor()[0]);
     100      glColor3fv( &this->foregroundColor()[0]);
    102101      this->drawRect(this->_checkBox);
    103102
     
    124123    else
    125124    {
    126       glColor3fv( &this->frontColor()[0]);
     125      glColor3fv( &this->foregroundColor()[0]);
    127126      this->drawRect(this->_checkBox);
    128127    }
  • trunk/src/lib/gui/gl/glgui_container.cc

    r8145 r8619  
    4343    this->setClassID(CL_GLGUI_CONTAINER, "GLGuiContainer");
    4444
     45    this->setBackgroundTexture("gui_container_background.png");
     46
    4547  }
    4648
  • trunk/src/lib/gui/gl/glgui_cursor.cc

    r8324 r8619  
    5757    this->setClassID(CL_GLGUI_CURSOR, "GLGuiCursor");
    5858
    59     this->backMaterial().setDiffuse(1.0,0.0,0.0);
    60     this->backMaterial().setDiffuseMap("cursor.png");
    61     this->backMaterial().setBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
     59    this->setBackgroundColor(Color(1.0, 1.0, 1.0, 1.0));
     60    this->setBackgroundTexture("cursor.png");
    6261    this->setSize2D(50, 50);
    6362    this->setAbsCoor2D(100, 100);
    6463    this->setLayer(E2D_LAYER_ABOVE_ALL);
    6564    this->color = 0.0f;
     65    this->frameNumber = 0.0f;
    6666
    6767    this->resize();
     
    7979  bool GLGuiCursor::loadTextureSequence(const std::string& imageNameSubstitue, unsigned int from, unsigned int to)
    8080  {
    81     this->backMaterial().setDiffuse(1.0, 1.0, 1.0);
     81    //this->background().setDiffuse(1.0, 1.0, 1.0);
    8282    return this->seq.loadImageSeries(imageNameSubstitue, from, to);
    8383  }
     
    9797        this->color -= 360.0;
    9898      Vector color =  Color::HSVtoRGB(Vector(this->color, 1.0, 1.0));
    99       this->backMaterial().setDiffuse(color.x, color.y, color.z);
     99      //this->setBackgroundColor(color.x, color.y, color.z);
     100      /// FIXME
     101
    100102    }
    101103    //if (this->movement != Vector2D())
     
    125127    this->beginDraw();
    126128
    127     this->backMaterial().select();
     129    this->background().select();
    128130    if (!this->seq.empty())
    129131      glBindTexture(GL_TEXTURE_2D, this->seq.getFrameTexture((int)frameNumber));
  • trunk/src/lib/gui/gl/glgui_defs.h

    r8448 r8619  
    2222  } Orientation;
    2323
     24  //! Names of Orientations
    2425  const std::string OrientationString[] = {
    2526    "Horizontal",
     
    3031  typedef enum {
    3132    Normal,           //!< Normal state of the GUI's Widgets.
    32     Active,           //!< If the widget is Active.
     33    Focused,           //!< If the widget is Active.
    3334    Selected,         //!< If the Widget is Selected.
    3435    Insensitive       //!< If the Widget is insensitive.
     
    3839#define GLGUI_DEFAULT_STYLE OrxGui::Normal
    3940
     41//! names of the States.
    4042  const std::string StateString[] =
    4143    {
    4244      "Normal",
    43       "Active",
     45      "Focused",
    4446      "Selected",
    4547      "Insensitive"
     
    5456    } FeaturePosition;
    5557
     58    //! Names of Feature-Positions
    5659    const std::string FeaturePositionString[] =
    5760    {
  • trunk/src/lib/gui/gl/glgui_image.cc

    r8448 r8619  
    4747    this->setClassID(CL_GLGUI_IMAGE, "GLGuiImage");
    4848
     49    this->setForegroundColor(Color(1,1,1,1));
    4950    this->_imageMaterial.setBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    5051
     
    7677  void GLGuiImage::updateFrontColor()
    7778  {
    78     this->_imageMaterial.setDiffuseColor(this->frontColor());
     79    this->_imageMaterial.setDiffuseColor(foregroundColor());
    7980  }
    8081
    8182  void GLGuiImage::resize()
    8283  {
    83     this->_imagePlane.setTopLeft(this->borderLeft(), this->borderTop());
     84    this->_imagePlane.setTopLeft(borderLeft(), borderTop());
    8485    this->_imagePlane.setSize(this->getSizeX2D() - (borderLeft() + borderRight()), this->getSizeY2D() - (borderTop() + borderBottom()) );
    8586    GLGuiWidget::resize();
  • trunk/src/lib/gui/gl/glgui_inputline.cc

    r8518 r8619  
    5252    this->_text.setRelCoor2D(4,4);
    5353    this->_text.setFont("fonts/final_frontier.ttf", 20);
    54     this->_text.setColor(this->frontColor());
     54    this->_text.setLineWidth(400);
     55    this->_text.setDotsPosition(LimitedWidthText::Begin);
     56    this->_text.setColor(foregroundColor());
    5557    this->_text.setVisibility(false);
    5658    this->resize();
     59
     60    this->delayNext = 0.0;
     61    this->pressedKey = SDLK_FIRST;
     62    this->pressedKeyName = SDLK_FIRST;
    5763
    5864  }
     
    116122    this->resize();
    117123    this->setFrontColor(Color(1,1,1,1), true);
    118     this->setFrontColor(Color(0,1,0,1));
    119     emit(this->textChanged(this->_text.getText()));
     124    emit(this->textChanged(this->_text.text()));
    120125  }
    121126
     
    139144  void GLGuiInputLine::pushEnter()
    140145  {
    141     emit(this->enterPushed(this->_text.getText()));
     146    emit(this->enterPushed(this->_text.text()));
    142147    if (this->_clearOnEnter)
    143148      this->clear();
     
    197202  void GLGuiInputLine::resize()
    198203  {
    199     this->_text.setRelCoor2D(this->borderLeft(), this->borderTop());
     204    this->_text.setRelCoor2D(borderLeft(), borderTop());
    200205    this->setSize2D( this->_text.getSize2D() + Vector2D(borderLeft() + borderRight(), borderTop() + borderBottom()));
    201206    GLGuiWidget::resize();
    202 /*    this->frontRect().setTopLeft(borderLeft(), borderTop());
    203     this->frontRect().setSize(this->getSize2D() - Vector2D(borderLeft() + borderRight(), borderTop() + borderBottom()));*/
     207    /*    this->frontRect().setTopLeft(borderLeft(), borderTop());
     208        this->frontRect().setSize(this->getSize2D() - Vector2D(borderLeft() + borderRight(), borderTop() + borderBottom()));*/
    204209  }
    205210
    206211  void GLGuiInputLine::updateFrontColor()
    207212  {
    208     this->_text.setColor(this->frontColor());
     213    this->_text.setColor(foregroundColor());
    209214  }
    210215
     
    228233    if (this->delayNext > 0.0)
    229234      this->delayNext -= dt;
    230         else if (this->pressedKey != SDLK_FIRST )
     235    else if (this->pressedKey != SDLK_FIRST )
    231236    {
    232237      this->delayNext = GLGuiInputLine::repeatRate;
     
    237242          break;
    238243        default:
    239         {
    240           if (likely(this->pressedKey < 127))
    241             this->appendCharacter(this->pressedKeyName);
    242         }
     244          {
     245            if (likely(this->pressedKey < 127))
     246              this->appendCharacter(this->pressedKeyName);
     247          }
    243248      }
    244249    }
     
    255260    GLGuiWidget::draw();
    256261
    257 //     this->frontMaterial().select();
    258 //     GLGuiWidget::drawRect(this->frontRect());
     262    //     this->frontMaterial().select();
     263    //     GLGuiWidget::drawRect(this->frontRect());
    259264
    260265    this->endDraw();
  • trunk/src/lib/gui/gl/glgui_inputline.h

    r8518 r8619  
    99
    1010#include "glgui_widget.h"
    11 #include "text.h"
     11#include "limited_width_text.h"
    1212#include "event.h"
    1313
     
    3232
    3333    /** @returns the text of the inputLine */
    34     const std::string& _getText() const { return this->_text.getText(); };
     34    const std::string& _getText() const { return this->_text.text(); };
    3535
    3636    void setText(const std::string& text);
     
    6666
    6767  private:
    68     Text                    _text;            //!< The Text to display inside of the InputLine.
     68    LimitedWidthText        _text;            //!< The Text to display inside of the InputLine.
    6969    bool                    _clearOnEnter;    //!< Clear on Enter
    7070
  • trunk/src/lib/gui/gl/glgui_slider.cc

    r8448 r8619  
    7474    else
    7575      this->_value = value;
    76     this->_handle.setCenter(this->sliderPosition(), this->borderTop() + (this->getSizeY2D() - this->borderTop() - borderBottom()) / 2.0);
     76    this->_handle.setCenter(this->sliderPosition(), borderTop() + (this->getSizeY2D() - borderTop() - borderBottom()) / 2.0);
    7777
    7878    emit(valueChanged(this->_value));
     
    165165//    this->frontRect().setTopLeft(this->borderLeft(), this->getSizeY2D()/2.0 - 2.0);
    166166//    this->frontRect().setSize(this->getSizeX2D() - borderLeft() - borderRight(), 4.0);
    167     this->_slider.setTopLeft(this->borderLeft(), this->getSizeY2D() / 2.0 -2.0);
     167    this->_slider.setTopLeft(borderLeft(), this->getSizeY2D() / 2.0 -2.0);
    168168    this->_slider.setSize(this->getSizeX2D() - borderLeft() - borderRight(), 4.0);
    169169    this->_handle.setSize(this->_sliderWidth, this->getSizeY2D() - borderTop() - borderBottom());
     
    211211  {
    212212    return (this->_value - this->_minValue)/( this->_maxValue - this->_minValue) *
    213            (this->getSizeX2D() - (borderLeft() + borderRight() + 2.0*_sliderWidth)) +
    214            (borderLeft() +_sliderWidth);
     213        (this->getSizeX2D() - (borderLeft() + borderRight() + 2.0*_sliderWidth)) +
     214        (borderLeft() +_sliderWidth);
    215215  }
    216216
     
    239239    GLGuiWidget::draw();
    240240
    241     glColor4fv(&this->frontColor()[0]);
     241    glColor4fv(&this->foregroundColor()[0]);
    242242    this->drawRect(this->_slider);
    243243    this->drawRect(this->_handle);
  • trunk/src/lib/gui/gl/glgui_widget.cc

    r8448 r8619  
    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"
     
    2323
    2424#include "debug.h"
     25
     26#include "loading/load_param.h"
    2527
    2628namespace OrxGui
     
    3941
    4042  /**
     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  /**
    4170   * @brief standard deconstructor
    4271   */
     
    4574    if (this == GLGuiWidget::_focused)
    4675      GLGuiWidget::_focused = NULL;
    47 
    48     if (this->_toFrontColor)
    49       delete this->_toFrontColor;
    5076  }
    5177
     
    6692    this->_clickable = false;
    6793    this->_pushed = false;
     94    this->_state = OrxGui::Normal;
     95
     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);
    68116
    69117    this->setVisibility(GLGUI_WIDGET_DEFAULT_VISIBLE);
    70118
    71     this->_backMat.setDiffuseColor(Color(1.0, 0.5, 0.4, 1.0));
    72     this->_backMat.setDiffuseMap("gui_element_background.png");
    73     this->_frontColor = Color(1.0, 0.0, 0.0);
    74     this->_toFrontColor = NULL;
    75 
    76 
    77     this->_borderLeft = 15.0;
    78     this->_borderRight = 1.0;
    79     this->_borderTop = 1.0;
    80     this->_borderBottom = 1.0;
     119    this->setBorderLeft(15);
     120    this->setBackgroundTexture("gui_element_background.png");
     121
     122    this->switchState(_state);
     123    this->_currentStyle = this->_style[_state];
    81124  }
    82125
     
    121164  }
    122165
     166
     167
    123168  void GLGuiWidget::setFrontColor(const Color& frontColor, bool instantaniously)
    124169  {
    125     if (instantaniously)
    126     {
    127       this->_frontColor = frontColor;
    128       if (this->_toFrontColor != NULL)
    129       {
    130         delete this->_toFrontColor;
    131         this->_toFrontColor = NULL;
    132       }
    133     }
    134     else if (!this->_toFrontColor)
    135       this->_toFrontColor = new Color(frontColor);
    136     else
    137       *this->_toFrontColor = frontColor;
    138     //this->_frontColor = frontColor;
    139     //this->updateFrontColor();
     170    this->_currentStyle._foreground.setDiffuseColor(frontColor);
     171    this->animateBack();
    140172  };
    141 
    142 
    143   void GLGuiWidget::setBorderSize(float borderSize)
    144   {
    145     this->_borderLeft = borderSize;
    146     this->_borderRight = borderSize;
    147     this->_borderTop = borderSize;
    148     this->_borderBottom = borderSize;
    149     this->resize();
    150   }
    151 
    152   void GLGuiWidget::setBorderLeft(float borderLeft)
    153   {
    154     this->_borderLeft = borderLeft;
    155     this->resize();
    156   }
    157   void GLGuiWidget::setBorderRight(float borderRight)
    158   {
    159     this->_borderRight = borderRight;
    160     this->resize();
    161   }
    162   void GLGuiWidget::setBorderTop(float borderTop)
    163   {
    164     this->_borderTop = borderTop;
    165     this->resize();
    166   }
    167   void GLGuiWidget::setBorderBottom(float borderBottom)
    168   {
    169     this->_borderBottom = borderBottom;
    170     this->resize();
    171   }
    172 
    173173
    174174
     
    201201  void GLGuiWidget::clicking(const Vector2D& pos)
    202202  {
    203     this->setFrontColor(Color(0, 0, 1));
    204 
     203    this->switchState(OrxGui::Selected);
    205204  }
    206205
    207206  void GLGuiWidget::releasing(const Vector2D& pos)
    208207  {
    209     this->setFrontColor(Color(0,1,0));
    210 
     208    this->switchState(OrxGui::Normal);
    211209  }
    212210
    213211  void GLGuiWidget::receivedFocus()
    214212  {
    215     this->setFrontColor(Color(0, 1, 0));
     213    this->switchState(OrxGui::Focused);
    216214  }
    217215
    218216  void GLGuiWidget::removedFocus()
    219217  {
    220     this->setFrontColor(Color(1, 0, 0));
     218    this->switchState(OrxGui::Normal);
    221219
    222220  }
     
    267265  }
    268266
    269   void GLGuiWidget::tick(float dt)
    270   {
    271     if (this->_toFrontColor)
     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)
    272668    {
    273       this->_frontColor.slerp(*_toFrontColor, dt*3.0);
    274       this->updateFrontColor();
    275       if (this->_frontColor.dist(*_toFrontColor) < .1)
     669      if (featurePosition == FeaturePositionString[i])
    276670      {
    277         delete _toFrontColor;
    278         _toFrontColor = NULL;
     671        this->setFeaturePosition((FeaturePosition)i);
    279672      }
    280673    }
    281674  }
    282675
     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
     721  void GLGuiWidget::tick(float dt)
     722  {
     723    if (this->_animating)
     724    {
     725      this->foregroundColor();
     726
     727      _animationCycle += dt / _animationDuration;
     728      if (_animationCycle >= 1.0)
     729      {
     730        _currentStyle._foreground.diffuseColor() = this->foregroundColor(_state);
     731        _currentStyle._background.diffuseColor() = this->backgroundColor(_state);
     732        _animating = false;
     733      }
     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();
     740    }
     741  }
     742
    283743
    284744  /**
     
    287747  void GLGuiWidget::draw() const
    288748  {
    289     this->backMaterial().select();
     749    this->background().select();
    290750    this->drawRect(this->backRect());
    291     this->backMaterial().unselect();
    292   }
     751    this->background().unselect();
     752  }
     753
     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
    293827
    294828}
  • trunk/src/lib/gui/gl/glgui_widget.h

    r8518 r8619  
    99#include "element_2d.h"
    1010
    11 #include "glgui_style.h"
     11#include "glgui_defs.h"
     12
    1213#include "material.h"
    1314#include "rect2D.h"
     
    1516#include "event.h"
    1617#include "signal_connector.h"
     18
     19class Font;
    1720
    1821namespace OrxGui
     
    6669    void disconnect(GLGuiWidget* sender, Signal& signal, BaseObject* receiver);
    6770
    68 
    69     GLGuiStyle& style() { return this->_style; };
    70     const GLGuiStyle style() const { return this->_style; };
    71 
    72     /// MATERIAL (looks)
    73     Material& backMaterial() { return this->_backMat; };
    74     const Material& backMaterial() const { return this->_backMat; };
     71    OrxGui::State state() const { return this->_state; };
     72
    7573    Rect2D& backRect() { return this->_backRect; };
    7674    const Rect2D& backRect() const { return this->_backRect; };
    7775
    7876    void setFrontColor(const Color& frontColor, bool instantaniously = false);
    79     const Color& frontColor() const { return this->_frontColor; };
    80 
    81     /** @brief sets all borders to the same value. */
    82     void setBorderSize(float borderSize);
    83     void setBorderLeft(float borderLeft);
    84     void setBorderRight(float borderRight);
    85     void setBorderTop(float borderTop);
    86     void setBorderBottom(float borderBottom);
    87 
    88     float borderLeft() const { return this->_borderLeft; };
    89     float borderRight() const { return this->_borderRight; };
    90     float borderTop() const { return this->_borderTop; };
    91     float borderBottom() const { return this->_borderBottom; };
    92 
    9377
    9478    void setWidgetSize(const Vector2D& size);
    9579    void setWidgetSize(float x, float y);
    9680
    97 
    98     void setBackgroundColor(float x, float y, float z) { this->backMaterial().setDiffuse(x,y,z); };
     81    void animateBack();
     82
     83    /// STYLE
     84    ////////////////////////////////
     85    /// Retrieve Current Values. ///
     86    ////////////////////////////////
     87    /** @returns current left borderWidth */
     88    inline float borderLeft() const { return _currentStyle._borderLeft; }
     89    /** @returns current right borderWidth */
     90    inline float borderRight() const { return _currentStyle._borderRight; }
     91    /** @returns current top borderWidth */
     92    inline float borderTop() const { return _currentStyle._borderTop; }
     93    /** @returns burrent bottom borderWidth */
     94    inline float borderBottom() const { return _currentStyle._borderBottom; }
     95
     96
     97    /** @returns current textSize */
     98    inline float textSize() const { return _currentStyle._textSize; }
     99    /** @returns the Background Color */
     100    inline const Color& backgroundColor() const { return _currentStyle._background.diffuseColor(); }
     101    /** @returns the current Background Material. */
     102    inline const Material& background() const { return _currentStyle._background; }
     103    /** @returns the current background Texture. */
     104    inline const Texture& backgroundTexture() const { return _currentStyle._background.diffuseTexture(); }
     105    /** @returns the current foreground Color */
     106    inline const Color& foregroundColor() const { return _currentStyle._foreground.diffuseColor(); }
     107    /** @returns the current ForeGroung Material. */
     108    inline const Material& foreground() const { return _currentStyle._foreground; }
     109
     110
     111    /** @returns FeaturePosition */
     112    inline FeaturePosition featurePosition() const { return _featurePosition; }
     113    /** @returns the font */
     114    inline const Font* const font() const { return _font; }
     115    /** @returns true if the Element is Animated */
     116    inline bool animating() const { return _animating; }
     117    /** @returns true if State-Changes are animated */
     118    inline bool animatedStateChanges() const { return _animatedStateChanges; }
     119
     120
     121    ///////////////////////////////////////////////////////////////
     122    /// Retrieve Values for the Saved Values inside the States. ///
     123    ///////////////////////////////////////////////////////////////
     124    /** @returns left borderWidth @param state the State to retrieve from */
     125    inline float borderLeft(OrxGui::State state) const { return _style[state]._borderLeft; }
     126    /** @returns right borderWidth @param state the State to retrieve from */
     127    inline float borderRight(OrxGui::State state) const { return _style[state]._borderRight; }
     128    /** @returns top borderWidth @param state the State to retrieve from */
     129    inline float borderTop(OrxGui::State state) const { return _style[state]._borderTop; }
     130    /** @returns bottom borderWidth @param state the State to retrieve from */
     131    inline float borderBottom(OrxGui::State state) const { return _style[state]._borderBottom; }
     132
     133    /** @returns textSize @param state the State to retrieve from */
     134    inline float textSize(OrxGui::State state) const { return _style[state]._textSize; }
     135    /** @returns the Background Color @param state the State to retrieve from */
     136    inline const Color& backgroundColor(OrxGui::State state) const { return _style[state]._background.diffuseColor(); }
     137    /** @returns the Background Material. @param state the state to retrieve from */
     138    inline const Material& background(OrxGui::State state) const { return _style[state]._background; }
     139    /** @returns background Texture. @param state the State to retrieve from */
     140    inline const Texture& backgroundTexture(OrxGui::State state) const { return _style[state]._background.diffuseTexture(); }
     141    /** @returns the foreground Color @param state the State to retrieve from */
     142    inline const Color& foregroundColor(OrxGui::State state) const { return _style[state]._foreground.diffuseColor(); }
     143    /** @returns the ForeGroung Material. @param state the state to retrieve from */
     144    inline const Material& foreground(OrxGui::State state) const { return _style[state]._foreground; }
     145
     146
     147    /// SETUP
     148    void resetStyle();
     149    void loadParams(const TiXmlElement* root);
     150
     151    void setBorderLeft(float value);
     152    void setBorderLeft(float value, OrxGui::State state);
     153    void setBorderLeftS(float value, const std::string& stateName);
     154
     155    void setBorderRight(float value);
     156    void setBorderRight(float value, OrxGui::State state);
     157    void setBorderRightS(float value, const std::string& stateName);
     158
     159    void setBorderTop(float value);
     160    void setBorderTop(float value, OrxGui::State state);
     161    void setBorderTopS(float value, const std::string& stateName);
     162
     163    void setBorderBottom(float value);
     164    void setBorderBottom(float value, OrxGui::State state);
     165    void setBorderBottomS(float value, const std::string& stateName);
     166
     167    void setTextSize(float value);
     168    void setTextSize(float value, OrxGui::State state);
     169    void setTextSizeS(float value, const std::string& stateName);
     170
     171    void setBackgroundColor(const Color& color);
     172    void setBackgroundColor(const Color& color, OrxGui::State state);
     173    void setBackgroundColorS(float r, float g, float b, float a, const std::string& stateName);
     174
     175    void setBackgroundTexture(const Texture& texture);
     176    void setBackgroundTexture(const std::string& textureName);
     177    void setBackgroundTexture(const Texture& texture, OrxGui::State state);
     178    void setBackgroundTexture(const std::string& textureName, const std::string& stateName);
     179
     180    void setForegroundColor(const Color& color);
     181    void setForegroundColor(const Color& color, OrxGui::State state);
     182    void setForegroundColorS(float r, float g, float b, float a, const std::string& stateName);
     183
     184    void loadBackgroundMaterial(const Material& material);
     185    void loadBackgroundMaterial(const Material& material, OrxGui::State state);
     186    void loadBackgroundMaterial(const TiXmlElement* element);
     187    void loadBackgroundMaterial(const TiXmlElement* element, OrxGui::State state);
     188    void loadBackgroundMaterialS(const TiXmlElement* element, const std::string& stateName);
     189
     190    void loadForegroundMaterial(const Material& material);
     191    void loadForegroundMaterial(const Material& material, OrxGui::State state);
     192    void loadForegroundMaterial(const TiXmlElement* element, OrxGui::State state);
     193    void loadForegroundMaterialS(const TiXmlElement* element, const std::string& stateName);
     194
     195    void setFeaturePosition(FeaturePosition featurePosition);
     196    void setFeaturePositionS(const std::string& featurePosition);
     197
     198    void setFont(Font* font);
     199    void setFont(const std::string& fontName);
     200
     201    void setAnimatedStateChanges(bool animated);
     202    void switchState(OrxGui::State state);
     203
     204
    99205
    100206    inline void drawRect(const Rect2D& rect) const
     
    116222    virtual bool processEvent(const Event& event) { return false; };
    117223
     224    bool getState(const std::string& stateName, OrxGui::State* state);
    118225
    119226  protected:
     
    137244    virtual void destroyed();
    138245
     246    virtual void debug() const;
     247
    139248  private:
    140249    void init();
    141250
    142251  private:
     252    static GLGuiWidget*            _selected;         //!< The currently selected Widget.
     253    static GLGuiWidget*            _focused;          //!< The currently Focused Widget.
     254    static GLGuiWidget*            _inputGrabber;     //!< The Widget that grabs input.
     255
     256
     257    /// WIDGET
    143258    GLGuiWidget*                   _parent;           //!< The parent of this Widget.
    144259
    145260    /// LOOKS
    146     Material                       _backMat;
    147261    Rect2D                         _backRect;
    148 
    149     Color                          _frontColor;
    150     Color*                         _toFrontColor;
    151 
    152     float                          _borderLeft;
    153     float                          _borderRight;
    154     float                          _borderTop;
    155     float                          _borderBottom;
    156 
    157262    Vector2D                       _minSize;
    158263
    159     GLGuiStyle                     _style;
    160264
    161265    /// EVENTS
     266    OrxGui::State                  _state;
     267
    162268    bool                           _focusable;        //!< If this widget can receive focus.
    163269    bool                           _clickable;        //!< if this widget can be clicked upon.
     
    166272
    167273
    168     static GLGuiWidget*            _selected;         //!< The currently selected Widget.
    169     static GLGuiWidget*            _focused;          //!< The currently Focused Widget.
    170 
    171     static GLGuiWidget*            _inputGrabber;     //!< The Widget that grabs input.
     274
     275    /// STYLE - Variables.
     276    typedef struct
     277    {
     278      float             _borderLeft;           //!< The Distance to the left Border of the widget, before any internal Element starts.
     279      float             _borderRight;          //!< The Distance to the right Border of the widget, before any internal Element starts.
     280      float             _borderTop;            //!< The Distance to the top Border of the widget, before any internal Element starts
     281      float             _borderBottom;         //!< The Distance to the bottom Border of the widget, before any internal Element starts
     282
     283      float             _textSize;             //!< The TextSize of the Widget.
     284
     285      Material          _background;           //!< The Background Material of the Widget.
     286
     287      Material          _foreground;           //!< The foreground Material of the Widget.
     288    }
     289    StatedStyle;
     290
     291
     292    StatedStyle         _style[GLGUI_STATE_COUNT]; //!< Styles configured for different States
     293
     294    FeaturePosition     _featurePosition;      //!< The Position a Feature will be layed at (checkbox(box), slider(text),...)
     295    Font*               _font;                 //!< The Font used in the current Widget.
     296
     297
     298    /// ANIMATION STUFF:
     299    bool                _animatedStateChanges; //!< If the Transitions between States are Animated automatically.
     300
     301    bool                _animating;            //!< If the Widget is animated at the moment (Texture might be an AnimatedTexture.)
     302    float               _animationCycle;
     303    float               _animationDuration;
     304    StatedStyle         _currentStyle;
     305
    172306  };
    173307}
  • trunk/src/lib/gui/gl/specials/glgui_notifier.cc

    r8518 r8619  
    2525
    2626  /**
    27    * standard constructor
     27   * @brief standard constructor
    2828   */
    2929  GLGuiNotifier::GLGuiNotifier ()
     
    3434    this->lineSpacing = 0;
    3535    this->linesProcessed = 0;
     36    this->_fadeAge = 3.0;
     37    this->setHideAge(4.0);
    3638
    3739    this->setDisplayLineCount(10);
     
    5759  }
    5860
     61  /**
     62   * @brief push a message onto the notifier.
     63   * @param message the message to be pushed.
     64   *
     65   * @note it is not guaranteed, that the message is delivered instantaniously
     66   * The possibility may arise, that the DisplayLines are all in use, then one
     67   * has to wait until a line gets hidden, until a new one can be pushed to be
     68   * displayed.
     69   */
    5970  void GLGuiNotifier::pushNotifyMessage(const std::string& message)
    6071  {
    6172    if (!this->hiddenText.empty())
    6273    {
    63       printf("%s\n", message.c_str());
    64       DisplayLine dl;
     74      DisplayLine dl; // put everything in here, and then display it
     75
     76      // retrieve a Text.
    6577      dl.text = this->hiddenText.top();
    66 
     78      this->hiddenText.pop();
     79
     80      // setup Text
    6781      dl.text->setBlending(1.0f);
    6882      dl.text->setText(message);
    69       this->hiddenText.pop();
     83      dl.text->setVisibility(true);
     84      dl.text->setRelCoor2D(this->calculateLinePosition(0));
     85
    7086      dl.age = 0.0f;
    7187      this->displayLines.push_front(dl);
    72 
    73       dl.text->setVisibility(true);
    74       dl.text->setRelCoor2D(this->calculateLinePosition(0));
    7588      this->repositionText();
    7689    }
    7790    else
    7891    {
     92      // push it onto the List of messages we still need.
    7993      this->inputBuffer.push_front(message);
    80       //printf("grumble... must be fixed\n");
    81     }
    82   }
    83 
    84 
     94    }
     95  }
     96
     97
     98  /**
     99   * @brief sets the Dipsplay Line Count of the Notifier.
     100   * @param coun the count of displayLines.
     101   */
    85102  void GLGuiNotifier::setDisplayLineCount(unsigned int count)
    86103  {
     
    96113  }
    97114
     115  void GLGuiNotifier::setFadeAge(float fadeAge)
     116  {
     117    this->_fadeAge = fadeAge;
     118    this->_transformAge = hideAge() - this->fadeAge();
     119  }
     120
     121  void GLGuiNotifier::setHideAge(float hideAge)
     122  {
     123    this->_hideAge = hideAge;
     124    this->_transformAge = this->hideAge() - fadeAge();
     125  }
     126
    98127
    99128  /**
     
    119148  void GLGuiNotifier::applyTextSettings(MultiLineText* text)
    120149  {
    121     text->setSize(this->style().textSize());
     150    text->setSize(this->textSize());
    122151    text->setLineWidth( 300 );
    123     text->setFont("fonts/final_frontier.ttf", (int)this->style().textSize());
    124 
    125     text->setColor(this->style().foregroundColor() );
     152    text->setFont("fonts/final_frontier.ttf", (int)this->textSize());
     153
     154    text->setColor(this->foregroundColor() );
    126155    if (text->getParent2D() != this)
    127156      text->setParent2D(this);
     
    129158
    130159
     160  /**
     161   * @brief ticks the entire Notifier.
     162   * @param dt the time passed since the last Tick
     163   */
    131164  void GLGuiNotifier::tick(float dt)
    132165  {
     
    135168    {
    136169      (*line).age+=dt;
    137       if ((*line).age > 3.0f)
     170      if ((*line).age > this->fadeAge())
    138171      {
    139         (*line).text->setBlending(4.0 - (*line).age);
    140         if ((*line).age > 4.0f)
     172        (*line).text->setBlending((hideAge() - (*line).age)/_transformAge);
     173        if ((*line).age > hideAge())
    141174        {
    142175          std::list<DisplayLine>::iterator tmp = line;
     
    167200    this->beginDraw();
    168201
    169     this->backMaterial().select();
     202    this->background().select();
    170203    this->drawRect(this->backRect());
    171204    this->endDraw();
     
    183216  Vector2D GLGuiNotifier::calculateLinePosition(unsigned int lineNumber)
    184217  {
    185     return Vector2D(0.0f, (float)(this->style().textSize() + this->lineSpacing)*(float)((int)this->bufferDisplaySize - (int)lineNumber - (int)1));
     218    return Vector2D(0.0f, (float)(textSize() + this->lineSpacing)*(float)((int)this->bufferDisplaySize - (int)lineNumber - (int)1));
    186219  }
    187220
  • trunk/src/lib/gui/gl/specials/glgui_notifier.h

    r8518 r8619  
    3030    void pushNotifyMessage(const std::string& message);
    3131
    32     // BUFFERS
     32    /// Setup
    3333    void setDisplayLineCount(unsigned int count);
     34    void setFadeAge(float fadeAge);
     35    void setHideAge(float hideAge);
     36
     37    /** @returns the beginning of the Hiding process */
     38    inline float fadeAge() const { return _fadeAge; };
     39    /** @returns at what age elements should be fully hidden */
     40    inline float hideAge() const { return _hideAge; };
    3441
    3542    void clear();
     
    5461
    5562  private:
     63    //! structure that defines a Displayed line.
    5664    typedef struct
    5765    {
     
    5967      MultiLineText*    text;
    6068
    61     }
    62     DisplayLine;
     69    } DisplayLine;
     70
     71
     72    float                       _fadeAge;
     73    float                       _hideAge;
     74    float                       _transformAge;
    6375
    6476    unsigned int                lineSpacing;            //!< The Spacing between lines.
     
    7284
    7385    unsigned long               linesProcessed;         //!< How many Lines have been processed so far.
    74     std::list<std::string>      inputBuffer;            //!<
     86    std::list<std::string>      inputBuffer;            //!< The input buffer for lines that were not yet printet out, because there is too much input.
    7587
    7688  };
Note: See TracChangeset for help on using the changeset viewer.