#include "Icon.h"


void TIcon::Init(u16 aX, u16 aY, u16 aW, u16 aH, u16 OwnerX, u16 OwnerY, u32 aSize, u32 aColor)
{
	Bound.SetBySize(aX+OwnerX, aY+OwnerY, aW, aH);
	Content.SetBySize(aX+OwnerX+1,aY+OwnerY+1,aW-2,aH-2);
	
	OwnerLeftTop.x 	= OwnerX;
	OwnerLeftTop.y 	= OwnerY;
	
	iSize = aSize;
	Color 	= aColor;
	BorderColor = clFrmFace;
	
	Dx = (Bound.Width - aSize)/2 + Bound.Left;
	Dy = (Bound.Height - aSize)/2 + Bound.Top;
	Active = true;
}

void TIcon::SetActive(void)
{
	Active = 1;
}

void TIcon::SetDeActive(void)
{
	Active = 0;
}

void TIcon::SetActiveIndex(unsigned int aIndex)
{
	ActiveImageIndex = aIndex;
}

void TIcon::SetDeActiveIndex(unsigned int aIndex)
{
	DeActiveImageIndex = aIndex;
}

void TIcon::DrawBorder(void)
{
	VertLineRender(Bound.Left,		Bound.Top, 		Bound.Height,	BorderColor);
	VertLineRender(Bound.Right,		Bound.Top, 		Bound.Height,	BorderColor);
	HorizLineRender(Bound.Left, 		Bound.Top, 		Bound.Width , 	BorderColor);
	HorizLineRender(Bound.Left, 		Bound.Bottom, 	Bound.Width , 	BorderColor);
}

void TIcon::DrawContent(void)
{
	RectFillRender(Content.Left, Content.Top, Content.Right, Content.Bottom, Color);
}

void TIcon::DrawIcon(void)
{
	if(IconList != nullptr)	{
		if(Active) 
			IconList->Render(iSize, ActiveImageIndex, Dx, Dy);
		else
			IconList->Render(iSize, DeActiveImageIndex, Dx, Dy);	
	}	
}

void TIcon::Show(void)
{
	DrawBorder();
	DrawContent();
	DrawIcon();
}



