# Home    # nevrax.com   
Nevrax
Nevrax.org
#News
#Mailing-list
#Documentation
#CVS
#Bugs
#License
Docs
 
Documentation  
Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages   Search  

text_context_user.h

Go to the documentation of this file.
00001 
00007 /* Copyright, 2001 Nevrax Ltd.
00008  *
00009  * This file is part of NEVRAX NEL.
00010  * NEVRAX NEL is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2, or (at your option)
00013  * any later version.
00014 
00015  * NEVRAX NEL is distributed in the hope that it will be useful, but
00016  * WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00018  * General Public License for more details.
00019 
00020  * You should have received a copy of the GNU General Public License
00021  * along with NEVRAX NEL; see the file COPYING. If not, write to the
00022  * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
00023  * MA 02111-1307, USA.
00024  */
00025 
00026 #ifndef NL_TEXT_CONTEXT_USER_H
00027 #define NL_TEXT_CONTEXT_USER_H
00028 
00029 #include "nel/misc/types_nl.h"
00030 #include "nel/3d/u_text_context.h"
00031 #include "3d/text_context.h"
00032 #include "3d/driver_user.h"
00033 
00034 
00035 namespace NL3D
00036 {
00037 
00038 
00045 class CTextContextUser : public UTextContext
00046 {
00047 private:
00048         CTextContext    _TextContext;
00049         CDriverUser             *_DriverUser;
00050         IDriver                 *_Driver;
00051 
00052 public:
00053 
00055         CTextContextUser(const std::string fontFileName, const std::string fontExFileName, CDriverUser *drv, CFontManager *fmg)
00056         {
00057                 nlassert(drv);
00058                 _DriverUser= drv;
00059 
00060                 // The enum of CComputedString and UTextContext MUST be the same!!!
00061                 nlassert((uint)UTextContext::HotSpotCount== (uint)CComputedString::HotSpotCount);
00062 
00063                 _Driver= drv->getDriver();
00064                 _TextContext.init(_Driver, fmg);
00065                 _TextContext.setFontGenerator(fontFileName, fontExFileName);
00066         }
00067         virtual ~CTextContextUser() {}
00068 
00069 
00071         // @{
00072         void setColor(NLMISC::CRGBA color)
00073         {
00074                 _TextContext.setColor(color);
00075         }
00076         void setFontSize(uint32 fontSize) 
00077         {
00078                 _TextContext.setFontSize(fontSize);
00079         }
00080         uint32 getFontSize() const  
00081         {
00082                 return _TextContext.getFontSize();
00083         }
00084         void setHotSpot(THotSpot hotSpot)  
00085         {
00086                 _TextContext.setHotSpot((CComputedString::THotSpot)(uint32)hotSpot) ;
00087         }
00088         THotSpot getHotSpot() const 
00089         {
00090                 return (THotSpot)(uint32)_TextContext.getHotSpot();
00091         }
00092         void setScaleX(float scaleX)  
00093         {
00094                 _TextContext.setScaleX(scaleX);
00095         }
00096         void setScaleY(float scaleY)  
00097         {
00098                 _TextContext.setScaleZ(scaleY);
00099         }
00100         float getScaleX() const 
00101         {
00102                 return _TextContext.getScaleX();
00103         }
00104         float getScaleY() const 
00105         {
00106                 return _TextContext.getScaleZ();
00107         }
00108         void setShaded(bool b) 
00109         {
00110                 _TextContext.setShaded(b);
00111         }
00112         bool getShaded() const  
00113         {
00114                 return _TextContext.getShaded();
00115         }
00116         void setShadeExtent(float shext) 
00117         {
00118                 _TextContext.setShadeExtent(shext);
00119         }
00120         virtual void                    setKeep800x600Ratio(bool keep)
00121         {
00122                 _TextContext.setKeep800x600Ratio(keep);
00123         }
00124         virtual bool                    getKeep800x600Ratio() const
00125         {
00126                 return _TextContext.getKeep800x600Ratio();
00127         }
00128         // @}
00129 
00130 
00132 
00135         // @{
00136         uint32 textPush(const char *format, ...)  
00137         {
00138                 char *str;
00139                 NLMISC_CONVERT_VARGS (str, format, NLMISC::MaxCStringSize);
00140 
00141                 return _TextContext.textPush(ucstring(str)) ;
00142         }
00143         uint32 textPush(const ucstring &str)  
00144         {
00145                 return _TextContext.textPush(str) ;
00146         }
00147         void erase(uint32 i)  
00148         {
00149                 _TextContext.erase(i);
00150         }
00151         virtual CStringInfo             getStringInfo(uint32 i)
00152         {
00153                 CComputedString         *cstr= _TextContext.getComputedString(i);
00154                 if(!cstr)
00155                         return CStringInfo(0,0);
00156                 else
00157                         return  CStringInfo(cstr->StringWidth, cstr->StringHeight);
00158         }
00159         void clear()  
00160         {
00161                 _TextContext.clear();
00162         }
00163         void printAt(float x, float y, uint32 i) 
00164         {
00165                 _TextContext.printAt(x, y, i);
00166                 _DriverUser->restoreMatrixContext();
00167         }
00168         void printAt(float x, float y, ucstring ucstr) 
00169         {
00170                 _TextContext.printAt(x, y, ucstr);
00171                 _DriverUser->restoreMatrixContext();
00172         }
00173         void printfAt(float x, float y, const char * format, ...) 
00174         {
00175                 char *str;
00176                 NLMISC_CONVERT_VARGS (str, format, NLMISC::MaxCStringSize);
00177 
00178                 _TextContext.printAt(x, y, ucstring(str)) ;
00179                 _DriverUser->restoreMatrixContext();
00180         }
00181 
00182         void render3D(const CMatrix &mat, ucstring ucstr) 
00183         {
00184                 CComputedString computedStr;
00185                 _TextContext.computeString(ucstr,computedStr);
00186                 
00187                 computedStr.render3D(*_Driver,mat);
00188 
00189                 _DriverUser->restoreMatrixContext();
00190         }
00191         void render3D(const CMatrix &mat, const char *format, ...) 
00192         {
00193                 char *str;
00194                 NLMISC_CONVERT_VARGS (str, format, NLMISC::MaxCStringSize);
00195 
00196                 render3D(mat, ucstring(str));
00197 
00198                 _DriverUser->restoreMatrixContext();
00199         }
00200 
00201 
00202         float getLastXBound() const 
00203         {
00204                 return _TextContext.getLastXBound();
00205         }
00206         // @}
00207 
00208         void                    dumpCacheTexture (const char *filename)
00209         {
00210                 _TextContext.dumpCache (filename);
00211         }
00212 
00213 };
00214 
00215 
00216 } // NL3D
00217 
00218 
00219 #endif // NL_TEXT_CONTEXT_USER_H
00220 
00221 /* End of text_context_user.h */