-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6058 from wieslawsoltes/feature/PolyLineSegment
Add PolyLineSegment path segment
- Loading branch information
Showing
1 changed file
with
61 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
using System.Collections.Generic; | ||
using Avalonia.Collections; | ||
|
||
namespace Avalonia.Media | ||
{ | ||
/// <summary> | ||
/// Represents a set of line segments defined by a points collection with each Point specifying the end point of a line segment. | ||
/// </summary> | ||
public sealed class PolyLineSegment : PathSegment | ||
{ | ||
/// <summary> | ||
/// Defines the <see cref="Points"/> property. | ||
/// </summary> | ||
public static readonly StyledProperty<Points> PointsProperty | ||
= AvaloniaProperty.Register<PolyLineSegment, Points>(nameof(Points)); | ||
|
||
/// <summary> | ||
/// Gets or sets the points. | ||
/// </summary> | ||
/// <value> | ||
/// The points. | ||
/// </value> | ||
public AvaloniaList<Point> Points | ||
{ | ||
get => GetValue(PointsProperty); | ||
set => SetValue(PointsProperty, value); | ||
} | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="PolyLineSegment"/> class. | ||
/// </summary> | ||
public PolyLineSegment() | ||
{ | ||
Points = new Points(); | ||
} | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="PolyLineSegment"/> class. | ||
/// </summary> | ||
/// <param name="points">The points.</param> | ||
public PolyLineSegment(IEnumerable<Point> points) : this() | ||
{ | ||
Points.AddRange(points); | ||
} | ||
|
||
protected internal override void ApplyTo(StreamGeometryContext ctx) | ||
{ | ||
var points = Points; | ||
if (points.Count > 0) | ||
{ | ||
for (int i = 0; i < points.Count; i++) | ||
{ | ||
ctx.LineTo(points[i]); | ||
} | ||
} | ||
} | ||
|
||
public override string ToString() | ||
=> Points.Count >= 1 ? "L " + string.Join(" ", Points) : ""; | ||
} | ||
} |