|
@@ -1,7 +1,7 @@
|
|
|
//----------------------------------------------
|
|
|
// ArrowLineBase.cs (c) 2007 by Charles Petzold
|
|
|
//----------------------------------------------
|
|
|
-using System;
|
|
|
+
|
|
|
using System.Windows;
|
|
|
using System.Windows.Media;
|
|
|
using System.Windows.Shapes;
|
|
@@ -34,7 +34,7 @@ namespace DrawGraph
|
|
|
DependencyProperty.Register("ArrowAngle",
|
|
|
typeof(double), typeof(ArrowLineBase),
|
|
|
new FrameworkPropertyMetadata(45.0,
|
|
|
- FrameworkPropertyMetadataOptions.AffectsMeasure));
|
|
|
+ FrameworkPropertyMetadataOptions.AffectsMeasure));
|
|
|
|
|
|
/// <summary>
|
|
|
/// Gets or sets the angle between the two sides of the arrowhead.
|
|
@@ -42,7 +42,7 @@ namespace DrawGraph
|
|
|
public double ArrowAngle
|
|
|
{
|
|
|
set { SetValue(ArrowAngleProperty, value); }
|
|
|
- get { return (double)GetValue(ArrowAngleProperty); }
|
|
|
+ get { return (double) GetValue(ArrowAngleProperty); }
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
@@ -52,7 +52,7 @@ namespace DrawGraph
|
|
|
DependencyProperty.Register("ArrowLength",
|
|
|
typeof(double), typeof(ArrowLineBase),
|
|
|
new FrameworkPropertyMetadata(12.0,
|
|
|
- FrameworkPropertyMetadataOptions.AffectsMeasure));
|
|
|
+ FrameworkPropertyMetadataOptions.AffectsMeasure));
|
|
|
|
|
|
/// <summary>
|
|
|
/// Gets or sets the length of the two sides of the arrowhead.
|
|
@@ -60,7 +60,7 @@ namespace DrawGraph
|
|
|
public double ArrowLength
|
|
|
{
|
|
|
set { SetValue(ArrowLengthProperty, value); }
|
|
|
- get { return (double)GetValue(ArrowLengthProperty); }
|
|
|
+ get { return (double) GetValue(ArrowLengthProperty); }
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
@@ -70,7 +70,7 @@ namespace DrawGraph
|
|
|
DependencyProperty.Register("ArrowEnds",
|
|
|
typeof(ArrowEnds), typeof(ArrowLineBase),
|
|
|
new FrameworkPropertyMetadata(ArrowEnds.End,
|
|
|
- FrameworkPropertyMetadataOptions.AffectsMeasure));
|
|
|
+ FrameworkPropertyMetadataOptions.AffectsMeasure));
|
|
|
|
|
|
/// <summary>
|
|
|
/// Gets or sets the property that determines which ends of the
|
|
@@ -79,7 +79,7 @@ namespace DrawGraph
|
|
|
public ArrowEnds ArrowEnds
|
|
|
{
|
|
|
set { SetValue(ArrowEndsProperty, value); }
|
|
|
- get { return (ArrowEnds)GetValue(ArrowEndsProperty); }
|
|
|
+ get { return (ArrowEnds) GetValue(ArrowEndsProperty); }
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
@@ -89,7 +89,7 @@ namespace DrawGraph
|
|
|
DependencyProperty.Register("IsArrowClosed",
|
|
|
typeof(bool), typeof(ArrowLineBase),
|
|
|
new FrameworkPropertyMetadata(false,
|
|
|
- FrameworkPropertyMetadataOptions.AffectsMeasure));
|
|
|
+ FrameworkPropertyMetadataOptions.AffectsMeasure));
|
|
|
|
|
|
/// <summary>
|
|
|
/// Gets or sets the property that determines if the arrow head
|
|
@@ -98,7 +98,7 @@ namespace DrawGraph
|
|
|
public bool IsArrowClosed
|
|
|
{
|
|
|
set { SetValue(IsArrowClosedProperty, value); }
|
|
|
- get { return (bool)GetValue(IsArrowClosedProperty); }
|
|
|
+ get { return (bool) GetValue(IsArrowClosedProperty); }
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
@@ -143,29 +143,28 @@ namespace DrawGraph
|
|
|
// Draw the arrow at the end of the line.
|
|
|
if ((ArrowEnds & ArrowEnds.End) == ArrowEnds.End)
|
|
|
{
|
|
|
- Point pt1 = count == 1 ? pathfigLine.StartPoint :
|
|
|
- polysegLine.Points[count - 2];
|
|
|
+ Point pt1 = count == 1 ? pathfigLine.StartPoint : polysegLine.Points[count - 2];
|
|
|
Point pt2 = polysegLine.Points[count - 1];
|
|
|
pathgeo.Figures.Add(CalculateArrow(pathfigHead2, pt1, pt2));
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
return pathgeo;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
PathFigure CalculateArrow(PathFigure pathfig, Point pt1, Point pt2)
|
|
|
{
|
|
|
- Matrix matx = new Matrix();
|
|
|
- Vector vect = pt1 - pt2;
|
|
|
+ var matx = new System.Windows.Media.Matrix();
|
|
|
+ var vect = pt1 - pt2;
|
|
|
vect.Normalize();
|
|
|
vect *= ArrowLength;
|
|
|
|
|
|
- PolyLineSegment polyseg = pathfig.Segments[0] as PolyLineSegment;
|
|
|
+ var polyseg = pathfig.Segments[0] as PolyLineSegment;
|
|
|
polyseg.Points.Clear();
|
|
|
matx.Rotate(ArrowAngle / 2);
|
|
|
pathfig.StartPoint = pt2 + vect * matx;
|
|
|
polyseg.Points.Add(pt2);
|
|
|
-
|
|
|
matx.Rotate(-ArrowAngle);
|
|
|
polyseg.Points.Add(pt2 + vect * matx);
|
|
|
pathfig.IsClosed = IsArrowClosed;
|