
function InitContextDrawLibrary(context)
{
	context.RoundedRect = RoundedRect;
	context.fillRoundedRect = fillRoundedRect;
	context.fillTextShadow = fillTextShadow;
	context.Arrow = Arrow;
	context.Star = Star;
	context.fillStar = fillStar;
}

RoundedRect = function(x, y, width, height, rounding)
{
	var PId2 = Math.PI/2;
	var PI3d2 = Math.PI + PId2;
	this.beginPath();
	this.arc(x + rounding, y + rounding, rounding, Math.PI, PI3d2, false);
	this.arc(x + width - rounding, y + rounding, rounding, PI3d2, 0, false);
	this.arc(x + width - rounding, y + height - rounding, rounding, 0, PId2, false);
	this.arc(x + rounding, y + height - rounding, rounding, PId2, Math.PI, false);
	this.closePath();
}

fillRoundedRect = function(x, y, width, height, rounding)
{
	this.RoundedRect(x, y, width, height, rounding);
	this.fill();
}

fillTextShadow = function(message, x, y, color, shadow)
{
	this.shadowOffsetX = 1;
	this.shadowOffsetY = 1;
	this.shadowBlur = 2;
	this.shadowColor = shadow

	this.fillStyle = color;
	this.fillText(message, x, y);
}


Arrow = function(x, y, x1, y1, headLength, headAngle)
{
    var angle = Math.atan2(y1-y,x1-x);
	
    this.moveTo(x, y);
    this.lineTo(x1, y1);
    this.lineTo(x1-headLength*Math.cos(angle-headAngle),y1-headLength*Math.sin(angle-headAngle));
    this.moveTo(x1, y1);
    this.lineTo(x1-headLength*Math.cos(angle+headAngle),y1-headLength*Math.sin(angle+headAngle));
}

Star = function(x, y, radius, rotation)
{
	if(rotation == undefined)
	{
		rotation = Math.PI/5;
	}
	else
	{
		var section = Math.PI/2.5;
		while(rotation > section)
		{
			rotation -= section;
		}
	}
	this.beginPath();
	var innerRadius = radius * 0.5;
	var step = Math.PI*2/5
	var stepD2 = step/2
	for(var i = rotation; i < (Math.PI * 2) + stepD2; i += step)
	{
		this.lineTo(x + (Math.sin(i) * radius), y + (Math.cos(i) * radius));
		this.lineTo(x + (Math.sin(i + stepD2) * innerRadius), y + (Math.cos(i + stepD2) * innerRadius));
	}
	this.closePath();
}

fillStar = function(x, y, radius, rotation)
{
	this.Star(x, y, radius, rotation);
	this.fill();
}
