Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8619 in orxonox.OLD for trunk/src/lib/graphics/text_engine/text.cc


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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/graphics/text_engine/text.cc

    r8518 r8619  
    2222#include "debug.h"
    2323
    24 using namespace std;
    25 
    2624/**
    2725 * @brief creates a new Text Element
     
    3432
    3533  // initialize this Text
    36   this->font = NULL;
    37   this->size = textSize;
    38   this->setSizeY2D(size);
    39   this->color = TEXT_DEFAULT_COLOR;
     34  this->_font = NULL;
     35  this->_size = textSize;
     36  this->setSizeY2D(textSize);
     37  this->_color = TEXT_DEFAULT_COLOR;
    4038
    4139  this->setAlignment(TEXT_DEFAULT_ALIGNMENT);
     
    4745{
    4846  this->setClassID(CL_TEXT, "Text");
    49   this->font = NULL;
     47  this->_font = NULL;
    5048
    5149  *this = text;
     
    5856Text::~Text()
    5957{
    60   if (this->font != NULL && this->font != Font::getDefaultFont())
    61     ResourceManager::getInstance()->unload(this->font);
     58  if (this->_font != NULL && this->_font != Font::getDefaultFont())
     59    ResourceManager::getInstance()->unload(this->_font);
    6260}
    6361
     
    6967bool Text::operator==(const Text& text) const
    7068{
    71   return (this->text == text.text &&
    72           this->size == text.size &&
    73           this->font == text.font &&
    74           this->color == text.color);
     69  return (this->_text == text._text &&
     70          this->_size == text._size &&
     71          this->_font == text._font &&
     72          this->_color == text._color);
    7573}
    7674
     
    8280bool Text::operator==(const std::string& text) const
    8381{
    84   return (this->text == text);
     82  return (this->_text == text);
    8583}
    8684
     
    9290Text& Text::operator=(const Text& text)
    9391{
    94   this->size = text.size;
    95   this->color = text.color;
     92  this->_size = text._size;
     93  this->_color = text._color;
    9694  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;
     95  if (this->_font != NULL)
     96    ResourceManager::getInstance()->unload(this->_font);
     97
     98  this->_font = (Font*)ResourceManager::getInstance()->copy( text._font ); //!< HACK
     99
     100  this->_text = text._text;
    103101  return *this;
    104102}
     
    110108void Text::setText(const std::string& text)
    111109{
    112   this->text = text;
     110  this->_text = text;
    113111  this->setupTextWidth();
    114112}
     
    120118void Text::append(const std::string& appendText)
    121119{
    122   this->text += appendText;
     120  this->_text += appendText;
    123121  this->setupTextWidth();
    124122}
     
    129127void Text::appendCharacter(char character)
    130128{
    131   this->text += character;
     129  this->_text += character;
    132130  this->setupTextWidth();
    133131}
     
    141139{
    142140  this->append(appendText);
    143   return this->text;
     141  return this->_text;
    144142}
    145143
     
    152150void Text::removeCharacters(unsigned int chars)
    153151{
    154   if (text.size() > chars)
    155     this->text.resize(this->text.size()-chars);
    156   else if (!text.empty())
    157     text.clear();
     152  if (this->_text.size() > chars)
     153    this->_text.resize(this->_text.size()-chars);
     154  else if (!this->_text.empty())
     155    this->_text.clear();
    158156  this->setupTextWidth();
    159157}
     
    165163void Text::clear()
    166164{
    167   text.clear();
     165  this->_text.clear();
    168166  this->setupTextWidth();
    169167}
     
    177175{
    178176  Font* newFont = NULL;
    179   Font* oldFont = this->font;
     177  Font* oldFont = this->_font;
    180178
    181179  // load a new Font
     
    194192
    195193  // unloading the Font if we alrady have one loaded.
    196   this->font = newFont;
     194  this->_font = newFont;
    197195  if (oldFont != NULL && oldFont != Font::getDefaultFont())
    198196    ResourceManager::getInstance()->unload(oldFont);
     
    207205void Text::setSize(float size)
    208206{
    209   this->size = size;
     207  this->_size = size;
    210208  this->setSizeY2D(size);
    211209  this->setupTextWidth();
     
    218216void Text::draw() const
    219217{
    220   if (unlikely(this->text.empty()))
     218  if (unlikely(this->_text.empty()))
    221219    return;
    222220  glPushMatrix();
     
    230228  // drawing this Text.
    231229  // setting the Blending effects
    232   glColor4fv(&this->color[0]);
     230  glColor4fv(&this->_color[0]);
    233231
    234232
     
    240238  glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, GL_MODULATE );
    241239
    242   glBindTexture(GL_TEXTURE_2D, font->getTexture());
     240  glBindTexture(GL_TEXTURE_2D, this->_font->getTexture());
    243241  glTranslatef(getAbsCoor2D().x, getAbsCoor2D().y, 0);
    244242  glRotatef(this->getAbsDir2D(), 0, 0, 1);
     
    247245  float posX = 0.0f;
    248246  glBegin(GL_QUADS);
    249   for (unsigned int i = 0; i < this->text.size(); i++)
     247  for (unsigned int i = 0; i < this->_text.size(); i++)
    250248  {
    251     if(likely((tmpGlyph = this->getFont()->getGlyphArray()[this->text[i]]) != NULL))
     249    if(likely((tmpGlyph = this->font()->getGlyphArray()[this->_text[i]]) != NULL))
    252250    {
    253251      glTexCoord2f(tmpGlyph->texCoord[1], tmpGlyph->texCoord[2]);
    254       glVertex2d(posX+tmpGlyph->maxX*this->getSize(), 0);
     252      glVertex2d(posX+tmpGlyph->maxX*this->size(), 0);
    255253
    256254      glTexCoord2f(tmpGlyph->texCoord[1], tmpGlyph->texCoord[3]);
    257       glVertex2d(posX+tmpGlyph->maxX*this->getSize(), this->getSize());
     255      glVertex2d(posX+tmpGlyph->maxX*this->size(), this->size());
    258256
    259257      glTexCoord2f(tmpGlyph->texCoord[0], tmpGlyph->texCoord[3]);
    260       glVertex2d(posX+tmpGlyph->minX*this->getSize(), this->getSize());
     258      glVertex2d(posX+tmpGlyph->minX*this->size(), this->size());
    261259
    262260      glTexCoord2f(tmpGlyph->texCoord[0], tmpGlyph->texCoord[2]);
    263       glVertex2d(posX+tmpGlyph->minX*this->getSize(), 0);
    264 
    265       posX += tmpGlyph->advance * this->getSize();
     261      glVertex2d(posX+tmpGlyph->minX*this->size(), 0);
     262
     263      posX += tmpGlyph->advance * this->size();
    266264    }
    267265  }
     
    278276{
    279277  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());
     278  for (unsigned int i = 0; i < this->_text.size(); i++)
     279    if(this->_font->getGlyphArray()[this->_text[i]] != NULL)
     280      width += this->_font->getGlyphArray()[this->_text[i]]->advance;
     281  this->setSizeX2D(width * this->size());
    284282}
    285283
     
    290288void Text::debug() const
    291289{
    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 
     290  PRINT(0)("=== TEXT: %s (with Font:'%s')  displaying %s ===\n", this->getName(), this->_font->getName(), this->_text.c_str());
     291  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());
     292}
     293
Note: See TracChangeset for help on using the changeset viewer.