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

*/

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


#ifdef SGX_PLATFORM_NDS
tUINT32	sgxGUICheckBoxParams::DEFAULT_WIDTH = 32;
tUINT32	sgxGUICheckBoxParams::DEFAULT_HEIGHT = 32;
#else
tUINT32	sgxGUICheckBoxParams::DEFAULT_WIDTH = 48;
tUINT32	sgxGUICheckBoxParams::DEFAULT_HEIGHT = 48;
#endif


sgxGUICheckBoxParams::sgxGUICheckBoxParams(const tBOOL initState) { 
	m_bInitialState = initState; 
	m_bTextOnRight = TRUE;
	m_Text = "";
	//
	m_Width = DEFAULT_WIDTH;
	m_Height = DEFAULT_HEIGHT;
}
	
sgxGUICheckBox::sgxGUICheckBox(const tINT32 x, const tINT32 y, const sgxGUICheckBoxParams &params) :
	sgxWidget(x,y, CGUIDesignScreen::widgetCheckBox), 
	m_SetupParams(params)
{
	m_pSkinParams = CSGXGUI::get()->getCurrentSkin()->getSkinnedCheckBox();
	m_bState = params.m_bInitialState;
}

void	
sgxGUICheckBox::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 sgxGUICheckBox::onSelect(const sgxPoint2i &position) {
	m_bState = !m_bState;
	return sgxWidget::onSelect(position);
}


tBOOL sgxGUICheckBox::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->selected = m_bState;
	m_pSkinParams->cursorOver = m_isOver;

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