Font.cpp
上传用户:whgydz
上传日期:2007-01-12
资源大小:2259k
文件大小:1k
源码类别:

其他书籍

开发平台:

HTML/CSS

  1. // Font.cpp: implementation of the CFont class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #include "Font.h"
  5. //////////////////////////////////////////////////////////////////////
  6. // Construction/Destruction
  7. //////////////////////////////////////////////////////////////////////
  8. CFont::CFont(LPDIRECT3DDEVICE8 pD3DDevice, LPSTR pFontFace, int nHeight, bool fBold, bool fItalic, bool fUnderlined)
  9. {
  10. HFONT hFont;
  11. m_pD3DDevice = pD3DDevice;
  12. int nWeight = FW_NORMAL;
  13. DWORD dwItalic = 0;
  14. DWORD dwUnderlined = 0;
  15. if(fBold)
  16. {
  17. nWeight = FW_BOLD;
  18. }
  19. if(fItalic)
  20. {
  21. dwItalic = 1;
  22. }
  23. if(fUnderlined)
  24. {
  25. dwUnderlined = 1;
  26. }
  27. hFont = CreateFont(nHeight, 0, 0, 0, nWeight, dwItalic, dwUnderlined, 0, ANSI_CHARSET, 0, 0, 0, 0, pFontFace);
  28. D3DXCreateFont(m_pD3DDevice, hFont, &m_pFont);
  29. LogInfo("<li>Font loaded OK");
  30. }
  31. CFont::~CFont()
  32. {
  33. SafeRelease(m_pFont);
  34. LogInfo("<li>Font destroyed OK");
  35. }
  36. void CFont::DrawText(LPSTR pText, int x, int y, D3DCOLOR rgbFontColour)
  37. {
  38. RECT Rect;
  39. Rect.left = x;
  40. Rect.top = y;
  41. Rect.right = 0;
  42. Rect.bottom = 0;
  43. m_pFont->Begin();
  44. m_pFont->DrawTextA(pText, -1, &Rect, DT_CALCRECT, 0); //Calculate the size of the rect needed
  45. m_pFont->DrawTextA(pText, -1, &Rect, DT_LEFT, rgbFontColour); //Draw the text
  46. m_pFont->End();
  47. }