www.pudn.com > GameEngine.rar > GameEngine_Font.cpp, change:2005-09-16,size:2587b


#include "..\GameEngine_Common.h" 
#include "GameEngine_Font.h" 
#include "..\GameEngine_SceneManager\GameEngine_SceneManager.h" 
#include "..\GameEngine_Texture\GameEngine_Texture.h" 
 
CGameEngine_Font::CGameEngine_Font(CGameEngine_SceneManager* pGameSceneManager){ 
	m_pGameSceneManager=pGameSceneManager;		 
	m_pFont=NULL; 
	m_pPanel=NULL; 
	m_pPanelTexture=NULL; 
} 
 
CGameEngine_Font::~CGameEngine_Font(){ 
	Closedown(); 
} 
 
bool CGameEngine_Font::CreateFont(TCHAR* FontName,int Width,int Height, 
							      int Weight,bool bBold,bool bItalic, 
							      bool bUnderline,bool bStrikeout){ 
	D3DXFONT_DESC d3dxFont; 
	//清空字体结构体 
	ZeroMemory(&d3dxFont,sizeof(d3dxFont)); 
	//设置字体属性 
	_tcscpy(d3dxFont.FaceName,FontName); 
	d3dxFont.Width=Width;   
	d3dxFont.Height=Height;  
	d3dxFont.Weight=Weight; 
	d3dxFont.Italic=bItalic; 
	d3dxFont.CharSet=DEFAULT_CHARSET; 
	if(FAILED(D3DXCreateFontIndirect(m_pGameSceneManager->GetDevice(),&d3dxFont,&m_pFont))){ 
		return false;	 
	} 
	return true; 
} 
 
 
void CGameEngine_Font::DrawText(TCHAR* Text,int PosX,int PosY, 
								int Width,int Height, 
								D3DCOLOR Color,DWORD Format){ 
	RECT rect; 
	rect.left=PosX; 
	rect.top=PosY; 
	rect.right=rect.left + Width; 
	rect.bottom=rect.top + Height; 
	m_pFont->DrawText(NULL,Text, -1, &rect, Format, Color); 
} 
 
bool CGameEngine_Font::CreatePanel(TCHAR* PanelFile){ 
	if(FAILED(D3DXCreateSprite(m_pGameSceneManager->GetDevice(),&m_pPanel))) 
		return false;  
	m_pPanelTexture=new CGameEngine_Texture(m_pGameSceneManager); 
	m_pPanelTexture->LoadTexture(PanelFile); 
	return true; 
} 
 
void CGameEngine_Font::DrawTextOnPanel(TCHAR* Text,int PosX,int PosY, 
					                   D3DCOLOR Color,DWORD Format){ 
	if(m_pPanel!=NULL && m_pPanelTexture!=NULL){ 
		//取得文字面板宽高 
		long Width,Height; 
		m_pPanelTexture->GetPicWidth(Width); 
		m_pPanelTexture->GetPicHeight(Height); 
		//文字面板区域 
		RECT rect; 
		rect.left=PosX; 
		rect.top=PosY; 
		rect.right=rect.left + Width; 
		rect.bottom=rect.top + Height; 
		//渲染面板和文字 
		m_pPanel->Begin(D3DXSPRITE_ALPHABLEND); 
		m_pPanel->Draw(m_pPanelTexture->GetTexture(),NULL,NULL, 
			           new D3DXVECTOR3((float)PosX,(float)PosY,0.0f), 
					   0xffffffff); 
		m_pPanel->Flush();  //确信已送出面板数据 
		m_pFont->DrawText(m_pPanel,Text, -1, &rect, Format, Color); 
		m_pPanel->End(); 
	} 
} 
 
void CGameEngine_Font::Closedown(){ 
	m_pGameSceneManager=NULL; 
	SafeRelease(m_pFont); 
	SafeRelease(m_pPanel); 
	if(!m_pPanelTexture) 
		m_pPanelTexture->Closedown(); 
}