Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

# KeosFontManager.h

Go to the documentation of this file.

    00001 /*
    00002  * This source file is part of KEOS (Free 3D Engine)
    00003  * For the latest info, see http://www.keosengine.org/
    00004  * E-mails : thierry.vouriot@keosengine.org, yeri@keosengine.org
    00005  *
    00006  * This program is free software; you can redistribute it and/or modify it under
    00007  * the terms of the GNU Lesser General Public License as published by the Free Software
    00008  * Foundation; either version 2 of the License, or (at your option) any later
    00009  * version.
    00010  *
    00011  * This program is distributed in the hope that it will be useful, but WITHOUT
    00012  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    00013  * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
    00014  *
    00015  * You should have received a copy of the GNU Lesser General Public License along with
    00016  * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
    00017  * Place - Suite 330, Boston, MA 02111-1307, USA, or go to
    00018  * http://www.gnu.org/copyleft/lesser.txt.
    00019  *
    00020  */
    00021 #ifndef KEOS_FONTMANAGER_H
    00022 #define KEOS_FONTMANAGER_H
    00023
    00024 #include "KeosPrerequisites.h"
    00025 #include "KeosSingleton.h"
    00026 #include "KeosDeclaration.h"
    00027 #include "KeosTexture.h"
    00028 #include "KeosBuffer.h"
    00029
    00030 namespace Keos
    00031 {
    00032     //-----------------------------------------------------------------------
    00035     class KEOS_EXPORT CFontManager : public CSingleton<CFontManager>
    00036     {
    00037     friend class CSingleton<CFontManager>;
    00038
    00039     public :
    00040
    00046         void LoadFont(const String& strFontFile, const String& strFontName, int nQuality = 16);
    00047
    00050         void UnloadFonts();
    00051
    00055         void DrawString(const CGraphicString& String);
    00056
    00061         TVector2I GetStringPixelSize(const CGraphicString& String);
    00062
    00065                 size_t GetFontHeight(const String& strFontName);
    00066
    00067     private :
    00068
    00071         CFontManager();
    00072
    00075         ~CFontManager();
    00076
    00079         void Initialize();
    00080
    00082         struct TVertex
    00083         {
    00084             TVector3F   Position;
    00085             ulong       Diffuse;
    00086             TVector2F   TexCoords;
    00087         };
    00088
    00090         typedef ushort TIndex;
    00091
    00093         struct Glyph
    00094         {
    00095             float Tex_x1, Tex_y1, Tex_x2;
    00096             size_t Advance;
    00097         };
    00098
    00100         struct TFont
    00101         {
    00103             CTexture Texture;
    00105             Glyph* Glyphs;
    00107             Glyph* GlyphsTable[256];
    00109             size_t LineHeight;
    00111             float TextureLineHeight;
    00112         };
    00113
    00114         typedef std::map<String, TFont> TFontsMap;
    00115
    00116         static const unsigned int NbCharMax = 512;
    00117
    00118         TFontsMap        m_Fonts;
    00119         CBuffer<TVertex> m_VertexBuffer;
    00120         CBuffer<TIndex>  m_IndexBuffer;
    00121         CDeclarationPtr  m_Declaration;
    00122     };
    00123
    00124 } // namespace Keos
    00125
    00126 #endif // KEOS_FONTMANAGER_H