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

*/

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

#ifdef SGX_PLATFORM_NDS
tUINT32	sgxGUIButtonParams::DEFAULT_WIDTH = 160;
tUINT32	sgxGUIButtonParams::DEFAULT_HEIGHT = 32;
#else
tUINT32	sgxGUIButtonParams::DEFAULT_WIDTH = 240;
tUINT32	sgxGUIButtonParams::DEFAULT_HEIGHT = 48;
#endif

sgxGUIButtonParams::sgxGUIButtonParams(const sgxString &text, const tINT32 widthPixels) {
	m_Width = widthPixels == -1 ? CSGXGUI::get()->getCurrentSkin()->getDefaultButtonWidth(): widthPixels; 
	m_Height= CSGXGUI::get()->getCurrentSkin()->getDefaultButtonHeight();
	m_Text = text;
}

sgxGUIButton::sgxGUIButton(const tINT32 x, const tINT32 y, const sgxGUIButtonParams &params) :
	sgxWidget(x,y, CGUIDesignScreen::widgetButton), 
	m_SetupParams(params)
{
	m_pSkinParams = CSGXGUI::get()->getCurrentSkin()->getSkinnedButton();
	m_pSkinParams->text = m_SetupParams.m_Text;
}

void 
sgxGUIButton::setText(const sgxString &s) {
	m_pSkinParams->text = m_SetupParams.m_Text = s;	
}

void	
sgxGUIButton::getArea(sgxRect2i &rc) const {
	rc.left = m_X;
	rc.top = m_Y;
	rc.right = m_X+m_SetupParams.m_Width;
	rc.bottom = m_Y+m_SetupParams.m_Height;
}

tBOOL sgxGUIButton::draw(CSGXDrawSurface *pSurface, const tINT32 offsetX, const tINT32 offsetY) const {
	m_pSkinParams->topleft.x = m_X+offsetX;
	m_pSkinParams->topleft.y = m_Y+offsetY;
	m_pSkinParams->bottomright.x = m_pSkinParams->topleft.x+m_SetupParams.m_Width;
	m_pSkinParams->bottomright.y = m_pSkinParams->topleft.y+m_SetupParams.m_Height;

	m_pSkinParams->focused = isFocused();
	m_pSkinParams->enabled = m_bEnabled;
	m_pSkinParams->selected = m_DirectedState;
	m_pSkinParams->cursorOver = m_isOver || isFocused();

	if (m_iFlags & eLifeless) {
		m_pSkinParams->focused = m_pSkinParams->selected = m_pSkinParams->cursorOver = FALSE;
		m_pSkinParams->enabled = TRUE;
	}
	
	m_pSkinParams->draw(pSurface);

	return sgxWidget::draw(pSurface, m_pSkinParams->topleft.x, m_pSkinParams->topleft.y);
}


	
