//Copyright (C) Ben Parbury - All Rights Reserved. Unauthorized copying of this file, via any medium is strictly prohibited. Written by Ben Parbury <ben@gridlockinteractive.com> 2014

function Icon(x, y, width, height, callback, downCallback)
{
	this.x = x;
	this.y = y;
	this.width = width;
	this.height = height;
	this.callback = callback;
	this.downCallback = downCallback;
	this.interacting = false;
	this.redraw = true;
	this.enabled = true;
	
	this.Enable = function(enable)
	{
		if(enable)
		{
			this.redraw = true;
			this.enabled = true;
		}
		else
		{
			this.redraw = true;
			this.DrawClear();
			this.enabled = false;
		}
	}
	
	this.GetX = function()
	{
		return this.interacting ? this.x + 1: this.x;
	}

	this.GetY = function()
	{
		return this.interacting ? this.y + 1: this.y;
	}
	
	this.DrawBackground = function()
	{
		gDraw.menu.shadowOffsetX = this.interacting ? -1 : 1;
		gDraw.menu.shadowOffsetY = this.interacting ? -1 : 1;
		gDraw.menu.shadowBlur = 2;
		gDraw.menu.shadowColor = "rgb(0, 0, 0)";

		this.redraw = false;
	}
	
	this.DrawClear = function()
	{
		var padding = 5;
		gDraw.menu.clearRect(this.x - padding, this.y - padding, this.width + (padding * 2), this.height + (padding * 2));
	}
	
	this.CanInteract = function(x, y)
	{
		if (this.enabled && this.x < x && x < this.x + this.width)
		{
			if (this.y < y && y < this.y + this.height)
			{
				return true;
			}
		}
		
		return false;
	}
	
	this.InteractMove = function(x, y)
	{
		if (this.CanInteract(x, y))
		{
			this.interacting = true;
			this.redraw = true;
		}
		else if (this.interacting)
		{
			this.redraw = true;
			this.interacting = false;
		}
	}
	
	this.InteractDown = function(x, y)
	{
		if (this.CanInteract(x, y) && this.downCallback)
		{
			this.downCallback();
		}
	}
	
	this.InteractRelease = function(x, y)
	{
		if (this.CanInteract(x, y))
		{
			this.callback();
		}
	}
	
	this.InteractMoveOut = function()
	{
		if(this.interacting)
		{
			this.interacting = false;
			this.redraw = true;
		}
	}
}
