From 34fa052bdab036525a907d339cc5fac5f3775e20 Mon Sep 17 00:00:00 2001 From: Emmanuel Hansen Date: Wed, 29 May 2024 10:33:16 +0000 Subject: [PATCH 1/2] add tiled brush alignment cross tests --- .../CrossTests/Brushes/CrossTileBrushTests.cs | 30 ++++++++++++++++++ .../Should_Render_Aligned_TileBrush.wpf.png | Bin 0 -> 393 bytes 2 files changed, 30 insertions(+) create mode 100644 tests/TestFiles/CrossTests/Media/TileBrushes/Should_Render_Aligned_TileBrush.wpf.png diff --git a/tests/Avalonia.RenderTests/CrossTests/Brushes/CrossTileBrushTests.cs b/tests/Avalonia.RenderTests/CrossTests/Brushes/CrossTileBrushTests.cs index 160aa259422..13d4930bc97 100644 --- a/tests/Avalonia.RenderTests/CrossTests/Brushes/CrossTileBrushTests.cs +++ b/tests/Avalonia.RenderTests/CrossTests/Brushes/CrossTileBrushTests.cs @@ -78,6 +78,36 @@ public void Should_Render_Scaled_TileBrush() } + [CrossFact] + public void Should_Render_Aligned_TileBrush() + { + var brush = new CrossDrawingBrush + { + TileMode = TileMode.Tile, + AlignmentX = AlignmentX.Center, + AlignmentY = AlignmentY.Center, + Stretch = Stretch.Uniform, + Drawing = new CrossDrawingGroup() + { + Children = new List() + { + new CrossGeometryDrawing(new CrossRectangleGeometry(new(0, 0, 100, 150))) + { + Brush = new CrossSolidColorBrush(Colors.Crimson) + }, + } + } + }; + + RenderAndCompare(new CrossControl() + { + Width = 100, + Height = 100, + Background = brush + }); + + } + [CrossFact] public void Should_Render_With_Transform() { diff --git a/tests/TestFiles/CrossTests/Media/TileBrushes/Should_Render_Aligned_TileBrush.wpf.png b/tests/TestFiles/CrossTests/Media/TileBrushes/Should_Render_Aligned_TileBrush.wpf.png new file mode 100644 index 0000000000000000000000000000000000000000..959613825b5b82d67807cc5eb6466196f28daf87 GIT binary patch literal 393 zcmeAS@N?(olHy`uVBq!ia0vp^DIm Date: Wed, 29 May 2024 13:22:40 +0000 Subject: [PATCH 2/2] apply Alignments to TileBrushes with uniform stretch --- src/Skia/Avalonia.Skia/DrawingContextImpl.cs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Skia/Avalonia.Skia/DrawingContextImpl.cs b/src/Skia/Avalonia.Skia/DrawingContextImpl.cs index 82c3040366a..c54643a8daa 100644 --- a/src/Skia/Avalonia.Skia/DrawingContextImpl.cs +++ b/src/Skia/Avalonia.Skia/DrawingContextImpl.cs @@ -1168,10 +1168,12 @@ private void ConfigureSceneBrushContentWithPicture(ref PaintWrapper paintWrapper brushTransform *= Matrix.CreateTranslation(-sourceRect.Position); + var scale = Vector.One; + if (sourceRect.Size != destinationRect.Size) { //scale source to destination size - var scale = tileBrush.Stretch.CalculateScaling(destinationRect.Size, sourceRect.Size); + scale = tileBrush.Stretch.CalculateScaling(destinationRect.Size, sourceRect.Size); var scaleTransform = Matrix.CreateScale(scale); @@ -1197,11 +1199,11 @@ private void ConfigureSceneBrushContentWithPicture(ref PaintWrapper paintWrapper } } - if (tileBrush.Stretch == Stretch.None && transform == Matrix.Identity) + if (tileBrush.Stretch != Stretch.Fill && transform == Matrix.Identity) { //align content var alignmentOffset = TileBrushCalculator.CalculateTranslate(tileBrush.AlignmentX, tileBrush.AlignmentY, - contentBounds, destinationRect, Vector.One); + contentBounds, destinationRect, tileBrush.Stretch == Stretch.None ? Vector.One : scale); brushTransform *= Matrix.CreateTranslation(alignmentOffset); }