Skip to content

Commit

Permalink
Merge pull request AvaloniaUI#8245 from Whiletru3/stable/0.10.x
Browse files Browse the repository at this point in the history
Use own Pen (if set) in GeometryDrawing.GetBounds
  • Loading branch information
maxkatz6 authored Jun 12, 2022
2 parents 82d55a1 + b446f21 commit 277d94c
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/Avalonia.Visuals/Media/GeometryDrawing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ public override void Draw(DrawingContext context)

public override Rect GetBounds()
{
return Geometry?.GetRenderBounds(s_boundsPen) ?? Rect.Empty;
IPen pen = Pen ?? s_boundsPen;
return Geometry?.GetRenderBounds(pen) ?? Rect.Empty;
}
}
}
52 changes: 52 additions & 0 deletions tests/Avalonia.RenderTests/Media/GeometryDrawingTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using Avalonia.Media;
using Xunit;

#if AVALONIA_SKIA
namespace Avalonia.Skia.RenderTests
#else

using Avalonia.Direct2D1.RenderTests;

namespace Avalonia.Direct2D1.RenderTests.Media
#endif
{
public class GeometryDrawingTests : TestBase
{
public GeometryDrawingTests()
: base(@"Media\GeometryDrawing")
{
}

private GeometryDrawing CreateGeometryDrawing()
{
GeometryDrawing geometryDrawing = new GeometryDrawing();
EllipseGeometry ellipse = new EllipseGeometry();
ellipse.RadiusX = 100;
ellipse.RadiusY = 100;
geometryDrawing.Geometry = ellipse;
return geometryDrawing;
}

[Fact]
public void DrawingGeometry_WithPen()
{
GeometryDrawing geometryDrawing = CreateGeometryDrawing();
geometryDrawing.Pen = new Pen(new SolidColorBrush(Color.FromArgb(255, 0, 0, 0)), 10);

Assert.Equal(210, geometryDrawing.GetBounds().Height);
Assert.Equal(210, geometryDrawing.GetBounds().Width);

}

[Fact]
public void DrawingGeometry_WithoutPen()
{
GeometryDrawing geometryDrawing = CreateGeometryDrawing();

Assert.Equal(200, geometryDrawing.GetBounds().Height);
Assert.Equal(200, geometryDrawing.GetBounds().Width);
}


}
}

0 comments on commit 277d94c

Please sign in to comment.