Commit 5bb598ad authored by Adam Barth's avatar Adam Barth

Merge pull request #767 from abarth/clip_image_repeat

Repeated background images should be clipped to the container
parents 3419b3e4 e46f4807
...@@ -669,6 +669,11 @@ void paintImage({ ...@@ -669,6 +669,11 @@ void paintImage({
// as we apply a nine-patch stretch. // as we apply a nine-patch stretch.
assert(sourceSize == inputSize); assert(sourceSize == inputSize);
} }
if (repeat != ImageRepeat.noRepeat && destinationSize == outputSize) {
// There's no need to repeat the image because we're exactly filling the
// output rect with the image.
repeat = ImageRepeat.noRepeat;
}
Paint paint = new Paint()..isAntiAlias = false; Paint paint = new Paint()..isAntiAlias = false;
if (colorFilter != null) if (colorFilter != null)
paint.colorFilter = colorFilter; paint.colorFilter = colorFilter;
...@@ -676,6 +681,10 @@ void paintImage({ ...@@ -676,6 +681,10 @@ void paintImage({
double dy = (outputSize.height - destinationSize.height) * (alignY ?? 0.5); double dy = (outputSize.height - destinationSize.height) * (alignY ?? 0.5);
Point destinationPosition = rect.topLeft + new Offset(dx, dy); Point destinationPosition = rect.topLeft + new Offset(dx, dy);
Rect destinationRect = destinationPosition & destinationSize; Rect destinationRect = destinationPosition & destinationSize;
if (repeat != ImageRepeat.noRepeat) {
canvas.save();
canvas.clipRect(rect);
}
if (centerSlice == null) { if (centerSlice == null) {
Rect sourceRect = Point.origin & sourceSize; Rect sourceRect = Point.origin & sourceSize;
for (Rect tileRect in _generateImageTileRects(rect, destinationRect, repeat)) for (Rect tileRect in _generateImageTileRects(rect, destinationRect, repeat))
...@@ -684,6 +693,8 @@ void paintImage({ ...@@ -684,6 +693,8 @@ void paintImage({
for (Rect tileRect in _generateImageTileRects(rect, destinationRect, repeat)) for (Rect tileRect in _generateImageTileRects(rect, destinationRect, repeat))
canvas.drawImageNine(image, centerSlice, tileRect, paint); canvas.drawImageNine(image, centerSlice, tileRect, paint);
} }
if (repeat != ImageRepeat.noRepeat)
canvas.restore();
} }
/// A background image for a box. /// A background image for a box.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment