📄 directxfont.cpp
字号:
// DirectXFont.cpp
//
#include "Common.h"
#include "DirectXFont.h"
using namespace std;
using namespace Resources;
// DirectXFont - Construction and deconstruction.
DirectXFont::DirectXFont()
: m_pFont(NULL)
{
}
DirectXFont::DirectXFont(LPCSTR lpszFontName,
INT nHeight,
UINT nWidth,
bool bBold,
bool bItalic,
UINT nMipLevels,
LPCSTR lpszTypeFace)
: m_pFont(NULL)
{
// Create font from specified paramaters.
if(FAILED(SetFont(lpszFontName, nHeight, nWidth, bBold,
bItalic, nMipLevels, lpszTypeFace)))
{
// Generate exception and then throw it.
ResException e = ResException::UnableToCreate EXTRA_DEBUGINFO;
string szExtraInfo = "DirectXFont - ";
szExtraInfo += lpszFontName;
e.SetExtraInfo(szExtraInfo.c_str());
throw e;
}
}
DirectXFont::~DirectXFont()
{
}
HRESULT DirectXFont::SetFont(LPCSTR lpszFontName,
INT nHeight,
UINT nWidth,
bool bBold,
bool bItalic,
UINT nMipLevels,
LPCSTR lpszTypeFace)
{
// Destroy any existing font.
Destroy();
// Attempt to create font.
HRESULT hResult = D3DXCreateFont(ResourceManager::GetActiveDevice(),
nHeight, nWidth, bBold == TRUE ? 10 : 0, nMipLevels, bItalic,
NULL, NULL, NULL, NULL, lpszTypeFace, &m_pFont);
if(FAILED(hResult)) return hResult;
// If the font was not created then return with error.
if(m_pFont == NULL)
return E_FAIL;
SetFilePath(lpszFontName);
return NOERROR;
}
void DirectXFont::CleanUp()
{
// Free font from memory, if any.
if(m_pFont != NULL)
{
m_pFont->Release();
m_pFont = NULL;
}
}
// DirectXFont - Functions which must be overriden.
DWORD DirectXFont::GetUniqueID() const
{
return DIRECTX_FONT;
}
// DirectXFont - Functions which can be overriden.
void DirectXFont::OnDestroy()
{
// Clean up texture object.
CleanUp();
}
// DirectXFont - Rendering.
void DirectXFont::DrawText(LPD3DXSPRITE pSprite,
LPCSTR lpszString,
int nLength,
RECT& rtRectOut,
DWORD dwFormat,
D3DCOLOR rgbColour)
{
// Draw text to sprite specified.
m_pFont->DrawText(pSprite, lpszString, nLength, &rtRectOut,
dwFormat, rgbColour);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -