diff --git a/src/Avalonia.Visuals/Media/BrushExtensions.cs b/src/Avalonia.Visuals/Media/BrushExtensions.cs index 522953eb04..081029e205 100644 --- a/src/Avalonia.Visuals/Media/BrushExtensions.cs +++ b/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 if the pen's brush /// is already immutable or null. /// - public static Pen ToImmutable(this Pen pen) + public static ImmutablePen ToImmutable(this IPen pen) { Contract.Requires(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(); } } } diff --git a/src/Avalonia.Visuals/Media/DrawingContext.cs b/src/Avalonia.Visuals/Media/DrawingContext.cs index d3af71ffcb..4c9bf9ebd4 100644 --- a/src/Avalonia.Visuals/Media/DrawingContext.cs +++ b/src/Avalonia.Visuals/Media/DrawingContext.cs @@ -94,7 +94,7 @@ namespace Avalonia.Media /// The stroke pen. /// The first point of the line. /// The second point of the line. - 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 /// The fill brush. /// The stroke pen. /// The geometry. - public void DrawGeometry(IBrush brush, Pen pen, Geometry geometry) + public void DrawGeometry(IBrush brush, IPen pen, Geometry geometry) { Contract.Requires(geometry != null); @@ -124,7 +124,7 @@ namespace Avalonia.Media /// The pen. /// The rectangle bounds. /// The corner radius. - 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; } diff --git a/src/Avalonia.Visuals/Media/GeometryDrawing.cs b/src/Avalonia.Visuals/Media/GeometryDrawing.cs index ac0cc1c17d..3dad10fb8f 100644 --- a/src/Avalonia.Visuals/Media/GeometryDrawing.cs +++ b/src/Avalonia.Visuals/Media/GeometryDrawing.cs @@ -23,7 +23,7 @@ public static readonly StyledProperty PenProperty = AvaloniaProperty.Register(nameof(Pen)); - public Pen Pen + public IPen Pen { get => GetValue(PenProperty); set => SetValue(PenProperty, value); diff --git a/src/Avalonia.Visuals/Media/IMutablePen.cs b/src/Avalonia.Visuals/Media/IMutablePen.cs new file mode 100644 index 0000000000..8b02929dec --- /dev/null +++ b/src/Avalonia.Visuals/Media/IMutablePen.cs @@ -0,0 +1,17 @@ +using System; +using Avalonia.Media.Immutable; + +namespace Avalonia.Media +{ + /// + /// Represents a mutable pen which can return an immutable clone of itself. + /// + public interface IMutablePen : IPen, IAffectsRender + { + /// + /// Creates an immutable clone of the pen. + /// + /// The immutable clone. + ImmutablePen ToImmutable(); + } +} diff --git a/src/Avalonia.Visuals/Media/IPen.cs b/src/Avalonia.Visuals/Media/IPen.cs new file mode 100644 index 0000000000..589595bb5c --- /dev/null +++ b/src/Avalonia.Visuals/Media/IPen.cs @@ -0,0 +1,39 @@ +namespace Avalonia.Media +{ + /// + /// Describes how a stroke is drawn. + /// + public interface IPen + { + /// + /// Gets the brush used to draw the stroke. + /// + IBrush Brush { get; } + + /// + /// Gets the style of dashed lines drawn with a object. + /// + DashStyle DashStyle { get; } + + /// + /// Gets the type of shape to use on both ends of a line. + /// + PenLineCap LineCap { get; } + + /// + /// Gets a value describing how to join consecutive line or curve segments in a + /// contained in a object. + /// + PenLineJoin LineJoin { get; } + + /// + /// Gets the limit of the thickness of the join on a mitered corner. + /// + double MiterLimit { get; } + + /// + /// Gets the stroke thickness. + /// + double Thickness { get; } + } +} diff --git a/src/Avalonia.Visuals/Media/Immutable/ImmutablePen.cs b/src/Avalonia.Visuals/Media/Immutable/ImmutablePen.cs new file mode 100644 index 0000000000..bcfec5dccf --- /dev/null +++ b/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 +{ + /// + /// Describes how a stroke is drawn. + /// + public class ImmutablePen : IPen + { + /// + /// Initializes a new instance of the class. + /// + /// The stroke color. + /// The stroke thickness. + /// The dash style. + /// Specifies the type of graphic shape to use on both ends of a line. + /// The line join. + /// The miter limit. + 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) + { + } + + /// + /// Initializes a new instance of the class. + /// + /// The brush used to draw. + /// The stroke thickness. + /// The dash style. + /// The line cap. + /// The line join. + /// The miter limit. + 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; + } + + /// + /// Gets the brush used to draw the stroke. + /// + public IBrush Brush { get; } + + /// + /// Gets the stroke thickness. + /// + public double Thickness { get; } + + /// + /// Specifies the style of dashed lines drawn with a object. + /// + public DashStyle DashStyle { get; } + + /// + /// Specifies the type of graphic shape to use on both ends of a line. + /// + public PenLineCap LineCap { get; } + + /// + /// Specifies how to join consecutive line or curve segments in a (subpath) contained in a object. + /// + public PenLineJoin LineJoin { get; } + + /// + /// The limit on the ratio of the miter length to half this pen's Thickness. + /// + public double MiterLimit { get; } + } +} diff --git a/src/Avalonia.Visuals/Media/Pen.cs b/src/Avalonia.Visuals/Media/Pen.cs index ee427c913b..2bfd4f472e 100644 --- a/src/Avalonia.Visuals/Media/Pen.cs +++ b/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 { /// /// Describes how a stroke is drawn. /// - public class Pen + public class Pen : AvaloniaObject, IMutablePen { + /// + /// Defines the property. + /// + public static readonly StyledProperty BrushProperty = + AvaloniaProperty.Register(nameof(Brush)); + + /// + /// Defines the property. + /// + public static readonly StyledProperty ThicknessProperty = + AvaloniaProperty.Register(nameof(Thickness), 1.0); + + /// + /// Defines the property. + /// + public static readonly StyledProperty DashStyleProperty = + AvaloniaProperty.Register(nameof(DashStyle)); + + /// + /// Defines the property. + /// + public static readonly StyledProperty LineCapProperty = + AvaloniaProperty.Register(nameof(LineCap)); + + /// + /// Defines the property. + /// + public static readonly StyledProperty LineJoinProperty = + AvaloniaProperty.Register(nameof(LineJoin)); + + /// + /// Defines the property. + /// + public static readonly StyledProperty MiterLimitProperty = + AvaloniaProperty.Register(nameof(MiterLimit), 10.0); + + /// + /// Initializes a new instance of the class. + /// + public Pen() + { + } + /// /// Initializes a new instance of the class. /// @@ -53,33 +99,78 @@ namespace Avalonia.Media } /// - /// Gets the brush used to draw the stroke. + /// Gets or sets the brush used to draw the stroke. + /// + public IBrush Brush + { + get => GetValue(BrushProperty); + set => SetValue(BrushProperty, value); + } + + /// + /// Gets or sets the stroke thickness. + /// + public double Thickness + { + get => GetValue(ThicknessProperty); + set => SetValue(ThicknessProperty, value); + } + + /// + /// Gets or sets the style of dashed lines drawn with a object. /// - public IBrush Brush { get; } + public DashStyle DashStyle + { + get => GetValue(DashStyleProperty); + set => SetValue(DashStyleProperty, value); + } /// - /// Gets the stroke thickness. + /// Gets or sets the type of shape to use on both ends of a line. /// - public double Thickness { get; } + public PenLineCap LineCap + { + get => GetValue(LineCapProperty); + set => SetValue(LineCapProperty, value); + } /// - /// Specifies the style of dashed lines drawn with a object. + /// Gets or sets the join style for the ends of two consecutive lines drawn with this + /// . /// - public DashStyle DashStyle { get; } + public PenLineJoin LineJoin + { + get => GetValue(LineJoinProperty); + set => SetValue(LineJoinProperty, value); + } /// - /// 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. /// - public PenLineCap LineCap { get; } + public double MiterLimit + { + get => GetValue(MiterLimitProperty); + set => SetValue(MiterLimitProperty, value); + } /// - /// Specifies how to join consecutive line or curve segments in a (subpath) contained in a object. + /// Raised when the pen changes. /// - public PenLineJoin LineJoin { get; } + public event EventHandler Invalidated; /// - /// The limit on the ratio of the miter length to half this pen's Thickness. + /// Creates an immutable clone of the brush. /// - public double MiterLimit { get; } + /// The immutable clone. + public ImmutablePen ToImmutable() + { + return new ImmutablePen( + Brush, + Thickness, + DashStyle, + LineCap, + LineJoin, + MiterLimit); + } } } diff --git a/src/Avalonia.Visuals/Platform/IDrawingContextImpl.cs b/src/Avalonia.Visuals/Platform/IDrawingContextImpl.cs index e5be04ebf9..f74c551fe0 100644 --- a/src/Avalonia.Visuals/Platform/IDrawingContextImpl.cs +++ b/src/Avalonia.Visuals/Platform/IDrawingContextImpl.cs @@ -50,7 +50,7 @@ namespace Avalonia.Platform /// The stroke pen. /// The first point of the line. /// The second point of the line. - void DrawLine(Pen pen, Point p1, Point p2); + void DrawLine(IPen pen, Point p1, Point p2); /// /// Draws a geometry. @@ -58,7 +58,7 @@ namespace Avalonia.Platform /// The fill brush. /// The stroke pen. /// The geometry. - void DrawGeometry(IBrush brush, Pen pen, IGeometryImpl geometry); + void DrawGeometry(IBrush brush, IPen pen, IGeometryImpl geometry); /// /// Draws the outline of a rectangle. @@ -66,7 +66,7 @@ namespace Avalonia.Platform /// The pen. /// The rectangle bounds. /// The corner radius. - void DrawRectangle(Pen pen, Rect rect, float cornerRadius = 0.0f); + void DrawRectangle(IPen pen, Rect rect, float cornerRadius = 0.0f); /// /// Draws text. diff --git a/src/Avalonia.Visuals/Platform/IGeometryImpl.cs b/src/Avalonia.Visuals/Platform/IGeometryImpl.cs index 4e8e6521bd..b762859d1d 100644 --- a/src/Avalonia.Visuals/Platform/IGeometryImpl.cs +++ b/src/Avalonia.Visuals/Platform/IGeometryImpl.cs @@ -20,7 +20,7 @@ namespace Avalonia.Platform /// /// The pen to use. May be null. /// The bounding rectangle. - Rect GetRenderBounds(Pen pen); + Rect GetRenderBounds(IPen pen); /// /// Indicates whether the geometry's fill contains the specified point. @@ -42,7 +42,7 @@ namespace Avalonia.Platform /// The stroke to use. /// The point. /// true if the geometry contains the point; otherwise, false. - bool StrokeContains(Pen pen, Point point); + bool StrokeContains(IPen pen, Point point); /// /// Makes a clone of the geometry with the specified transform. diff --git a/src/Avalonia.Visuals/Rendering/SceneGraph/BrushDrawOperation.cs b/src/Avalonia.Visuals/Rendering/SceneGraph/BrushDrawOperation.cs index 4c09dc2ddd..b2c0581388 100644 --- a/src/Avalonia.Visuals/Rendering/SceneGraph/BrushDrawOperation.cs +++ b/src/Avalonia.Visuals/Rendering/SceneGraph/BrushDrawOperation.cs @@ -12,7 +12,7 @@ namespace Avalonia.Rendering.SceneGraph /// 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) { } diff --git a/src/Avalonia.Visuals/Rendering/SceneGraph/DeferredDrawingContextImpl.cs b/src/Avalonia.Visuals/Rendering/SceneGraph/DeferredDrawingContextImpl.cs index 0b33851911..3af56f5215 100644 --- a/src/Avalonia.Visuals/Rendering/SceneGraph/DeferredDrawingContextImpl.cs +++ b/src/Avalonia.Visuals/Rendering/SceneGraph/DeferredDrawingContextImpl.cs @@ -100,7 +100,7 @@ namespace Avalonia.Rendering.SceneGraph } /// - public void DrawGeometry(IBrush brush, Pen pen, IGeometryImpl geometry) + public void DrawGeometry(IBrush brush, IPen pen, IGeometryImpl geometry) { var next = NextDrawAs(); @@ -137,7 +137,7 @@ namespace Avalonia.Rendering.SceneGraph } /// - public void DrawLine(Pen pen, Point p1, Point p2) + public void DrawLine(IPen pen, Point p1, Point p2) { var next = NextDrawAs(); @@ -152,7 +152,7 @@ namespace Avalonia.Rendering.SceneGraph } /// - public void DrawRectangle(Pen pen, Rect rect, float cornerRadius = 0) + public void DrawRectangle(IPen pen, Rect rect, float cornerRadius = 0) { var next = NextDrawAs(); diff --git a/src/Avalonia.Visuals/Rendering/SceneGraph/DrawOperation.cs b/src/Avalonia.Visuals/Rendering/SceneGraph/DrawOperation.cs index 1a5a6fad3f..d9dfd8bd55 100644 --- a/src/Avalonia.Visuals/Rendering/SceneGraph/DrawOperation.cs +++ b/src/Avalonia.Visuals/Rendering/SceneGraph/DrawOperation.cs @@ -9,7 +9,7 @@ namespace Avalonia.Rendering.SceneGraph /// 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( diff --git a/src/Avalonia.Visuals/Rendering/SceneGraph/GeometryNode.cs b/src/Avalonia.Visuals/Rendering/SceneGraph/GeometryNode.cs index 2d01b117d9..0940533070 100644 --- a/src/Avalonia.Visuals/Rendering/SceneGraph/GeometryNode.cs +++ b/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 childScenes = null) : base(geometry.GetRenderBounds(pen), transform, null) @@ -49,7 +50,7 @@ namespace Avalonia.Rendering.SceneGraph /// /// Gets the stroke pen. /// - public Pen Pen { get; } + public ImmutablePen Pen { get; } /// /// 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. /// - 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); } diff --git a/src/Avalonia.Visuals/Rendering/SceneGraph/LineNode.cs b/src/Avalonia.Visuals/Rendering/SceneGraph/LineNode.cs index 11c763fcc9..0781a233f7 100644 --- a/src/Avalonia.Visuals/Rendering/SceneGraph/LineNode.cs +++ b/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 /// Child scenes for drawing visual brushes. public LineNode( Matrix transform, - Pen pen, + IPen pen, Point p1, Point p2, IDictionary childScenes = null) @@ -44,7 +45,7 @@ namespace Avalonia.Rendering.SceneGraph /// /// Gets the stroke pen. /// - public Pen Pen { get; } + public ImmutablePen Pen { get; } /// /// 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. /// - 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; } diff --git a/src/Avalonia.Visuals/Rendering/SceneGraph/RectangleNode.cs b/src/Avalonia.Visuals/Rendering/SceneGraph/RectangleNode.cs index c622dc8a43..a10364e9ba 100644 --- a/src/Avalonia.Visuals/Rendering/SceneGraph/RectangleNode.cs +++ b/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 childScenes = null) @@ -52,7 +53,7 @@ namespace Avalonia.Rendering.SceneGraph /// /// Gets the stroke pen. /// - public Pen Pen { get; } + public ImmutablePen Pen { get; } /// /// 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. /// - 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; } diff --git a/src/Skia/Avalonia.Skia/DrawingContextImpl.cs b/src/Skia/Avalonia.Skia/DrawingContextImpl.cs index 262d87d8b6..47e651ce91 100644 --- a/src/Skia/Avalonia.Skia/DrawingContextImpl.cs +++ b/src/Skia/Avalonia.Skia/DrawingContextImpl.cs @@ -154,7 +154,7 @@ namespace Avalonia.Skia } /// - 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 } /// - 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 } /// - 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 /// Source pen. /// Target size. /// - 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. diff --git a/src/Skia/Avalonia.Skia/GeometryImpl.cs b/src/Skia/Avalonia.Skia/GeometryImpl.cs index 5940de418e..23980fb913 100644 --- a/src/Skia/Avalonia.Skia/GeometryImpl.cs +++ b/src/Skia/Avalonia.Skia/GeometryImpl.cs @@ -26,7 +26,7 @@ namespace Avalonia.Skia } /// - 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 } /// - public Rect GetRenderBounds(Pen pen) + public Rect GetRenderBounds(IPen pen) { var strokeWidth = (float)(pen?.Thickness ?? 0); diff --git a/src/Windows/Avalonia.Direct2D1/Media/DrawingContextImpl.cs b/src/Windows/Avalonia.Direct2D1/Media/DrawingContextImpl.cs index e90d444c44..39d801eb2f 100644 --- a/src/Windows/Avalonia.Direct2D1/Media/DrawingContextImpl.cs +++ b/src/Windows/Avalonia.Direct2D1/Media/DrawingContextImpl.cs @@ -174,7 +174,7 @@ namespace Avalonia.Direct2D1.Media /// The stroke pen. /// The first point of the line. /// The second point of the line. - 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 /// The fill brush. /// The stroke pen. /// The geometry. - 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 /// The pen. /// The rectangle bounds. /// The corner radius. - 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)) diff --git a/src/Windows/Avalonia.Direct2D1/Media/GeometryImpl.cs b/src/Windows/Avalonia.Direct2D1/Media/GeometryImpl.cs index 7c8ddaca3f..51ca2520ad 100644 --- a/src/Windows/Avalonia.Direct2D1/Media/GeometryImpl.cs +++ b/src/Windows/Avalonia.Direct2D1/Media/GeometryImpl.cs @@ -22,7 +22,7 @@ namespace Avalonia.Direct2D1.Media public Geometry Geometry { get; } /// - 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 } /// - 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)); } diff --git a/src/Windows/Avalonia.Direct2D1/PrimitiveExtensions.cs b/src/Windows/Avalonia.Direct2D1/PrimitiveExtensions.cs index 6b0d30f250..065895859d 100644 --- a/src/Windows/Avalonia.Direct2D1/PrimitiveExtensions.cs +++ b/src/Windows/Avalonia.Direct2D1/PrimitiveExtensions.cs @@ -109,7 +109,7 @@ namespace Avalonia.Direct2D1 /// The pen to convert. /// The render target. /// The Direct2D brush. - 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 /// The pen to convert. /// The factory associated with this resource. /// The Direct2D brush. - 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(); diff --git a/tests/Avalonia.UnitTests/MockStreamGeometryImpl.cs b/tests/Avalonia.UnitTests/MockStreamGeometryImpl.cs index 63da9ed3f0..4fa3fbf523 100644 --- a/tests/Avalonia.UnitTests/MockStreamGeometryImpl.cs +++ b/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) { diff --git a/tests/Avalonia.Visuals.UnitTests/VisualTree/MockRenderInterface.cs b/tests/Avalonia.Visuals.UnitTests/VisualTree/MockRenderInterface.cs index 03470670d2..d31210bc71 100644 --- a/tests/Avalonia.Visuals.UnitTests/VisualTree/MockRenderInterface.cs +++ b/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(); }