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

*/

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

tUINT32	sgxGUIImageButtonParams::DEFAULT_WIDTH = 48;
tUINT32	sgxGUIImageButtonParams::DEFAULT_HEIGHT = 48;

sgxGUIImageButtonParams::sgxGUIImageButtonParams(const sgxGUISkinnedImageButton::tButtonType type) {
	m_Type = type;
}

sgxGUIImageButtonParams::sgxGUIImageButtonParams(const CSGXTexture *pTexture, const tUINT32 region) {
	m_Type = sgxGUISkinnedImageButton::eCustom;
	m_pCustomTexture = pTexture;
	m_iCustomRegion = region;
}

sgxGUIImageButton::sgxGUIImageButton(const tINT32 x, const tINT32 y, const sgxGUIImageButtonParams &params) :
	sgxWidget(x,y,CGUIDesignScreen::widgetImageButton), 
	m_SetupParams(params)
{
	m_pSkinParams = CSGXGUI::get()->getCurrentSkin()->getSkinnedImageButton();
	m_pSkinParams->cursorOver = m_isOver;
	m_pSkinParams->m_Type = m_SetupParams.m_Type;
	//
	if (m_SetupParams.m_Type == sgxGUISkinnedImageButton::eCustom) {
		m_pSkinParams->m_pTexture = m_SetupParams.m_pCustomTexture;
		m_pSkinParams->m_iRegion = m_SetupParams.m_iCustomRegion;
	}
	
}

void	
sgxGUIImageButton::getArea(sgxRect2i &rc) const {
	rc.left = m_X;
	rc.top = m_Y;
	rc.right = m_X+DEFAULT_WIDTH;
	rc.bottom = m_Y+DEFAULT_HEIGHT;
}

tBOOL sgxGUIImageButton::draw(CSGXDrawSurface *pSurface, const tINT32 offsetX, const tINT32 offsetY) const {
	sgxRect2i rc;

	getArea(rc);

	m_pSkinParams->topleft.x = rc.left+offsetX;
	m_pSkinParams->topleft.y = rc.top+offsetY;
	m_pSkinParams->bottomright.x = rc.right+DEFAULT_WIDTH;
	m_pSkinParams->bottomright.y = rc.bottom+DEFAULT_HEIGHT;

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

	m_pSkinParams->draw(pSurface);
#if 0
	if (m_DirectedState) {
		// "in" state
	}
	if (isFocused()) {
		// dotted lines around it
	}
	
//		drawButton(position, position2, m_DirectedState, isFocused());
#endif

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


	
