Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8539 in orxonox.OLD


Ignore:
Timestamp:
Jun 16, 2006, 4:52:35 PM (18 years ago)
Author:
bensch
Message:

new imrpooved interface in text

Location:
branches/gui/src/lib
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • branches/gui/src/lib/graphics/text_engine/limited_width_text.cc

    r8538 r8539  
    6262  // drawing this Text.
    6363  // setting the Blending effects
    64   glColor4fv(&this->getColor()[0]);
     64  glColor4fv(&this->color()[0]);
    6565
    6666
     
    7272  glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, GL_MODULATE );
    7373
    74   glBindTexture(GL_TEXTURE_2D, this->getFont()->getTexture());
     74  glBindTexture(GL_TEXTURE_2D, this->font()->getTexture());
    7575  glTranslatef(getAbsCoor2D().x, getAbsCoor2D().y, 0);
    7676  glRotatef(this->getAbsDir2D(), 0, 0, 1);
     
    8181  for (unsigned int i = 0; i < this->_dotedText.size(); i++)
    8282  {
    83     if(likely((tmpGlyph = this->getFont()->getGlyphArray()[this->_dotedText[i]]) != NULL))
     83    if(likely((tmpGlyph = this->font()->getGlyphArray()[this->_dotedText[i]]) != NULL))
    8484    {
    8585      glTexCoord2f(tmpGlyph->texCoord[1], tmpGlyph->texCoord[2]);
    86       glVertex2d(posX+tmpGlyph->maxX*this->getSize(), 0);
     86      glVertex2d(posX+tmpGlyph->maxX*this->size(), 0);
    8787
    8888      glTexCoord2f(tmpGlyph->texCoord[1], tmpGlyph->texCoord[3]);
    89       glVertex2d(posX+tmpGlyph->maxX*this->getSize(), this->getSize());
     89      glVertex2d(posX+tmpGlyph->maxX*this->size(), this->size());
    9090
    9191      glTexCoord2f(tmpGlyph->texCoord[0], tmpGlyph->texCoord[3]);
    92       glVertex2d(posX+tmpGlyph->minX*this->getSize(), this->getSize());
     92      glVertex2d(posX+tmpGlyph->minX*this->size(), this->size());
    9393
    9494      glTexCoord2f(tmpGlyph->texCoord[0], tmpGlyph->texCoord[2]);
    95       glVertex2d(posX+tmpGlyph->minX*this->getSize(), 0);
     95      glVertex2d(posX+tmpGlyph->minX*this->size(), 0);
    9696
    97       posX += tmpGlyph->advance * this->getSize();
     97      posX += tmpGlyph->advance * this->size();
    9898    }
    9999  }
     
    109109void LimitedWidthText::setupTextWidth()
    110110{
    111   float dotsSize = this->getFont()->getGlyphArray()[46]->advance * 3.0;
     111  float dotsSize = this->font()->getGlyphArray()[46]->advance * 3.0;
    112112
    113113  float width = 0.0f;
    114   float maxWidth = this->_lineWidth / this->getSize();
     114  float maxWidth = this->_lineWidth / this->size();
    115115
    116116  switch (this->_dotsPosition)
    117117  {
    118118    case End:
    119       for (unsigned int i = 0; i < this->getText().size(); i++)
     119      for (unsigned int i = 0; i < this->text().size(); i++)
    120120      {
    121121        if (width + dotsSize > maxWidth )
    122122        {
    123           this->_dotedText = this->getText().substr(0, i) + "...";
     123          this->_dotedText = this->text().substr(0, i) + "...";
    124124          width += dotsSize;
    125125          break;
    126126        }
    127127        // Advance the Text.
    128         if(this->getFont()->getGlyphArray()[this->getText()[i]] != NULL)
    129           width += this->getFont()->getGlyphArray()[this->getText()[i]]->advance;
     128        if(this->font()->getGlyphArray()[this->text()[i]] != NULL)
     129          width += this->font()->getGlyphArray()[this->text()[i]]->advance;
    130130      }
    131131      this->setSizeX2D(width);
    132132      break;
    133133    case Begin:
    134       for (unsigned int i = this->getText().size() - 1; i < 0; i--)
     134      for (unsigned int i = this->text().size() - 1; i < 0; i--)
    135135      {
    136136        if (width + dotsSize > maxWidth )
    137137        {
    138           this->_dotedText = std::string("...") + this->getText().substr(i);
     138          this->_dotedText = std::string("...") + this->text().substr(i);
    139139          width += dotsSize;
    140140          break;
    141141        }
    142142        // Advance the Text.
    143         if(this->getFont()->getGlyphArray()[this->getText()[i]] != NULL)
    144           width += this->getFont()->getGlyphArray()[this->getText()[i]]->advance;
     143        if(this->font()->getGlyphArray()[this->text()[i]] != NULL)
     144          width += this->font()->getGlyphArray()[this->text()[i]]->advance;
    145145      }
    146146      this->setSizeX2D(width);
  • branches/gui/src/lib/graphics/text_engine/multi_line_text.cc

    r8448 r8539  
    6161void MultiLineText::draw() const
    6262{
    63   if (unlikely(this->getText().empty()))
     63  if (unlikely(this->text().empty()))
    6464    return;
    6565  glPushMatrix();
     
    7676  glActiveTexture(GL_TEXTURE0);
    7777
    78   glColor4fv(&this->getColor()[0]);
     78  glColor4fv(&this->color()[0]);
    7979  glEnable(GL_BLEND);
    8080  glEnable(GL_TEXTURE_2D);
     
    8282  glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, GL_MODULATE );
    8383
    84   glBindTexture(GL_TEXTURE_2D, this->getFont()->getTexture());
     84  glBindTexture(GL_TEXTURE_2D, this->font()->getTexture());
    8585  glTranslatef(this->getAbsCoor2D().x, this->getAbsCoor2D().y, 0);
    8686  glRotatef(this->getAbsDir2D(), 0, 0, 1);
     
    9292
    9393  glBegin(GL_QUADS);
    94   for (unsigned int i = 0; i < this->getText().size(); ++i)
     94  for (unsigned int i = 0; i < this->text().size(); ++i)
    9595  {
    9696    if (unlikely(this->lineEnds.size() > lineNumber && i == this->lineEnds[lineNumber]))
     
    9999      ++lineNumber;
    100100      posX = 0.0f;
    101       posY += this->lineSpacing + this->getSize(); //this->getFont()->getMaxHeight();
     101      posY += this->lineSpacing + this->size(); //this->font()->getMaxHeight();
    102102    }
    103103
    104     if(likely((tmpGlyph = this->getFont()->getGlyphArray()[this->getText()[i]]) != NULL))
     104    if(likely((tmpGlyph = this->font()->getGlyphArray()[this->text()[i]]) != NULL))
    105105    {
    106106      glTexCoord2f(tmpGlyph->texCoord[1], tmpGlyph->texCoord[2]);
    107       glVertex2d(posX+tmpGlyph->maxX*this->getSize(), posY);
     107      glVertex2d(posX+tmpGlyph->maxX*this->size(), posY);
    108108
    109109      glTexCoord2f(tmpGlyph->texCoord[1], tmpGlyph->texCoord[3]);
    110       glVertex2d(posX+tmpGlyph->maxX*this->getSize(), posY + this->getSize());
     110      glVertex2d(posX+tmpGlyph->maxX*this->size(), posY + this->size());
    111111
    112112      glTexCoord2f(tmpGlyph->texCoord[0], tmpGlyph->texCoord[3]);
    113       glVertex2d(posX+tmpGlyph->minX*this->getSize(), posY+ this->getSize());
     113      glVertex2d(posX+tmpGlyph->minX*this->size(), posY+ this->size());
    114114
    115115      glTexCoord2f(tmpGlyph->texCoord[0], tmpGlyph->texCoord[2]);
    116       glVertex2d(posX+tmpGlyph->minX*this->getSize(), posY);
     116      glVertex2d(posX+tmpGlyph->minX*this->size(), posY);
    117117
    118       posX += tmpGlyph->advance * this->getSize();
     118      posX += tmpGlyph->advance * this->size();
    119119    }
    120120  }
     
    132132  this->lineEnds.clear();
    133133  float width = 0.0f;
    134   float maxWidth = this->lineWidth / this->getSize();
     134  float maxWidth = this->lineWidth / this->size();
    135135
    136   for (unsigned int i = 0; i < this->getText().size(); i++)
     136  for (unsigned int i = 0; i < this->text().size(); i++)
    137137  {
    138     if (width > maxWidth || this->getText()[i] == '\n')
     138    if (width > maxWidth || this->text()[i] == '\n')
    139139    {
    140140      if (likely(i > 0))
    141141      {
    142142        this->lineEnds.push_back( i -1 );
    143         width = this->getFont()->getGlyphArray()[this->getText()[i-1]]->advance;
     143        width = this->font()->getGlyphArray()[this->text()[i-1]]->advance;
    144144      }
    145145      else
     
    148148
    149149    // Advance the Text.
    150     if(this->getFont()->getGlyphArray()[this->getText()[i]] != NULL)
    151       width += this->getFont()->getGlyphArray()[this->getText()[i]]->advance;
     150    if(this->font()->getGlyphArray()[this->text()[i]] != NULL)
     151      width += this->font()->getGlyphArray()[this->text()[i]]->advance;
    152152  }
    153153  this->lineCount = lineEnds.size() + 1;
    154   this->setSizeY2D((this->lineEnds.size()+1) * (this->lineSpacing + this->getFont()->getMaxHeight()));
     154  this->setSizeY2D((this->lineEnds.size()+1) * (this->lineSpacing + this->font()->getMaxHeight()));
    155155}
    156156
     
    162162 printf("Debug %s::%s: %d lines\n", this->getClassName(), this->getName(), this->getLineCount());
    163163
    164  std::string tmpText = this->getText();
     164 std::string tmpText = this->text();
    165165 std::vector<unsigned int> ends = this->lineEnds;
    166166 ends.push_back(tmpText.size());
  • branches/gui/src/lib/graphics/text_engine/text.cc

    r8518 r8539  
    3434
    3535  // initialize this Text
    36   this->font = NULL;
    37   this->size = textSize;
    38   this->setSizeY2D(size);
    39   this->color = TEXT_DEFAULT_COLOR;
     36  this->_font = NULL;
     37  this->_size = textSize;
     38  this->setSizeY2D(textSize);
     39  this->_color = TEXT_DEFAULT_COLOR;
    4040
    4141  this->setAlignment(TEXT_DEFAULT_ALIGNMENT);
     
    4747{
    4848  this->setClassID(CL_TEXT, "Text");
    49   this->font = NULL;
     49  this->_font = NULL;
    5050
    5151  *this = text;
     
    5858Text::~Text()
    5959{
    60   if (this->font != NULL && this->font != Font::getDefaultFont())
    61     ResourceManager::getInstance()->unload(this->font);
     60  if (this->_font != NULL && this->_font != Font::getDefaultFont())
     61    ResourceManager::getInstance()->unload(this->_font);
    6262}
    6363
     
    6969bool Text::operator==(const Text& text) const
    7070{
    71   return (this->text == text.text &&
    72           this->size == text.size &&
    73           this->font == text.font &&
    74           this->color == text.color);
     71  return (this->_text == text._text &&
     72          this->_size == text._size &&
     73          this->_font == text._font &&
     74          this->_color == text._color);
    7575}
    7676
     
    8282bool Text::operator==(const std::string& text) const
    8383{
    84   return (this->text == text);
     84  return (this->_text == text);
    8585}
    8686
     
    9292Text& Text::operator=(const Text& text)
    9393{
    94   this->size = text.size;
    95   this->color = text.color;
     94  this->_size = text._size;
     95  this->_color = text._color;
    9696  this->setAlignment(text.getAlignment());
    97   if (this->font != NULL)
    98     ResourceManager::getInstance()->unload(this->font);
    99 
    100   this->font = (Font*)ResourceManager::getInstance()->copy( text.font ); //!< HACK
    101 
    102   this->text = text.text;
     97  if (this->_font != NULL)
     98    ResourceManager::getInstance()->unload(this->_font);
     99
     100  this->_font = (Font*)ResourceManager::getInstance()->copy( text._font ); //!< HACK
     101
     102  this->_text = text._text;
    103103  return *this;
    104104}
     
    110110void Text::setText(const std::string& text)
    111111{
    112   this->text = text;
     112  this->_text = text;
    113113  this->setupTextWidth();
    114114}
     
    120120void Text::append(const std::string& appendText)
    121121{
    122   this->text += appendText;
     122  this->_text += appendText;
    123123  this->setupTextWidth();
    124124}
     
    129129void Text::appendCharacter(char character)
    130130{
    131   this->text += character;
     131  this->_text += character;
    132132  this->setupTextWidth();
    133133}
     
    141141{
    142142  this->append(appendText);
    143   return this->text;
     143  return this->_text;
    144144}
    145145
     
    152152void Text::removeCharacters(unsigned int chars)
    153153{
    154   if (text.size() > chars)
    155     this->text.resize(this->text.size()-chars);
    156   else if (!text.empty())
    157     text.clear();
     154  if (this->_text.size() > chars)
     155    this->_text.resize(this->_text.size()-chars);
     156  else if (!this->_text.empty())
     157    this->_text.clear();
    158158  this->setupTextWidth();
    159159}
     
    165165void Text::clear()
    166166{
    167   text.clear();
     167  this->_text.clear();
    168168  this->setupTextWidth();
    169169}
     
    177177{
    178178  Font* newFont = NULL;
    179   Font* oldFont = this->font;
     179  Font* oldFont = this->_font;
    180180
    181181  // load a new Font
     
    194194
    195195  // unloading the Font if we alrady have one loaded.
    196   this->font = newFont;
     196  this->_font = newFont;
    197197  if (oldFont != NULL && oldFont != Font::getDefaultFont())
    198198    ResourceManager::getInstance()->unload(oldFont);
     
    207207void Text::setSize(float size)
    208208{
    209   this->size = size;
     209  this->_size = size;
    210210  this->setSizeY2D(size);
    211211  this->setupTextWidth();
     
    218218void Text::draw() const
    219219{
    220   if (unlikely(this->text.empty()))
     220  if (unlikely(this->_text.empty()))
    221221    return;
    222222  glPushMatrix();
     
    230230  // drawing this Text.
    231231  // setting the Blending effects
    232   glColor4fv(&this->color[0]);
     232  glColor4fv(&this->_color[0]);
    233233
    234234
     
    240240  glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, GL_MODULATE );
    241241
    242   glBindTexture(GL_TEXTURE_2D, font->getTexture());
     242  glBindTexture(GL_TEXTURE_2D, this->_font->getTexture());
    243243  glTranslatef(getAbsCoor2D().x, getAbsCoor2D().y, 0);
    244244  glRotatef(this->getAbsDir2D(), 0, 0, 1);
     
    247247  float posX = 0.0f;
    248248  glBegin(GL_QUADS);
    249   for (unsigned int i = 0; i < this->text.size(); i++)
     249  for (unsigned int i = 0; i < this->_text.size(); i++)
    250250  {
    251     if(likely((tmpGlyph = this->getFont()->getGlyphArray()[this->text[i]]) != NULL))
     251    if(likely((tmpGlyph = this->font()->getGlyphArray()[this->_text[i]]) != NULL))
    252252    {
    253253      glTexCoord2f(tmpGlyph->texCoord[1], tmpGlyph->texCoord[2]);
    254       glVertex2d(posX+tmpGlyph->maxX*this->getSize(), 0);
     254      glVertex2d(posX+tmpGlyph->maxX*this->size(), 0);
    255255
    256256      glTexCoord2f(tmpGlyph->texCoord[1], tmpGlyph->texCoord[3]);
    257       glVertex2d(posX+tmpGlyph->maxX*this->getSize(), this->getSize());
     257      glVertex2d(posX+tmpGlyph->maxX*this->size(), this->size());
    258258
    259259      glTexCoord2f(tmpGlyph->texCoord[0], tmpGlyph->texCoord[3]);
    260       glVertex2d(posX+tmpGlyph->minX*this->getSize(), this->getSize());
     260      glVertex2d(posX+tmpGlyph->minX*this->size(), this->size());
    261261
    262262      glTexCoord2f(tmpGlyph->texCoord[0], tmpGlyph->texCoord[2]);
    263       glVertex2d(posX+tmpGlyph->minX*this->getSize(), 0);
    264 
    265       posX += tmpGlyph->advance * this->getSize();
     263      glVertex2d(posX+tmpGlyph->minX*this->size(), 0);
     264
     265      posX += tmpGlyph->advance * this->size();
    266266    }
    267267  }
     
    278278{
    279279  float width = 0;
    280   for (unsigned int i = 0; i < this->text.size(); i++)
    281     if(this->font->getGlyphArray()[this->text[i]] != NULL)
    282       width += this->font->getGlyphArray()[this->text[i]]->advance;
    283   this->setSizeX2D(width * this->getSize());
     280  for (unsigned int i = 0; i < this->_text.size(); i++)
     281    if(this->_font->getGlyphArray()[this->_text[i]] != NULL)
     282      width += this->_font->getGlyphArray()[this->_text[i]]->advance;
     283  this->setSizeX2D(width * this->size());
    284284}
    285285
     
    290290void Text::debug() const
    291291{
    292   PRINT(0)("=== TEXT: %s (with Font:'%s')  displaying %s ===\n", this->getName(), this->font->getName(), this->text.c_str());
    293   PRINT(0)("Color: r=%0.2f g=%0.2f b=%0.2f a=%0.2f\n", this->color.r(), this->color.g(), this->color.b(), this->color.a());
    294 }
    295 
     292  PRINT(0)("=== TEXT: %s (with Font:'%s')  displaying %s ===\n", this->getName(), this->_font->getName(), this->_text.c_str());
     293  PRINT(0)("Color: r=%0.2f g=%0.2f b=%0.2f a=%0.2f\n", this->_color.r(), this->_color.g(), this->_color.b(), this->_color.a());
     294}
     295
  • branches/gui/src/lib/graphics/text_engine/text.h

    r8518 r8539  
    4545    void setFont(const std::string& fontFile, unsigned int renderSize);
    4646    /** @param blending the blending intensity to set (between 0.0 and 1.0) */
    47     inline void setBlending(float blending) { this->color.a() = blending; };
     47    inline void setBlending(float blending) { this->_color.a() = blending; };
    4848    /** @param r red @param g green @param b blue @brief sets the Color of the Text to render (values in [0-1]) */
    49     void setColor(float r, float g, float b) { this->color = Color(r, g, b, this->color.a()); };
    50     void setColor(float r, float g, float b, float a) { this->color = Color(r, g, b, a); };
    51     void setColor(const Color& color) { this->color = color; };
     49    void setColor(float r, float g, float b) { this->_color = Color(r, g, b, this->_color.a()); };
     50    void setColor(float r, float g, float b, float a) { this->_color = Color(r, g, b, a); };
     51    void setColor(const Color& color) { this->_color = color; };
    5252    void setSize(float size);
    5353
     
    5555    /// RETRIEVE
    5656    /** @returns the String this Text displays */
    57     inline const std::string& getText() const { return this->text; };
     57    inline const std::string& text() const { return this->_text; };
    5858
    5959    /** @returns the pointer to the stored Font (not changeable) */
    60     inline const Font* const getFont() const { return this->font; };
     60    inline const Font* const font() const { return this->_font; };
    6161    /** @returns the Blending Value [0 invisible 1.0 full visible */
    62     inline float getBlending() const { return this->color.a(); };
     62    inline float blending() const { return this->_color.a(); };
    6363    /** @returns: a Vector(r,g,b) @brief: retrieve a Vector holding the Color of the Text */
    64     inline const Color& getColor() const { return this->color; };
     64    inline const Color& color() const { return this->_color; };
    6565    /** @returns the Size of the Text */
    66     inline float getSize() const { return this->size; };
     66    inline float size() const { return this->_size; };
    6767
    6868    virtual void draw() const;
     
    7676
    7777  private:
    78     Font*             font;           //!< Font of this text
     78    Font*             _font;           //!< Font of this text
    7979
    80     std::string       text;           //!< The text to display
    81     Color             color;          //!< The color of the font.
    82     float             size;           //!< The size of the Text.
     80    std::string       _text;           //!< The text to display
     81    Color             _color;          //!< The color of the font.
     82    float             _size;           //!< The size of the Text.
    8383};
    8484
  • branches/gui/src/lib/gui/gl/glgui_button.h

    r8448 r8539  
    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
  • branches/gui/src/lib/gui/gl/glgui_inputline.cc

    r8529 r8539  
    121121    this->setFrontColor(Color(1,1,1,1), true);
    122122    this->setFrontColor(Color(0,1,0,1));
    123     emit(this->textChanged(this->_text.getText()));
     123    emit(this->textChanged(this->_text.text()));
    124124  }
    125125
     
    143143  void GLGuiInputLine::pushEnter()
    144144  {
    145     emit(this->enterPushed(this->_text.getText()));
     145    emit(this->enterPushed(this->_text.text()));
    146146    if (this->_clearOnEnter)
    147147      this->clear();
  • branches/gui/src/lib/gui/gl/glgui_inputline.h

    r8518 r8539  
    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);
Note: See TracChangeset for help on using the changeset viewer.