00001
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "std3d.h"
00025
00026 #include "nel/3d/text_context_user.h"
00027 #include "nel/misc/hierarchical_timer.h"
00028
00029
00030 namespace NL3D
00031 {
00032
00033 H_AUTO_DECL( NL3D_Render_TextContext_3D )
00034 #define NL3D_HAUTO_RENDER_3D_TEXTCONTEXT H_AUTO_USE( NL3D_Render_TextContext_3D )
00035
00036
00037 NLMISC::CVector UTextContext::CStringInfo::getHotSpotVector(UTextContext::THotSpot hotspot)
00038 {
00039 H_AUTO2;
00040
00041 NLMISC::CVector hotspotVector(0,0,0);
00042
00043 if(hotspot==UTextContext::MiddleLeft)
00044 hotspotVector = CVector(0,0,-StringHeight/2);
00045
00046 if(hotspot==UTextContext::TopLeft)
00047 hotspotVector = CVector(0,0,StringHeight);
00048
00049 if(hotspot==UTextContext::MiddleBottom)
00050 hotspotVector = CVector(-StringWidth/2,0,0);
00051
00052 if(hotspot==UTextContext::MiddleMiddle)
00053 hotspotVector = CVector(-StringWidth/2,0,-StringHeight/2);
00054
00055 if(hotspot==UTextContext::MiddleTop)
00056 hotspotVector = CVector(-StringWidth/2,0,-StringHeight);
00057
00058 if(hotspot==UTextContext::BottomRight)
00059 hotspotVector = CVector(-StringWidth,0,0);
00060
00061 if(hotspot==UTextContext::MiddleRight)
00062 hotspotVector = CVector(-StringWidth,0,-StringHeight/2);
00063
00064 if(hotspot==UTextContext::TopRight)
00065 hotspotVector = CVector(-StringWidth,0,-StringHeight);
00066
00067 return hotspotVector;
00068 }
00069
00070
00071
00072 void UTextContext::CStringInfo::convertTo01Size(UDriver *drv)
00073 {
00074 uint32 w,h;
00075 drv->getWindowSize(w,h);
00076 StringWidth/= w;
00077 StringHeight/= h;
00078 StringLine/= h;
00079 }
00080 void UTextContext::CStringInfo::convertToPixelSize(UDriver *drv)
00081 {
00082 uint32 w,h;
00083 drv->getWindowSize(w,h);
00084 StringWidth*= w;
00085 StringHeight*= h;
00086 StringLine*= h;
00087 }
00088
00089
00090
00091
00092 void CTextContextUser::setColor(NLMISC::CRGBA color)
00093 {
00094 H_AUTO2;
00095
00096 _TextContext.setColor(color);
00097 }
00098 void CTextContextUser::setFontSize(uint32 fontSize)
00099 {
00100 H_AUTO2;
00101
00102 _TextContext.setFontSize(fontSize);
00103 }
00104 uint32 CTextContextUser::getFontSize() const
00105 {
00106 H_AUTO2;
00107
00108 return _TextContext.getFontSize();
00109 }
00110 void CTextContextUser::setHotSpot(THotSpot hotSpot)
00111 {
00112 H_AUTO2;
00113
00114 _TextContext.setHotSpot((CComputedString::THotSpot)(uint32)hotSpot) ;
00115 }
00116 UTextContext::THotSpot CTextContextUser::getHotSpot() const
00117 {
00118 H_AUTO2;
00119
00120 return (THotSpot)(uint32)_TextContext.getHotSpot();
00121 }
00122 void CTextContextUser::setScaleX(float scaleX)
00123 {
00124 H_AUTO2;
00125
00126 _TextContext.setScaleX(scaleX);
00127 }
00128 void CTextContextUser::setScaleY(float scaleY)
00129 {
00130 H_AUTO2;
00131
00132 _TextContext.setScaleZ(scaleY);
00133 }
00134 float CTextContextUser::getScaleX() const
00135 {
00136 H_AUTO2;
00137
00138 return _TextContext.getScaleX();
00139 }
00140 float CTextContextUser::getScaleY() const
00141 {
00142 H_AUTO2;
00143
00144 return _TextContext.getScaleZ();
00145 }
00146 void CTextContextUser::setShaded(bool b)
00147 {
00148 H_AUTO2;
00149
00150 _TextContext.setShaded(b);
00151 }
00152 bool CTextContextUser::getShaded() const
00153 {
00154 H_AUTO2;
00155
00156 return _TextContext.getShaded();
00157 }
00158 void CTextContextUser::setShadeExtent(float shext)
00159 {
00160 H_AUTO2;
00161
00162 _TextContext.setShadeExtent(shext);
00163 }
00164 void CTextContextUser::setShadeColor (NLMISC::CRGBA sc)
00165 {
00166 H_AUTO2;
00167
00168 _TextContext.setShadeColor (sc);
00169 }
00170 NLMISC::CRGBA CTextContextUser::getShadeColor () const
00171 {
00172 H_AUTO2;
00173
00174 return _TextContext.getShadeColor();
00175 }
00176 void CTextContextUser::setKeep800x600Ratio(bool keep)
00177 {
00178 H_AUTO2;
00179
00180 _TextContext.setKeep800x600Ratio(keep);
00181 }
00182 bool CTextContextUser::getKeep800x600Ratio() const
00183 {
00184 H_AUTO2;
00185
00186 return _TextContext.getKeep800x600Ratio();
00187 }
00188
00189
00190 uint32 CTextContextUser::textPush(const char *format, ...)
00191 {
00192 H_AUTO2;
00193
00194 char *str;
00195 NLMISC_CONVERT_VARGS (str, format, NLMISC::MaxCStringSize);
00196
00197 return _TextContext.textPush(ucstring(str)) ;
00198 }
00199 uint32 CTextContextUser::textPush(const ucstring &str)
00200 {
00201 H_AUTO2;
00202
00203 return _TextContext.textPush(str) ;
00204 }
00205 void CTextContextUser::setStringColor(uint32 i, CRGBA newCol)
00206 {
00207 CComputedString *str= _TextContext.getComputedString(i);
00208 if(str)
00209 {
00210 str->Color= newCol;
00211 }
00212 }
00213 void CTextContextUser::setStringSelection(uint32 i, uint32 selectStart, uint32 selectSize)
00214 {
00215 CComputedString *str= _TextContext.getComputedString(i);
00216 if(str)
00217 {
00218 str->SelectStart= selectStart;
00219 str->SelectSize= selectSize;
00220 }
00221 }
00222 void CTextContextUser::resetStringSelection(uint32 i)
00223 {
00224 CComputedString *str= _TextContext.getComputedString(i);
00225 if(str)
00226 {
00227 str->SelectStart= 0;
00228 str->SelectSize= ~0;
00229 }
00230 }
00231 void CTextContextUser::erase(uint32 i)
00232 {
00233 H_AUTO2;
00234
00235 _TextContext.erase(i);
00236 }
00237 UTextContext::CStringInfo CTextContextUser::getStringInfo(uint32 i)
00238 {
00239 H_AUTO2;
00240
00241 CComputedString *cstr= _TextContext.getComputedString(i);
00242 if(!cstr)
00243 return CStringInfo(0, 0, 0);
00244 else
00245 return CStringInfo(cstr->StringWidth, cstr->StringHeight, cstr->StringLine);
00246 }
00247 UTextContext::CStringInfo CTextContextUser::getStringInfo(const ucstring &str)
00248 {
00249 H_AUTO2;
00250
00251 _TextContext.computeStringInfo(str, _CacheString);
00252 return CStringInfo (_CacheString.StringWidth, _CacheString.StringHeight, _CacheString.StringLine);
00253 }
00254 void CTextContextUser::clear()
00255 {
00256 H_AUTO2;
00257
00258 _TextContext.clear();
00259 }
00260 void CTextContextUser::printAt(float x, float y, uint32 i)
00261 {
00262 H_AUTO2;
00263
00264 _TextContext.printAt(x, y, i);
00265 _DriverUser->restoreMatrixContext();
00266 }
00267 void CTextContextUser::printClipAt(URenderStringBuffer &renderBuffer, float x, float y, uint32 i, float xmin, float ymin, float xmax, float ymax)
00268 {
00269 H_AUTO2;
00270
00271 _TextContext.printClipAt(static_cast<CRenderStringBuffer&>(renderBuffer), x, y, i, xmin, ymin, xmax, ymax);
00272
00273 }
00274 void CTextContextUser::printClipAtUnProjected(URenderStringBuffer &renderBuffer, class NL3D::CFrustum &frustum, const NLMISC::CMatrix &scaleMatrix, float x, float y, float depth, uint32 i, float xmin, float ymin, float xmax, float ymax)
00275 {
00276 H_AUTO2;
00277
00278 _TextContext.printClipAtUnProjected(static_cast<CRenderStringBuffer&>(renderBuffer), frustum, scaleMatrix, x, y, depth, i, xmin, ymin, xmax, ymax);
00279
00280 }
00281 void CTextContextUser::printClipAtOld (float x, float y, uint32 i, float xmin, float ymin, float xmax, float ymax)
00282 {
00283 static CRenderStringBuffer rdrBuffer;
00284 printClipAt(rdrBuffer, x, y ,i, xmin, ymin, xmax, ymax);
00285 flushRenderBuffer(&rdrBuffer);
00286 }
00287 void CTextContextUser::printAt(float x, float y, const ucstring &ucstr)
00288 {
00289 H_AUTO2;
00290
00291 _TextContext.printAt(x, y, ucstr);
00292 _DriverUser->restoreMatrixContext();
00293 }
00294 void CTextContextUser::printfAt(float x, float y, const char * format, ...)
00295 {
00296 H_AUTO2;
00297
00298 char *str;
00299 NLMISC_CONVERT_VARGS (str, format, NLMISC::MaxCStringSize);
00300
00301 _TextContext.printAt(x, y, ucstring(str)) ;
00302 _DriverUser->restoreMatrixContext();
00303 }
00304
00305 void CTextContextUser::render3D(const CMatrix &mat, const ucstring &ucstr)
00306 {
00307 NL3D_HAUTO_RENDER_3D_TEXTCONTEXT;
00308
00309 CComputedString computedStr;
00310 _TextContext.computeString(ucstr,computedStr);
00311
00312 computedStr.render3D(*_Driver,mat);
00313
00314 _DriverUser->restoreMatrixContext();
00315 }
00316 void CTextContextUser::render3D(const CMatrix &mat, const char *format, ...)
00317 {
00318 NL3D_HAUTO_RENDER_3D_TEXTCONTEXT;
00319
00320 char *str;
00321 NLMISC_CONVERT_VARGS (str, format, NLMISC::MaxCStringSize);
00322
00323 render3D(mat, ucstring(str));
00324
00325 _DriverUser->restoreMatrixContext();
00326 }
00327
00328
00329 float CTextContextUser::getLastXBound() const
00330 {
00331 H_AUTO2;
00332
00333 return 0.0f;
00334 }
00335
00336
00337 void CTextContextUser::dumpCacheTexture (const char *filename)
00338 {
00339 _TextContext.dumpCache (filename);
00340 }
00341
00342
00343
00344 URenderStringBuffer *CTextContextUser::createRenderBuffer()
00345 {
00346 return new CRenderStringBuffer;
00347 }
00348
00349
00350 void CTextContextUser::deleteRenderBuffer(URenderStringBuffer *buffer)
00351 {
00352 delete buffer;
00353 }
00354
00355
00356 void CTextContextUser::flushRenderBuffer(URenderStringBuffer *buffer)
00357 {
00358 nlassert(buffer);
00359 CRenderStringBuffer *rdrBuffer= static_cast<CRenderStringBuffer*>(buffer);
00360 if(rdrBuffer->NumQuads)
00361 {
00362 rdrBuffer->flush(*_Driver, _TextContext.getFontManager()->getFontMaterial());
00363
00364
00365 _DriverUser->restoreMatrixContextMatrixOnly();
00366 }
00367 }
00368
00369
00370 void CTextContextUser::flushRenderBufferUnProjected(URenderStringBuffer *buffer, bool zwrite)
00371 {
00372 nlassert(buffer);
00373 CRenderStringBuffer *rdrBuffer= static_cast<CRenderStringBuffer*>(buffer);
00374 if(rdrBuffer->NumQuads)
00375 {
00376 rdrBuffer->flushUnProjected(*_Driver, _TextContext.getFontManager()->getFontMaterial(), zwrite);
00377 }
00378 }
00379
00380
00381
00382 void CTextContextUser::setLetterColors(ULetterColors * letterColors, uint index)
00383 {
00384 H_AUTO2;
00385
00386 _TextContext.setLetterColors(static_cast<CLetterColors*>(letterColors), index);
00387 }
00388
00389
00390 ULetterColors * CTextContextUser::createLetterColors()
00391 {
00392 H_AUTO2;
00393
00394 ULetterColors * uLetterColors = new CLetterColors();
00395 return uLetterColors;
00396 }
00397
00398 bool CTextContextUser::isSameLetterColors(ULetterColors * letterColors, uint index)
00399 {
00400 H_AUTO2;
00401
00402 return _TextContext.isSameLetterColors(static_cast<CLetterColors*>(letterColors), index);
00403 }
00404
00405 }