/** 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/gui/static_text.cpp

*/

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

sgxGUIStaticTextParams::sgxGUIStaticTextParams(const sgxString &text, const sgxColorRGBA color) { 
	m_Text = text;
	m_Color = color;
}
	
sgxGUIStaticText::sgxGUIStaticText(const tINT32 x, const tINT32 y, CGUIDesign::tJustify jx, CGUIDesign::tJustify jy, const sgxGUIStaticTextParams &params) :
	sgxWidget(x,y,CGUIDesignScreen::widgetText), 
	m_BaseX(x), m_BaseY(y),
	m_JustifyX(jx),
	m_JustifyY(jy),
	m_SetupParams(params)
{
	m_Text = m_SetupParams.m_Text;
}

void	
sgxGUIStaticText::getArea(sgxRect2i &rc) const {
	rc.left = m_X;
	rc.top = m_Y;
	rc.right = m_X;
	rc.bottom = m_Y;
	rc.right += CSGXFontManager::get()->getCurrentFont()->getStringWidth((const tCHAR *)m_SetupParams.m_Text.c_str());
	rc.bottom += CSGXFontManager::get()->getCurrentFont()->getHeight();
}

void 
sgxGUIStaticText::setText(const sgxString &s) {
	m_Text = s;

}

tBOOL sgxGUIStaticText::draw(CSGXDrawSurface *pSurface, const tINT32 offsetX, const tINT32 offsetY) const {
	tUINT32 width = pSurface->getWidth();
	tUINT32 height = pSurface->getHeight();

	CSGXFontFormatting fmt((CSGXFontFormatting::tJustify)m_JustifyX, (CSGXFontFormatting::tJustify)m_JustifyY);
	fmt.setRenderArea(sgxRect2i(width/6,m_BaseY,(5*width)/6,height));

	pSurface->setFontColor(m_SetupParams.m_Color);
	pSurface->drawText(m_Text.c_str(), m_BaseX+offsetX, m_BaseY+offsetY, fmt);
	
	return sgxWidget::draw(pSurface, m_X + offsetX, m_Y + offsetY);
}
