Advertisement
Guest User

Untitled

a guest
Feb 24th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.93 KB | None | 0 0
  1.     void CRender::Text( int x , int y , bool center , bool shadow , int font, Color color , const char* format , ... )
  2.     {
  3.         if ( m_pStateBlockText )
  4.             m_pStateBlockText->Capture();
  5.  
  6.         m_pDevice->SetFVF( D3DFVF_CUSTOM_TEXT );
  7.  
  8.         m_pDevice->SetRenderState( D3DRS_LIGHTING , false );
  9.         m_pDevice->SetRenderState( D3DRS_ALPHABLENDENABLE , true );
  10.         m_pDevice->SetRenderState( D3DRS_ALPHATESTENABLE , false );
  11.         m_pDevice->SetRenderState( D3DRS_CULLMODE , D3DCULL_NONE );
  12.         m_pDevice->SetRenderState( D3DRS_SRCBLEND , D3DBLEND_SRCALPHA );
  13.         m_pDevice->SetRenderState( D3DRS_DESTBLEND , D3DBLEND_INVSRCALPHA );
  14.  
  15.         char Buffer[128] = { '\0' };
  16.         va_list va_alist;
  17.         va_start( va_alist , format );
  18.         vsprintf_s( Buffer , format , va_alist );
  19.         va_end( va_alist );
  20.  
  21.         BSTR text = CSX::Utils::ConvertStringToBSTR_UTF8( Buffer );
  22.  
  23.         DWORD dxTextColor = D3DCOLOR_XRGB( color.r() , color.g() , color.b() );
  24.  
  25.         auto drawShadow = [&]( RECT rect )
  26.         {
  27.             rect.left++;
  28.             m_pFont[font]->DrawTextW( NULL , text , -1 , &rect , DT_TOP | DT_LEFT | DT_NOCLIP , 0xFF000000 );
  29.             rect.top++;
  30.             m_pFont[font]->DrawTextW( NULL , text , -1 , &rect , DT_TOP | DT_LEFT | DT_NOCLIP , 0xFF000000 );
  31.         };
  32.  
  33.         if ( center )
  34.         {
  35.             RECT rec = { 0,0,0,0 };
  36.  
  37.             m_pFont[font]->DrawTextW( NULL , text , -1 , &rec , DT_CALCRECT | DT_NOCLIP , dxTextColor );
  38.  
  39.             rec =
  40.             {
  41.                 static_cast<LONG>( x ) - rec.right / 2,
  42.                 static_cast<LONG>( y ),
  43.                 0,
  44.                 0
  45.             };
  46.  
  47.             if ( shadow )
  48.                 drawShadow( rec );
  49.  
  50.             m_pFont[font]->DrawTextW( NULL , text , -1 , &rec , DT_TOP | DT_LEFT | DT_NOCLIP , dxTextColor );
  51.         }
  52.         else
  53.         {
  54.             RECT rec =
  55.             {
  56.                 static_cast<LONG>( x ),
  57.                 static_cast<LONG>( y ),
  58.                 0,
  59.                 0
  60.             };
  61.  
  62.             if ( shadow )
  63.                 drawShadow( rec );
  64.  
  65.             m_pFont[font]->DrawTextW( NULL , text , -1 , &rec , DT_TOP | DT_LEFT | DT_NOCLIP , dxTextColor );
  66.         }
  67.  
  68.         if ( m_pStateBlockText )
  69.             m_pStateBlockText->Apply();
  70.  
  71.         SysFreeString( text );
  72.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement