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

*/

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

//
// Null widgets
//
sgxGUISkinnedWidget::sgxGUISkinnedWidget() :
enabled(FALSE),
cursorOver(TRUE) {
	
}

void 
sgxGUISkinnedWidget::update(const tREAL32 telaps) {
	SGX_UNUSED(telaps);
}

void 
sgxGUISkinnedWidget::draw() const {
}

//
// Skin
//
CSGXGUISkin::CSGXGUISkin() {
}

CSGXGUISkin::CSGXGUISkin(const sgxGUISkinSettings &settings) :
	m_BaseSettings(settings)
{
}

sgxGUISkinnedButton *
CSGXGUISkin::getSkinnedButton() const {
	return new sgxGUISkinnedButton();
}

sgxGUISkinnedImageButton *
CSGXGUISkin::getSkinnedImageButton() const {
	return new sgxGUISkinnedImageButton();
}

sgxGUISkinnedCheckBox *
CSGXGUISkin::getSkinnedCheckBox() const {
	return new sgxGUISkinnedCheckBox();
}

sgxGUISkinnedRadioButton *
CSGXGUISkin::getSkinnedRadioButton() const {
	return new sgxGUISkinnedRadioButton();
}

sgxGUISkinnedHotSpot *
CSGXGUISkin::getSkinnedHotSpot() const {
	return new sgxGUISkinnedHotSpot();
}

sgxGUISkinnedStaticImage *
CSGXGUISkin::getSkinnedStaticImage(const sgxGUIStaticImageParams &params) const {
	return new sgxGUISkinnedStaticImage(params);
}

sgxGUISkinnedDynamicImage *
CSGXGUISkin::getSkinnedDynamicImage(const sgxGUIDynamicImageParams &params) const {
	return new sgxGUISkinnedDynamicImage(params);
}


sgxGUISkinnedStaticText *
CSGXGUISkin::getSkinnedStaticText() const {
	return new sgxGUISkinnedStaticText();
}

CSGXTexture *
CSGXGUISkin::getStandardTexture() {
	return m_pTexture;
}

CSGXTexture *
CSGXGUISkin::getStandardPointerTexture() {
	return m_pTexture;
}

tUINT32
CSGXGUISkin::getStandardPointerRegionIn()  const{
	return FACE_CURSOR_NORMAL;
}

tUINT32
CSGXGUISkin::getStandardPointerRegionOut()  const{
	return FACE_CURSOR_SELECTED;
}


sgxGUISkinnedStaticImage::sgxGUISkinnedStaticImage(const sgxGUIStaticImageParams &params) :
sgxGUISkinnedWidget(),
m_Params(params) {
}

void
sgxGUISkinnedStaticImage::draw() const {
	CSGXDrawSurface *pSurface = CSGXDrawSurfaceManager::get()->getDisplaySurface();

	pSurface->setFillTexture(m_Params.m_pTexture);
	pSurface->setFillTextureRegion(m_Params.m_Region);

	CSGXGraphicsEngine::get()->setColor(m_Params.m_Color);	

	switch(m_Params.m_Style) {
		case sgxGUIStaticImageParams::eImage:
			pSurface->fillBox(topleft, bottomright);
			break;
		case sgxGUIStaticImageParams::eTileArea:
			pSurface->tileBox(topleft, bottomright);
			break;
		case sgxGUIStaticImageParams::eSurroundArea:
			pSurface->surroundBox(topleft.x, topleft.y, bottomright.x,bottomright.y, TRUE);
			break;
		case sgxGUIStaticImageParams::eHollowSurround:
			pSurface->surroundBox(topleft.x, topleft.y, bottomright.x,bottomright.y, FALSE);
			break;
	}
	
}

//
sgxGUISkinnedDynamicImage::sgxGUISkinnedDynamicImage(const sgxGUIDynamicImageParams &params) :
sgxGUISkinnedWidget(),
m_Params(params) {
}

void
sgxGUISkinnedDynamicImage::draw() const {
	CSGXDrawSurface *pSurface = CSGXDrawSurfaceManager::get()->getDisplaySurface();

	pSurface->setFillTexture(m_Params.m_pTexture);
	pSurface->setFillTextureRegion(m_iCurrentRegion);

//	CSGXGraphicsEngine::get()->setColor(m_Params.m_Color);	
	CSGXGraphicsEngine::get()->setColor(sgxColorRGBA::White);	

	pSurface->fillBox(topleft, bottomright);
}

//
void
sgxGUISkinnedStaticText::draw() const {
}

//
//
//
tUINT32
CSGXGUISkin::getDefaultButtonWidth() const {
	if (m_pTexture) {
		return m_pTexture->getRegionWidth(FACE_BUTTON_LEFT_IN) * 4;
	}
	return sgxGUIButtonParams::DEFAULT_WIDTH;
}

tUINT32
CSGXGUISkin::getDefaultButtonHeight() const {
	if (m_pTexture) {
		return m_pTexture->getRegionHeight(FACE_BUTTON_LEFT_IN);
	}
	return sgxGUIButtonParams::DEFAULT_HEIGHT;
}

tUINT32
CSGXGUISkin::getDefaultImageButtonWidth() const {
	if (m_pTexture) {
		return m_pTexture->getRegionWidth(FACE_FACE_ARROW_LEFT_IN);
	}
	return sgxGUIImageButtonParams::DEFAULT_HEIGHT;
}

tUINT32
CSGXGUISkin::getDefaultImageButtonHeight() const {
	if (m_pTexture) {
		return m_pTexture->getRegionHeight(FACE_FACE_ARROW_LEFT_IN);
	}
	return sgxGUIImageButtonParams::DEFAULT_HEIGHT;
}

tUINT32
CSGXGUISkin::getDefaultCheckBoxWidth() const {
	if (m_pTexture) {
		return m_pTexture->getRegionHeight(FACE_CHECK_BOX_IN);
	}
	return sgxGUICheckBoxParams::DEFAULT_HEIGHT;
}

tUINT32
CSGXGUISkin::getDefaultCheckBoxHeight() const {
	if (m_pTexture) {
		return m_pTexture->getRegionHeight(FACE_CHECK_BOX_IN);
	}
	return sgxGUICheckBoxParams::DEFAULT_HEIGHT;
}

tUINT32
CSGXGUISkin::getDefaultRadioButtonWidth() const {
	if (m_pTexture) {
		return m_pTexture->getRegionHeight(FACE_RADIO_BUTTON_IN);
	}
	return sgxGUIRadioButtonParams::DEFAULT_HEIGHT;
}

tUINT32
CSGXGUISkin::getDefaultRadioButtonHeight() const {
	if (m_pTexture) {
		return m_pTexture->getRegionHeight(FACE_RADIO_BUTTON_IN);
	}
	return sgxGUIRadioButtonParams::DEFAULT_HEIGHT;
}
