markus / MarkupToPDF / Controls / Common / DrawSet.cs @ 2a2e72c2
이력 | 보기 | 이력해설 | 다운로드 (1.59 KB)
1 | d251456f | humkyung | using System; |
---|---|---|---|
2 | using System.Collections.Generic; |
||
3 | using System.Linq; |
||
4 | using System.Text; |
||
5 | using System.Threading.Tasks; |
||
6 | using System.Windows; |
||
7 | using System.Windows.Media; |
||
8 | |||
9 | namespace MarkupToPDF.Controls.Common |
||
10 | { |
||
11 | class DrawSet |
||
12 | { |
||
13 | /// <summary> |
||
14 | /// draw a arrow with given two points |
||
15 | /// </summary> |
||
16 | /// <param name="p2"></param> |
||
17 | /// <param name="p1"></param> |
||
18 | /// <param name="lineSize"></param> |
||
19 | /// <returns></returns> |
||
20 | public static PathGeometry DrawArrow(Point p2, Point p1, double lineSize) |
||
21 | { |
||
22 | double theta = Math.Atan2((p2.Y - p1.Y), (p2.X - p1.X)) * 180 / Math.PI; |
||
23 | PathGeometry pathGeometry = new PathGeometry(); |
||
24 | PathFigure pathFigure = new PathFigure(); |
||
25 | pathFigure.StartPoint = p1; |
||
26 | |||
27 | Point lpoint = new Point(p1.X + lineSize * 2, p1.Y + lineSize * 6); |
||
28 | Point rpoint = new Point(p1.X - lineSize * 2, p1.Y + lineSize * 6); |
||
29 | |||
30 | List<Point> points = new List<Point>() { lpoint, rpoint, p1 }; |
||
31 | PolyLineSegment polyline = new PolyLineSegment(points, true); |
||
32 | pathFigure.Segments.Add(polyline); |
||
33 | |||
34 | pathFigure.IsClosed = true; |
||
35 | pathFigure.IsFilled = true; |
||
36 | |||
37 | pathGeometry.Figures.Add(pathFigure); |
||
38 | pathGeometry.FillRule = FillRule.Nonzero; |
||
39 | RotateTransform transform = new RotateTransform(); |
||
40 | transform.Angle = theta - 90; |
||
41 | transform.CenterX = p1.X; |
||
42 | transform.CenterY = p1.Y; |
||
43 | pathGeometry.Transform = transform; |
||
44 | return pathGeometry; |
||
45 | } |
||
46 | } |
||
47 | } |