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://www.ogre3d.org/
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 "OgreResource.h"
00031 
00032 namespace Ogre
00033 {
00034     // Define the number of glyphs allowed
00035     // We ignore 0-31 since these are control characters
00036 #if OGRE_WCHAR_T_STRINGS
00037     // Allow wide chars
00038     #define OGRE_NUM_GLYPHS (1024 - 32)
00039 #else
00040     // Allow 8-bit ASCII 
00041     // (we don't want to offend people with charcodes 127-256 in their name eh cearny? ;)
00042     // Only chars 33+ are any use though
00043     #define OGRE_NUM_GLYPHS (256 - 32)
00044 #endif
00045 
00046     // How to look up chars
00047     #define OGRE_GLYPH_INDEX(c) c - 33
00048 
00050     enum FontType
00051     {
00053         FT_TRUETYPE = 1,
00055         FT_IMAGE = 2
00056     };
00057 
00058 
00068     class _OgreExport Font : public Resource
00069     {
00070     protected:
00072         FontType mType;
00073 
00075         String mSource;
00076 
00078         Real mTtfSize;
00080         uint mTtfResolution;
00081 
00082 
00084         Real mTexCoords_u1[OGRE_NUM_GLYPHS];
00086         Real mTexCoords_u2[OGRE_NUM_GLYPHS];
00088         Real mTexCoords_v1[OGRE_NUM_GLYPHS];
00090         Real mTexCoords_v2[OGRE_NUM_GLYPHS];
00091 
00093         Real mAspectRatio[OGRE_NUM_GLYPHS];
00094 
00096         Material *mpMaterial;
00097 
00099         bool mAntialiasColour;
00100 
00102         void createTextureFromFont(void);
00103 
00104     public:
00105 
00109         Font( const String& name);
00110         virtual ~Font();
00111 
00113         void setType(FontType ftype);
00114 
00116         FontType getType(void) const;
00117 
00131         void setSource(const String& source);
00132 
00135         const String& getSource(void) const;
00136 
00142         void setTrueTypeSize(Real ttfSize);
00147         void setTrueTypeResolution(uint ttfResolution);
00148 
00155         Real getTrueTypeSize(void) const;
00160         uint getTrueTypeResolution(void) const;
00161 
00164         std::pair< uint, uint > StrBBox( const String & text, Real char_height, RenderWindow & window  );
00165 
00167         virtual void load();
00169         virtual void unload();
00170 
00176         inline void getGlyphTexCoords(OgreChar id, Real& u1, Real& v1, Real& u2, Real& v2 ) const
00177         {
00178             unsigned OgreChar idx = OGRE_GLYPH_INDEX(id);
00179             u1 = mTexCoords_u1[ idx ];
00180             v1 = mTexCoords_v1[ idx ];
00181             u2 = mTexCoords_u2[ idx ];
00182             v2 = mTexCoords_v2[ idx ];
00183         }
00184 
00191         inline void setGlyphTexCoords( OgreChar id, Real u1, Real v1, Real u2, Real v2 )
00192         {
00193             unsigned OgreChar idx = OGRE_GLYPH_INDEX(id);
00194             mTexCoords_u1[ idx ] = u1;
00195             mTexCoords_v1[ idx ] = v1;
00196             mTexCoords_u2[ idx ] = u2;
00197             mTexCoords_v2[ idx ] = v2;
00198             mAspectRatio[ idx ] = ( u2 - u1 ) / ( v2 - v1 );
00199         }
00201         inline Real getGlyphAspectRatio( OgreChar id ) const
00202         {
00203             unsigned OgreChar idx = OGRE_GLYPH_INDEX(id);
00204             return mAspectRatio[ idx ];
00205         }
00211         inline void setGlyphAspectRatio( OgreChar id, Real ratio )
00212         {
00213             unsigned OgreChar idx = OGRE_GLYPH_INDEX(id);
00214             mAspectRatio[ idx ] = ratio;
00215         }
00220         inline const Material * getMaterial() const
00221         {
00222             return mpMaterial;
00223         }
00228         inline Material * getMaterial()
00229         {
00230             return mpMaterial;
00231         }
00243         inline void setAntialiasColour(bool enabled)
00244         {
00245             mAntialiasColour = enabled;
00246         }
00247 
00248         inline bool getAntialiasColour(void) const
00249         {
00250             return mAntialiasColour;
00251         }
00252     };
00253 }
00254 
00255 #endif

Copyright © 2002-2003 by The OGRE Team
Last modified Fri May 14 23:22:09 2004