Browse Source

Make Pen mutable.

And add `IPen` interface and `ImmutablePen` class.
pull/2744/head
Steven Kirk 7 years ago
parent
commit
ec45084e6a
  1. 14
      src/Avalonia.Visuals/Media/BrushExtensions.cs
  2. 8
      src/Avalonia.Visuals/Media/DrawingContext.cs
  3. 2
      src/Avalonia.Visuals/Media/GeometryDrawing.cs
  4. 17
      src/Avalonia.Visuals/Media/IMutablePen.cs
  5. 39
      src/Avalonia.Visuals/Media/IPen.cs
  6. 85
      src/Avalonia.Visuals/Media/Immutable/ImmutablePen.cs
  7. 117
      src/Avalonia.Visuals/Media/Pen.cs
  8. 6
      src/Avalonia.Visuals/Platform/IDrawingContextImpl.cs
  9. 4
      src/Avalonia.Visuals/Platform/IGeometryImpl.cs
  10. 2
      src/Avalonia.Visuals/Rendering/SceneGraph/BrushDrawOperation.cs
  11. 6
      src/Avalonia.Visuals/Rendering/SceneGraph/DeferredDrawingContextImpl.cs
  12. 2
      src/Avalonia.Visuals/Rendering/SceneGraph/DrawOperation.cs
  13. 9
      src/Avalonia.Visuals/Rendering/SceneGraph/GeometryNode.cs
  14. 7
      src/Avalonia.Visuals/Rendering/SceneGraph/LineNode.cs
  15. 9
      src/Avalonia.Visuals/Rendering/SceneGraph/RectangleNode.cs
  16. 8
      src/Skia/Avalonia.Skia/DrawingContextImpl.cs
  17. 4
      src/Skia/Avalonia.Skia/GeometryImpl.cs
  18. 6
      src/Windows/Avalonia.Direct2D1/Media/DrawingContextImpl.cs
  19. 4
      src/Windows/Avalonia.Direct2D1/Media/GeometryImpl.cs
  20. 4
      src/Windows/Avalonia.Direct2D1/PrimitiveExtensions.cs
  21. 4
      tests/Avalonia.UnitTests/MockStreamGeometryImpl.cs
  22. 4
      tests/Avalonia.Visuals.UnitTests/VisualTree/MockRenderInterface.cs

14
src/Avalonia.Visuals/Media/BrushExtensions.cs

@ -1,4 +1,5 @@
using System;
using Avalonia.Media.Immutable;
namespace Avalonia.Media
{
@ -30,20 +31,11 @@ namespace Avalonia.Media
/// A copy of the pen with an immutable brush, or <paramref name="pen"/> if the pen's brush
/// is already immutable or null.
/// </returns>
public static Pen ToImmutable(this Pen pen)
public static ImmutablePen ToImmutable(this IPen pen)
{
Contract.Requires<ArgumentNullException>(pen != null);
var brush = pen.Brush?.ToImmutable();
return ReferenceEquals(pen.Brush, brush) ?
pen :
new Pen(
brush,
thickness: pen.Thickness,
dashStyle: pen.DashStyle,
lineCap: pen.LineCap,
lineJoin: pen.LineJoin,
miterLimit: pen.MiterLimit);
return pen as ImmutablePen ?? ((IMutablePen)pen).ToImmutable();
}
}
}

8
src/Avalonia.Visuals/Media/DrawingContext.cs

@ -94,7 +94,7 @@ namespace Avalonia.Media
/// <param name="pen">The stroke pen.</param>
/// <param name="p1">The first point of the line.</param>
/// <param name="p2">The second point of the line.</param>
public void DrawLine(Pen pen, Point p1, Point p2)
public void DrawLine(IPen pen, Point p1, Point p2)
{
if (PenIsVisible(pen))
{
@ -108,7 +108,7 @@ namespace Avalonia.Media
/// <param name="brush">The fill brush.</param>
/// <param name="pen">The stroke pen.</param>
/// <param name="geometry">The geometry.</param>
public void DrawGeometry(IBrush brush, Pen pen, Geometry geometry)
public void DrawGeometry(IBrush brush, IPen pen, Geometry geometry)
{
Contract.Requires<ArgumentNullException>(geometry != null);
@ -124,7 +124,7 @@ namespace Avalonia.Media
/// <param name="pen">The pen.</param>
/// <param name="rect">The rectangle bounds.</param>
/// <param name="cornerRadius">The corner radius.</param>
public void DrawRectangle(Pen pen, Rect rect, float cornerRadius = 0.0f)
public void DrawRectangle(IPen pen, Rect rect, float cornerRadius = 0.0f)
{
if (PenIsVisible(pen))
{
@ -328,7 +328,7 @@ namespace Avalonia.Media
PlatformImpl.Dispose();
}
private static bool PenIsVisible(Pen pen)
private static bool PenIsVisible(IPen pen)
{
return pen?.Brush != null && pen.Thickness > 0;
}

2
src/Avalonia.Visuals/Media/GeometryDrawing.cs

@ -23,7 +23,7 @@
public static readonly StyledProperty<Pen> PenProperty =
AvaloniaProperty.Register<GeometryDrawing, Pen>(nameof(Pen));
public Pen Pen
public IPen Pen
{
get => GetValue(PenProperty);
set => SetValue(PenProperty, value);

17
src/Avalonia.Visuals/Media/IMutablePen.cs

@ -0,0 +1,17 @@
using System;
using Avalonia.Media.Immutable;
namespace Avalonia.Media
{
/// <summary>
/// Represents a mutable pen which can return an immutable clone of itself.
/// </summary>
public interface IMutablePen : IPen, IAffectsRender
{
/// <summary>
/// Creates an immutable clone of the pen.
/// </summary>
/// <returns>The immutable clone.</returns>
ImmutablePen ToImmutable();
}
}

39
src/Avalonia.Visuals/Media/IPen.cs

@ -0,0 +1,39 @@
namespace Avalonia.Media
{
/// <summary>
/// Describes how a stroke is drawn.
/// </summary>
public interface IPen
{
/// <summary>
/// Gets the brush used to draw the stroke.
/// </summary>
IBrush Brush { get; }
/// <summary>
/// Gets the style of dashed lines drawn with a <see cref="Pen"/> object.
/// </summary>
DashStyle DashStyle { get; }
/// <summary>
/// Gets the type of shape to use on both ends of a line.
/// </summary>
PenLineCap LineCap { get; }
/// <summary>
/// Gets a value describing how to join consecutive line or curve segments in a
/// <see cref="PathFigure"/> contained in a <see cref="PathGeometry"/> object.
/// </summary>
PenLineJoin LineJoin { get; }
/// <summary>
/// Gets the limit of the thickness of the join on a mitered corner.
/// </summary>
double MiterLimit { get; }
/// <summary>
/// Gets the stroke thickness.
/// </summary>
double Thickness { get; }
}
}

85
src/Avalonia.Visuals/Media/Immutable/ImmutablePen.cs

@ -0,0 +1,85 @@
// Copyright (c) The Avalonia Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
namespace Avalonia.Media.Immutable
{
/// <summary>
/// Describes how a stroke is drawn.
/// </summary>
public class ImmutablePen : IPen
{
/// <summary>
/// Initializes a new instance of the <see cref="Pen"/> class.
/// </summary>
/// <param name="color">The stroke color.</param>
/// <param name="thickness">The stroke thickness.</param>
/// <param name="dashStyle">The dash style.</param>
/// <param name="lineCap">Specifies the type of graphic shape to use on both ends of a line.</param>
/// <param name="lineJoin">The line join.</param>
/// <param name="miterLimit">The miter limit.</param>
public ImmutablePen(
uint color,
double thickness = 1.0,
DashStyle dashStyle = null,
PenLineCap lineCap = PenLineCap.Flat,
PenLineJoin lineJoin = PenLineJoin.Miter,
double miterLimit = 10.0) : this(new SolidColorBrush(color), thickness, dashStyle, lineCap, lineJoin, miterLimit)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="Pen"/> class.
/// </summary>
/// <param name="brush">The brush used to draw.</param>
/// <param name="thickness">The stroke thickness.</param>
/// <param name="dashStyle">The dash style.</param>
/// <param name="lineCap">The line cap.</param>
/// <param name="lineJoin">The line join.</param>
/// <param name="miterLimit">The miter limit.</param>
public ImmutablePen(
IBrush brush,
double thickness = 1.0,
DashStyle dashStyle = null,
PenLineCap lineCap = PenLineCap.Flat,
PenLineJoin lineJoin = PenLineJoin.Miter,
double miterLimit = 10.0)
{
Brush = brush;
Thickness = thickness;
LineCap = lineCap;
LineJoin = lineJoin;
MiterLimit = miterLimit;
DashStyle = dashStyle;
}
/// <summary>
/// Gets the brush used to draw the stroke.
/// </summary>
public IBrush Brush { get; }
/// <summary>
/// Gets the stroke thickness.
/// </summary>
public double Thickness { get; }
/// <summary>
/// Specifies the style of dashed lines drawn with a <see cref="Pen"/> object.
/// </summary>
public DashStyle DashStyle { get; }
/// <summary>
/// Specifies the type of graphic shape to use on both ends of a line.
/// </summary>
public PenLineCap LineCap { get; }
/// <summary>
/// Specifies how to join consecutive line or curve segments in a <see cref="PathFigure"/> (subpath) contained in a <see cref="PathGeometry"/> object.
/// </summary>
public PenLineJoin LineJoin { get; }
/// <summary>
/// The limit on the ratio of the miter length to half this pen's Thickness.
/// </summary>
public double MiterLimit { get; }
}
}

117
src/Avalonia.Visuals/Media/Pen.cs

@ -1,13 +1,59 @@
// Copyright (c) The Avalonia Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using System;
using Avalonia.Media.Immutable;
namespace Avalonia.Media
{
/// <summary>
/// Describes how a stroke is drawn.
/// </summary>
public class Pen
public class Pen : AvaloniaObject, IMutablePen
{
/// <summary>
/// Defines the <see cref="Brush"/> property.
/// </summary>
public static readonly StyledProperty<IBrush> BrushProperty =
AvaloniaProperty.Register<Pen, IBrush>(nameof(Brush));
/// <summary>
/// Defines the <see cref="Thickness"/> property.
/// </summary>
public static readonly StyledProperty<double> ThicknessProperty =
AvaloniaProperty.Register<Pen, double>(nameof(Thickness), 1.0);
/// <summary>
/// Defines the <see cref="DashStyle"/> property.
/// </summary>
public static readonly StyledProperty<DashStyle> DashStyleProperty =
AvaloniaProperty.Register<Pen, DashStyle>(nameof(DashStyle));
/// <summary>
/// Defines the <see cref="LineCap"/> property.
/// </summary>
public static readonly StyledProperty<PenLineCap> LineCapProperty =
AvaloniaProperty.Register<Pen, PenLineCap>(nameof(LineCap));
/// <summary>
/// Defines the <see cref="LineJoin"/> property.
/// </summary>
public static readonly StyledProperty<PenLineJoin> LineJoinProperty =
AvaloniaProperty.Register<Pen, PenLineJoin>(nameof(LineJoin));
/// <summary>
/// Defines the <see cref="MiterLimit"/> property.
/// </summary>
public static readonly StyledProperty<double> MiterLimitProperty =
AvaloniaProperty.Register<Pen, double>(nameof(MiterLimit), 10.0);
/// <summary>
/// Initializes a new instance of the <see cref="Pen"/> class.
/// </summary>
public Pen()
{
}
/// <summary>
/// Initializes a new instance of the <see cref="Pen"/> class.
/// </summary>
@ -53,33 +99,78 @@ namespace Avalonia.Media
}
/// <summary>
/// Gets the brush used to draw the stroke.
/// Gets or sets the brush used to draw the stroke.
/// </summary>
public IBrush Brush
{
get => GetValue(BrushProperty);
set => SetValue(BrushProperty, value);
}
/// <summary>
/// Gets or sets the stroke thickness.
/// </summary>
public double Thickness
{
get => GetValue(ThicknessProperty);
set => SetValue(ThicknessProperty, value);
}
/// <summary>
/// Gets or sets the style of dashed lines drawn with a <see cref="Pen"/> object.
/// </summary>
public IBrush Brush { get; }
public DashStyle DashStyle
{
get => GetValue(DashStyleProperty);
set => SetValue(DashStyleProperty, value);
}
/// <summary>
/// Gets the stroke thickness.
/// Gets or sets the type of shape to use on both ends of a line.
/// </summary>
public double Thickness { get; }
public PenLineCap LineCap
{
get => GetValue(LineCapProperty);
set => SetValue(LineCapProperty, value);
}
/// <summary>
/// Specifies the style of dashed lines drawn with a <see cref="Pen"/> object.
/// Gets or sets the join style for the ends of two consecutive lines drawn with this
/// <see cref="Pen"/>.
/// </summary>
public DashStyle DashStyle { get; }
public PenLineJoin LineJoin
{
get => GetValue(LineJoinProperty);
set => SetValue(LineJoinProperty, value);
}
/// <summary>
/// Specifies the type of graphic shape to use on both ends of a line.
/// Gets or sets the limit of the thickness of the join on a mitered corner.
/// </summary>
public PenLineCap LineCap { get; }
public double MiterLimit
{
get => GetValue(MiterLimitProperty);
set => SetValue(MiterLimitProperty, value);
}
/// <summary>
/// Specifies how to join consecutive line or curve segments in a <see cref="PathFigure"/> (subpath) contained in a <see cref="PathGeometry"/> object.
/// Raised when the pen changes.
/// </summary>
public PenLineJoin LineJoin { get; }
public event EventHandler Invalidated;
/// <summary>
/// The limit on the ratio of the miter length to half this pen's Thickness.
/// Creates an immutable clone of the brush.
/// </summary>
public double MiterLimit { get; }
/// <returns>The immutable clone.</returns>
public ImmutablePen ToImmutable()
{
return new ImmutablePen(
Brush,
Thickness,
DashStyle,
LineCap,
LineJoin,
MiterLimit);
}
}
}

6
src/Avalonia.Visuals/Platform/IDrawingContextImpl.cs

@ -50,7 +50,7 @@ namespace Avalonia.Platform
/// <param name="pen">The stroke pen.</param>
/// <param name="p1">The first point of the line.</param>
/// <param name="p2">The second point of the line.</param>
void DrawLine(Pen pen, Point p1, Point p2);
void DrawLine(IPen pen, Point p1, Point p2);
/// <summary>
/// Draws a geometry.
@ -58,7 +58,7 @@ namespace Avalonia.Platform
/// <param name="brush">The fill brush.</param>
/// <param name="pen">The stroke pen.</param>
/// <param name="geometry">The geometry.</param>
void DrawGeometry(IBrush brush, Pen pen, IGeometryImpl geometry);
void DrawGeometry(IBrush brush, IPen pen, IGeometryImpl geometry);
/// <summary>
/// Draws the outline of a rectangle.
@ -66,7 +66,7 @@ namespace Avalonia.Platform
/// <param name="pen">The pen.</param>
/// <param name="rect">The rectangle bounds.</param>
/// <param name="cornerRadius">The corner radius.</param>
void DrawRectangle(Pen pen, Rect rect, float cornerRadius = 0.0f);
void DrawRectangle(IPen pen, Rect rect, float cornerRadius = 0.0f);
/// <summary>
/// Draws text.

4
src/Avalonia.Visuals/Platform/IGeometryImpl.cs

@ -20,7 +20,7 @@ namespace Avalonia.Platform
/// </summary>
/// <param name="pen">The pen to use. May be null.</param>
/// <returns>The bounding rectangle.</returns>
Rect GetRenderBounds(Pen pen);
Rect GetRenderBounds(IPen pen);
/// <summary>
/// Indicates whether the geometry's fill contains the specified point.
@ -42,7 +42,7 @@ namespace Avalonia.Platform
/// <param name="pen">The stroke to use.</param>
/// <param name="point">The point.</param>
/// <returns><c>true</c> if the geometry contains the point; otherwise, <c>false</c>.</returns>
bool StrokeContains(Pen pen, Point point);
bool StrokeContains(IPen pen, Point point);
/// <summary>
/// Makes a clone of the geometry with the specified transform.

2
src/Avalonia.Visuals/Rendering/SceneGraph/BrushDrawOperation.cs

@ -12,7 +12,7 @@ namespace Avalonia.Rendering.SceneGraph
/// </summary>
internal abstract class BrushDrawOperation : DrawOperation
{
public BrushDrawOperation(Rect bounds, Matrix transform, Pen pen)
public BrushDrawOperation(Rect bounds, Matrix transform, IPen pen)
: base(bounds, transform, pen)
{
}

6
src/Avalonia.Visuals/Rendering/SceneGraph/DeferredDrawingContextImpl.cs

@ -100,7 +100,7 @@ namespace Avalonia.Rendering.SceneGraph
}
/// <inheritdoc/>
public void DrawGeometry(IBrush brush, Pen pen, IGeometryImpl geometry)
public void DrawGeometry(IBrush brush, IPen pen, IGeometryImpl geometry)
{
var next = NextDrawAs<GeometryNode>();
@ -137,7 +137,7 @@ namespace Avalonia.Rendering.SceneGraph
}
/// <inheritdoc/>
public void DrawLine(Pen pen, Point p1, Point p2)
public void DrawLine(IPen pen, Point p1, Point p2)
{
var next = NextDrawAs<LineNode>();
@ -152,7 +152,7 @@ namespace Avalonia.Rendering.SceneGraph
}
/// <inheritdoc/>
public void DrawRectangle(Pen pen, Rect rect, float cornerRadius = 0)
public void DrawRectangle(IPen pen, Rect rect, float cornerRadius = 0)
{
var next = NextDrawAs<RectangleNode>();

2
src/Avalonia.Visuals/Rendering/SceneGraph/DrawOperation.cs

@ -9,7 +9,7 @@ namespace Avalonia.Rendering.SceneGraph
/// </summary>
internal abstract class DrawOperation : IDrawOperation
{
public DrawOperation(Rect bounds, Matrix transform, Pen pen)
public DrawOperation(Rect bounds, Matrix transform, IPen pen)
{
bounds = bounds.Inflate((pen?.Thickness ?? 0) / 2).TransformToAABB(transform);
Bounds = new Rect(

9
src/Avalonia.Visuals/Rendering/SceneGraph/GeometryNode.cs

@ -3,6 +3,7 @@
using System.Collections.Generic;
using Avalonia.Media;
using Avalonia.Media.Immutable;
using Avalonia.Platform;
using Avalonia.VisualTree;
@ -24,7 +25,7 @@ namespace Avalonia.Rendering.SceneGraph
public GeometryNode(
Matrix transform,
IBrush brush,
Pen pen,
IPen pen,
IGeometryImpl geometry,
IDictionary<IVisual, Scene> childScenes = null)
: base(geometry.GetRenderBounds(pen), transform, null)
@ -49,7 +50,7 @@ namespace Avalonia.Rendering.SceneGraph
/// <summary>
/// Gets the stroke pen.
/// </summary>
public Pen Pen { get; }
public ImmutablePen Pen { get; }
/// <summary>
/// Gets the geometry to draw.
@ -71,11 +72,11 @@ namespace Avalonia.Rendering.SceneGraph
/// The properties of the other draw operation are passed in as arguments to prevent
/// allocation of a not-yet-constructed draw operation object.
/// </remarks>
public bool Equals(Matrix transform, IBrush brush, Pen pen, IGeometryImpl geometry)
public bool Equals(Matrix transform, IBrush brush, IPen pen, IGeometryImpl geometry)
{
return transform == Transform &&
Equals(brush, Brush) &&
pen == Pen &&
Equals(pen, Pen) &&
Equals(geometry, Geometry);
}

7
src/Avalonia.Visuals/Rendering/SceneGraph/LineNode.cs

@ -3,6 +3,7 @@
using System.Collections.Generic;
using Avalonia.Media;
using Avalonia.Media.Immutable;
using Avalonia.Platform;
using Avalonia.VisualTree;
@ -23,7 +24,7 @@ namespace Avalonia.Rendering.SceneGraph
/// <param name="childScenes">Child scenes for drawing visual brushes.</param>
public LineNode(
Matrix transform,
Pen pen,
IPen pen,
Point p1,
Point p2,
IDictionary<IVisual, Scene> childScenes = null)
@ -44,7 +45,7 @@ namespace Avalonia.Rendering.SceneGraph
/// <summary>
/// Gets the stroke pen.
/// </summary>
public Pen Pen { get; }
public ImmutablePen Pen { get; }
/// <summary>
/// Gets the start point of the line.
@ -71,7 +72,7 @@ namespace Avalonia.Rendering.SceneGraph
/// The properties of the other draw operation are passed in as arguments to prevent
/// allocation of a not-yet-constructed draw operation object.
/// </remarks>
public bool Equals(Matrix transform, Pen pen, Point p1, Point p2)
public bool Equals(Matrix transform, IPen pen, Point p1, Point p2)
{
return transform == Transform && pen == Pen && p1 == P1 && p2 == P2;
}

9
src/Avalonia.Visuals/Rendering/SceneGraph/RectangleNode.cs

@ -3,6 +3,7 @@
using System.Collections.Generic;
using Avalonia.Media;
using Avalonia.Media.Immutable;
using Avalonia.Platform;
using Avalonia.VisualTree;
@ -25,7 +26,7 @@ namespace Avalonia.Rendering.SceneGraph
public RectangleNode(
Matrix transform,
IBrush brush,
Pen pen,
IPen pen,
Rect rect,
float cornerRadius,
IDictionary<IVisual, Scene> childScenes = null)
@ -52,7 +53,7 @@ namespace Avalonia.Rendering.SceneGraph
/// <summary>
/// Gets the stroke pen.
/// </summary>
public Pen Pen { get; }
public ImmutablePen Pen { get; }
/// <summary>
/// Gets the rectangle to draw.
@ -80,11 +81,11 @@ namespace Avalonia.Rendering.SceneGraph
/// The properties of the other draw operation are passed in as arguments to prevent
/// allocation of a not-yet-constructed draw operation object.
/// </remarks>
public bool Equals(Matrix transform, IBrush brush, Pen pen, Rect rect, float cornerRadius)
public bool Equals(Matrix transform, IBrush brush, IPen pen, Rect rect, float cornerRadius)
{
return transform == Transform &&
Equals(brush, Brush) &&
pen == Pen &&
Equals(pen, Pen) &&
rect == Rect &&
cornerRadius == CornerRadius;
}

8
src/Skia/Avalonia.Skia/DrawingContextImpl.cs

@ -154,7 +154,7 @@ namespace Avalonia.Skia
}
/// <inheritdoc />
public void DrawLine(Pen pen, Point p1, Point p2)
public void DrawLine(IPen pen, Point p1, Point p2)
{
using (var paint = CreatePaint(pen, new Size(Math.Abs(p2.X - p1.X), Math.Abs(p2.Y - p1.Y))))
{
@ -163,7 +163,7 @@ namespace Avalonia.Skia
}
/// <inheritdoc />
public void DrawGeometry(IBrush brush, Pen pen, IGeometryImpl geometry)
public void DrawGeometry(IBrush brush, IPen pen, IGeometryImpl geometry)
{
var impl = (GeometryImpl) geometry;
var size = geometry.Bounds.Size;
@ -184,7 +184,7 @@ namespace Avalonia.Skia
}
/// <inheritdoc />
public void DrawRectangle(Pen pen, Rect rect, float cornerRadius = 0)
public void DrawRectangle(IPen pen, Rect rect, float cornerRadius = 0)
{
using (var paint = CreatePaint(pen, rect.Size))
{
@ -561,7 +561,7 @@ namespace Avalonia.Skia
/// <param name="pen">Source pen.</param>
/// <param name="targetSize">Target size.</param>
/// <returns></returns>
private PaintWrapper CreatePaint(Pen pen, Size targetSize)
private PaintWrapper CreatePaint(IPen pen, Size targetSize)
{
// In Skia 0 thickness means - use hairline rendering
// and for us it means - there is nothing rendered.

4
src/Skia/Avalonia.Skia/GeometryImpl.cs

@ -26,7 +26,7 @@ namespace Avalonia.Skia
}
/// <inheritdoc />
public bool StrokeContains(Pen pen, Point point)
public bool StrokeContains(IPen pen, Point point)
{
// Skia requires to compute stroke path to check for point containment.
// Due to that we are caching using stroke width.
@ -89,7 +89,7 @@ namespace Avalonia.Skia
}
/// <inheritdoc />
public Rect GetRenderBounds(Pen pen)
public Rect GetRenderBounds(IPen pen)
{
var strokeWidth = (float)(pen?.Thickness ?? 0);

6
src/Windows/Avalonia.Direct2D1/Media/DrawingContextImpl.cs

@ -174,7 +174,7 @@ namespace Avalonia.Direct2D1.Media
/// <param name="pen">The stroke pen.</param>
/// <param name="p1">The first point of the line.</param>
/// <param name="p2">The second point of the line.</param>
public void DrawLine(Pen pen, Point p1, Point p2)
public void DrawLine(IPen pen, Point p1, Point p2)
{
if (pen != null)
{
@ -202,7 +202,7 @@ namespace Avalonia.Direct2D1.Media
/// <param name="brush">The fill brush.</param>
/// <param name="pen">The stroke pen.</param>
/// <param name="geometry">The geometry.</param>
public void DrawGeometry(IBrush brush, Pen pen, IGeometryImpl geometry)
public void DrawGeometry(IBrush brush, IPen pen, IGeometryImpl geometry)
{
if (brush != null)
{
@ -236,7 +236,7 @@ namespace Avalonia.Direct2D1.Media
/// <param name="pen">The pen.</param>
/// <param name="rect">The rectangle bounds.</param>
/// <param name="cornerRadius">The corner radius.</param>
public void DrawRectangle(Pen pen, Rect rect, float cornerRadius)
public void DrawRectangle(IPen pen, Rect rect, float cornerRadius)
{
using (var brush = CreateBrush(pen.Brush, rect.Size))
using (var d2dStroke = pen.ToDirect2DStrokeStyle(_deviceContext))

4
src/Windows/Avalonia.Direct2D1/Media/GeometryImpl.cs

@ -22,7 +22,7 @@ namespace Avalonia.Direct2D1.Media
public Geometry Geometry { get; }
/// <inheritdoc/>
public Rect GetRenderBounds(Avalonia.Media.Pen pen)
public Rect GetRenderBounds(Avalonia.Media.IPen pen)
{
return Geometry.GetWidenedBounds((float)(pen?.Thickness ?? 0)).ToAvalonia();
}
@ -46,7 +46,7 @@ namespace Avalonia.Direct2D1.Media
}
/// <inheritdoc/>
public bool StrokeContains(Avalonia.Media.Pen pen, Point point)
public bool StrokeContains(Avalonia.Media.IPen pen, Point point)
{
return Geometry.StrokeContainsPoint(point.ToSharpDX(), (float)(pen?.Thickness ?? 0));
}

4
src/Windows/Avalonia.Direct2D1/PrimitiveExtensions.cs

@ -109,7 +109,7 @@ namespace Avalonia.Direct2D1
/// <param name="pen">The pen to convert.</param>
/// <param name="renderTarget">The render target.</param>
/// <returns>The Direct2D brush.</returns>
public static StrokeStyle ToDirect2DStrokeStyle(this Avalonia.Media.Pen pen, SharpDX.Direct2D1.RenderTarget renderTarget)
public static StrokeStyle ToDirect2DStrokeStyle(this Avalonia.Media.IPen pen, SharpDX.Direct2D1.RenderTarget renderTarget)
{
return pen.ToDirect2DStrokeStyle(renderTarget.Factory);
}
@ -120,7 +120,7 @@ namespace Avalonia.Direct2D1
/// <param name="pen">The pen to convert.</param>
/// <param name="factory">The factory associated with this resource.</param>
/// <returns>The Direct2D brush.</returns>
public static StrokeStyle ToDirect2DStrokeStyle(this Avalonia.Media.Pen pen, Factory factory)
public static StrokeStyle ToDirect2DStrokeStyle(this Avalonia.Media.IPen pen, Factory factory)
{
var d2dLineCap = pen.LineCap.ToDirect2D();

4
tests/Avalonia.UnitTests/MockStreamGeometryImpl.cs

@ -47,12 +47,12 @@ namespace Avalonia.UnitTests
return _context.FillContains(point);
}
public bool StrokeContains(Pen pen, Point point)
public bool StrokeContains(IPen pen, Point point)
{
return false;
}
public Rect GetRenderBounds(Pen pen) => Bounds;
public Rect GetRenderBounds(IPen pen) => Bounds;
public IGeometryImpl Intersect(IGeometryImpl geometry)
{

4
tests/Avalonia.Visuals.UnitTests/VisualTree/MockRenderInterface.cs

@ -96,7 +96,7 @@ namespace Avalonia.Visuals.UnitTests.VisualTree
return _impl.FillContains(point);
}
public Rect GetRenderBounds(Pen pen)
public Rect GetRenderBounds(IPen pen)
{
throw new NotImplementedException();
}
@ -111,7 +111,7 @@ namespace Avalonia.Visuals.UnitTests.VisualTree
return _impl;
}
public bool StrokeContains(Pen pen, Point point)
public bool StrokeContains(IPen pen, Point point)
{
throw new NotImplementedException();
}

Loading…
Cancel
Save