diff --git a/engine/core/painting/CanvasGradient.cpp b/engine/core/painting/CanvasGradient.cpp index b1d8cf1f7447177ae99ec6a3a5d253a3b4e1c66d..5ceaae149883336a51b08da8a9d848fff4b6b101 100644 --- a/engine/core/painting/CanvasGradient.cpp +++ b/engine/core/painting/CanvasGradient.cpp @@ -13,9 +13,11 @@ PassRefPtr CanvasGradient::create() { void CanvasGradient::initLinear(const Vector& end_points, const Vector& colors, - const Vector& color_stops) { + const Vector& color_stops, + unsigned tile_mode) { ASSERT(end_points.size() == 2); ASSERT(colors.size() == color_stops.size() || color_stops.data() == nullptr); + ASSERT(tile_mode < SkShader::kTileModeCount); SkPoint sk_end_points[2]; for (int i = 0; i < 2; ++i) sk_end_points[i] = end_points[i].sk_point; @@ -23,19 +25,21 @@ void CanvasGradient::initLinear(const Vector& end_points, // TODO(mpcomplete): allow setting the TileMode. SkShader* shader = SkGradientShader::CreateLinear( sk_end_points, colors.data(), color_stops.data(), colors.size(), - SkShader::kClamp_TileMode); + static_cast(tile_mode)); set_shader(adoptRef(shader)); } void CanvasGradient::initRadial(const Point& center, double radius, const Vector& colors, - const Vector& color_stops) { + const Vector& color_stops, + unsigned tile_mode) { ASSERT(colors.size() == color_stops.size() || color_stops.data() == nullptr); + ASSERT(tile_mode < SkShader::kTileModeCount); SkShader* shader = SkGradientShader::CreateRadial( center.sk_point, radius, colors.data(), color_stops.data(), colors.size(), - SkShader::kClamp_TileMode); + static_cast(tile_mode)); set_shader(adoptRef(shader)); } diff --git a/engine/core/painting/CanvasGradient.h b/engine/core/painting/CanvasGradient.h index fed61ec3d7cd2efa943c099bac65bcdb21678777..8779eaa72aca3c16a5f4642a7f74f9ba003e1061 100644 --- a/engine/core/painting/CanvasGradient.h +++ b/engine/core/painting/CanvasGradient.h @@ -21,11 +21,13 @@ class CanvasGradient : public Shader { void initLinear(const Vector& end_points, const Vector& colors, - const Vector& color_stops); + const Vector& color_stops, + unsigned tile_mode); void initRadial(const Point& center, double radius, const Vector& colors, - const Vector& color_stops); + const Vector& color_stops, + unsigned tile_mode); private: CanvasGradient(); diff --git a/engine/core/painting/Gradient.dart b/engine/core/painting/Gradient.dart index 58381812fd72f42ef6709daa89458fcfab11d5eb..6eb199b8b340ef126b6fcde7eb710a8612cd23d3 100644 --- a/engine/core/painting/Gradient.dart +++ b/engine/core/painting/Gradient.dart @@ -4,26 +4,34 @@ part of dart.sky; +enum TileMode { + clamp, + repeated, + mirror +} + // Extends the generated _Gradient interface via the PrivateDart attribute. class Gradient extends _Gradient { // TODO(mpcomplete): Maybe pass a list of (color, colorStop) pairs instead? Gradient.Linear(List endPoints, List colors, - List colorStops) + List colorStops, + [TileMode tileMode = TileMode.clamp]) : super() { if (endPoints == null || endPoints.length != 2) throw new ArgumentError("Expected exactly 2 [endPoints]."); validateColorStops(colors, colorStops); - this._initLinear(endPoints, colors, colorStops); + this._initLinear(endPoints, colors, colorStops, tileMode.index); } Gradient.Radial(Point center, double radius, List colors, - List colorStops) + List colorStops, + [TileMode tileMode = TileMode.clamp]) : super() { validateColorStops(colors, colorStops); - this._initRadial(center, radius, colors, colorStops); + this._initRadial(center, radius, colors, colorStops, tileMode.index); } void validateColorStops(List colors, List colorStops) { diff --git a/engine/core/painting/Gradient.idl b/engine/core/painting/Gradient.idl index 84e1f822451a76b2de0876d0905ba0797f5a0c53..343d6e18987011b1a04619acfdee82e5c68d9638 100644 --- a/engine/core/painting/Gradient.idl +++ b/engine/core/painting/Gradient.idl @@ -7,7 +7,8 @@ PrivateDart, Constructor() ] interface Gradient : Shader { - void initLinear(Point[] endPoints, Color[] colors, float[] colorStops); + void initLinear(Point[] endPoints, Color[] colors, float[] colorStops, + /*TileMode*/unsigned long tileMode); void initRadial(Point center, double radius, Color[] colors, - float[] colorStops); + float[] colorStops, /*TileMode*/unsigned long tileMode); }; diff --git a/examples/raw/painting.sky b/examples/raw/painting.sky index 9e2b84079c6bedd82f860365d5606a5d900cff62..feb702c813ab54b8542f851eb6a4fe969f3161df 100644 --- a/examples/raw/painting.sky +++ b/examples/raw/painting.sky @@ -68,9 +68,9 @@ void main() { ..setPaintBits(-1), (Paint layerPaint) { Gradient redYellow = new Gradient.Radial( - new Point(0.0, 0.0), radius, + new Point(0.0, 0.0), radius/3.0, [const Color(0xFFFFFF00), const Color(0xFFFF0000)], - null); + null, TileMode.mirror); layerPaint.setShader(redYellow); }) ..addLayerOnTop(