Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

OgreFont.h

Go to the documentation of this file.
00001 /*-------------------------------------------------------------------------
00002 This source file is a part of OGRE
00003 (Object-oriented Graphics Rendering Engine)
00004 
00005 For the latest info, see http://ogre.sourceforge.net/
00006 
00007 Copyright © 2000-2002 The OGRE Team
00008 Also see acknowledgements in Readme.html
00009 
00010 This library is free software; you can redistribute it and/or modify it
00011 under the terms of the GNU Lesser General Public License (LGPL) as 
00012 published by the Free Software Foundation; either version 2.1 of the 
00013 License, or (at your option) any later version.
00014 
00015 This library is distributed in the hope that it will be useful, but 
00016 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
00017 or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public 
00018 License for more details.
00019 
00020 You should have received a copy of the GNU Lesser General Public License 
00021 along with this library; if not, write to the Free Software Foundation, 
00022 Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA or go to
00023 http://www.gnu.org/copyleft/lesser.txt
00024 -------------------------------------------------------------------------*/
00025 
00026 #ifndef _Font_H__
00027 #define _Font_H__
00028 
00029 #include "OgrePrerequisites.h"
00030 #include "OgreTextureManager.h"
00031 #include "OgreMaterial.h"
00032 #include "OgreMaterialManager.h"
00033 
00034 
00035 namespace Ogre
00036 {
00037     // Define the number of glyphs allowed
00038     // We ignore 0-31 since these are control characters
00039 #if OGRE_WCHAR_T_STRINGS
00040     // Allow wide chars
00041     #define OGRE_NUM_GLYPHS (1024 - 32)
00042 #else
00043     // Allow 8-bit ASCII 
00044     // (we don't want to offend people with charcodes 127-256 in their name eh cearny? ;)
00045     // Only chars 33+ are any use though
00046     #define OGRE_NUM_GLYPHS (256 - 32)
00047 #endif
00048 
00049     // How to look up chars
00050     #define OGRE_GLYPH_INDEX(c) c - 33
00051 
00053     enum FontType
00054     {
00056         FT_TRUETYPE = 1,
00058         FT_IMAGE = 2
00059     };
00060 
00061 
00071     class _OgreExport Font : public Resource
00072     {
00073     protected:
00075         FontType mType;
00076 
00078         String mSource;
00079 
00081         Real mTtfSize;
00083         uint mTtfResolution;
00084 
00085 
00087         Real mTexCoords_u1[OGRE_NUM_GLYPHS];
00089         Real mTexCoords_u2[OGRE_NUM_GLYPHS];
00091         Real mTexCoords_v1[OGRE_NUM_GLYPHS];
00093         Real mTexCoords_v2[OGRE_NUM_GLYPHS];
00094 
00096         Real mAspectRatio[OGRE_NUM_GLYPHS];
00097 
00099         Material *mpMaterial;
00100 
00102         bool mAntialiasColour;
00103 
00105         void createTextureFromFont(void);
00106 
00107     public:
00108 
00112         Font( const String& name);
00113         virtual ~Font();
00114 
00116         void setType(FontType ftype);
00117 
00119         FontType getType(void);
00120 
00134         void setSource(const String& source);
00135 
00138         const String& getSource(void);
00139 
00145         void setTrueTypeSize(Real ttfSize);
00150         void setTrueTypeResolution(uint ttfResolution);
00151 
00158         Real getTrueTypeSize(void);
00163         uint getTrueTypeResolution(void);
00164 
00167         std::pair< uint, uint > StrBBox( const String & text, Real char_height, RenderWindow & window  );
00168 
00170         virtual void load();
00172         virtual void unload();
00173 
00179         inline void getGlyphTexCoords(OgreChar id, Real& u1, Real& v1, Real& u2, Real& v2 ) const
00180         {
00181             OgreChar idx = OGRE_GLYPH_INDEX(id);
00182             u1 = mTexCoords_u1[ idx ];
00183             v1 = mTexCoords_v1[ idx ];
00184             u2 = mTexCoords_u2[ idx ];
00185             v2 = mTexCoords_v2[ idx ];
00186         }
00187 
00194         inline void setGlyphTexCoords( OgreChar id, Real u1, Real v1, Real u2, Real v2 )
00195         {
00196             OgreChar idx = OGRE_GLYPH_INDEX(id);
00197             mTexCoords_u1[ idx ] = u1;
00198             mTexCoords_v1[ idx ] = v1;
00199             mTexCoords_u2[ idx ] = u2;
00200             mTexCoords_v2[ idx ] = v2;
00201             mAspectRatio[ idx ] = ( u2 - u1 ) / ( v1 - v2 );
00202         }
00204         inline Real getGlyphAspectRatio( OgreChar id ) const
00205         {
00206             OgreChar idx = OGRE_GLYPH_INDEX(id);
00207             return mAspectRatio[ idx ];
00208         }
00214         inline void setGlyphAspectRatio( OgreChar id, Real ratio )
00215         {
00216             OgreChar idx = OGRE_GLYPH_INDEX(id);
00217             mAspectRatio[ idx ] = ratio;
00218         }
00223         inline const Material * getMaterial() const
00224         {
00225             return mpMaterial;
00226         }
00231         inline Material * getMaterial()
00232         {
00233             return mpMaterial;
00234         }
00246         inline void setAntialiasColour(bool enabled)
00247         {
00248             mAntialiasColour = enabled;
00249         }
00250 
00251         inline bool getAntialiasColour(void)
00252         {
00253             return mAntialiasColour;
00254         }
00255     };
00256 }
00257 
00258 #endif

Copyright © 2002 by The OGRE Team