Changeset 9869 in orxonox.OLD for trunk/src/lib/graphics/text_engine
- Timestamp:
- Oct 3, 2006, 12:19:30 AM (18 years ago)
- Location:
- trunk/src/lib/graphics/text_engine
- Files:
-
- 11 edited
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/graphics/text_engine/font.cc
r8989 r9869 29 29 #include "compiler.h" 30 30 31 ObjectListDefinition(Font); 31 32 32 33 Font::Font() … … 34 35 { 35 36 this->init(); 36 37 37 } 38 38 … … 118 118 Material::operator=(font); 119 119 this->data = font.data; 120 this->setTexture(this->data->textureData()); 120 121 121 122 return *this; … … 130 131 this->setBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 131 132 132 this-> setClassID(CL_FONT, "Font");133 if (Font::defaultFontData. get() == NULL)133 this->registerObject(this, Font::_objectList); 134 if (Font::defaultFontData.isNull()) 134 135 { 135 136 Font::initDefaultFont(); … … 138 139 } 139 140 140 FontData Pointer Font::defaultFontData(NULL);141 FontData::Pointer Font::defaultFontData(NULL); 141 142 142 143 /** … … 146 147 { 147 148 // temporarily create a Font. 148 Font::defaultFontData = FontData Pointer(new FontData);149 Font::defaultFontData = FontData::Pointer(new FontData); 149 150 // apply the Data. 150 151 Font::defaultFontData = Font(font_xpm).data; … … 159 160 bool Font::loadFontFromTTF(const std::string& fontFile, unsigned int renderSize) 160 161 { 161 this->data = FontData Pointer (new FontData());162 this->data = FontData::Pointer (new FontData()); 162 163 bool retVal = this->data->loadFontFromTTF(fontFile, renderSize); 163 164 if (!retVal) … … 174 175 bool Font::loadFontFromSDL_Surface(SDL_Surface* surface) 175 176 { 176 this->data = FontData Pointer (new FontData());177 this->data = FontData::Pointer (new FontData()); 177 178 bool retVal = this->data->loadFontFromSDL_Surface(surface); 178 179 if (!retVal) … … 196 197 197 198 198 void Font::setTexture(const TextureData Pointer& texDataPointer)199 void Font::setTexture(const TextureData::Pointer& texDataPointer) 199 200 { 200 201 this->setDiffuseMap(texDataPointer); -
trunk/src/lib/graphics/text_engine/font.h
r8766 r9869 19 19 class Font : public Material 20 20 { 21 21 ObjectListDeclaration(Font); 22 public: 23 typedef FontData::Glyph Glyph; 22 24 public: 23 25 Font(); … … 39 41 40 42 /** @returns a Pointer to the Array of Glyphs */ 41 inline Glyph**getGlyphArray() const { return this->data->getGlyphArray(); };43 inline const Glyph* const * const getGlyphArray() const { return this->data->getGlyphArray(); }; 42 44 43 45 inline int getMaxHeight() const { return data->getMaxHeight(); }; … … 50 52 void debug() const; 51 53 54 void acquireData(const FontData::Pointer& data) { this->data = data; }; 55 const FontData::Pointer& dataPointer() const { return data; }; 52 56 private: 53 57 void init(); 54 58 static void initDefaultFont(); 55 59 56 void setTexture(const TextureData Pointer& texDataPointer);60 void setTexture(const TextureData::Pointer& texDataPointer); 57 61 58 62 private: 59 FontData Pointerdata; //!< A Data-Pointer to a Font.63 FontData::Pointer data; //!< A Data-Pointer to a Font. 60 64 61 static FontData PointerdefaultFontData; //!< a default font, that is used, if other fonts were unable to be loaded.65 static FontData::Pointer defaultFontData; //!< a default font, that is used, if other fonts were unable to be loaded. 62 66 }; 63 67 -
trunk/src/lib/graphics/text_engine/font_data.h
r8768 r9869 26 26 #define FONT_DEFAULT_RENDER_SIZE 50 //!< At what Resolution to render fonts. 27 27 28 class FontData 29 { 30 31 32 public: 33 28 34 //! A struct for handling glyphs 29 35 /** 30 36 * a Glyph is one letter of a certain font 31 37 */ 32 struct Glyph33 {38 struct Glyph 39 { 34 40 // Glyph-specific (size and so on) 35 Uint16 character; //!< The character36 float minX; //!< The minimum distance from the origin in X37 float maxX; //!< The maximum distance from the origin in X38 float minY; //!< The minimum distance from the origin in Y39 float maxY; //!< The maximum distance from the origin in Y40 float width; //!< The width of the Glyph41 float height; //!< The height of the Glyph42 float bearingX; //!< How much is right of the Origin43 float bearingY; //!< How much is above the Origin44 float advance; //!< How big a Glyph would be in monospace-mode41 Uint16 character; //!< The character 42 float minX; //!< The minimum distance from the origin in X 43 float maxX; //!< The maximum distance from the origin in X 44 float minY; //!< The minimum distance from the origin in Y 45 float maxY; //!< The maximum distance from the origin in Y 46 float width; //!< The width of the Glyph 47 float height; //!< The height of the Glyph 48 float bearingX; //!< How much is right of the Origin 49 float bearingY; //!< How much is above the Origin 50 float advance; //!< How big a Glyph would be in monospace-mode 45 51 46 GLfloat texCoord[4]; //!< Texture coordinates: 0:left, 1:right, 2: top, 3: bottom.47 };52 GLfloat texCoord[4]; //!< Texture coordinates: 0:left, 1:right, 2: top, 3: bottom. 53 }; 48 54 49 50 class FontData 51 { 55 typedef CountPointer<FontData> Pointer; 52 56 public: 53 57 FontData(); … … 61 65 62 66 /** @returns a Pointer to the Array of Glyphs */ 63 inline Glyph**getGlyphArray() const { return this->glyphArray; };67 inline const Glyph* const * const getGlyphArray() const { return this->glyphArray; }; 64 68 65 69 int getMaxHeight() const { return maxHeight; }; … … 68 72 69 73 /** @returns the Texture-Data of this FontData */ 70 const TextureData Pointer& textureData() const { return texData; };74 const TextureData::Pointer& textureData() const { return texData; }; 71 75 72 76 bool rebuild() { return texData->rebuild(); }; … … 91 95 int maxDescent; //!< Max Desent of the Font. 92 96 93 TextureData Pointer texData;97 TextureData::Pointer texData; 94 98 }; 95 99 96 typedef CountPointer<FontData> FontDataPointer;97 98 100 #endif /* _FONT_DATA_H */ -
trunk/src/lib/graphics/text_engine/limited_width_text.cc
r9406 r9869 19 19 #include "font.h" 20 20 21 ObjectListDefinition(LimitedWidthText); 21 22 /** 22 23 * @brief creates a new Text Element … … 27 28 : Text(fontFile, textSize) 28 29 { 29 this-> setClassID(CL_LIMITED_WIDTH_TEXT, "LimitedWidthText");30 this->registerObject(this, LimitedWidthText::_objectList); 30 31 31 32 this->_dotsPosition = End; … … 75 76 glRotatef(this->getAbsDir2D(), 0, 0, 1); 76 77 77 Glyph* tmpGlyph;78 const Font::Glyph* tmpGlyph; 78 79 float posX = 0.0f; 79 80 glBegin(GL_QUADS); -
trunk/src/lib/graphics/text_engine/limited_width_text.h
r8980 r9869 14 14 class LimitedWidthText : public Text 15 15 { 16 ObjectListDeclaration(LimitedWidthText); 16 17 public: 17 18 typedef enum { -
trunk/src/lib/graphics/text_engine/multi_line_text.cc
r9406 r9869 19 19 #include "font.h" 20 20 21 ObjectListDefinition(MultiLineText); 22 21 23 /** 22 24 * @brief creates a new Text Element … … 27 29 : Text(fontFile, textSize) 28 30 { 29 this-> setClassID(CL_MULTI_LINE_TEXT, "MultiLineText");31 this->registerObject(this, MultiLineText::_objectList); 30 32 31 33 this->lineSpacing = 1.0; … … 78 80 glRotatef(this->getAbsDir2D(), 0, 0, 1); 79 81 80 Glyph* tmpGlyph;82 const Font::Glyph* tmpGlyph; 81 83 float posX = 0.0f; 82 84 float posY = 0.0f; -
trunk/src/lib/graphics/text_engine/multi_line_text.h
r7757 r9869 14 14 class MultiLineText : public Text 15 15 { 16 ObjectListDeclaration(MultiLineText); 16 17 public: 17 18 MultiLineText(const std::string& fontFile = "", unsigned int fontSize = TEXT_DEFAULT_SIZE, float lineWidth = 100.0); -
trunk/src/lib/graphics/text_engine/text.cc
r9406 r9869 17 17 18 18 #include "text.h" 19 #include "resource_font.h" 19 20 #include "font.h" 20 21 #include "util/loading/resource_manager.h"22 21 #include "debug.h" 22 23 ObjectListDefinition(Text); 23 24 24 25 /** … … 28 29 */ 29 30 Text::Text(const std::string& fontFile, unsigned int textSize) 30 31 { 32 this-> setClassID(CL_TEXT, "Text");31 // : _font(fontFile, FONT_DEFAULT_RENDER_SIZE) 32 { 33 this->registerObject(this, Text::_objectList); 33 34 34 35 // initialize this Text 35 this->setFont(fontFile, FONT_DEFAULT_RENDER_SIZE); 36 if (!fontFile.empty()) 37 this->setFont(fontFile, FONT_DEFAULT_RENDER_SIZE); 38 else 39 this->setFont("fonts/final_frontier.ttf", FONT_DEFAULT_RENDER_SIZE); 36 40 this->_size = textSize; 37 41 this->setSizeY2D(textSize); … … 44 48 : _font() 45 49 { 46 this-> setClassID(CL_TEXT, "Text");50 this->registerObject(this, Text::_objectList); 47 51 48 52 *this = text; … … 169 173 void Text::setFont(const std::string& fontFile, unsigned int fontSize) 170 174 { 171 Font* newFont = NULL; 172 // Font* oldFont = this->_font; 173 174 // load a new Font 175 if (!fontFile.empty()) 176 { 177 newFont = (Font*)ResourceManager::getInstance()->load(fontFile, TTF, RP_GAME, (int)fontSize); 178 if (newFont == NULL) 179 { 180 // newFont = &Font::(); 181 PRINTF(2)("Font %s could not be loaded, probably file not found\n", fontFile.c_str()); 182 } 183 } 184 185 if (newFont == NULL) 186 this->_font = Font(); 187 else 188 this->_font = *newFont; 175 this->_font = ResourceFont(fontFile, fontSize); 189 176 190 177 this->setupTextWidth(); … … 233 220 glRotatef(this->getAbsDir2D(), 0, 0, 1); 234 221 235 Glyph* tmpGlyph;222 const Font::Glyph* tmpGlyph; 236 223 float posX = 0.0f; 237 224 glBegin(GL_QUADS); -
trunk/src/lib/graphics/text_engine/text.h
r8764 r9869 26 26 class Text : public Element2D 27 27 { 28 ObjectListDeclaration(Text); 28 29 public: 29 30 Text(const std::string& fontFile = "", unsigned int fontSize = TEXT_DEFAULT_SIZE); -
trunk/src/lib/graphics/text_engine/text_engine.cc
r9406 r9869 33 33 34 34 #include "graphics_engine.h" 35 #include "util/loading/resource_manager.h"36 #include "class_list.h"37 35 38 36 #include "debug.h" … … 40 38 /// TEXT-ENGINE /// 41 39 /////////////////// 40 ObjectListDefinition(TextEngine); 42 41 /** 43 42 * standard constructor … … 45 44 TextEngine::TextEngine () 46 45 { 47 this->setClassID(CL_TEXT_ENGINE, "TextEngine");48 49 46 this->registerObject(this, TextEngine::_objectList); 47 this->setName("TextEngine"); 48 this->enableFonts(); 50 49 } 51 50 … … 62 61 { 63 62 // first remove all the remaining Texts (if any). 64 const std::list<BaseObject*>* textList = ClassList::getList(CL_TEXT); 65 if (textList != NULL) 66 { 67 while(textList->size() > 0) 68 delete dynamic_cast<Text*>(textList->front()); 69 } 63 while (!Text::objectList().empty()) 64 delete Text::objectList().front(); 70 65 // delete all remaining fonts (There should not be Anything to do here) 71 const std::list<BaseObject*>* fontList = ClassList::getList(CL_FONT); 72 if (fontList != NULL) 66 67 //const std::list<BaseObject*>* fontList = ClassList::getList(CL_FONT); 68 //if (fontList != NULL) 73 69 { 74 70 ///FIXME 75 // while (fontList->size() > 0)71 // while (fontList->size() > 0) 76 72 { 77 // Font* font = dynamic_cast<Font*>(fontList->back());73 // Font* font = dynamic_cast<Font*>(fontList->back()); 78 74 //if (likely(font != Font::getDefaultFont())) 79 75 // ResourceManager::getInstance()->unload(font, RP_GAME); … … 91 87 { 92 88 if (!TTF_WasInit()) 93 94 95 89 { 90 if(TTF_Init()==-1) 91 PRINTF(1)("TTF_Init: %s\n", TTF_GetError()); 96 92 97 98 93 TextEngine::checkVersion(); 94 } 99 95 else 100 96 PRINTF(4)("Fonts already initialized\n"); … … 107 103 { 108 104 if (TTF_WasInit()) 109 110 // Font::removeDefaultFont();111 112 105 { 106 // Font::removeDefaultFont(); 107 TTF_Quit(); 108 } 113 109 else 114 110 PRINTF(4)("Fonts were not initialized.\n"); … … 122 118 void TextEngine::debug() const 123 119 { 124 const std::list<BaseObject*>* textList = ClassList::getList(CL_TEXT); 125 if (textList != NULL) 120 PRINT(0)("+-------------------------------+\n"); 121 PRINT(0)("+ TEXT ENGINE DEBUG INFORMATION +\n"); 122 PRINT(0)("+-------------------------------+\n"); 123 PRINT(0)("Reference: %p; Text Counts: %d\n", this, Text::objectList().size()); 124 125 for (ObjectList<Text>::const_iterator it = Text::objectList().begin(); 126 it != Text::objectList().end(); 127 ++it) 126 128 { 127 PRINT(0)("+-------------------------------+\n"); 128 PRINT(0)("+ TEXT ENGINE DEBUG INFORMATION +\n"); 129 PRINT(0)("+-------------------------------+\n"); 130 PRINT(0)("Reference: %p; Text Counts: %d\n", this, textList->size()); 131 132 std::list<BaseObject*>::const_iterator text; 133 for ( text = textList->begin(); text != textList->end(); text++) 134 dynamic_cast<Text*>(*text)->debug(); 129 (*it)->debug(); 135 130 PRINT(0)("+---------------------------TE--+\n"); 136 131 } … … 152 147 compile_version.minor == link_version.minor && 153 148 compile_version.patch == link_version.patch) 154 155 156 149 { 150 return true; 151 } 157 152 else 158 159 160 161 162 153 { 154 PRINTF(2)("compiled with SDL_ttf version: %d.%d.%d\n", 155 compile_version.major, 156 compile_version.minor, 157 compile_version.patch); 163 158 164 165 166 167 168 169 159 PRINTF(2)("running with SDL_ttf version: %d.%d.%d\n", 160 link_version.major, 161 link_version.minor, 162 link_version.patch); 163 return false; 164 } 170 165 } -
trunk/src/lib/graphics/text_engine/text_engine.h
r5515 r9869 24 24 class TextEngine : public BaseObject 25 25 { 26 public: 26 ObjectListDeclaration(TextEngine); 27 public: 27 28 virtual ~TextEngine(); 28 29 /** @returns a Pointer to the only object of this Class */
Note: See TracChangeset
for help on using the changeset viewer.