- Timestamp:
- Aug 25, 2005, 2:07:12 AM (19 years ago)
- Location:
- trunk/src
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/graphics/graphics_engine.cc
r5121 r5122 464 464 if (this->geTextCFPS == NULL) 465 465 { 466 this->geTextCFPS = TextEngine::getInstance()->createText("fonts/arial_black.ttf", 15, TEXT_ DYNAMIC);466 this->geTextCFPS = TextEngine::getInstance()->createText("fonts/arial_black.ttf", 15, TEXT_RENDER_DYNAMIC); 467 467 this->geTextCFPS->setAlignment(TEXT_ALIGN_LEFT); 468 468 this->geTextCFPS->setAbsCoor2D(5, 5); … … 470 470 if (this->geTextMaxFPS == NULL) 471 471 { 472 this->geTextMaxFPS = TextEngine::getInstance()->createText("fonts/arial_black.ttf", 15, TEXT_ DYNAMIC);472 this->geTextMaxFPS = TextEngine::getInstance()->createText("fonts/arial_black.ttf", 15, TEXT_RENDER_DYNAMIC); 473 473 this->geTextMaxFPS->setAlignment(TEXT_ALIGN_LEFT); 474 474 this->geTextMaxFPS->setAbsCoor2D(5, 35); … … 476 476 if (this->geTextMinFPS == NULL) 477 477 { 478 this->geTextMinFPS = TextEngine::getInstance()->createText("fonts/arial_black.ttf", 15, TEXT_ DYNAMIC);478 this->geTextMinFPS = TextEngine::getInstance()->createText("fonts/arial_black.ttf", 15, TEXT_RENDER_DYNAMIC); 479 479 this->geTextMinFPS->setAlignment(TEXT_ALIGN_LEFT); 480 480 this->geTextMinFPS->setAbsCoor2D(5, 65); -
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 -
trunk/src/lib/graphics/text_engine.h
r5121 r5122 39 39 #define TEXT_ALIGN_CENTER E2D_ALIGN_CENTER 40 40 #define TEXT_ALIGN_SCREEN_CENTER E2D_ALIGN_SCREEN_CENTER 41 #define TEXT_DEFAULT_COLOR Vector(1.0, 1.0, 1.0) //!< the default Color (white) 42 #define TEXT_DEFAULT_BLENDING 1.0f //!< the default blending of the text, (no blending at all) 41 43 42 44 /* some default values */ 43 #define FONT_DEFAULT_SIZE 50//!< default size of the Text44 #define FONT_ DEFAULT_TEXT "orxonox 1234567890" //!< default text to display45 #define FONT_DEFAULT_COLOR_R 255 //!< default red part (color) of the text 46 #define FONT_ DEFAULT_COLOR_G 255 //!< default red green (color) of the text47 #define FONT_DEFAULT_COLOR_B 255 //!< default red blue (color) of the text 48 #define FONT_NUM_COLORS 256 //!< number of colors.49 50 #define FONT_HIGHEST_KNOWN_CHAR 128 //!< The highest character known to the textEngine. 51 52 #define TEXT_DEFAULT_ALIGNMENT TEXT_ALIGN_CENTER //!< default alignment 53 #define TEXT_STATIC 0 //!< Static Text 54 #define TEXT_DYNAMIC 1 //!< Dynamic Text 45 #define FONT_DEFAULT_SIZE 50 //!< default size of the Text 46 #define FONT_NUM_COLORS 256 //!< number of colors. 47 48 #define FONT_HIGHEST_KNOWN_CHAR 128 //!< The highest character known to the textEngine. 49 50 #define TEXT_DEFAULT_ALIGNMENT TEXT_ALIGN_CENTER //!< default alignment 51 52 typedef enum TEXT_RENDER_TYPE 53 { 54 TEXT_RENDER_STATIC = 1, 55 TEXT_RENDER_DYNAMIC = 2 56 }; 55 57 /** 56 58 * STATIC means: a font, that is only one GL-face. … … 103 105 class Text : public Element2D 104 106 { 105 friend class TextEngine;106 107 public: 108 Text(Font* font, TEXT_RENDER_TYPE type = TEXT_RENDER_DYNAMIC); 107 109 ~Text(); 108 110 109 void setType( inttype);110 void setText(const char* text );111 void setType(TEXT_RENDER_TYPE type); 112 void setText(const char* text, bool isExtern = false); 111 113 /** @param blending the blending intensity to set (between 0.0 and 1.0) */ 112 114 inline void setBlending(float blending) { this->blending = blending; }; … … 122 124 123 125 private: 124 Text(Font* font, int type = TEXT_DYNAMIC);125 126 126 static GLuint loadTexture(SDL_Surface* surface, TexCoord* texCoord); 127 127 static int powerOfTwo(int input); … … 130 130 Font* font; //!< Font of this text 131 131 132 inttype; //!< The type of this Font.132 TEXT_RENDER_TYPE type; //!< The type of this Font. 133 133 char* text; //!< The text to display 134 const char* externText; //!< the text to Display from an external Source. 134 135 Vector color; //!< The color of the font. 135 136 float blending; //!< The blending intensity. … … 207 208 Text* createText(const char* fontFile, 208 209 unsigned int fontSize = FONT_DEFAULT_SIZE, 209 int textType = TEXT_ DYNAMIC);210 int textType = TEXT_RENDER_DYNAMIC); 210 211 211 212 void debug() const; -
trunk/src/util/shell.cc
r5121 r5122 158 158 if (this->inputLineText == NULL) 159 159 delete this->inputLineText; 160 this->inputLineText = TextEngine::getInstance()->createText("fonts/Aniron_Bold.ttf", this->textSize, TEXT_ DYNAMIC);160 this->inputLineText = TextEngine::getInstance()->createText("fonts/Aniron_Bold.ttf", this->textSize, TEXT_RENDER_DYNAMIC); 161 161 this->inputLineText->setColor(1, 0, 0); 162 162 this->inputLineText->setAlignment(TEXT_ALIGN_LEFT); … … 184 184 for (unsigned int i = 0; i < bufferDisplaySize; i++) 185 185 { 186 this->bufferText[i] = TextEngine::getInstance()->createText("fonts/Aniron_Bold.ttf", this->textSize, TEXT_ DYNAMIC);186 this->bufferText[i] = TextEngine::getInstance()->createText("fonts/Aniron_Bold.ttf", this->textSize, TEXT_RENDER_DYNAMIC); 187 187 this->bufferText[i]->setColor(1, 0, 0); 188 188 this->bufferText[i]->setAlignment(TEXT_ALIGN_LEFT); … … 299 299 this->bufferText[0] = lastText; 300 300 301 this->bufferText[0]->setText(text );301 this->bufferText[0]->setText(text, true); 302 302 } 303 303 } -
trunk/src/util/track/track_manager.cc
r5121 r5122 380 380 this->setBindSlave(this->trackNode); 381 381 // initializing the Text 382 this->trackText = TextEngine::getInstance()->createText("fonts/earth.ttf", 30, TEXT_ DYNAMIC);382 this->trackText = TextEngine::getInstance()->createText("fonts/earth.ttf", 30, TEXT_RENDER_DYNAMIC); 383 383 this->trackText->setAlignment(E2D_ALIGN_SCREEN_CENTER); 384 384 // initializing the Animation for the Text.
Note: See TracChangeset
for help on using the changeset viewer.