12 changed files with 140 additions and 0 deletions
@ -0,0 +1,36 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
using Perspex.Media; |
|||
|
|||
namespace Perspex.Controls.Shapes |
|||
{ |
|||
public class Line : Shape |
|||
{ |
|||
private Geometry _geometry; |
|||
|
|||
private Size _geometrySize; |
|||
|
|||
public override Geometry DefiningGeometry |
|||
{ |
|||
get |
|||
{ |
|||
if (_geometry == null || _geometrySize != Bounds.Size) |
|||
{ |
|||
var rect = new Rect(Bounds.Size).Deflate(StrokeThickness); |
|||
_geometry = new LineGeometry(rect.TopLeft, rect.BottomRight); |
|||
_geometrySize = Bounds.Size; |
|||
} |
|||
|
|||
return _geometry; |
|||
} |
|||
} |
|||
|
|||
protected override Size MeasureOverride(Size availableSize) |
|||
{ |
|||
return new Size(StrokeThickness, StrokeThickness); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,47 @@ |
|||
// 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.Platform; |
|||
|
|||
namespace Perspex.Media |
|||
{ |
|||
/// <summary>
|
|||
/// Represents the geometry of a line.
|
|||
/// </summary>
|
|||
public class LineGeometry : Geometry |
|||
{ |
|||
private Point _startPoint; |
|||
private Point _endPoint; |
|||
|
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="LineGeometry"/> class.
|
|||
/// </summary>
|
|||
/// <param name="startPoint">The start point.</param>
|
|||
/// <param name="endPoint">The end point.</param>
|
|||
public LineGeometry(Point startPoint, Point endPoint) |
|||
{ |
|||
_startPoint = startPoint; |
|||
_endPoint = endPoint; |
|||
IPlatformRenderInterface factory = PerspexLocator.Current.GetService<IPlatformRenderInterface>(); |
|||
IStreamGeometryImpl impl = factory.CreateStreamGeometry(); |
|||
|
|||
using (IStreamGeometryContextImpl context = impl.Open()) |
|||
{ |
|||
context.BeginFigure(startPoint, false); |
|||
context.LineTo(endPoint); |
|||
context.EndFigure(false); |
|||
} |
|||
|
|||
PlatformImpl = impl; |
|||
} |
|||
|
|||
/// <inheritdoc/>
|
|||
public override Rect Bounds => new Rect(_startPoint, _endPoint); |
|||
|
|||
/// <inheritdoc/>
|
|||
public override Geometry Clone() |
|||
{ |
|||
return new LineGeometry(Bounds.TopLeft, Bounds.BottomRight); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,43 @@ |
|||
// 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 LineTests : TestBase |
|||
{ |
|||
public LineTests() |
|||
: base(@"Shapes\Line") |
|||
{ |
|||
} |
|||
|
|||
[Fact] |
|||
public void Line_1px_Stroke() |
|||
{ |
|||
Decorator target = new Decorator |
|||
{ |
|||
Padding = new Thickness(8), |
|||
Width = 200, |
|||
Height = 200, |
|||
Child = new Line |
|||
{ |
|||
Stroke = Brushes.Black, |
|||
StrokeThickness = 1, |
|||
} |
|||
}; |
|||
|
|||
RenderToFile(target); |
|||
CompareImages(); |
|||
} |
|||
} |
|||
} |
|||
|
After Width: | Height: | Size: 618 B |
|
After Width: | Height: | Size: 618 B |
|
After Width: | Height: | Size: 618 B |
Loading…
Reference in new issue