/** 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: 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 tUINT32 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(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;
	
	m_pSkinParams->draw();
#if 0
	if (m_DirectedState) {
		// "in" state
	}
	if (isFocused()) {
		// dotted lines around it
	}
	extern CSGXDrawSurface *		g_DisplaySurface;

	sgxPoint2i position(m_SetupParams.m_X+offsetX,m_SetupParams.m_Y+offsetY);
	char str[100];
	sprintf(str, "d:%d", m_DirectedState);
	CSGXGraphicsEngine::get()->drawFont(str, sgxVector2(position.x,position.y));

	sgxPoint2i position2(position);
	position2.x += m_SetupParams.m_Width;
	position2.y += m_SetupParams.m_Height;
	g_DisplaySurface->drawRectangle(position, position2);
//	CSGXGraphicsEngine::get()->drawRect2D(position, position2);
	//
	
//		drawButton(position, position2, m_DirectedState, isFocused());
#endif

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


	
