Commit dd51bd53 authored by Adam Barth's avatar Adam Barth

Add the ability to color filter background images

parent 338dc618
...@@ -176,10 +176,13 @@ enum BackgroundRepeat { repeat, repeatX, repeatY, noRepeat } ...@@ -176,10 +176,13 @@ enum BackgroundRepeat { repeat, repeatX, repeatY, noRepeat }
class BackgroundImage { class BackgroundImage {
final BackgroundFit fit; final BackgroundFit fit;
final BackgroundRepeat repeat; final BackgroundRepeat repeat;
final sky.ColorFilter colorFilter;
BackgroundImage({ BackgroundImage({
Future<sky.Image> image, Future<sky.Image> image,
this.fit: BackgroundFit.scaleDown, this.fit: BackgroundFit.scaleDown,
this.repeat: BackgroundRepeat.noRepeat this.repeat: BackgroundRepeat.noRepeat,
this.colorFilter
}) { }) {
image.then((resolvedImage) { image.then((resolvedImage) {
if (resolvedImage == null) if (resolvedImage == null)
...@@ -365,15 +368,16 @@ class BoxPainter { ...@@ -365,15 +368,16 @@ class BoxPainter {
} }
void _paintBackgroundImage(sky.Canvas canvas, Rect rect) { void _paintBackgroundImage(sky.Canvas canvas, Rect rect) {
if (_decoration.backgroundImage == null) final BackgroundImage backgroundImage = _decoration.backgroundImage;
if (backgroundImage == null)
return; return;
sky.Image image = _decoration.backgroundImage.image; sky.Image image = backgroundImage.image;
if (image != null) { if (image != null) {
Size bounds = rect.size; Size bounds = rect.size;
Size imageSize = _decoration.backgroundImage._size; Size imageSize = backgroundImage._size;
Size src; Size src;
Size dst; Size dst;
switch(_decoration.backgroundImage.fit) { switch(backgroundImage.fit) {
case BackgroundFit.fill: case BackgroundFit.fill:
src = imageSize; src = imageSize;
dst = bounds; dst = bounds;
...@@ -410,7 +414,10 @@ class BoxPainter { ...@@ -410,7 +414,10 @@ class BoxPainter {
} }
break; 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);
} }
} }
......
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