Changeset 8538 in orxonox.OLD for branches/gui/src/lib/graphics
- Timestamp:
- Jun 16, 2006, 4:36:12 PM (18 years ago)
- Location:
- branches/gui/src/lib/graphics
- Files:
-
- 1 edited
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/gui/src/lib/graphics/Makefile.am
r8293 r8538 15 15 text_engine/text.cc \ 16 16 text_engine/multi_line_text.cc \ 17 text_engine/limited_width_text.cc \ 17 18 text_engine/font.cc \ 18 19 \ … … 40 41 text_engine/text.h \ 41 42 text_engine/multi_line_text.h \ 43 text_engine/limited_width_text.h \ 42 44 text_engine/font.h \ 43 45 text_engine/default_font.xpm \ -
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 } -
branches/gui/src/lib/graphics/text_engine/limited_width_text.h
r8529 r8538 1 1 /*! 2 * @file multi_line_text.h2 * @file limited_width_text.h 3 3 * @brief Definition of a text Class, that is able to render text. 4 4 */ 5 5 6 #ifndef _ MULTI_LINE_TEXT_H7 #define _ MULTI_LINE_TEXT_H6 #ifndef _LIMITED_WIDTH_TEXT_H 7 #define _LIMITED_WIDTH_TEXT_H 8 8 9 9 #include "text.h" … … 12 12 13 13 //! Represents one textElement. 14 class MultiLineText : public Text14 class LimitedWidthText : public Text 15 15 { 16 16 public: 17 MultiLineText(const std::string& fontFile = "", unsigned int fontSize = TEXT_DEFAULT_SIZE, float lineWidth = 100.0); 17 typedef enum { 18 Begin, 19 End, 20 } DotsPosition; 21 22 23 public: 24 LimitedWidthText(const std::string& fontFile = "", unsigned int fontSize = TEXT_DEFAULT_SIZE, float lineWidth = 100.0, DotsPosition dotsPosition = Begin); 18 25 19 26 // Setup: 20 27 void setLineWidth(float lineWidth); 21 void set LineSpacing(float lineSpacing);28 void setDotsPosition(DotsPosition dotsPosition); 22 29 23 30 // Retrieve: 24 31 /** @returns the LineWidth (maximum distance from the left to the right */ 25 inline float getLineWidth() const { return this->lineWidth; }; 26 /** @returns the LineSpacing */ 27 inline float getLineSpacing() const { return this->lineSpacing; }; 28 inline unsigned int getLineCount() const { return this->lineCount; }; 29 32 inline float lineWidth() const { return this->_lineWidth; }; 33 /** @returns the dots position. */ 34 inline float dotsPosition() const { return this->_dotsPosition; }; 30 35 virtual void draw() const; 31 36 … … 36 41 37 42 private: 38 float lineWidth; 39 float lineSpacing; 40 std::vector<unsigned int> lineEnds; 41 unsigned int lineCount; 43 std::string _dotedText; 44 45 DotsPosition _dotsPosition; 46 float _lineWidth; 47 unsigned int _lineEnds; 42 48 }; 43 49 44 #endif /* _ MULTI_LINE_TEXT_H */50 #endif /* _LIMITED_WIDTH_TEXT_H */
Note: See TracChangeset
for help on using the changeset viewer.