/** SGX

The   sss    gggg x   x   
     s      g      x x    Engine
      sss   g  gg   x
         s  g   g  x x          Copyright 1995-2009.
     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: sgx/src/sgx/graphics/gfx_font_manager.cpp

*/

#include "sgx/core/core.hpp"
#include "sgx/graphics/graphics.hpp"

CSGXFontManager *CSGXFontManager::m_pSingleton = NULL;

CSGXFontManager *CSGXFontManager::create()
{
	m_pSingleton = new CSGXFontManager;
	if (m_pSingleton) {
		m_pSingleton->initialize();
	}
	return m_pSingleton;
}

CSGXFontManager *CSGXFontManager::get()
{
	if (!m_pSingleton) {
		return create();
	}
	return m_pSingleton;
}

CSGXFontManager::CSGXFontManager()
{
	m_CurrentFont = NULL;
}

CSGXFontManager::~CSGXFontManager()
{
    RegisteredFontMap::iterator it = m_Fonts.begin();

	for(;it!=m_Fonts.end();++it) {
		delete (*it).second;
	}
}

void
CSGXFontManager::initialize()
{
}

CSGXFont *		
CSGXFontManager::registerFont(const sgxString &name, CSGXFont *pFont) {
	m_Fonts.insert(RegisteredFontMap::value_type(name, pFont));
	return pFont;
}

CSGXFont *	
CSGXFontManager::registerFont(const sgxString &name, const sgxString &filename, const CSGXFontParams &params)
{
	switch(params.m_iFontType) {
	case	CSGXFontParams::eRegionedTextureFontType:
		{
			CSGXRegionedTextureFont *pFont = new CSGXRegionedTextureFont(filename);
			return registerFont(name, pFont);
		}
	}
			
	return NULL;
}


CSGXFont *		
CSGXFontManager::getFont(const sgxString &name)
{
    RegisteredFontMap::iterator it = m_Fonts.find(name);

    if (it != m_Fonts.end()) {
        return ((*it).second);
    }
	return NULL;
}

void		
CSGXFontManager::setCurrentFont(const sgxString &name)
{
	setCurrentFont(getFont(name));
}

void		
CSGXFontManager::setCurrentFont(const CSGXFont *pFont)
{
	m_CurrentFont = pFont;
}

const CSGXFont *	
CSGXFontManager::getCurrentFont() const
{
	return m_CurrentFont;
}
