font.cpp

来自「对游戏编程感兴趣的 朋友可以 下载下来看看 对DX讲解的很很详细」· C++ 代码 · 共 64 行

CPP
64
字号
// Font.cpp: implementation of the CFont class.
//
//////////////////////////////////////////////////////////////////////

#include "Font.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CFont::CFont(LPDIRECT3DDEVICE8 pD3DDevice, LPSTR pFontFace, int nHeight, bool fBold, bool fItalic, bool fUnderlined)
{
	HFONT hFont;

	m_pD3DDevice = pD3DDevice;
	
	int nWeight = FW_NORMAL;
	DWORD dwItalic = 0;
	DWORD dwUnderlined = 0;

	if(fBold)
	{
		nWeight = FW_BOLD;
	}

	if(fItalic)
	{
		dwItalic = 1;
	}

	if(fUnderlined)
	{
		dwUnderlined = 1;
	}

	hFont = CreateFont(nHeight, 0, 0, 0, nWeight, dwItalic, dwUnderlined, 0, ANSI_CHARSET, 0, 0, 0, 0, pFontFace);
	
	D3DXCreateFont(m_pD3DDevice, hFont, &m_pFont);

	LogInfo("<li>Font loaded OK");
}

CFont::~CFont()
{
	SafeRelease(m_pFont);

	LogInfo("<li>Font destroyed OK");
}

void CFont::DrawText(LPSTR pText, int x, int y, D3DCOLOR rgbFontColour)
{
	RECT Rect;

	Rect.left = x;
	Rect.top = y;
	Rect.right = 0;
	Rect.bottom = 0;

	m_pFont->Begin();
	m_pFont->DrawTextA(pText, -1, &Rect, DT_CALCRECT, 0);			//Calculate the size of the rect needed
	m_pFont->DrawTextA(pText, -1, &Rect, DT_LEFT, rgbFontColour);	//Draw the text
	m_pFont->End();
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?