Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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


Ignore:
Timestamp:
Mar 15, 2006, 3:10:45 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: merged the std-branche back, it runs on windows and Linux

svn merge https://svn.orxonox.net/orxonox/branches/std . -r7202:HEAD

File:
1 edited

Legend:

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

    r7193 r7221  
    3232 * @param type The renderType to display this font in
    3333 */
    34 Text::Text(const char* fontFile, unsigned int textSize)
     34Text::Text(const std::string& fontFile, unsigned int textSize)
    3535{
    3636  this->init();
    3737
    38   if (fontFile != NULL)
     38  if (!fontFile.empty())
    3939    this->setFont(fontFile, FONT_DEFAULT_RENDER_SIZE);
    4040  this->setSizeY2D(textSize);
     
    5050  if (this->font != NULL && this->font != Font::getDefaultFont())
    5151    ResourceManager::getInstance()->unload(this->font);
    52 
    53   if (this->text)
    54     delete[] this->text;
    5552}
    5653
     
    6461  // initialize this Text
    6562  this->font = NULL;
    66   this->text = NULL;
    67   this->externText = NULL;
     63  this->text = "";
    6864  this->setAlignment(TEXT_DEFAULT_ALIGNMENT);
    6965  this->blending = TEXT_DEFAULT_BLENDING;
    7066  this->color = TEXT_DEFAULT_COLOR;
    7167  this->setSize(TEXT_DEFAULT_SIZE);
    72   this->setText(NULL);
     68  this->setText("");
    7369}
    7470
     
    7874 * @param fontSize the Size of the Font
    7975 */
    80 void Text::setFont(const char* fontFile, unsigned int fontSize)
     76void Text::setFont(const std::string& fontFile, unsigned int fontSize)
    8177{
    8278  Font* tmpFont;
     
    9086
    9187  // load a new Font
    92   if (fontFile != NULL)
     88  if (!fontFile.empty())
    9389  {
    9490    tmpFont = (Font*)ResourceManager::getInstance()->load(fontFile, TTF, RP_GAME, (int)fontSize);
     
    9692      this->font = tmpFont;
    9793    else
    98       PRINTF(2)("Font %s could not be loaded, probably file not found\n", fontFile);
     94      PRINTF(2)("Font %s could not be loaded, probably file not found\n", fontFile.c_str());
    9995  }
    10096}
     
    104100 * @param text the new text to set
    105101 */
    106 void Text::setText(const char* text, bool isExtern)
    107 {
    108   if (isExtern)
    109   {
    110     this->externText = text;
    111 
    112     if (unlikely(this->text != NULL))
    113     {
    114       delete[] this->text;
    115       this->text = NULL;
    116     }
    117   }
    118   else
    119   {
    120     this->externText = NULL;
    121     if (this->text)
    122       delete[] this->text;
    123     if (text != NULL)
    124     {
    125       this->text = new char[strlen(text)+1];
    126       strcpy(this->text, text);
    127     }
    128     else
    129       this->text = NULL;
    130   }
     102void Text::setText(const std::string& text)
     103{
     104  this->text = text;
    131105
    132106  // setting up the Text-Width if DYNAMIC
     
    138112
    139113    float width = 0;
    140     const char* tmpText = this->externText;
    141     if (this->externText == NULL)
    142       tmpText = this->text;
    143     if (tmpText != NULL)
     114    if (!this->text.empty())
    144115    {
    145       while (*tmpText != '\0')
     116      for (unsigned int i = 0; i < this->text.size(); i++)
    146117      {
    147         if(glyphArray[*tmpText] != NULL)
     118        if(glyphArray[this->text[i]] != NULL)
    148119        {
    149           width += glyphArray[*tmpText]->advance;
     120          width += glyphArray[this->text[i]]->advance;
    150121        }
    151         tmpText++;
    152122      }
    153123      this->setSizeX2D(width *this->getSizeY2D());
     
    190160    glBindTexture(GL_TEXTURE_2D, Font::getDefaultFont()->getTexture());
    191161  }
    192   const char* tmpText = this->externText;
    193   if (this->externText == NULL)
    194     tmpText = this->text;
    195   if (likely(tmpText != NULL))
     162  if (likely(!this->text.empty()))
    196163  {
    197164    glTranslatef(getAbsCoor2D().x, getAbsCoor2D().y, 0);
     
    201168
    202169    glBegin(GL_QUADS);
    203     while (likely(*tmpText != '\0'))
     170    for (unsigned int i = 0; i < this->text.size(); i++)
    204171    {
    205       if(likely((tmpGlyph = glyphArray[*tmpText]) != NULL))
     172      if(likely((tmpGlyph = glyphArray[this->text[i]]) != NULL))
    206173      {
    207174        glTexCoord2f(tmpGlyph->texCoord[1], tmpGlyph->texCoord[2]);
     
    219186        posX += tmpGlyph->advance * this->getSizeY2D();
    220187      }
    221       ++tmpText;
    222188    }
    223189    glEnd();
     
    232198void Text::debug() const
    233199{
    234   if (this->externText == NULL)
    235     PRINT(0)("=== TEXT: %s ===\n", this->text);
    236   else
    237     PRINT(0)("=== TEXT: %s ===\n", this->externText);
     200  PRINT(0)("=== TEXT: %s ===\n", this->text.c_str());
    238201
    239202  if (this->getBindNode())
Note: See TracChangeset for help on using the changeset viewer.