Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

763 lines
22 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #define SUPPORT_CUSTOM_FONT_FORMAT
  8. #ifdef SUPPORT_CUSTOM_FONT_FORMAT
  9. #define _WIN32_WINNT 0x0500
  10. #endif
  11. #include "gameuisystemsurface.h"
  12. #include "gameuisystemmgr.h"
  13. #include "vgui_surfacelib/fontmanager.h"
  14. #include "vgui_surfacelib/texturedictionary.h"
  15. #include "vgui_surfacelib/fonttexturecache.h"
  16. #include "vgui/isystem.h"
  17. #include "tier1/utlbuffer.h"
  18. #include "tier1/keyvalues.h"
  19. #include "materialsystem/imesh.h"
  20. #include "gameuischeme.h"
  21. #include "vgui_controls/Controls.h"
  22. #include "rendersystem/irendercontext.h"
  23. #include "rendersystem/vertexdata.h"
  24. #include "rendersystem/indexdata.h"
  25. #include "GameLayer.h"
  26. #if defined( _X360 )
  27. #include "xbox/xbox_win32stubs.h"
  28. #endif
  29. #include "xbox/xboxstubs.h"
  30. #include "valvefont.h"
  31. // memdbgon must be the last include file in a .cpp file!!!
  32. #include "tier0/memdbgon.h"
  33. //-----------------------------------------------------------------------------
  34. // Helper function for getting the language the game ui should use.
  35. //-----------------------------------------------------------------------------
  36. static void HelperGetLanguage( char *pLanguageBuf, int bufSize )
  37. {
  38. bool bValid = false;
  39. if ( IsPC() )
  40. {
  41. bValid = vgui::system()->GetRegistryString( "HKEY_CURRENT_USER\\Software\\Valve\\Steam\\Language", pLanguageBuf, bufSize - 1 );
  42. }
  43. else
  44. {
  45. Q_strncpy( pLanguageBuf, XBX_GetLanguageString(), bufSize );
  46. bValid = true;
  47. }
  48. if ( !bValid )
  49. {
  50. Q_strncpy( pLanguageBuf, "english", bufSize );
  51. }
  52. }
  53. //-----------------------------------------------------------------------------
  54. // Globals...
  55. //-----------------------------------------------------------------------------
  56. static CFontTextureCache g_FontTextureCache;
  57. //-----------------------------------------------------------------------------
  58. // Singleton instance
  59. //-----------------------------------------------------------------------------
  60. CGameUISystemSurface g_GameUISystemSurface;
  61. CGameUISystemSurface *g_pGameUISystemSurface = &g_GameUISystemSurface;
  62. //-----------------------------------------------------------------------------
  63. // Constructor
  64. //-----------------------------------------------------------------------------
  65. CGameUISystemSurface::CGameUISystemSurface()
  66. {
  67. m_bIsInitialized = false;
  68. g_FontTextureCache.SetPrefix( "ingameui" );
  69. }
  70. //-----------------------------------------------------------------------------
  71. // Constructor
  72. //-----------------------------------------------------------------------------
  73. CGameUISystemSurface::~CGameUISystemSurface()
  74. {
  75. m_CustomFontFileNames.RemoveAll();
  76. m_BitmapFontFileNames.RemoveAll();
  77. m_BitmapFontFileMapping.RemoveAll();
  78. }
  79. //-----------------------------------------------------------------------------
  80. //
  81. //-----------------------------------------------------------------------------
  82. InitReturnVal_t CGameUISystemSurface::Init()
  83. {
  84. if ( m_bIsInitialized )
  85. return INIT_OK;
  86. // fonts initialization
  87. char language[64];
  88. HelperGetLanguage( language, 64 );
  89. FontManager().SetLanguage( language );
  90. m_bIsInitialized = true;
  91. return INIT_OK;
  92. }
  93. //-----------------------------------------------------------------------------
  94. // Purpose:
  95. //-----------------------------------------------------------------------------
  96. void CGameUISystemSurface::Shutdown( void )
  97. {
  98. // Release all textures
  99. TextureDictionary()->DestroyAllTextures();
  100. #if !defined( _GAMECONSOLE )
  101. HMODULE gdiModule = NULL;
  102. #ifdef SUPPORT_CUSTOM_FONT_FORMAT
  103. ; // on custom font format Windows takes care of cleaning up the font when the process quits
  104. #else
  105. // release any custom font files
  106. // use newer function if possible
  107. gdiModule = ::LoadLibrary( "gdi32.dll" );
  108. typedef int (WINAPI *RemoveFontResourceExProc)(LPCTSTR, DWORD, PVOID);
  109. RemoveFontResourceExProc pRemoveFontResourceEx = NULL;
  110. if ( gdiModule )
  111. {
  112. pRemoveFontResourceEx = (RemoveFontResourceExProc)::GetProcAddress(gdiModule, "RemoveFontResourceExA");
  113. }
  114. for (int i = 0; i < m_CustomFontFileNames.Count(); i++)
  115. {
  116. if ( pRemoveFontResourceEx )
  117. {
  118. // dvs: Keep removing the font until we get an error back. After consulting with Microsoft, it appears
  119. // that RemoveFontResourceEx must sometimes be called multiple times to work. Doing this insures that
  120. // when we load the font next time we get the real font instead of Ariel.
  121. int nRetries = 0;
  122. while ( (*pRemoveFontResourceEx)(m_CustomFontFileNames[i].String(), 0x10, NULL) && ( nRetries < 10 ) )
  123. {
  124. nRetries++;
  125. Msg( "Removed font resource %s on attempt %d.\n", m_CustomFontFileNames[i].String(), nRetries );
  126. }
  127. }
  128. else
  129. {
  130. // dvs: Keep removing the font until we get an error back. After consulting with Microsoft, it appears
  131. // that RemoveFontResourceEx must sometimes be called multiple times to work. Doing this insures that
  132. // when we load the font next time we get the real font instead of Ariel.
  133. int nRetries = 0;
  134. while ( ::RemoveFontResource(m_CustomFontFileNames[i].String()) && ( nRetries < 10 ) )
  135. {
  136. nRetries++;
  137. Msg( "Removed font resource %s on attempt %d.\n", m_CustomFontFileNames[i].String(), nRetries );
  138. }
  139. }
  140. }
  141. #endif // SUPPORT_CUSTOM_FONT_FORMAT
  142. #endif
  143. m_CustomFontFileNames.RemoveAll();
  144. m_BitmapFontFileNames.RemoveAll();
  145. m_BitmapFontFileMapping.RemoveAll();
  146. #if !defined( _GAMECONSOLE )
  147. if ( gdiModule )
  148. {
  149. ::FreeLibrary(gdiModule);
  150. }
  151. #endif
  152. }
  153. //-----------------------------------------------------------------------------
  154. // Purpose: adds a custom font file (supports valve .vfont files)
  155. //-----------------------------------------------------------------------------
  156. bool CGameUISystemSurface::AddCustomFontFile( const char *fontFileName )
  157. {
  158. if ( IsGameConsole() )
  159. {
  160. // custom fonts are not supported (not needed) on xbox, all .vfonts are offline converted to ttfs
  161. // ttfs are mounted/handled elsewhere
  162. return true;
  163. }
  164. char fullPath[MAX_PATH];
  165. bool bFound = false;
  166. // windows needs an absolute path for ttf
  167. bFound = g_pFullFileSystem->GetLocalPath( fontFileName, fullPath, sizeof( fullPath ) ) ? true : false;
  168. if ( !bFound )
  169. {
  170. Warning( "Couldn't find custom font file '%s'\n", fontFileName );
  171. return false;
  172. }
  173. // only add if it's not already in the list
  174. Q_strlower( fullPath );
  175. CUtlSymbol sym( fullPath );
  176. int i;
  177. for ( i = 0; i < m_CustomFontFileNames.Count(); i++ )
  178. {
  179. if ( m_CustomFontFileNames[i] == sym )
  180. break;
  181. }
  182. if ( !m_CustomFontFileNames.IsValidIndex( i ) )
  183. {
  184. m_CustomFontFileNames.AddToTail( fullPath );
  185. if ( IsPC() )
  186. {
  187. #ifdef SUPPORT_CUSTOM_FONT_FORMAT
  188. // We don't need the actual file on disk
  189. #else
  190. // make sure it's on disk
  191. // only do this once for each font since in steam it will overwrite the
  192. // registered font file, causing windows to invalidate the font
  193. g_pFullFileSystem->GetLocalCopy( fullPath );
  194. #endif
  195. }
  196. }
  197. #if !defined( _GAMECONSOLE )
  198. #ifdef SUPPORT_CUSTOM_FONT_FORMAT
  199. // Just load the font data, decrypt in memory and register for this process
  200. CUtlBuffer buf;
  201. if ( !g_pFullFileSystem->ReadFile( fontFileName, NULL, buf ) )
  202. {
  203. Msg( "Failed to load custom font file '%s'\n", fontFileName );
  204. return false;
  205. }
  206. if ( !ValveFont::DecodeFont( buf ) )
  207. {
  208. Msg( "Failed to parse custom font file '%s'\n", fontFileName );
  209. return false;
  210. }
  211. DWORD dwNumFontsRegistered = 0;
  212. HANDLE hRegistered = NULL;
  213. hRegistered = ::AddFontMemResourceEx( buf.Base(), buf.TellPut(), NULL, &dwNumFontsRegistered );
  214. if ( !hRegistered )
  215. {
  216. Msg( "Failed to register custom font file '%s'\n", fontFileName );
  217. return false;
  218. }
  219. return hRegistered != NULL;
  220. #else
  221. // try and use the optimal custom font loader, will makes sure fonts are unloaded properly
  222. // this function is in a newer version of the gdi library (win2k+), so need to try get it directly
  223. bool successfullyAdded = false;
  224. HMODULE gdiModule = ::LoadLibrary( "gdi32.dll" );
  225. if (gdiModule)
  226. {
  227. typedef int (WINAPI *AddFontResourceExProc)(LPCTSTR, DWORD, PVOID);
  228. AddFontResourceExProc pAddFontResourceEx = (AddFontResourceExProc)::GetProcAddress( gdiModule, "AddFontResourceExA" );
  229. if (pAddFontResourceEx)
  230. {
  231. int result = (*pAddFontResourceEx)(fullPath, 0x10, NULL);
  232. if (result > 0)
  233. {
  234. successfullyAdded = true;
  235. }
  236. }
  237. ::FreeLibrary(gdiModule);
  238. }
  239. // add to windows
  240. bool success = successfullyAdded || (::AddFontResource(fullPath) > 0);
  241. if ( !success )
  242. {
  243. Msg( "Failed to load custom font file '%s'\n", fullPath );
  244. }
  245. Assert( success );
  246. return success;
  247. #endif // SUPPORT_CUSTOM_FONT_FORMAT
  248. #else
  249. return true;
  250. #endif
  251. }
  252. //-----------------------------------------------------------------------------
  253. // Purpose: adds a bitmap font file
  254. //-----------------------------------------------------------------------------
  255. bool CGameUISystemSurface::AddBitmapFontFile( const char *fontFileName )
  256. {
  257. bool bFound = false;
  258. bFound = ( ( g_pFullFileSystem->GetDVDMode() == DVDMODE_STRICT ) || g_pFullFileSystem->FileExists( fontFileName, IsGameConsole() ? "GAME" : NULL ) );
  259. if ( !bFound )
  260. {
  261. Msg( "Couldn't find bitmap font file '%s'\n", fontFileName );
  262. return false;
  263. }
  264. char path[MAX_PATH];
  265. Q_strncpy( path, fontFileName, MAX_PATH );
  266. // only add if it's not already in the list
  267. Q_strlower( path );
  268. CUtlSymbol sym( path );
  269. int i;
  270. for ( i = 0; i < m_BitmapFontFileNames.Count(); i++ )
  271. {
  272. if ( m_BitmapFontFileNames[i] == sym )
  273. break;
  274. }
  275. if ( !m_BitmapFontFileNames.IsValidIndex( i ) )
  276. {
  277. m_BitmapFontFileNames.AddToTail( path );
  278. if ( IsPC() )
  279. {
  280. // make sure it's on disk
  281. // only do this once for each font since in steam it will overwrite the
  282. // registered font file, causing windows to invalidate the font
  283. g_pFullFileSystem->GetLocalCopy( path );
  284. }
  285. }
  286. return true;
  287. }
  288. //-----------------------------------------------------------------------------
  289. // Purpose:
  290. //-----------------------------------------------------------------------------
  291. void CGameUISystemSurface::SetBitmapFontName( const char *pName, const char *pFontFilename )
  292. {
  293. char fontPath[MAX_PATH];
  294. Q_strncpy( fontPath, pFontFilename, MAX_PATH );
  295. Q_strlower( fontPath );
  296. CUtlSymbol sym( fontPath );
  297. for ( int i = 0; i < m_BitmapFontFileNames.Count(); i++ )
  298. {
  299. if ( m_BitmapFontFileNames[i] == sym )
  300. {
  301. // found it, update the mapping
  302. int index = m_BitmapFontFileMapping.Find( pName );
  303. if ( !m_BitmapFontFileMapping.IsValidIndex( index ) )
  304. {
  305. index = m_BitmapFontFileMapping.Insert( pName );
  306. }
  307. m_BitmapFontFileMapping.Element( index ) = i;
  308. break;
  309. }
  310. }
  311. }
  312. //-----------------------------------------------------------------------------
  313. // Purpose:
  314. //-----------------------------------------------------------------------------
  315. const char *CGameUISystemSurface::GetBitmapFontName( const char *pName )
  316. {
  317. // find it in the mapping symbol table
  318. int index = m_BitmapFontFileMapping.Find( pName );
  319. if ( index == m_BitmapFontFileMapping.InvalidIndex() )
  320. {
  321. return "";
  322. }
  323. return m_BitmapFontFileNames[m_BitmapFontFileMapping.Element( index )].String();
  324. }
  325. //-----------------------------------------------------------------------------
  326. // Purpose:
  327. //-----------------------------------------------------------------------------
  328. void CGameUISystemSurface::ClearTemporaryFontCache( void )
  329. {
  330. FontManager().ClearTemporaryFontCache();
  331. }
  332. //-----------------------------------------------------------------------------
  333. //
  334. //-----------------------------------------------------------------------------
  335. const char *CGameUISystemSurface::GetFontName( FontHandle_t font )
  336. {
  337. return FontManager().GetFontName( font );
  338. }
  339. //-----------------------------------------------------------------------------
  340. // Causes fonts to get reloaded, etc.
  341. //-----------------------------------------------------------------------------
  342. void CGameUISystemSurface::ResetFontCaches()
  343. {
  344. // Don't do this on x360!!!
  345. if ( IsGameConsole() )
  346. return;
  347. // clear font texture cache
  348. g_FontTextureCache.Clear();
  349. g_pGameUISchemeManager->ReloadFonts();
  350. }
  351. //-----------------------------------------------------------------------------
  352. // Purpose: cap bits
  353. // Warning: if you change this, make sure the SurfaceV28 wrapper above reports
  354. // the correct capabilities.
  355. //-----------------------------------------------------------------------------
  356. bool CGameUISystemSurface::SupportsFontFeature( FontFeature_t feature )
  357. {
  358. switch ( feature )
  359. {
  360. case FONT_FEATURE_ANTIALIASED_FONTS:
  361. case FONT_FEATURE_DROPSHADOW_FONTS:
  362. return true;
  363. case FONT_FEATURE_OUTLINE_FONTS:
  364. if ( IsGameConsole() )
  365. return false;
  366. return true;
  367. default:
  368. return false;
  369. };
  370. }
  371. //-----------------------------------------------------------------------------
  372. // Purpose: Force a set of characters to be rendered into the font page.
  373. //-----------------------------------------------------------------------------
  374. void CGameUISystemSurface::PrecacheFontCharacters( FontHandle_t font, wchar_t *pCharacterString )
  375. {
  376. wchar_t *pCommonChars = L"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789,.!:-/%";
  377. if ( !pCharacterString || !pCharacterString[0] )
  378. {
  379. // use the common chars, alternate languages are not handled
  380. pCharacterString = pCommonChars;
  381. }
  382. int numChars = 0;
  383. while( pCharacterString[ numChars ] )
  384. {
  385. numChars++;
  386. }
  387. int *pTextureIDs_ignored = (int *)_alloca( numChars*sizeof( int ) );
  388. float **pTexCoords_ignored = (float **)_alloca( numChars*sizeof( float * ) );
  389. g_FontTextureCache.GetTextureForChars( font, FONT_DRAW_DEFAULT, pCharacterString, pTextureIDs_ignored, pTexCoords_ignored, numChars );
  390. }
  391. //-----------------------------------------------------------------------------
  392. // Purpose:
  393. //-----------------------------------------------------------------------------
  394. void CGameUISystemSurface::DrawFontTexture( int textureId, int xPos, int yPos )
  395. {
  396. Assert( g_pMaterialSystem );
  397. IMaterial *pMaterial = GetMaterial( textureId );
  398. if (!pMaterial)
  399. {
  400. return;
  401. }
  402. CMatRenderContextPtr pRenderContext( g_pMaterialSystem );
  403. IMesh *pMesh = pRenderContext->GetDynamicMesh( true, NULL, NULL, pMaterial );
  404. if ( !pMesh )
  405. return;
  406. unsigned char textColor[4];
  407. textColor[0] = 255;
  408. textColor[1] = 255;
  409. textColor[2] = 255;
  410. textColor[3] = 255;
  411. int x = xPos;
  412. int y = yPos;
  413. int wide;
  414. int tall;
  415. TextureDictionary()->GetTextureSize( textureId, wide, tall );
  416. CMeshBuilder meshBuilder;
  417. meshBuilder.Begin( pMesh, MATERIAL_QUADS, 1 );
  418. meshBuilder.Position3f( x, y, 0 );
  419. meshBuilder.Color4ubv( textColor );
  420. meshBuilder.TexCoord2f( 0, 0, 0 );
  421. meshBuilder.AdvanceVertexF<VTX_HAVEPOS | VTX_HAVECOLOR, 1>();
  422. meshBuilder.Position3f( x + wide, y, 0 );
  423. meshBuilder.Color4ubv( textColor );
  424. meshBuilder.TexCoord2f( 0, 1, 0 );
  425. meshBuilder.AdvanceVertexF<VTX_HAVEPOS | VTX_HAVECOLOR, 1>();
  426. meshBuilder.Position3f( x + wide, y + tall, 0 );
  427. meshBuilder.Color4ubv( textColor );
  428. meshBuilder.TexCoord2f( 0, 1, 1 );
  429. meshBuilder.AdvanceVertexF<VTX_HAVEPOS | VTX_HAVECOLOR, 1>();
  430. meshBuilder.Position3f( x, y + tall, 0 );
  431. meshBuilder.Color4ubv( textColor );
  432. meshBuilder.TexCoord2f( 0, 0, 1 );
  433. meshBuilder.AdvanceVertexF<VTX_HAVEPOS | VTX_HAVECOLOR, 1>();
  434. meshBuilder.End();
  435. pMesh->Draw();
  436. }
  437. //-----------------------------------------------------------------------------
  438. // Purpose:
  439. //-----------------------------------------------------------------------------
  440. void CGameUISystemSurface::DrawFontTexture( IRenderContext *pRenderContext, int textureId, int xPos, int yPos )
  441. {
  442. HRenderTexture fontTextureHandle = g_pGameUISystemSurface->GetTextureHandle( textureId );
  443. pRenderContext->BindTexture( 0, fontTextureHandle );
  444. VertexColor_t textColor( 255, 255, 255, 255);
  445. int x = xPos;
  446. int y = yPos;
  447. int wide;
  448. int tall;
  449. TextureDictionary()->GetTextureSize( textureId, wide, tall );
  450. CDynamicVertexData< GameUIVertex_t > vb( pRenderContext, 4, "gamelayer2", "game_controls2" );
  451. vb.Lock();
  452. vb->m_vecPosition.Init( x, y, 0.0f );
  453. vb->m_color = textColor;
  454. vb->m_vecTexCoord.Init( 0, 0 );
  455. vb.AdvanceVertex();
  456. vb->m_vecPosition.Init( x + wide, y, 0.0f );
  457. vb->m_color = textColor;
  458. vb->m_vecTexCoord.Init( 1, 0 );
  459. vb.AdvanceVertex();
  460. vb->m_vecPosition.Init( x+ wide, y + tall, 0.0f );
  461. vb->m_color = textColor;
  462. vb->m_vecTexCoord.Init( 1, 1 );
  463. vb.AdvanceVertex();
  464. vb->m_vecPosition.Init( x, y + tall, 0.0f );
  465. vb->m_color = textColor;
  466. vb->m_vecTexCoord.Init( 0, 1 );
  467. vb.AdvanceVertex();
  468. vb.Unlock();
  469. vb.Bind( 0, 0 );
  470. CDynamicIndexData< uint16 > ib( pRenderContext, 6, "gamelayer", "game_controls" );
  471. ib.Lock();
  472. ib.Index( 0 );
  473. ib.Index( 1 );
  474. ib.Index( 2 );
  475. ib.Index( 0);
  476. ib.Index( 2 );
  477. ib.Index( 3 );
  478. ib.Unlock();
  479. ib.Bind( 0 );
  480. pRenderContext->DrawIndexed( RENDER_PRIM_TRIANGLES, 0, 6 );
  481. }
  482. //-----------------------------------------------------------------------------
  483. // Purpose: Gets the material and texture coords for this char.
  484. // Set up info.drawtype and set the font first.
  485. //-----------------------------------------------------------------------------
  486. IMaterial *CGameUISystemSurface::GetTextureForChar( FontCharRenderInfo &info, float **texCoords )
  487. {
  488. bool bSuccess = g_FontTextureCache.GetTextureForChar( info.currentFont, info.drawType, info.ch, &info.textureId, texCoords );
  489. if ( !bSuccess )
  490. {
  491. return NULL;
  492. }
  493. return TextureDictionary()->GetTextureMaterial( info.textureId );
  494. }
  495. //-----------------------------------------------------------------------------
  496. // Purpose: Gets the material and texture coords for this char.
  497. // Set up info.drawtype and set the font first.
  498. // This call doesnt use the static in the font cache to store the texcoords.
  499. //-----------------------------------------------------------------------------
  500. IMaterial *CGameUISystemSurface::GetTextureAndCoordsForChar( FontCharRenderInfo &info, float *texCoords )
  501. {
  502. bool bSuccess = g_FontTextureCache.GetTextureAndCoordsForChar( info.currentFont, info.drawType, info.ch, &info.textureId, texCoords );
  503. if ( !bSuccess )
  504. {
  505. return NULL;
  506. }
  507. return TextureDictionary()->GetTextureMaterial( info.textureId );
  508. }
  509. //-----------------------------------------------------------------------------
  510. // Purpose:
  511. //-----------------------------------------------------------------------------
  512. bool CGameUISystemSurface::GetUnicodeCharRenderPositions( FontCharRenderInfo& info, Vector2D *pPositions )
  513. {
  514. info.valid = false;
  515. if ( !info.currentFont )
  516. {
  517. return info.valid;
  518. }
  519. info.valid = true;
  520. info.fontTall = GetFontTall( info.currentFont );
  521. GetCharABCwide( info.currentFont, info.ch, info.abcA, info.abcB, info.abcC );
  522. bool bUnderlined = FontManager().GetFontUnderlined( info.currentFont );
  523. // Do prestep before generating texture coordinates, etc.
  524. if ( !bUnderlined )
  525. {
  526. info.x += info.abcA;
  527. }
  528. // get the character texture from the cache
  529. info.textureId = 0;
  530. float *texCoords = NULL;
  531. if ( !g_FontTextureCache.GetTextureForChar( info.currentFont, info.drawType, info.ch, &info.textureId, &texCoords ) )
  532. {
  533. info.valid = false;
  534. return info.valid;
  535. }
  536. int fontWide = info.abcB;
  537. if ( bUnderlined )
  538. {
  539. fontWide += ( info.abcA + info.abcC );
  540. info.x-= info.abcA;
  541. }
  542. pPositions[0].x = info.x;
  543. pPositions[0].y = info.y;
  544. pPositions[1].x = info.x + fontWide;
  545. pPositions[1].y = info.y;
  546. pPositions[2].x = info.x + fontWide;
  547. pPositions[2].y = info.y + info.fontTall;
  548. pPositions[3].x = info.x;
  549. pPositions[3].y = info.y + info.fontTall;
  550. return info.valid;
  551. }
  552. //-----------------------------------------------------------------------------
  553. // Purpose: adds glyphs to a font created by CreateFont()
  554. //-----------------------------------------------------------------------------
  555. bool CGameUISystemSurface::SetBitmapFontGlyphSet( FontHandle_t font, const char *windowsFontName, float scalex, float scaley, int flags)
  556. {
  557. return FontManager().SetBitmapFontGlyphSet( font, windowsFontName, scalex, scaley, flags );
  558. }
  559. //-----------------------------------------------------------------------------
  560. // Purpose: creates a new empty font
  561. //-----------------------------------------------------------------------------
  562. FontHandle_t CGameUISystemSurface::CreateFont()
  563. {
  564. return FontManager().CreateFont();
  565. }
  566. //-----------------------------------------------------------------------------
  567. // Purpose: adds glyphs to a font created by CreateFont()
  568. //-----------------------------------------------------------------------------
  569. bool CGameUISystemSurface::SetFontGlyphSet( FontHandle_t font, const char *windowsFontName, int tall, int weight, int blur, int scanlines, int flags, int nRangeMin, int nRangeMax)
  570. {
  571. return FontManager().SetFontGlyphSet( font, windowsFontName, tall, weight, blur, scanlines,
  572. flags, nRangeMin, nRangeMax );
  573. }
  574. //-----------------------------------------------------------------------------
  575. // Purpose: returns the max height of a font
  576. //-----------------------------------------------------------------------------
  577. int CGameUISystemSurface::GetFontTall( FontHandle_t font )
  578. {
  579. return FontManager().GetFontTall( font );
  580. }
  581. //-----------------------------------------------------------------------------
  582. // Purpose: returns the abc widths of a single character
  583. // This is used by text classes to handle kerning.
  584. //-----------------------------------------------------------------------------
  585. void CGameUISystemSurface::GetCharABCwide( FontHandle_t font, int ch, int &a, int &b, int &c )
  586. {
  587. FontManager().GetCharABCwide( font, ch, a, b, c );
  588. }
  589. //-----------------------------------------------------------------------------
  590. // Purpose: returns the pixel width of a single character
  591. //-----------------------------------------------------------------------------
  592. int CGameUISystemSurface::GetCharacterWidth( FontHandle_t font, int ch )
  593. {
  594. return FontManager().GetCharacterWidth( font, ch );
  595. }
  596. //-----------------------------------------------------------------------------
  597. //
  598. //-----------------------------------------------------------------------------
  599. IMaterial *CGameUISystemSurface::GetMaterial( int textureId )
  600. {
  601. return TextureDictionary()->GetTextureMaterial( textureId );
  602. }
  603. //-----------------------------------------------------------------------------
  604. //
  605. //-----------------------------------------------------------------------------
  606. HRenderTexture CGameUISystemSurface::GetTextureHandle( int textureId )
  607. {
  608. return TextureDictionary()->GetTextureHandle( textureId );
  609. }
  610. //-----------------------------------------------------------------------------
  611. //
  612. //-----------------------------------------------------------------------------
  613. void CGameUISystemSurface::SetLanguage( const char *pLanguage )
  614. {
  615. FontManager().SetLanguage( pLanguage );
  616. }
  617. //-----------------------------------------------------------------------------
  618. //
  619. //-----------------------------------------------------------------------------
  620. const char *CGameUISystemSurface::GetLanguage()
  621. {
  622. return FontManager().GetLanguage();
  623. }