Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply Alignments to TileBrushes with uniform stretch #15846

Merged
merged 2 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/Skia/Avalonia.Skia/DrawingContextImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<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()
{
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading