/** 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/utils/graphics/safearea.cpp

*/

#include "sgx/core/core.hpp"
#include "sgx/graphics/graphics.hpp"
#include "utils/graphics/safearea.hpp"



CSGXSafeArea::CSGXSafeArea(const tUINT32 w, const tUINT32 h) {
	tUINT32 sw = CSGXGraphicsEngine::get()->getScreenWidth();
	tUINT32 sh = CSGXGraphicsEngine::get()->getScreenHeight();

	m_SafeArea.left = sw>w?(sw-w)/2:0;
	m_SafeArea.top = sh>h?(sh-h)/2:0;
	m_SafeArea.right = m_SafeArea.left+w;
	m_SafeArea.bottom = m_SafeArea.top+h;
}

CSGXSafeArea::CSGXSafeArea(const tPOINT x, const tPOINT y, const tUINT32 w, const tUINT32 h) {
	m_SafeArea.left = x;
	m_SafeArea.top = y;
	m_SafeArea.right = m_SafeArea.left+w;
	m_SafeArea.bottom = m_SafeArea.top+h;
}

CSGXSafeArea::CSGXSafeArea(const sgxRect2i &rc) {
	m_SafeArea = rc;
}


tBOOL 
CSGXSafeArea::isInside(const sgxPoint2i &pt) {
	return m_SafeArea.isInside(pt);
}

tBOOL 
CSGXSafeArea::isInside(const sgxRect2i &rc) {
	return m_SafeArea.isInside(rc);
}


void 
CSGXSafeArea::render(CSGXTexture *pTexture, tUINT32 region) {

	tUINT32 sw = CSGXGraphicsEngine::get()->getScreenWidth();
	tUINT32 sh = CSGXGraphicsEngine::get()->getScreenHeight();
	sgxUV uv;
	if (pTexture) {
		pTexture->getRegion(region, uv);
	}
	CSGXTextureManager::get()->setCurrentTexture(pTexture);
	CSGXTextureManager::get()->applyTextureRegion(uv);
	CSGXGraphicsEngine::get()->setColor(sgxColorRGBA(0,0,0,0.5f));

	CSGXGraphicsEngine::get()->drawRect2D(0, 0, sw, 0, sw, m_SafeArea.top, 0, m_SafeArea.top);	// top
	CSGXGraphicsEngine::get()->drawRect2D(0, 0, m_SafeArea.left, 0, m_SafeArea.left, sh, 0, sh);	// left
	CSGXGraphicsEngine::get()->drawRect2D(m_SafeArea.right, 0, sw, 0, sw, sh, m_SafeArea.right, sh);	// right
	CSGXGraphicsEngine::get()->drawRect2D(0, m_SafeArea.bottom, sw, m_SafeArea.bottom, sw, sh, 0, sh);	// bottom

}

