//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 PadControls()
{
	this.__proto__ = new MenuItem("PadControls");
	
	this.padImage = new Image();
	this.padImage.src = "data/images/pad.svg";
	
	this.redraw = true;

	this.Redraw = function()
	{
		this.redraw = true;
	}

	this.DrawClear = function()
	{
		if(this.redraw)
		{
			gDraw.menu.clearRect(this.x - this.width/2, this.y - this.height/2, this.width, this.height);
		}
	}
	
	this.Draw = function()
	{
		if(this.redraw && this.padImage.complete)
		{
			this.DrawPad();
			this.redraw = false;
		}
	}
	
	this.DrawPad = function()
	{
		var scale = 0.7;
		var desiredMaxWidth = this.width * scale;
		var desiredMaxHeight = this.height * scale;
		
		var srcWidth = this.padImage.width;
		var srcHeight = this.padImage.height;
		var widthScale = desiredMaxWidth/srcWidth;
		var heightScale = desiredMaxHeight/srcHeight;
		var imageScale = Math.min(widthScale, heightScale);
		var width = srcWidth * imageScale;
		var height = srcHeight * imageScale;
		gDraw.menu.drawImage(this.padImage, this.x - (width/2), this.y - (height/2), width , height);
		
		this.SetupLabelDrawing();
		this.DrawLabel("Undo", 0.245, 0.305, 'right');
		
		this.DrawLabel("Restart", 0.56, 0.13, 'center');
		
		this.DrawLabel("Move", 0.42, 0.88, 'center');
		this.DrawLabel("Pause", 0.695, 0.88, 'center');
		
		this.DrawLabel("Level Select", 0.755, 0.35, 'left');
		this.DrawLabel("Back", 0.755, 0.5, 'left');
		this.DrawLabel("Select", 0.755, 0.705, 'left');
	}
	
	this.SetupLabelDrawing = function()
	{
		gDraw.menu.font	 = GetFont(this.fontSize);
		gDraw.menu.textBaseline	 = 'middle';
		gDraw.menu.shadowOffsetX = 1;
		gDraw.menu.shadowOffsetY = 1;
		gDraw.menu.shadowBlur = 2;
		gDraw.menu.shadowColor = "rgb(0, 0, 0)";
	}
	
	this.DrawLabel = function(label, xfrac, yfrac, alignment)
	{
		var x = (this.x - this.width/2) + (this.width * xfrac);
		var y = (this.y - this.height/2) + (this.height * yfrac);
		gDraw.menu.textAlign = alignment;
		gDraw.menu.fillTextShadow(label, x, y, "rgb(255, 255, 255)", "rgb(0, 0, 0)");
	}
}
