#pragma once

#include "dllinterface.h"
#include "..\Utilities\list.h"
#include "..\Utilities\XString.h"
#include "devicestatemanager.h"
#include "dxtexture.h"
#include "..\Utilities\util.h"
#include "DXVector2.h"
#include "DXVector4.h"

class FontManager;

#define MAX_NUM_VERTICES 300  //50 Chars * 6

struct FONTVERTEX
{
	DXVector4 p;
	DWORD color;
	float tu,tv; 
};
#define D3DFVF_FONTVERTEX (D3DFVF_XYZRHW|D3DFVF_DIFFUSE|D3DFVF_TEX1)

struct DXFUNCTIONS_API FontParam
{
	XString m_Facename; 
	int m_Height;
	int m_Width;
	int m_Escapement;
	int m_Orientation;
	int m_Weight; //FW_NORMAL, FW_REGULAR, FW_BOLD
	unsigned m_Italic;
	unsigned m_Underline;
	unsigned m_StrikeOut;
	unsigned m_CharSet;
	unsigned m_OutPrecision;
	unsigned m_ClipPrecision;
	unsigned m_Quality;
	unsigned m_PitchAndFamily;
	unsigned m_Spacing;

	FontParam(void);
	bool operator ==(FontParam&fnt);
	HFONT Create(void);
};

class DXFUNCTIONS_API Font : public Ressource
{
	friend FontManager;
	friend ListElement<Font>;
	friend LList<Font>;

	FontManager*m_Manager;

	FontParam	m_Param;

	DXTexture *m_Texture;
	float	m_TexCoords[256-32][4];
    //LPDIRECT3DVERTEXBUFFER9 m_VertexBuffer; 

	HRESULT PaintAlphabet(HDC hDC);

	//bool m_Invalidated;

	void DrawAlphabetTex(void);

protected:

	Font(FontManager*manager,FontParam&fnt);
	~Font(void);

public:
	
	void DrawTest(void){Draw("Test",100,100,0xff15ff15);}
	void Draw(XString text,float x, float y,DWORD dwColor,float maxwidth = 1.0e33f);
	//void Restore(void);
    //void Invalidate(void);

	DXVector2 TextSize(const XString& Text, const float maxwidth = 1.e33f);
	FontParam* GetParam(void);
};
