Advertisement
keybode

FontManager.cpp

May 21st, 2014
351
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.84 KB | None | 0 0
  1. #include "FontManager.h"
  2. #include "WinCustom.h"
  3.  
  4. CFontManager gFontManager;
  5.  
  6. CFontManager::CFontManager ( void )
  7. {
  8.     m_font.clear ();
  9. }
  10.  
  11. CFontManager::~CFontManager ( void )
  12. {
  13.     m_font.clear ();
  14. }
  15.  
  16. void CFontManager::AddFont ( const char* fontName, int fontSize )
  17. {
  18.     renderer_font_t fontSlot;
  19.  
  20.     strncpy_s ( fontSlot.m_fontName, fontName, 128 );
  21.  
  22.     fontSlot.m_fontSize = fontSize;
  23.     fontSlot.m_fontPointer = 0;
  24.  
  25.     m_font.push_back ( fontSlot );
  26. }
  27.  
  28. void CFontManager::Update ( IDirect3DDevice9* pDevice )
  29. {
  30.     if ( !m_font.empty () )
  31.     {
  32.         for ( int i = 0; i < m_font.size (); i++ )
  33.         {
  34.             if ( !m_font.at ( i ).m_fontPointer )
  35.             {
  36.                 if ( FAILED(D3DXCreateFontA ( pDevice, m_font.at ( i ).m_fontSize, 0, 0, 0, 0, DEFAULT_CHARSET, OUT_CHARACTER_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH, m_font.at ( i ).m_fontName, &m_font.at ( i ).m_fontPointer )) )
  37.                 {
  38.                     DbgPrint ( "Can't create font %s with size of %i!", m_font.at ( i ).m_fontName, m_font.at ( i ).m_fontSize );
  39.                 }
  40.             }
  41.         }
  42.     }
  43. }
  44.  
  45. void CFontManager::Release ( void )
  46. {
  47.     if ( !m_font.empty () )
  48.     {
  49.         for ( int i = 0; i < m_font.size (); i++ )
  50.         {
  51.             if ( m_font.at ( i ).m_fontPointer )
  52.             {
  53.                 m_font.at ( i ).m_fontPointer->OnLostDevice ();
  54.                 m_font.at ( i ).m_fontPointer->OnResetDevice ();
  55.             }
  56.         }
  57.     }
  58. }
  59.  
  60. ID3DXFont* CFontManager::GetFont ( const char* fontName )
  61. {
  62.     if ( !m_font.empty () )
  63.     {
  64.         for ( int i = 0; i < m_font.size (); i++ )
  65.         {
  66.             if ( !strcmp ( m_font.at ( i ).m_fontName, fontName ) )
  67.             {
  68.                 return m_font.at ( i ).m_fontPointer;
  69.             }
  70.         }
  71.     }
  72.  
  73.     return 0;
  74. }
  75.  
  76. int CFontManager::GetFontSize ( const char* fontName )
  77. {
  78.     if ( !m_font.empty () )
  79.     {
  80.         for ( int i = 0; i < m_font.size (); i++ )
  81.         {
  82.             if ( !strcmp ( m_font.at ( i ).m_fontName, fontName ) )
  83.             {
  84.                 return m_font.at ( i ).m_fontSize;
  85.             }
  86.         }
  87.     }
  88.  
  89.     return 0;
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement