#include "StdAfx.h"
#include "UIImage.h"

//#include "RenderSystem.h"

//cUIImage::cUIImage()
//{
//	mTexture = 0;
//	mScreenTexture = NiNew NiScreenTexture(0);
//
//	mScreenTexture->SetApplyMode( NiTexturingProperty::APPLY_MODULATE );
//	mScreenTexture->AddNewScreenRect( 0, 0, 0, 0, 0, 0, NiColorA::WHITE );
//	mScreenTexture->MarkAsChanged( NiScreenTexture::EVERYTHING_MASK );
//}

cUIImage::cUIImage( NiTexture* tex, unsigned int x, unsigned int y, unsigned int tx, unsigned int ty, unsigned int tw, unsigned int th )
{
	assert( tex && "null texture" );

	mTexture = tex;
	mScreenTexture = NiNew NiScreenTexture( tex );

	//mTextureWidth = tex->GetWidth();
	//mTextureHeight = tex->GetHeight();

	mScreenTexture->SetApplyMode( NiTexturingProperty::APPLY_MODULATE );
	mScreenTexture->AddNewScreenRect(
		(short)y, (short)x,
		(unsigned short)tw, (unsigned short)th,
		(unsigned short)ty, (unsigned short)tx, NiColorA::WHITE );
	//mScreenTexture->AddNewScreenRect( 0, 0,
	//	(unsigned short)tex->GetWidth(), (unsigned short)tex->GetHeight(),
	//	0, 0, NiColorA::WHITE );
	mScreenTexture->MarkAsChanged( NiScreenTexture::EVERYTHING_MASK );
}

cUIImage::~cUIImage()
{
	mTexture = 0;
	NiDelete mScreenTexture;
}

void cUIImage::Draw()
{
	if( mTexture )
	{
		mScreenTexture->Draw( NiRenderer::GetRenderer() );
	}
}

//void cUIImage::SetTexture( NiTexture* tex )
//{
//	assert( tex );
//
//	//mTextureWidth = tex->GetWidth();
//	//mTextureHeight = tex->GetHeight();
//
//	mTexture = tex;
//	mScreenTexture->SetTexture( tex );
//}

//void cUIImage::SetPos( unsigned int x, unsigned int y )
//{
//	NiScreenTexture::ScreenRect& rc = mScreenTexture->GetScreenRect( 0 );
//	rc.m_sPixLeft = (short)x;
//	rc.m_sPixTop = (short)y;
//
//	mScreenTexture->MarkAsChanged( NiScreenTexture::VERTEX_MASK );
//}

//void cUIImage::SetScreenRect( const cUIRect& rect )
//{
//	NiScreenTexture::ScreenRect& rc = mScreenTexture->GetScreenRect( 0 );
//	rc.m_sPixLeft = (short)rect.mLeft;
//	rc.m_sPixTop = (short)rect.mTop;
//	rc.m_usPixWidth = (unsigned short)(rect.mRight - rect.mLeft);
//	rc.m_usPixHeight = (unsigned short)(rect.mBottom - rect.mTop);
//
//	mScreenTexture->MarkAsChanged( NiScreenTexture::VERTEX_MASK );
//}

//void cUIImage::SetScreenRect( unsigned int x, unsigned int y, unsigned int w, unsigned int h )
//{
//	NiScreenTexture::ScreenRect& rc = mScreenTexture->GetScreenRect( 0 );
//	rc.m_sPixLeft = (short)x;
//	rc.m_sPixTop = (short)y;
//	rc.m_usPixWidth = (unsigned short)w;
//	rc.m_usPixHeight = (unsigned short)h;
//
//	mScreenTexture->MarkAsChanged( NiScreenTexture::VERTEX_MASK );
//}

//void cUIImage::SetTextureRect( unsigned int tx, unsigned int ty, unsigned int tw, unsigned int th )
//{
//	//mTexRect.Set( tl, tt, tr, tb );
//
//	NiScreenTexture::ScreenRect& rc = mScreenTexture->GetScreenRect( 0 );
//	rc.m_usTexLeft = (unsigned short)tx;
//	rc.m_usTexTop = (unsigned short)ty;
//	tw;
//	th;
//
//	mScreenTexture->MarkAsChanged( NiScreenTexture::TEXTURE_MASK );
//}
//
//void cUIImage::SetTextureRect( const cUIRect& rect )
//{
//	mTexRect = rect;
//
//	NiScreenTexture::ScreenRect& rc = mScreenTexture->GetScreenRect( 0 );
//	rc.m_usTexLeft = (short)rect.mLeft;
//	rc.m_usTexTop = (short)rect.mTop;
//
//	mScreenTexture->MarkAsChanged( NiScreenTexture::TEXTURE_MASK );
//}

//void cUIImage::SetColor( const NiColorA& color )
//{
//	NiScreenTexture::ScreenRect& rc = mScreenTexture->GetScreenRect( 0 );
//	rc.m_kColor = color;
//
//	mScreenTexture->MarkAsChanged( NiScreenTexture::COLOR_MASK );
//}
//
//const NiColorA& cUIImage::GetColor() const
//{
//	const NiScreenTexture::ScreenRect& rc = mScreenTexture->GetScreenRect( 0 );
//	return rc.m_kColor;
//}

void cUIImage::SetAlpha( float a )
{
	assert(mScreenTexture->GetNumScreenRects());
	NiScreenTexture::ScreenRect& rect = mScreenTexture->GetScreenRect( 0 );
	rect.m_kColor.a = a;

	mScreenTexture->MarkAsChanged( NiScreenTexture::COLOR_MASK );
}
