From dd51bd53268fc7aba5c45bafe749fedc0144a9c7 Mon Sep 17 00:00:00 2001 From: Adam Barth Date: Mon, 10 Aug 2015 13:30:52 -0700 Subject: [PATCH] Add the ability to color filter background images --- .../flutter/lib/painting/box_painter.dart | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/packages/flutter/lib/painting/box_painter.dart b/packages/flutter/lib/painting/box_painter.dart index 1bec305d84..a600b86c44 100644 --- a/packages/flutter/lib/painting/box_painter.dart +++ b/packages/flutter/lib/painting/box_painter.dart @@ -176,10 +176,13 @@ enum BackgroundRepeat { repeat, repeatX, repeatY, noRepeat } class BackgroundImage { final BackgroundFit fit; final BackgroundRepeat repeat; + final sky.ColorFilter colorFilter; + BackgroundImage({ Future image, this.fit: BackgroundFit.scaleDown, - this.repeat: BackgroundRepeat.noRepeat + this.repeat: BackgroundRepeat.noRepeat, + this.colorFilter }) { image.then((resolvedImage) { if (resolvedImage == null) @@ -365,15 +368,16 @@ class BoxPainter { } void _paintBackgroundImage(sky.Canvas canvas, Rect rect) { - if (_decoration.backgroundImage == null) + final BackgroundImage backgroundImage = _decoration.backgroundImage; + if (backgroundImage == null) return; - sky.Image image = _decoration.backgroundImage.image; + sky.Image image = backgroundImage.image; if (image != null) { Size bounds = rect.size; - Size imageSize = _decoration.backgroundImage._size; + Size imageSize = backgroundImage._size; Size src; Size dst; - switch(_decoration.backgroundImage.fit) { + switch(backgroundImage.fit) { case BackgroundFit.fill: src = imageSize; dst = bounds; @@ -410,7 +414,10 @@ class BoxPainter { } break; } - canvas.drawImageRect(image, Point.origin & src, rect.topLeft & dst, new Paint()); + Paint paint = new Paint(); + if (backgroundImage.colorFilter != null) + paint.setColorFilter(backgroundImage.colorFilter); + canvas.drawImageRect(image, Point.origin & src, rect.topLeft & dst, paint); } }