/**
 * @author chrisjones@twofour.co.uk
 */
if(!window.Twofour)
	window.Twofour = {};
if(!Twofour.Xaml)
	Twofour.Xaml = {};
	
Twofour.Xaml.UI = {};

Twofour.Xaml.UI.Point = function(top,left){
	this['Canvas.Top'] = top;
	this['Canvas.Left'] = left;
}
Twofour.Xaml.UI.Point.prototype = {
	toString: function(){
		return 	this['Canvas.Top']+','+this['Canvas.Left'];
	}
}

Twofour.Xaml.UI.Size = function(height,width){
	this['Height'] = height;
	this['Width'] = width;
}
Twofour.Xaml.UI.Size.prototype = {
	toString: function(){
		return 	this['Height']+','+this['Width'];
	}
}

Twofour.Xaml.UI.Bounds = function(top,left,height,width){
	this['Canvas.Top'] = top;
	this['Canvas.Left'] = left;
	this['Height'] = height;
	this['Width'] = width;
}
Twofour.Xaml.UI.Bounds.prototype = {
	toString: function(){
		return 	this['Canvas.Top']+','+this['Canvas.Left']+','+this['Height']+','+this['Width'];
	}
}

Twofour.Xaml.UI.UIElement = function(top,left,height,width,zIndex,cursor,opacity,opacityMask,visible,isHitTestVisible,clip,tag,renderTransform,renderTransformOrigin){
	this['Canvas.Top'] = top;
	this['Canvas.Left'] = left;
	this['Height'] = height;
	this['Width'] = width;
	if(zIndex)
		this['Canvas.ZIndex'] = zIndex;	
	if(cursor)
		this['Cursor'] = cursor;
	if(opacity)
		this['Opacity'] = opacity;
	if(opacityMask)
		this['OpacityMask'] = opacityMask;
	if(visible==false)
		this['Visibility'] = 'Collapsed';
	if(isHitTestVisible==false)
		this['IsHitTestVisible'] = 'false';
	if(clip)
		this['Clip'] = clip;
	if(tag)
		this['Tag'] = tag;
	if(renderTransform)
		this['RenderTransform'] = renderTransform;
	if(renderTransformOrigin)
		this['RenderTransformOrigin'] = renderTransformOrigin;
}
Twofour.Xaml.UI.UIElement.prototype = {
	getBounds: function(){
		return new Twofour.Xaml.UI.Bounds(this['Canvas.Top'],this['Canvas.Left'],this['Height'],this['Width']);
	}
}

Twofour.Xaml.UI.Geometry = function (data){
	this.figure = [];
	if(data){
		this.figure.push(data);
	}
}
Twofour.Xaml.UI.Geometry.prototype = {
	typeName: 'Twofour.Xaml.UI.Geometry',
	addMove: function (x,y) {
		this.figure.push('M '+x+','+y+' ');
	},
	addLine: function (x,y){
		this.figure.push('L '+x+','+y+' ');
	},

	addHorizontalLine: function (x){
		this.figure.push('H '+x+' ');
	},
	
	addVerticalLine: function (y){
		this.figure.push('V '+y+' ');
	},
	
	addCubicBezierCurve: function (x1,y1,x2,y2,x3,y3){
		this.figure.push('C '+x1+','+y1+' '+x2+','+y2+' '+x3+','+y3+' ');
	},
	
	addQuadraticBezierCurve: function (x1,y1,x2,y2) {
		this.figure.push('Q '+x1+','+y1+' '+x2+','+y2+' ');
	},

	addSmoothCubicBezierCurve: function (x1,y1,x2,y2) {
		this.figure.push('S '+x1+','+y1+' '+x2+','+y2+' ');
	},
	
	addSmoothQuadraticBezierCurve: function (x1,y1,x2,y2) {
		this.figure.push('T '+x1+','+y1+' '+x2+','+y2+' ');
	},
	
	addArc: function (sizeX,sizeY,rotationAngle,endX,endY,isLargeArc,sweepDirection) {
		var dir = 0;
		if(sweepDirection && sweepDirection.toLowerCase()=='clockwise')
			dir = 1;
		var arc = 0;
		if(isLargeArc)
			arc = 1;
		this.figure.push('A '+sizeX+','+sizeY+' '+rotationAngle+' '+arc+' '+dir+' '+endX+','+endY+' ');
	},
	
	close: function(){
		this.figure.push('Z');
	},
	
	toString: function(){
		var serialise = function(iterable){
			var out = '';
			if(iterable)
				for(var i=0;i<iterable.length;i++)
					out += iterable[i].toString();
			return out;
		};
		return serialise(this.figure);
	},
	
	undo: function (){
		this.figure.pop();
	},
	
	clear: function (){
		this.figure = [];
	}
}
