Changeset 7221 in orxonox.OLD for trunk/src/lib/graphics/text_engine/text.cc
- Timestamp:
- Mar 15, 2006, 3:10:45 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/graphics/text_engine/text.cc
r7193 r7221 32 32 * @param type The renderType to display this font in 33 33 */ 34 Text::Text(const char*fontFile, unsigned int textSize)34 Text::Text(const std::string& fontFile, unsigned int textSize) 35 35 { 36 36 this->init(); 37 37 38 if ( fontFile != NULL)38 if (!fontFile.empty()) 39 39 this->setFont(fontFile, FONT_DEFAULT_RENDER_SIZE); 40 40 this->setSizeY2D(textSize); … … 50 50 if (this->font != NULL && this->font != Font::getDefaultFont()) 51 51 ResourceManager::getInstance()->unload(this->font); 52 53 if (this->text)54 delete[] this->text;55 52 } 56 53 … … 64 61 // initialize this Text 65 62 this->font = NULL; 66 this->text = NULL; 67 this->externText = NULL; 63 this->text = ""; 68 64 this->setAlignment(TEXT_DEFAULT_ALIGNMENT); 69 65 this->blending = TEXT_DEFAULT_BLENDING; 70 66 this->color = TEXT_DEFAULT_COLOR; 71 67 this->setSize(TEXT_DEFAULT_SIZE); 72 this->setText( NULL);68 this->setText(""); 73 69 } 74 70 … … 78 74 * @param fontSize the Size of the Font 79 75 */ 80 void Text::setFont(const char*fontFile, unsigned int fontSize)76 void Text::setFont(const std::string& fontFile, unsigned int fontSize) 81 77 { 82 78 Font* tmpFont; … … 90 86 91 87 // load a new Font 92 if ( fontFile != NULL)88 if (!fontFile.empty()) 93 89 { 94 90 tmpFont = (Font*)ResourceManager::getInstance()->load(fontFile, TTF, RP_GAME, (int)fontSize); … … 96 92 this->font = tmpFont; 97 93 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()); 99 95 } 100 96 } … … 104 100 * @param text the new text to set 105 101 */ 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 } 102 void Text::setText(const std::string& text) 103 { 104 this->text = text; 131 105 132 106 // setting up the Text-Width if DYNAMIC … … 138 112 139 113 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()) 144 115 { 145 while (*tmpText != '\0')116 for (unsigned int i = 0; i < this->text.size(); i++) 146 117 { 147 if(glyphArray[ *tmpText] != NULL)118 if(glyphArray[this->text[i]] != NULL) 148 119 { 149 width += glyphArray[ *tmpText]->advance;120 width += glyphArray[this->text[i]]->advance; 150 121 } 151 tmpText++;152 122 } 153 123 this->setSizeX2D(width *this->getSizeY2D()); … … 190 160 glBindTexture(GL_TEXTURE_2D, Font::getDefaultFont()->getTexture()); 191 161 } 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())) 196 163 { 197 164 glTranslatef(getAbsCoor2D().x, getAbsCoor2D().y, 0); … … 201 168 202 169 glBegin(GL_QUADS); 203 while (likely(*tmpText != '\0'))170 for (unsigned int i = 0; i < this->text.size(); i++) 204 171 { 205 if(likely((tmpGlyph = glyphArray[ *tmpText]) != NULL))172 if(likely((tmpGlyph = glyphArray[this->text[i]]) != NULL)) 206 173 { 207 174 glTexCoord2f(tmpGlyph->texCoord[1], tmpGlyph->texCoord[2]); … … 219 186 posX += tmpGlyph->advance * this->getSizeY2D(); 220 187 } 221 ++tmpText;222 188 } 223 189 glEnd(); … … 232 198 void Text::debug() const 233 199 { 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()); 238 201 239 202 if (this->getBindNode())
Note: See TracChangeset
for help on using the changeset viewer.