Changeset 8538 in orxonox.OLD for branches/gui/src/lib/graphics/text_engine/limited_width_text.cc
- Timestamp:
- Jun 16, 2006, 4:36:12 PM (19 years ago)
- File:
-
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/gui/src/lib/graphics/text_engine/limited_width_text.cc
r8529 r8538 16 16 #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_GRAPHICS 17 17 18 #include " multi_line_text.h"18 #include "limited_width_text.h" 19 19 #include "font.h" 20 20 … … 24 24 * @param type The renderType to display this font in 25 25 */ 26 MultiLineText::MultiLineText(const std::string& fontFile, unsigned int textSize, float lineWidth)27 : Text(fontFile, textSize)26 LimitedWidthText::LimitedWidthText(const std::string& fontFile, unsigned int textSize, float lineWidth, DotsPosition dotsPosition) 27 : Text(fontFile, textSize) 28 28 { 29 this->setClassID(CL_ MULTI_LINE_TEXT, "MultiLineText");29 this->setClassID(CL_LIMITED_WIDTH_TEXT, "LimitedWidthText"); 30 30 31 this->lineSpacing = 1.0; 32 this->lineCount = 0; 31 this->_dotsPosition = End; 33 32 this->setLineWidth(lineWidth); 34 33 } … … 38 37 * @param lineWidth the maximum lineWidth. 39 38 */ 40 void MultiLineText::setLineWidth(float lineWidth)39 void LimitedWidthText::setLineWidth(float lineWidth) 41 40 { 42 this-> lineWidth = lineWidth;41 this->_lineWidth = lineWidth; 43 42 this->setSizeX2D(lineWidth); 44 43 this->setupTextWidth(); … … 47 46 48 47 /** 49 * @param lineSpacing: the Spacing between the lines50 */51 void MultiLineText::setLineSpacing(float lineSpacing)52 {53 this->lineSpacing = lineSpacing;54 this->setupTextWidth();55 }56 57 58 /**59 48 * @brief draws the Text 60 49 */ 61 void MultiLineText::draw() const50 void LimitedWidthText::draw() const 62 51 { 63 if (unlikely(this-> getText().empty()))52 if (unlikely(this->_dotedText.empty())) 64 53 return; 65 54 glPushMatrix(); 66 55 glPushAttrib(GL_ENABLE_BIT); 67 56 // transform for alignment. 68 // TODO make the Stuff with the alignment69 57 if (this->getAlignment() == TEXT_ALIGN_RIGHT) 70 58 glTranslatef(-this->getSizeX2D(), 0, 0); … … 74 62 // drawing this Text. 75 63 // setting the Blending effects 64 glColor4fv(&this->getColor()[0]); 65 66 76 67 glActiveTexture(GL_TEXTURE0); 77 68 78 glColor4fv(&this->getColor()[0]);79 69 glEnable(GL_BLEND); 80 70 glEnable(GL_TEXTURE_2D); … … 83 73 84 74 glBindTexture(GL_TEXTURE_2D, this->getFont()->getTexture()); 85 glTranslatef( this->getAbsCoor2D().x, this->getAbsCoor2D().y, 0);75 glTranslatef(getAbsCoor2D().x, getAbsCoor2D().y, 0); 86 76 glRotatef(this->getAbsDir2D(), 0, 0, 1); 87 77 88 78 Glyph* tmpGlyph; 89 79 float posX = 0.0f; 90 float posY = 0.0f;91 unsigned int lineNumber = 0;92 93 80 glBegin(GL_QUADS); 94 for (unsigned int i = 0; i < this-> getText().size(); ++i)81 for (unsigned int i = 0; i < this->_dotedText.size(); i++) 95 82 { 96 if (unlikely(this->lineEnds.size() > lineNumber && i == this->lineEnds[lineNumber])) 97 { 98 // go to the next Line. 99 ++lineNumber; 100 posX = 0.0f; 101 posY += this->lineSpacing + this->getSize(); //this->getFont()->getMaxHeight(); 102 } 103 104 if(likely((tmpGlyph = this->getFont()->getGlyphArray()[this->getText()[i]]) != NULL)) 83 if(likely((tmpGlyph = this->getFont()->getGlyphArray()[this->_dotedText[i]]) != NULL)) 105 84 { 106 85 glTexCoord2f(tmpGlyph->texCoord[1], tmpGlyph->texCoord[2]); 107 glVertex2d(posX+tmpGlyph->maxX*this->getSize(), posY);86 glVertex2d(posX+tmpGlyph->maxX*this->getSize(), 0); 108 87 109 88 glTexCoord2f(tmpGlyph->texCoord[1], tmpGlyph->texCoord[3]); 110 glVertex2d(posX+tmpGlyph->maxX*this->getSize(), posY +this->getSize());89 glVertex2d(posX+tmpGlyph->maxX*this->getSize(), this->getSize()); 111 90 112 91 glTexCoord2f(tmpGlyph->texCoord[0], tmpGlyph->texCoord[3]); 113 glVertex2d(posX+tmpGlyph->minX*this->getSize(), posY+this->getSize());92 glVertex2d(posX+tmpGlyph->minX*this->getSize(), this->getSize()); 114 93 115 94 glTexCoord2f(tmpGlyph->texCoord[0], tmpGlyph->texCoord[2]); 116 glVertex2d(posX+tmpGlyph->minX*this->getSize(), posY);95 glVertex2d(posX+tmpGlyph->minX*this->getSize(), 0); 117 96 118 97 posX += tmpGlyph->advance * this->getSize(); … … 128 107 * @brief setting up the Text-Width if DYNAMIC 129 108 */ 130 void MultiLineText::setupTextWidth()109 void LimitedWidthText::setupTextWidth() 131 110 { 132 this->lineEnds.clear(); 111 float dotsSize = this->getFont()->getGlyphArray()[46]->advance * 3.0; 112 133 113 float width = 0.0f; 134 float maxWidth = this-> lineWidth / this->getSize();114 float maxWidth = this->_lineWidth / this->getSize(); 135 115 136 for (unsigned int i = 0; i < this->getText().size(); i++)116 switch (this->_dotsPosition) 137 117 { 138 if (width > maxWidth || this->getText()[i] == '\n') 139 { 140 if (likely(i > 0)) 118 case End: 119 for (unsigned int i = 0; i < this->getText().size(); i++) 141 120 { 142 this->lineEnds.push_back( i -1 ); 143 width = this->getFont()->getGlyphArray()[this->getText()[i-1]]->advance; 121 if (width + dotsSize > maxWidth ) 122 { 123 this->_dotedText = this->getText().substr(0, i) + "..."; 124 width += dotsSize; 125 break; 126 } 127 // Advance the Text. 128 if(this->getFont()->getGlyphArray()[this->getText()[i]] != NULL) 129 width += this->getFont()->getGlyphArray()[this->getText()[i]]->advance; 144 130 } 145 else 146 width = 0.0f; 147 } 148 149 // Advance the Text. 150 if(this->getFont()->getGlyphArray()[this->getText()[i]] != NULL) 151 width += this->getFont()->getGlyphArray()[this->getText()[i]]->advance; 131 this->setSizeX2D(width); 132 break; 133 case Begin: 134 for (unsigned int i = this->getText().size() - 1; i < 0; i--) 135 { 136 if (width + dotsSize > maxWidth ) 137 { 138 this->_dotedText = std::string("...") + this->getText().substr(i); 139 width += dotsSize; 140 break; 141 } 142 // Advance the Text. 143 if(this->getFont()->getGlyphArray()[this->getText()[i]] != NULL) 144 width += this->getFont()->getGlyphArray()[this->getText()[i]]->advance; 145 } 146 this->setSizeX2D(width); 147 break; 152 148 } 153 this->lineCount = lineEnds.size() + 1;154 this->setSizeY2D((this->lineEnds.size()+1) * (this->lineSpacing + this->getFont()->getMaxHeight()));155 149 } 156 150 … … 158 152 * @brief print out some nice debug output 159 153 */ 160 void MultiLineText::debug() const154 void LimitedWidthText::debug() const 161 155 { 162 printf("Debug %s::%s: %d lines\n", this->getClassName(), this->getName(), this->getLineCount()); 163 164 std::string tmpText = this->getText(); 165 std::vector<unsigned int> ends = this->lineEnds; 166 ends.push_back(tmpText.size()); 167 168 unsigned int prev = 0; 169 for (unsigned int i = 0; i < ends.size(); i++) 170 { 171 printf("Line %d: %s\n", i, tmpText.substr(prev, ends[i] - prev).c_str()); 172 prev = ends[i]; 173 } 156 printf("Debug %s::%s \n", this->getClassName(), this->getName() ); 174 157 }
Note: See TracChangeset
for help on using the changeset viewer.