using System.Windows;
using System.Windows.Media;
using System;

namespace Microsoft.Research.DynamicDataDisplay.PointMarkers
{
    /// <summary>Class that renders triangular marker at every point of graph</summary>
	public class TrianglePointMarker : ShapePointMarker 
  {
		public override void Render(DrawingContext dc, Point screenPoint) 
        {
            Point? pt0 = null;
            Point? pt1 = null;
            Point? pt2 = null;

            if (Orientation.Equals("up"))
            {
              pt0 = Point.Add(screenPoint, new Vector(-Size / 2, Size / 2));
              pt1 = Point.Add(screenPoint, new Vector(0, -Size / 2));
              pt2 = Point.Add(screenPoint, new Vector(Size / 2, Size / 2));
            }
            else
            {
              pt0 = Point.Add(screenPoint, new Vector(-Size / 2, -Size / 2));
              pt1 = Point.Add(screenPoint, new Vector(0, Size / 2));
              pt2 = Point.Add(screenPoint, new Vector(Size / 2, -Size / 2));
            }
			  StreamGeometry streamGeom = new StreamGeometry();
			  using (var context = streamGeom.Open()) {
				context.BeginFigure(pt0.Value, true, true);
				context.LineTo(pt1.Value, true, true);
				context.LineTo(pt2.Value, true, true);
			}
			dc.DrawGeometry(Fill, Pen, streamGeom);
		}
        public String Orientation
        {
            get { return (String)GetValue(OrientationProperty); }
            set { SetValue(OrientationProperty, value); }
        }
        public static readonly DependencyProperty OrientationProperty =
          DependencyProperty.Register(
            "Orientation",
            typeof(String),
            typeof(TrianglePointMarker),
            new FrameworkPropertyMetadata("up")
              );
	}
}
