![[]](/images/special/trans.gif)
LibN2L-4 Library Code ReferenceClassesCompounds Files Members Method Index Full Reference cTextureFont.hGo to the documentation of this file.00001 /************************************************************************ 00002 Nova-2 Library (libN2L, or simply n2l) Game development C++ Library 00003 Copyright (C) 2003 Aaron Cameron 00004 00005 This library is free software; you can redistribute it and/or 00006 modify it under the terms of the GNU Lesser General Public 00007 License as published by the Free Software Foundation; either 00008 version 2.1 of the License, or (at your option) any later version. 00009 00010 This library is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 Lesser General Public License for more details. 00014 00015 You should have received a copy of the GNU Lesser General Public 00016 License along with this library; if not, write to the Free Software 00017 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00018 00019 A copy of the GNU Lesser General Public License has been provided with 00020 this library in the file 'COPYING'. 00021 00022 Contact information for the author of this library has been provided 00023 with this library in the file 'AUTHOR'. 00024 ************************************************************************/ 00025 #ifndef _n2l4_cTextureFont_h 00026 #define _n2l4_cTextureFont_h 00027 00028 #include "n2l/n2l.h" 00029 #include "n2l/geometry.h" 00030 00031 #include "types.h" 00032 #include "cFontInterface.h" 00033 #include "cTTFSurfaceFactory.h" 00034 00035 #include <map> 00036 00037 /******************************************************************************/ 00038 namespace n2l { 00039 00040 class cGLTexture; 00041 class cSurfaceInterface; 00042 00043 /**************************************************************************/ 00047 class cTextureFont : public cFontInterface 00048 { 00049 private: 00055 template <typename TNum> 00056 class cCoordSetBase 00057 { 00058 public: 00059 cCoordSetBase() {} 00060 cCoordSetBase( const TNum iX, const TNum iY, const TNum iA, 00061 const TNum iB ) : 00062 mX(iX), mY(iY), mA(iA), mB(iB) {} 00063 const TNum x() const { return mX; } 00064 const TNum y() const { return mY; } 00065 const TNum x2() const { return mA; } 00066 const TNum y2() const { return mB; } 00067 const TNum w() const { return mA-mX; } 00068 const TNum h() const { return mB-mY; } 00069 private: 00070 TNum mX,mY,mA,mB; 00071 }; 00072 00073 public: 00074 typedef cCoordSetBase<tUint> tCoordSet; 00075 typedef std::map<tGlyphID,tCoordSet> tCoordMap; 00076 00077 static const tUint MaxGlyphs; 00078 static const tUbyte UndefinedGlyphID; 00079 00080 cTextureFont( const cVfsNodeInterface &iFile, 00081 const tUint iPtSize = 24 ); 00082 00083 cTextureFont( const cSurfaceInterface &iSurface, 00084 const tCoordMap &iMap ); 00085 00086 cTextureFont( const cTTFSurfaceFactory &iFactory ); 00087 00088 virtual ~cTextureFont(); 00089 00090 void buildGlyphs( const cSurfaceInterface &iSurface, 00091 const tCoordMap &iMap ); 00092 00093 void buildGlyphs( const cTTFSurfaceFactory &iFactory ); 00094 00095 virtual void draw( const tString &iText ) const; 00096 virtual void draw( const tVector2f &iPos, const tString &iText, 00097 const tFloat &iGlyphHeight = 1.0f, 00098 const tString::size_type iStartPos = 0, 00099 const tString::size_type iLength = tString::npos ) const; 00100 00101 virtual void drawGlyph( const tGlyphID iGlyphID ) const; 00102 00103 virtual const tVector2f calcSize( const tString &iText, 00104 const tFloat &iGlyphHeight = 1.0f, 00105 const tString::size_type iStartPos = 0, 00106 const tString::size_type iLength = tString::npos ) const; 00107 00108 virtual const tFloat glyphWidth( const tGlyphID iGlyphID, 00109 const tFloat &iGlyphHeight = 1.0f ) const; 00110 00111 virtual const tFloat glyphSeperation( 00112 const tFloat &iGlyphHeight = 1.0f ) const; 00113 00114 virtual const tFloat glyphRowSeperation( 00115 const tFloat &iGlyphHeight = 1.0f ) const; 00116 00117 private: 00118 typedef cCoordSetBase<tFloat> tTexCoords; 00119 00120 static const tGlyphID MinGenGlyphID; 00121 static const tGlyphID MaxGenGlyphID; 00122 00123 static const tUint PreferredMaxGenTexXSize; 00124 static const tUint PreferredMaxGenTexYSize; 00125 00126 static const tUint MaxGenTexXSize; 00127 static const tUint MaxGenTexYSize; 00128 00135 static const tUint GlyphPadding; 00136 00137 cAutoPtr<const cGLTexture> mGlyphs; 00138 tTexCoords *mTexCoords; 00139 tFloat *mGlyphWidths; 00140 tFloat mGlyphSeperation; 00141 tFloat mGlyphRowSeperation; 00142 00143 cTextureFont(); 00144 00145 const tBool willFitIn( const cTTFSurfaceFactory &iFactory, 00146 const tUint iMaxX, const tUint iMaxY, tUint &oActualXSize, 00147 tUint &oActualYSize ) const; 00148 00149 }; // class 00150 00151 } 00152 00153 #endif |