﻿function PolygonKeyFrame(timeCode, points, toolVisual)
{
    this.TimeCode = timeCode;
    this.Points = new Array();
    this.Left = toolVisual["Canvas.Left"];
    this.Top = toolVisual["Canvas.Top"];
    
    for (var i = 0; i < points.length; i++)
    {
        this.Points.push(points[i]);
    }
    //this.Points.concat(points);
}

function formatPoint(point)
{
    return "" + point.X + "," + point.Y;
}

PolygonKeyFrame.prototype.GetShapeXaml = function(name)
{
    var xaml = '\t<Path x:Name="' + name + '" Stroke="Gold" Opacity="0" Fill="#33FFFFFF">\n';
	xaml += '<Path.Data>\n';
    xaml += '<PathGeometry>\n';
    xaml += '<PathGeometry.Figures>\n';
    xaml += '<PathFigure x:Name="Path" IsClosed="true" StartPoint="' + formatPoint(this.Points[0]) + '">\n';
    xaml += '<PathFigure.Segments>\n';
    
    for (var i = 1; i < this.Points.length; i++)
    {
        xaml += '<LineSegment Point="' + formatPoint(this.Points[i]) + '"/>\n';
    }
    
    xaml += '</PathFigure.Segments>\n';
	xaml += '</PathFigure>\n';
    xaml += '</PathGeometry.Figures>\n';
    xaml += '</PathGeometry>\n';
	xaml += '</Path.Data>\n';
	xaml += '</Path>\n';
    
    return xaml;
}

PolygonKeyFrame.prototype.GetKeyFrameXaml = function(index, first)
{
    var xaml = '\t\t\t';
    
    if (first)
    {
       xaml+= '<DiscretePointKeyFrame  ';
    }
    else
    {
        xaml+= '<LinearPointKeyFrame ';
    }
    
    var point = this.Points[index];
    
    xaml+=  'KeyTime="' + formatTime(this.TimeCode) + '" Value="' + formatPoint(point);
    
    xaml += '"/>\n';
    
    return xaml;
}
