Browse Source
Apply Alignments to TileBrushes with uniform stretch (#15846)
* add tiled brush alignment cross tests
* apply Alignments to TileBrushes with uniform stretch
pull/15852/head
Emmanuel Hansen
2 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with
35 additions and
3 deletions
-
src/Skia/Avalonia.Skia/DrawingContextImpl.cs
-
tests/Avalonia.RenderTests/CrossTests/Brushes/CrossTileBrushTests.cs
-
BIN
tests/TestFiles/CrossTests/Media/TileBrushes/Should_Render_Aligned_TileBrush.wpf.png
|
|
|
@ -1168,10 +1168,12 @@ namespace Avalonia.Skia |
|
|
|
|
|
|
|
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 @@ namespace Avalonia.Skia |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
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); |
|
|
|
} |
|
|
|
|
|
|
|
@ -78,6 +78,36 @@ public class CrossTileBrushTests : CrossTestBase |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
[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<CrossDrawing>() |
|
|
|
{ |
|
|
|
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() |
|
|
|
{ |
|
|
|
|
Width:
|
Height:
|
Size: 393 B
|