1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Documents;
using System.Windows.Media;
using System.Windows.Shapes;
namespace Tango.Visuals.Components
{
internal class Arc : Shape
{
public double StartAngle
{
get { return (double)GetValue(StartAngleProperty); }
set { SetValue(StartAngleProperty, value); }
}
public static readonly DependencyProperty StartAngleProperty =
DependencyProperty.Register("StartAngle", typeof(double), typeof(Arc), new PropertyMetadata(0.0));
public double EndAngle
{
get { return (double)GetValue(EndAngleProperty); }
set { SetValue(EndAngleProperty, value); }
}
public static readonly DependencyProperty EndAngleProperty =
DependencyProperty.Register("EndAngle", typeof(double), typeof(Arc), new PropertyMetadata(90.0));
protected override Geometry DefiningGeometry
{
get
{
double maxWidth = RenderSize.Width;
double maxHeight = RenderSize.Height;
double maxRadius = Math.Min(maxWidth, maxHeight) / 2.0;
PolarPoint arcStart = new PolarPoint(maxRadius, StartAngle);
PolarPoint arcFinish = new PolarPoint(maxRadius, EndAngle);
StreamGeometry geom = new StreamGeometry();
using (StreamGeometryContext ctx = geom.Open())
{
ctx.BeginFigure(
new Point((maxWidth / 2.0) + arcStart.X,
(maxHeight / 2.0) - arcStart.Y),
false,
false);
ctx.ArcTo(
new Point((maxWidth / 2.0) + arcFinish.X,
(maxHeight / 2.0) - arcFinish.Y),
new Size(maxRadius, maxRadius),
0.0, // rotationAngle
EndAngle > 180 && StartAngle < 180 && (EndAngle - StartAngle) > 180, // greater than 180 deg?
SweepDirection.Counterclockwise,
true, // isStroked
true);
}
geom.Transform = new RotateTransform((-90 + EndAngle) + StartAngle, maxWidth / 2, maxHeight / 2);
return geom;
}
}
}
}
|