#include "GameFont.h"

GameFont::GameFont(void)
{
	m_font = NULL; m_d3dSprite = NULL;
}

GameFont::~GameFont(void)
{
	Destroy();
}

void GameFont::Create(GameGraphics &g, wstring fontname, int size)
{
	if(m_font != NULL) return;

	m_d3dSprite = g.m_d3dSprite;
	D3DXFONT_DESC desc = {0,};
	desc.CharSet = DEFAULT_CHARSET;
	desc.MipLevels = 1;
	memcpy(desc.FaceName, fontname.c_str(), wcslen(fontname.c_str()) * sizeof(wchar_t));
	desc.Height = size;

	D3DXCreateFontIndirect(g.m_d3dDevice, &desc, &m_font);
}

void GameFont::Destroy()
{
	SAFE_RELEASE(m_font);
	m_d3dSprite = NULL;
}

void GameFont::Draw(float x, float y, wstring text)
{
	m_d3dSprite->Begin(D3DXSPRITE_ALPHABLEND);
	RECT rect = {(int)x, (int)y, -1, -1};
	m_font->DrawText(m_d3dSprite, text.c_str(), wcslen(text.c_str()), &rect, DT_NOCLIP, 0xffffffff);
	m_d3dSprite->End();
}