📄 mcfonts.cpp
字号:
#include "MCFonts.h"
CBaseFonts::CBaseFonts()
{
}
CBaseFonts::~CBaseFonts()
{
vector<CBaseFonts *>::iterator iter;
for(iter = g_pApp->m_listFont.begin() ; iter != g_pApp->m_listFont.end() ; ++iter)
{
CBaseFonts * pFont = (CBaseFonts *)*iter;
if(this == pFont)
{
if(m_pFonts)
SAFE_RELEASE(m_pFonts);
g_pApp->m_listFont.erase(iter);
return;
}
}
}
HRESULT CBaseFonts::CreateFont()
{
g_pApp->m_listFont.push_back(this);
return S_OK;
}
HRESULT CBaseFonts::Invalidate()
{
if(m_pFonts)
m_pFonts->OnLostDevice();
return S_OK;
}
HRESULT CBaseFonts::Restore()
{
if(m_pFonts)
m_pFonts->OnResetDevice();
return S_OK;
}
CMcFonts::CMcFonts()
{
m_pFonts = NULL;
m_dwColor = D3DCOLOR_ARGB(255,0,0,0);
}
CMcFonts::~CMcFonts()
{
Release();
}
HRESULT CMcFonts::CreateMCFont(LPDIRECT3DDEVICE9 m_pDevice, UINT Height, UINT Width, bool Italic, LPCSTR pFaceName)
{
HRESULT hr;
CreateFont();
if( FAILED( hr = D3DXCreateFont( m_pDevice, Height, Width, FW_NORMAL, 0, Italic, DEFAULT_CHARSET,
OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE,
pFaceName, &m_pFonts ) ) )
{
switch(hr)
{
case D3DERR_INVALIDCALL:
{
int a=0;
}
break;
case E_OUTOFMEMORY:
{
int b=0;
}
break;
}
OutputDebugString("\n迄飘 积己 角菩");
return hr;
}
int cd = 0;
return S_OK;
}
void CMcFonts::Release()
{
if(m_pFonts)
SAFE_RELEASE(m_pFonts);
}
void CMcFonts::DrawText(LPCSTR pString, int iX, int iY, int iWidth, int iHeight, DWORD Format, DWORD color)
{
RECT rect;
rect.left = iX;
rect.top = iY;
if(iWidth == 0)
rect.right = g_pApp->GetScreenWidth();
else
rect.right = iX + iWidth;
if(iHeight == 0)
rect.bottom = g_pApp->GetScreenHeight();
else
rect.bottom = iY + iHeight;
if(color == D3DCOLOR_ARGB(255,0,0,0))
color = m_dwColor;
m_pFonts->DrawTextA(NULL, pString, -1, &rect, Format, color);
}
void CMcFonts::DrawText_Bold(LPCSTR pString, int iX, int iY, int iWidth, int iHeight, DWORD Format, DWORD color)
{
static char szMsg[512] ={NULL,};
strcpy(&szMsg[0],pString);
DrawText(&szMsg[0], iX, iY, iWidth, iHeight, Format, color);
DrawText(&szMsg[0], iX+1, iY, iWidth, iHeight, Format, color);
}
void CMcFonts::DrawText_Shadow(LPCSTR pString, int iX, int iY, int iWidth, int iHeight, DWORD Format, DWORD color, DWORD ShadowColor)
{
static char szMsg[512] ={NULL,};
strcpy(&szMsg[0],pString);
DrawText(&szMsg[0], iX+1, iY+1, iWidth, iHeight, Format, ShadowColor);
DrawText(&szMsg[0], iX, iY, iWidth, iHeight, Format, color);
}
void CMcFonts::DrawTextEx(DWORD nX, DWORD nY,char *strFormat, ...)
{
static char string[512]={NULL,};
va_list ap;
va_start(ap,strFormat); // 颇扼皋磐狼 矫累困摹甫 掘绰促.
vsprintf(&string[0], strFormat, ap); // 器杆俊 措茄 免仿阑 茄促.
va_end(ap); // 场阑 舅赴促.
CMcFonts::DrawText(&string[0],nX,nY,0,0,DT_LEFT,m_dwColor);
}
void CMcFonts::DrawTextEx(DWORD nX, DWORD nY,int iWidth, DWORD Format, DWORD dwColor, char *strFormat, ...)
{
static char string[512]={NULL,};
va_list ap;
va_start(ap,strFormat); // 颇扼皋磐狼 矫累困摹甫 掘绰促.
vsprintf(&string[0], strFormat, ap); // 器杆俊 措茄 免仿阑 茄促.
va_end(ap); // 场阑 舅赴促.
this->DrawText(&string[0],nX,nY,iWidth,0,Format,dwColor);
}
void CMcFonts::DrawTextEx_Shadow(DWORD nX, DWORD nY,int iWidth, DWORD Format, DWORD dwColor, DWORD shadowcolor, char *strFormat, ...)
{
static char string[512]={NULL,};
va_list ap;
va_start(ap,strFormat); // 颇扼皋磐狼 矫累困摹甫 掘绰促.
vsprintf(&string[0], strFormat, ap); // 器杆俊 措茄 免仿阑 茄促.
va_end(ap); // 场阑 舅赴促.
this->DrawText_Shadow(&string[0],nX,nY,iWidth,0,Format,dwColor,shadowcolor);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -