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

*/

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


sgxGUIStaticImageParams::sgxGUIStaticImageParams(const CSGXTexture *pTexture, const tUINT32 region, const tStyle style, const sgxColorRGBA &color, const tUINT32 w, const tUINT32 h) :
	m_pTexture(pTexture),
	m_Region(region),
	m_Style(style),
	m_Color(color),
	m_Width(w), 
	m_Height(h)
	{ 
}
	
sgxGUIStaticImage::sgxGUIStaticImage(const tINT32 x, const tINT32 y, const sgxGUIStaticImageParams &params) :
	sgxWidget(x,y,CGUIDesignScreen::widgetImage), 
	m_SetupParams(params)
{
	m_pSkinParams = CSGXGUI::get()->getCurrentSkin()->getSkinnedStaticImage(m_SetupParams);
}

void
sgxGUIStaticImage::getArea(sgxRect2i &rc) const {
	rc.left = rc.right = m_X;
	rc.top = rc.bottom = m_Y;

	rc.right += m_SetupParams.m_Width == 0 ? m_SetupParams.m_pTexture->getRegionWidth(m_SetupParams.m_Region) : m_SetupParams.m_Width;
	rc.bottom += m_SetupParams.m_Height == 0 ? m_SetupParams.m_pTexture->getRegionHeight(m_SetupParams.m_Region) : m_SetupParams.m_Height;
}


void 			
sgxGUIStaticImage::setSize(const tINT32 w, const tINT32 h) {
	m_SetupParams.m_Width = w;
	m_SetupParams.m_Height = h;
}

tBOOL sgxGUIStaticImage::draw(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+offsetX;
	m_pSkinParams->bottomright.y = rc.bottom+offsetY;


	m_pSkinParams->enabled = m_bEnabled;
	m_pSkinParams->cursorOver = m_isOver;
	
	m_pSkinParams->draw();

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