Changeset 8619 in orxonox.OLD for trunk/src/lib/graphics/text_engine
- Timestamp:
- Jun 20, 2006, 1:24:11 PM (19 years ago)
- Location:
- trunk/src/lib/graphics/text_engine
- Files:
-
- 3 edited
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/graphics/text_engine/multi_line_text.cc
r8448 r8619 61 61 void MultiLineText::draw() const 62 62 { 63 if (unlikely(this-> getText().empty()))63 if (unlikely(this->text().empty())) 64 64 return; 65 65 glPushMatrix(); … … 76 76 glActiveTexture(GL_TEXTURE0); 77 77 78 glColor4fv(&this-> getColor()[0]);78 glColor4fv(&this->color()[0]); 79 79 glEnable(GL_BLEND); 80 80 glEnable(GL_TEXTURE_2D); … … 82 82 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, GL_MODULATE ); 83 83 84 glBindTexture(GL_TEXTURE_2D, this-> getFont()->getTexture());84 glBindTexture(GL_TEXTURE_2D, this->font()->getTexture()); 85 85 glTranslatef(this->getAbsCoor2D().x, this->getAbsCoor2D().y, 0); 86 86 glRotatef(this->getAbsDir2D(), 0, 0, 1); … … 92 92 93 93 glBegin(GL_QUADS); 94 for (unsigned int i = 0; i < this-> getText().size(); ++i)94 for (unsigned int i = 0; i < this->text().size(); ++i) 95 95 { 96 96 if (unlikely(this->lineEnds.size() > lineNumber && i == this->lineEnds[lineNumber])) … … 99 99 ++lineNumber; 100 100 posX = 0.0f; 101 posY += this->lineSpacing + this-> getSize(); //this->getFont()->getMaxHeight();101 posY += this->lineSpacing + this->size(); //this->font()->getMaxHeight(); 102 102 } 103 103 104 if(likely((tmpGlyph = this-> getFont()->getGlyphArray()[this->getText()[i]]) != NULL))104 if(likely((tmpGlyph = this->font()->getGlyphArray()[this->text()[i]]) != NULL)) 105 105 { 106 106 glTexCoord2f(tmpGlyph->texCoord[1], tmpGlyph->texCoord[2]); 107 glVertex2d(posX+tmpGlyph->maxX*this-> getSize(), posY);107 glVertex2d(posX+tmpGlyph->maxX*this->size(), posY); 108 108 109 109 glTexCoord2f(tmpGlyph->texCoord[1], tmpGlyph->texCoord[3]); 110 glVertex2d(posX+tmpGlyph->maxX*this-> getSize(), posY + this->getSize());110 glVertex2d(posX+tmpGlyph->maxX*this->size(), posY + this->size()); 111 111 112 112 glTexCoord2f(tmpGlyph->texCoord[0], tmpGlyph->texCoord[3]); 113 glVertex2d(posX+tmpGlyph->minX*this-> getSize(), posY+ this->getSize());113 glVertex2d(posX+tmpGlyph->minX*this->size(), posY+ this->size()); 114 114 115 115 glTexCoord2f(tmpGlyph->texCoord[0], tmpGlyph->texCoord[2]); 116 glVertex2d(posX+tmpGlyph->minX*this-> getSize(), posY);116 glVertex2d(posX+tmpGlyph->minX*this->size(), posY); 117 117 118 posX += tmpGlyph->advance * this-> getSize();118 posX += tmpGlyph->advance * this->size(); 119 119 } 120 120 } … … 132 132 this->lineEnds.clear(); 133 133 float width = 0.0f; 134 float maxWidth = this->lineWidth / this-> getSize();134 float maxWidth = this->lineWidth / this->size(); 135 135 136 for (unsigned int i = 0; i < this-> getText().size(); i++)136 for (unsigned int i = 0; i < this->text().size(); i++) 137 137 { 138 if (width > maxWidth || this-> getText()[i] == '\n')138 if (width > maxWidth || this->text()[i] == '\n') 139 139 { 140 140 if (likely(i > 0)) 141 141 { 142 142 this->lineEnds.push_back( i -1 ); 143 width = this-> getFont()->getGlyphArray()[this->getText()[i-1]]->advance;143 width = this->font()->getGlyphArray()[this->text()[i-1]]->advance; 144 144 } 145 145 else … … 148 148 149 149 // Advance the Text. 150 if(this-> getFont()->getGlyphArray()[this->getText()[i]] != NULL)151 width += this-> getFont()->getGlyphArray()[this->getText()[i]]->advance;150 if(this->font()->getGlyphArray()[this->text()[i]] != NULL) 151 width += this->font()->getGlyphArray()[this->text()[i]]->advance; 152 152 } 153 153 this->lineCount = lineEnds.size() + 1; 154 this->setSizeY2D((this->lineEnds.size()+1) * (this->lineSpacing + this-> getFont()->getMaxHeight()));154 this->setSizeY2D((this->lineEnds.size()+1) * (this->lineSpacing + this->font()->getMaxHeight())); 155 155 } 156 156 … … 162 162 printf("Debug %s::%s: %d lines\n", this->getClassName(), this->getName(), this->getLineCount()); 163 163 164 std::string tmpText = this-> getText();164 std::string tmpText = this->text(); 165 165 std::vector<unsigned int> ends = this->lineEnds; 166 166 ends.push_back(tmpText.size()); -
trunk/src/lib/graphics/text_engine/text.cc
r8518 r8619 22 22 #include "debug.h" 23 23 24 using namespace std;25 26 24 /** 27 25 * @brief creates a new Text Element … … 34 32 35 33 // 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; 40 38 41 39 this->setAlignment(TEXT_DEFAULT_ALIGNMENT); … … 47 45 { 48 46 this->setClassID(CL_TEXT, "Text"); 49 this-> font = NULL;47 this->_font = NULL; 50 48 51 49 *this = text; … … 58 56 Text::~Text() 59 57 { 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); 62 60 } 63 61 … … 69 67 bool Text::operator==(const Text& text) const 70 68 { 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); 75 73 } 76 74 … … 82 80 bool Text::operator==(const std::string& text) const 83 81 { 84 return (this-> text == text);82 return (this->_text == text); 85 83 } 86 84 … … 92 90 Text& Text::operator=(const Text& text) 93 91 { 94 this-> size = text.size;95 this-> color = text.color;92 this->_size = text._size; 93 this->_color = text._color; 96 94 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 ); //!< HACK101 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; 103 101 return *this; 104 102 } … … 110 108 void Text::setText(const std::string& text) 111 109 { 112 this-> text = text;110 this->_text = text; 113 111 this->setupTextWidth(); 114 112 } … … 120 118 void Text::append(const std::string& appendText) 121 119 { 122 this-> text += appendText;120 this->_text += appendText; 123 121 this->setupTextWidth(); 124 122 } … … 129 127 void Text::appendCharacter(char character) 130 128 { 131 this-> text += character;129 this->_text += character; 132 130 this->setupTextWidth(); 133 131 } … … 141 139 { 142 140 this->append(appendText); 143 return this-> text;141 return this->_text; 144 142 } 145 143 … … 152 150 void Text::removeCharacters(unsigned int chars) 153 151 { 154 if (t ext.size() > chars)155 this-> text.resize(this->text.size()-chars);156 else if (!t ext.empty())157 t ext.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(); 158 156 this->setupTextWidth(); 159 157 } … … 165 163 void Text::clear() 166 164 { 167 t ext.clear();165 this->_text.clear(); 168 166 this->setupTextWidth(); 169 167 } … … 177 175 { 178 176 Font* newFont = NULL; 179 Font* oldFont = this-> font;177 Font* oldFont = this->_font; 180 178 181 179 // load a new Font … … 194 192 195 193 // unloading the Font if we alrady have one loaded. 196 this-> font = newFont;194 this->_font = newFont; 197 195 if (oldFont != NULL && oldFont != Font::getDefaultFont()) 198 196 ResourceManager::getInstance()->unload(oldFont); … … 207 205 void Text::setSize(float size) 208 206 { 209 this-> size = size;207 this->_size = size; 210 208 this->setSizeY2D(size); 211 209 this->setupTextWidth(); … … 218 216 void Text::draw() const 219 217 { 220 if (unlikely(this-> text.empty()))218 if (unlikely(this->_text.empty())) 221 219 return; 222 220 glPushMatrix(); … … 230 228 // drawing this Text. 231 229 // setting the Blending effects 232 glColor4fv(&this-> color[0]);230 glColor4fv(&this->_color[0]); 233 231 234 232 … … 240 238 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, GL_MODULATE ); 241 239 242 glBindTexture(GL_TEXTURE_2D, font->getTexture());240 glBindTexture(GL_TEXTURE_2D, this->_font->getTexture()); 243 241 glTranslatef(getAbsCoor2D().x, getAbsCoor2D().y, 0); 244 242 glRotatef(this->getAbsDir2D(), 0, 0, 1); … … 247 245 float posX = 0.0f; 248 246 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++) 250 248 { 251 if(likely((tmpGlyph = this-> getFont()->getGlyphArray()[this->text[i]]) != NULL))249 if(likely((tmpGlyph = this->font()->getGlyphArray()[this->_text[i]]) != NULL)) 252 250 { 253 251 glTexCoord2f(tmpGlyph->texCoord[1], tmpGlyph->texCoord[2]); 254 glVertex2d(posX+tmpGlyph->maxX*this-> getSize(), 0);252 glVertex2d(posX+tmpGlyph->maxX*this->size(), 0); 255 253 256 254 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()); 258 256 259 257 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()); 261 259 262 260 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(); 266 264 } 267 265 } … … 278 276 { 279 277 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()); 284 282 } 285 283 … … 290 288 void Text::debug() const 291 289 { 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 -
trunk/src/lib/graphics/text_engine/text.h
r8518 r8619 45 45 void setFont(const std::string& fontFile, unsigned int renderSize); 46 46 /** @param blending the blending intensity to set (between 0.0 and 1.0) */ 47 inline void setBlending(float blending) { this-> color.a() = blending; };47 inline void setBlending(float blending) { this->_color.a() = blending; }; 48 48 /** @param r red @param g green @param b blue @brief sets the Color of the Text to render (values in [0-1]) */ 49 void setColor(float r, float g, float b) { this-> color = Color(r, g, b, this->color.a()); };50 void setColor(float r, float g, float b, float a) { this-> color = Color(r, g, b, a); };51 void setColor(const Color& color) { this-> color = color; };49 void setColor(float r, float g, float b) { this->_color = Color(r, g, b, this->_color.a()); }; 50 void setColor(float r, float g, float b, float a) { this->_color = Color(r, g, b, a); }; 51 void setColor(const Color& color) { this->_color = color; }; 52 52 void setSize(float size); 53 53 … … 55 55 /// RETRIEVE 56 56 /** @returns the String this Text displays */ 57 inline const std::string& getText() const { return this->text; };57 inline const std::string& text() const { return this->_text; }; 58 58 59 59 /** @returns the pointer to the stored Font (not changeable) */ 60 inline const Font* const getFont() const { return this->font; };60 inline const Font* const font() const { return this->_font; }; 61 61 /** @returns the Blending Value [0 invisible 1.0 full visible */ 62 inline float getBlending() const { return this->color.a(); };62 inline float blending() const { return this->_color.a(); }; 63 63 /** @returns: a Vector(r,g,b) @brief: retrieve a Vector holding the Color of the Text */ 64 inline const Color& getColor() const { return this->color; };64 inline const Color& color() const { return this->_color; }; 65 65 /** @returns the Size of the Text */ 66 inline float getSize() const { return this->size; };66 inline float size() const { return this->_size; }; 67 67 68 68 virtual void draw() const; … … 76 76 77 77 private: 78 Font* font; //!< Font of this text78 Font* _font; //!< Font of this text 79 79 80 std::string text; //!< The text to display81 Color color; //!< The color of the font.82 float size; //!< The size of the Text.80 std::string _text; //!< The text to display 81 Color _color; //!< The color of the font. 82 float _size; //!< The size of the Text. 83 83 }; 84 84
Note: See TracChangeset
for help on using the changeset viewer.