Changeset 5122 in orxonox.OLD for trunk/src/lib/graphics/text_engine.cc
- Timestamp:
- Aug 25, 2005, 2:07:12 AM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/graphics/text_engine.cc
r5121 r5122 50 50 a text with the TextEngine. 51 51 */ 52 Text::Text(Font* font, inttype)52 Text::Text(Font* font, TEXT_RENDER_TYPE type) 53 53 { 54 54 this->setClassID(CL_TEXT, "Text"); … … 57 57 this->font = font; 58 58 this->text = NULL; 59 this->externText = NULL; 59 60 this->setAlignment(TEXT_DEFAULT_ALIGNMENT); 60 61 this->texture = 0; 61 this->blending = 1.0f;62 this->color = Vector(1.0, 1.0, 1.0);62 this->blending = TEXT_DEFAULT_BLENDING; 63 this->color = TEXT_DEFAULT_COLOR; 63 64 this->setType(type); 64 65 65 this->setText( FONT_DEFAULT_TEXT);66 this->setText(NULL); 66 67 } 67 68 68 69 /** 69 70 * deletes a Text out of memory 70 71 71 * 72 * This also ereases the text from the textList of the TextEngine 72 73 */ 73 74 Text::~Text() 74 75 { 75 ResourceManager::getInstance()->unload(this->font); 76 if (this->font != NULL) 77 ResourceManager::getInstance()->unload(this->font); 76 78 77 79 if (this->text) … … 83 85 * @param type the type to set. 84 86 */ 85 void Text::setType( inttype)87 void Text::setType(TEXT_RENDER_TYPE type) 86 88 { 87 89 if (this->font->font) 88 90 this->type = type; 89 91 else 90 this->type = TEXT_ DYNAMIC;92 this->type = TEXT_RENDER_DYNAMIC; 91 93 } 92 94 … … 95 97 * @param text the new text to set 96 98 */ 97 void Text::setText(const char* text) 98 { 99 if (this->text) 100 delete []this->text; 101 if (text != NULL) 99 void Text::setText(const char* text, bool isExtern) 100 { 101 if (isExtern) 102 102 { 103 this->text = new char[strlen(text)+1]; 104 strcpy(this->text, text); 103 this->externText = text; 104 105 if (unlikely(this->text != NULL)) 106 { 107 delete[] this->text; 108 this->text = NULL; 109 } 105 110 } 106 111 else 107 112 { 108 this->text = new char[1]; 109 *this->text = '\0'; 113 this->externText = NULL; 114 if (this->text) 115 delete[] this->text; 116 if (text != NULL) 117 { 118 this->text = new char[strlen(text)+1]; 119 strcpy(this->text, text); 120 } 121 else 122 { 123 this->text = new char[1]; 124 *this->text = '\0'; 125 } 110 126 } 111 127 112 113 128 // setting up the Text-Width if DYNAMIC 114 if (this->type == TEXT_DYNAMIC && this->getAlignment() != TEXT_ALIGN_LEFT)129 if (this->type & TEXT_RENDER_DYNAMIC && this->getAlignment() != TEXT_ALIGN_LEFT) 115 130 { 116 131 Glyph** glyphArray = this->font->getGlyphArray(); 117 132 118 133 int width = 0; 119 char* tmpText = this->text; 134 const char* tmpText = this->externText; 135 if (this->externText == NULL) 136 tmpText = this->text; 120 137 while (*tmpText != '\0') 121 138 { … … 177 194 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, GL_MODULATE ); 178 195 179 if(type == TEXT_STATIC) 180 { 181 glBindTexture(GL_TEXTURE_2D, this->texture); 182 glBegin(GL_QUADS); 183 184 glTexCoord2f(this->texCoord.minU, this->texCoord.minV); 185 glVertex2f(this->getAbsCoor2D().x, this->getAbsCoor2D().y ); 186 187 glTexCoord2f(this->texCoord.maxU, this->texCoord.minV); 188 glVertex2f(this->getAbsCoor2D().x + this->posSize.w, this->getAbsCoor2D().y ); 189 190 glTexCoord2f(this->texCoord.maxU, this->texCoord.maxV); 191 glVertex2f(this->getAbsCoor2D().x + this->posSize.w, getAbsCoor2D().y + this->posSize.h); 192 193 glTexCoord2f(this->texCoord.minU, this->texCoord.maxV); 194 glVertex2f(getAbsCoor2D().x, getAbsCoor2D().y + this->posSize.h); 195 196 glEnd(); 197 } 198 else //(if type == TEXT_DYNAMIC) 196 if(likely(type & TEXT_RENDER_DYNAMIC)) 199 197 { 200 198 Glyph** glyphArray = this->font->getGlyphArray(); … … 204 202 // glRotatef(this->getAbsDir2D(), 0,0,1); 205 203 206 const char* tmpText = this->text; 204 const char* tmpText = this->externText; 205 if (this->externText == NULL) 206 tmpText = this->text; 207 207 while (*tmpText != '\0') 208 { 209 if(glyphArray[*tmpText]) 208 210 { 209 if(glyphArray[*tmpText]) 210 { 211 glCallList(glyphArray[*tmpText]->displayList); 212 glTranslatef(glyphArray[*tmpText]->width, 0, 0); 213 } 214 tmpText++; 211 glCallList(glyphArray[*tmpText]->displayList); 212 glTranslatef(glyphArray[*tmpText]->width, 0, 0); 215 213 } 214 tmpText++; 215 } } 216 else //(if type & TEXT_RENDER_STATIC) 217 { 218 glBindTexture(GL_TEXTURE_2D, this->texture); 219 glBegin(GL_QUADS); 220 221 glTexCoord2f(this->texCoord.minU, this->texCoord.minV); 222 glVertex2f(this->getAbsCoor2D().x, this->getAbsCoor2D().y ); 223 224 glTexCoord2f(this->texCoord.maxU, this->texCoord.minV); 225 glVertex2f(this->getAbsCoor2D().x + this->posSize.w, this->getAbsCoor2D().y ); 226 227 glTexCoord2f(this->texCoord.maxU, this->texCoord.maxV); 228 glVertex2f(this->getAbsCoor2D().x + this->posSize.w, getAbsCoor2D().y + this->posSize.h); 229 230 glTexCoord2f(this->texCoord.minU, this->texCoord.maxV); 231 glVertex2f(getAbsCoor2D().x, getAbsCoor2D().y + this->posSize.h); 232 233 glEnd(); 234 216 235 } 217 236 glPopMatrix(); … … 223 242 void Text::debug() const 224 243 { 225 PRINT(0)("=== TEXT: %s ===\n", this->text); 244 if (this->externText == NULL) 245 PRINT(0)("=== TEXT: %s ===\n", this->text); 246 else 247 PRINT(0)("=== TEXT: %s ===\n", this->externText); 248 226 249 if (this->getBindNode()) 227 250 PRINT(0)("is bind to %s; ref=%p\n", this->getBindNode()->getName(), this->getBindNode()); … … 808 831 return NULL; 809 832 } 810 811 return new Text(tmpFont, TEXT_DYNAMIC);833 else 834 return new Text(tmpFont, TEXT_RENDER_DYNAMIC); 812 835 } 813 836
Note: See TracChangeset
for help on using the changeset viewer.