17 changed files with 230 additions and 4 deletions
@ -0,0 +1,28 @@ |
|||
using Perspex.Media; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace Perspex.Controls.Shapes |
|||
{ |
|||
public class Polygon : Shape |
|||
{ |
|||
public static readonly PerspexProperty<IList<Point>> PointsProperty = |
|||
PerspexProperty.Register<Polygon, IList<Point>>("Points"); |
|||
|
|||
public IList<Point> Points |
|||
{ |
|||
get { return GetValue(PointsProperty); } |
|||
set { SetValue(PointsProperty, value); } |
|||
} |
|||
|
|||
public override Geometry DefiningGeometry => new PolylineGeometry(Points, true); |
|||
|
|||
protected override Size MeasureOverride(Size availableSize) |
|||
{ |
|||
return new Size(StrokeThickness, StrokeThickness); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,33 @@ |
|||
using Perspex.Media; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace Perspex.Controls.Shapes |
|||
{ |
|||
public class Polyline: Shape |
|||
{ |
|||
public static readonly PerspexProperty<IList<Point>> PointsProperty = |
|||
PerspexProperty.Register<Polyline, IList<Point>>("Points"); |
|||
|
|||
public Polyline() |
|||
{ |
|||
StrokeThickness = 1; // Default Thickness
|
|||
} |
|||
|
|||
public IList<Point> Points |
|||
{ |
|||
get { return GetValue(PointsProperty); } |
|||
set { SetValue(PointsProperty, value); } |
|||
} |
|||
|
|||
public override Geometry DefiningGeometry => new PolylineGeometry(Points, false); |
|||
|
|||
protected override Size MeasureOverride(Size availableSize) |
|||
{ |
|||
return new Size(StrokeThickness, StrokeThickness); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,50 @@ |
|||
using Perspex.Platform; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace Perspex.Media |
|||
{ |
|||
/// <summary>
|
|||
/// Represents the geometry of an polyline or polygon.
|
|||
/// </summary>
|
|||
public class PolylineGeometry : Geometry |
|||
{ |
|||
private IList<Point> _points; |
|||
private bool _isFilled; |
|||
|
|||
public PolylineGeometry(IList<Point> points, bool isFilled) |
|||
{ |
|||
_points = points; |
|||
_isFilled = isFilled; |
|||
IPlatformRenderInterface factory = PerspexLocator.Current.GetService<IPlatformRenderInterface>(); |
|||
IStreamGeometryImpl impl = factory.CreateStreamGeometry(); |
|||
|
|||
using (IStreamGeometryContextImpl context = impl.Open()) |
|||
{ |
|||
if (points.Count > 0) |
|||
{ |
|||
context.BeginFigure(points[0], isFilled); |
|||
for (int i = 1; i < points.Count; i++) |
|||
{ |
|||
context.LineTo(points[i]); |
|||
} |
|||
context.EndFigure(isFilled); |
|||
} |
|||
} |
|||
|
|||
PlatformImpl = impl; |
|||
} |
|||
|
|||
/// <inheritdoc/>
|
|||
public override Rect Bounds => PlatformImpl.Bounds; |
|||
|
|||
/// <inheritdoc/>
|
|||
public override Geometry Clone() |
|||
{ |
|||
return new PolylineGeometry(new List<Point>(_points), _isFilled); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,24 @@ |
|||
// Copyright (c) The Perspex Project. All rights reserved.
|
|||
// Licensed under the MIT license. See licence.md file in the project root for full license information.
|
|||
|
|||
using Perspex.Controls; |
|||
using Perspex.Controls.Shapes; |
|||
using Perspex.Media; |
|||
using Xunit; |
|||
|
|||
#if PERSPEX_CAIRO
|
|||
namespace Perspex.Cairo.RenderTests.Shapes |
|||
#elif PERSPEX_SKIA
|
|||
namespace Perspex.Skia.RenderTests |
|||
#else
|
|||
namespace Perspex.Direct2D1.RenderTests.Shapes |
|||
#endif
|
|||
{ |
|||
public class PolygonTests : TestBase |
|||
{ |
|||
public PolygonTests() |
|||
: base(@"Shapes\Polygon") |
|||
{ |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,52 @@ |
|||
// Copyright (c) The Perspex Project. All rights reserved.
|
|||
// Licensed under the MIT license. See licence.md file in the project root for full license information.
|
|||
|
|||
using Perspex.Controls; |
|||
using Perspex.Controls.Shapes; |
|||
using Perspex.Media; |
|||
using Xunit; |
|||
|
|||
#if PERSPEX_CAIRO
|
|||
namespace Perspex.Cairo.RenderTests.Shapes |
|||
#elif PERSPEX_SKIA
|
|||
namespace Perspex.Skia.RenderTests |
|||
#else
|
|||
namespace Perspex.Direct2D1.RenderTests.Shapes |
|||
#endif
|
|||
{ |
|||
public class PolylineTests : TestBase |
|||
{ |
|||
public PolylineTests() |
|||
: base(@"Shapes\Polyline") |
|||
{ |
|||
} |
|||
|
|||
[Fact] |
|||
public void Polyline_1px_Stroke() |
|||
{ |
|||
var polylinePoints = new Point[] { new Point(0, 0), new Point(5, 0), new Point(6, -2), new Point(7, 3), new Point(8, -3), |
|||
new Point(9, 1), new Point(10, 0), new Point(15, 0) }; |
|||
var offsetPoint = new Point(0, 50); |
|||
for (int i = 0; i < polylinePoints.Length; i++) |
|||
{ |
|||
polylinePoints[i] = polylinePoints[i] * 13 + offsetPoint; |
|||
} |
|||
|
|||
Decorator target = new Decorator |
|||
{ |
|||
Padding = new Thickness(8), |
|||
Width = 230, |
|||
Height = 130, |
|||
Child = new Polyline |
|||
{ |
|||
Stroke = Brushes.Brown, |
|||
Points = polylinePoints, |
|||
StrokeThickness = 1 |
|||
} |
|||
}; |
|||
|
|||
RenderToFile(target); |
|||
CompareImages(); |
|||
} |
|||
} |
|||
} |
|||
|
After Width: | Height: | Size: 3.9 KiB |
|
After Width: | Height: | Size: 1.6 KiB |
|
After Width: | Height: | Size: 3.9 KiB |
|
After Width: | Height: | Size: 1.6 KiB |
|
After Width: | Height: | Size: 3.9 KiB |
|
After Width: | Height: | Size: 1.6 KiB |
Loading…
Reference in new issue