Skip to content

Commit 151a7a0

Browse files
authored
Merge pull request #6058 from wieslawsoltes/feature/PolyLineSegment
Add PolyLineSegment path segment
2 parents e2a5bef + 9a2965c commit 151a7a0

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
using System.Collections.Generic;
2+
using Avalonia.Collections;
3+
4+
namespace Avalonia.Media
5+
{
6+
/// <summary>
7+
/// Represents a set of line segments defined by a points collection with each Point specifying the end point of a line segment.
8+
/// </summary>
9+
public sealed class PolyLineSegment : PathSegment
10+
{
11+
/// <summary>
12+
/// Defines the <see cref="Points"/> property.
13+
/// </summary>
14+
public static readonly StyledProperty<Points> PointsProperty
15+
= AvaloniaProperty.Register<PolyLineSegment, Points>(nameof(Points));
16+
17+
/// <summary>
18+
/// Gets or sets the points.
19+
/// </summary>
20+
/// <value>
21+
/// The points.
22+
/// </value>
23+
public AvaloniaList<Point> Points
24+
{
25+
get => GetValue(PointsProperty);
26+
set => SetValue(PointsProperty, value);
27+
}
28+
29+
/// <summary>
30+
/// Initializes a new instance of the <see cref="PolyLineSegment"/> class.
31+
/// </summary>
32+
public PolyLineSegment()
33+
{
34+
Points = new Points();
35+
}
36+
37+
/// <summary>
38+
/// Initializes a new instance of the <see cref="PolyLineSegment"/> class.
39+
/// </summary>
40+
/// <param name="points">The points.</param>
41+
public PolyLineSegment(IEnumerable<Point> points) : this()
42+
{
43+
Points.AddRange(points);
44+
}
45+
46+
protected internal override void ApplyTo(StreamGeometryContext ctx)
47+
{
48+
var points = Points;
49+
if (points.Count > 0)
50+
{
51+
for (int i = 0; i < points.Count; i++)
52+
{
53+
ctx.LineTo(points[i]);
54+
}
55+
}
56+
}
57+
58+
public override string ToString()
59+
=> Points.Count >= 1 ? "L " + string.Join(" ", Points) : "";
60+
}
61+
}

0 commit comments

Comments
 (0)