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

font.h

Go to the documentation of this file.
00001 /***************************************************************************
00002                     font.h  -  Font class for text rendering
00003                              -------------------
00004     begin                : Fri Nov 16 2001
00005     copyright            : (C) 2001 by Reality Rift Studios
00006     email                : mattias@realityrift.com
00007  ***************************************************************************
00008 
00009  The contents of this file are subject to the Mozilla Public License Version
00010  1.1 (the "License"); you may not use this file except in compliance with
00011  the License. You may obtain a copy of the License at 
00012  http://www.mozilla.org/MPL/
00013 
00014  Software distributed under the License is distributed on an "AS IS" basis,
00015  WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00016  for the specific language governing rights and limitations under the
00017  License.
00018 
00019  The Original Code is the NeoEngine, font.h
00020 
00021  The Initial Developer of the Original Code is Mattias Jansson.
00022  Portions created by Mattias Jansson are Copyright (C) 2001
00023  Reality Rift Studios. All Rights Reserved.
00024 
00025  ***************************************************************************/
00026 
00027 #ifndef __NEFONT_H
00028 #define __NEFONT_H
00029 
00030 
00031 #include "base.h"
00032 #include "loadableentity.h"
00033 #include "texture.h"
00034 #include "material.h"
00035 #include "pointer.h"
00036 
00037 
00043 namespace NeoEngine
00044 {
00045 
00046 
00047 // External classes
00048 class RenderDevice;
00049 
00050 
00051 
00056 class NEOENGINE_API FontCharacter
00057 {
00058     public:
00059 
00061         float                           m_fU;
00062 
00064         float                           m_fV;
00065 
00067         float                           m_fUWidth;
00068 
00070         float                           m_fVHeight;
00071 
00073         int                             m_iX;
00074 
00076         int                             m_iY;
00077 
00079         int                             m_iWidth;
00080 
00082         int                             m_iHeight;
00083 };
00084 
00085 
00086 
00087 
00088 
00093 class NEOENGINE_API Font : public RefCounter, public LoadableEntity
00094 {
00095     friend class FontManager;
00096 
00097     public:
00098 
00103         enum FONTALIGN
00104         {
00105           LEFT,
00106           RIGHT
00107         };
00108 
00113         enum FONTLINEWRAP
00114         {
00115             NOWRAP,
00116             WORDWRAP
00117         };
00118 
00119 
00120 
00121     protected:
00122 
00124         MaterialPtr                     m_pkMaterial;
00125 
00127         FontCharacter                   m_akCharacters[256];
00128 
00130         int                             m_iSpacing;
00131 
00133         int                             m_iLineHeight;
00134 
00136         int                             m_iSpaceWidth;
00137 
00139         int                             m_iClipX;
00140 
00142         int                             m_iClipY;
00143 
00145         int                             m_iClipWidth;
00146 
00148         int                             m_iClipHeight;
00149 
00151         FONTLINEWRAP                    m_eLineWrap;
00152 
00154         std::string                     m_strName;
00155 
00157         FontManager                    *m_pkFontManager;
00158 
00160         std::string                     m_strWordSeparators;
00161 
00163         FONTALIGN                       m_eHorizontalAlign;
00164 
00166         Color                           m_kColor;
00167 
00168 
00174         bool                            LoadNode( unsigned int uiFlags );
00175 
00176 
00181                                         Font( FontManager *pkFontManager );
00182 
00183 
00184   public:
00185 
00187         static NE_STATIC float          s_fSubPixelOffset;
00188 
00191         virtual                        ~Font();
00192 
00200         int                             Printf( int iX, int iY, const char *pszFormat, ... );
00201 
00209         int                             Printf( float fX, float fY, const char *pszFormat, ... );
00210 
00218         void                            SetClipBox( int iX, int iY, int iWidth, int iHeight );
00219 
00227         void                            GetClipBox( int *piX, int *piY, int *piWidth, int *piHeight );
00228 
00232         void                            ResetClipBox();
00233 
00239         FONTLINEWRAP                    SetLineWrap( FONTLINEWRAP eWrap ) { FONTLINEWRAP eRet = m_eLineWrap; m_eLineWrap = eWrap; return eRet; }
00240 
00244         FONTLINEWRAP                    GetLineWrap() const { return m_eLineWrap; }
00245 
00249         int                             GetLineHeight() const { return m_iLineHeight; }
00250 
00255         int                             GetStringLength( const std::string &rstrString );
00256 
00262         int                             GetStringHeight( const std::string &rstrString, int iX );
00263 
00267         const std::string              &GetName() const { return m_strName; }
00268 
00272         const Color                    &GetColor() const;
00273 
00278         Color                           SetColor( const Color &rkColor );
00279 
00284         void                            SetWordSeparators( const std::string &rstrSeparators );
00285 
00291         FONTALIGN                       SetHorizontalAlign( FONTALIGN eAlign );
00292 
00296         FONTALIGN                       GetHorizontalAlign();
00297 
00306         std::string                     ClipLine( const std::string &rstrLine, int iX, int iY, int *piLines = 0 );
00307 };
00308 
00309 
00310 #ifndef __NESMARTPOINTER_FONT
00311    //Define smart pointer
00312    SmartPointer(Font);
00313 #  define __NESMARTPOINTER_FONT
00314 #endif
00315 
00316 
00317 #ifdef WIN32
00318 #  ifndef __HAVE_VECTOR_NEFONT
00319 #    ifdef _MSC_VER
00320 #      pragma warning( disable : 4231 )
00321 #    endif
00322      UDTVectorEXPIMP( class Font* );
00323 #    define __HAVE_VECTOR_NEFONT
00324 #  endif
00325 #endif
00326 
00327 
00328 
00329 
00334 class NEOENGINE_API FontManager
00335 {
00336     friend class Font;
00337         
00338     protected:
00339 
00341         std::vector< Font* >            m_vpkFonts;
00342 
00347         void                            DeregisterFont( Font *pkFont );
00348 
00349 
00350     public:
00351 
00354                                         FontManager();
00355 
00358                                        ~FontManager();
00359 
00366         FontPtr                         CreateFont( const std::string &rstrName, bool bLoad = true );
00367 
00373         FontPtr                         FindFont( const std::string &rstrName );
00374 };
00375 
00376 
00377 }; // namespace NeoEngine
00378 
00379 
00380 #endif

Generated on Wed Jan 21 14:21:06 2004 for NeoEngine by doxygen 1.3.5