/** SGX

The   sss    gggg x   x   
     s      g      x x    Engine
      sss   g  gg   x
         s  g   g  x x          Copyright 1995-2008.
     ssss    gggg x   x         Steven Goodwin. All Rights Reserved.
    
This version has been released under the GNU Public License v2.0.

Please see the license files for details.

File: include/sgx/graphics/gfx_font_manager.hpp

*/

#ifndef SGX_GRAPHICS_FONT_MANAGER_HPP
#define SGX_GRAPHICS_FONT_MANAGER_HPP	1

class CSGXFontFormatting {
public:
	typedef enum {
		// Horizontal formatting
		fmtLeftJustify,
		fmtCentreJustify,
		fmtRightJustify,
		// Vertical formatting
		fmtTopAlignment,
		fmtMiddleAlignment,
		fmtMiddleXHeightAlignment,
		fmtOnBaselineAlignment,
		fmtBottomAlignment,
	} tJustify;

	// These change the meaning of the 'position' parameter. 
	// e.g. 'centre' means that pos is the centre of the text you're displaying
	tJustify	m_iHorizontal;
	tJustify	m_iVertical;

	tBOOL		m_bForceToRenderArea;
	sgxRect2i	m_RenderArea;

	CSGXFontFormatting(const tJustify horizontal = fmtLeftJustify, const tJustify vertical = fmtTopAlignment) {
		m_iHorizontal = horizontal;
		m_iVertical = vertical;
		m_bForceToRenderArea = FALSE;
	}

	void setRenderArea(const sgxRect2i &rc) {
		m_RenderArea = rc;
		m_bForceToRenderArea = TRUE;
	}
};

class CSGXFont {
public:
	CSGXFont();

	virtual tUINT32 getCharacterSpacing() const;
	virtual tUINT32 getLineSpacing() const;
	virtual tUINT32 setCharacterSpacing(const tUINT32 spacing);
	virtual tUINT32 setLineSpacing(const tUINT32 spacing);

	virtual tUINT32 getHeight() const;

	virtual tUINT32 getBaseline() const;
	virtual tUINT32 getXHeight() const;
	virtual tUINT32 getAscender() const;
	virtual tUINT32 getCharacterWidth(const tCHAR c) const;
	virtual tUINT32 getStringWidth(const tCHAR *pStr) const;
	
	virtual void draw(CSGXDrawSurface *pSurface, const tCHAR c, const tPOINT x, const tPOINT y) const;
	virtual void draw(CSGXDrawSurface *pSurface, const tCHAR *pStr, const tPOINT x, const tPOINT y) const;
	virtual void draw(CSGXDrawSurface *pSurface, const tCHAR *pStr, const tPOINT x, const tPOINT y, const CSGXFontFormatting &formatting) const;

protected:
	tUINT32	m_LineSpacing;
	tUINT32	m_CharacterSpacing;
};

class CSGXFontParams {
public:
	typedef enum {
		tDefaultFontType = 0,
		tBitmapFontType = tDefaultFontType,
		tOutlineFontType,
		tExtrudedFontType,
		tPolygonFontType,
		tPixmapFontType,
		tTextureFontType,
	} tFontTypes;

	tMEM_SIZE	m_iTypeSize;
	tMEM_SIZE	m_iTypeDepth;		// If extruded fonts are supported
	tFontTypes	m_iFontType;

	sgxString	m_CharacterOrder;	// if partial fonts are used, and not specified by the file format. =ABC0123
	
	CSGXFontParams();
	CSGXFontParams(tUINT32 defaultSize);
	CSGXFontParams(tUINT32 defaultSize, tFontTypes type);
};

class CSGXFontManager
{
public:
	typedef sgxMap<const sgxString, CSGXFont *> RegisteredFontMap;

	static CSGXFontManager *get();
	static CSGXFontManager *create();

	CSGXFontManager();
	virtual ~CSGXFontManager();
	virtual void			initialize();
	virtual CSGXFont *		registerFont(const sgxString &name, const sgxString &filename, const CSGXFontParams &params=CSGXFontParams());
	virtual CSGXFont *		getFont(const sgxString &name);
	virtual void			setCurrentFont(const sgxString &name);
	virtual void			setCurrentFont(const CSGXFont *pFont);
	virtual const CSGXFont *getCurrentFont() const;

protected:

	static CSGXFontManager	*m_pSingleton;

	RegisteredFontMap		m_Fonts;

	const CSGXFont			*m_CurrentFont;
};

#endif /* SGX_GRAPHICS_FONT_MANAGER_HPP */
