| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 part of dart.sky; | 5 part of dart.sky; |
| 6 | 6 |
| 7 /// Defines what happens at the edge of the gradient. |
| 7 enum TileMode { | 8 enum TileMode { |
| 9 /// Edge is clamped to the final color. |
| 8 clamp, | 10 clamp, |
| 11 /// Edge is repeated from first color to last. |
| 9 repeated, | 12 repeated, |
| 13 /// Edge is mirrored from last color to first. |
| 10 mirror | 14 mirror |
| 11 } | 15 } |
| 12 | 16 |
| 13 // Extends the generated _Gradient interface via the PrivateDart attribute. | 17 /// Extends the generated _Gradient interface via the PrivateDart attribute. |
| 14 class Gradient extends _Gradient { | 18 class Gradient extends _Gradient { |
| 19 /// Creates a linear gradient from [endPoint[0]] to [endPoint[1]]. If |
| 20 /// [colorStops] is provided, [colorStops[i]] is a number from 0 to 1 that |
| 21 /// specifies where [color[i]] begins in the gradient. |
| 15 // TODO(mpcomplete): Maybe pass a list of (color, colorStop) pairs instead? | 22 // TODO(mpcomplete): Maybe pass a list of (color, colorStop) pairs instead? |
| 16 Gradient.Linear(List<Point> endPoints, | 23 Gradient.linear(List<Point> endPoints, |
| 17 List<Color> colors, | 24 List<Color> colors, |
| 18 List<double> colorStops, | 25 [List<double> colorStops = null, |
| 19 [TileMode tileMode = TileMode.clamp]) | 26 TileMode tileMode = TileMode.clamp]) |
| 20 : super() { | 27 : super() { |
| 21 if (endPoints == null || endPoints.length != 2) | 28 if (endPoints == null || endPoints.length != 2) |
| 22 throw new ArgumentError("Expected exactly 2 [endPoints]."); | 29 throw new ArgumentError("Expected exactly 2 [endPoints]."); |
| 23 validateColorStops(colors, colorStops); | 30 validateColorStops(colors, colorStops); |
| 24 this._initLinear(endPoints, colors, colorStops, tileMode); | 31 this._initLinear(endPoints, colors, colorStops, tileMode); |
| 25 } | 32 } |
| 26 | 33 |
| 27 Gradient.Radial(Point center, | 34 /// Creates a radial gradient centered at [center] that ends at [radius] |
| 35 /// distance from the center. If [colorStops] is provided, [colorStops[i]] is |
| 36 /// a number from 0 to 1 that specifies where [color[i]] begins in the |
| 37 /// gradient. |
| 38 Gradient.radial(Point center, |
| 28 double radius, | 39 double radius, |
| 29 List<Color> colors, | 40 List<Color> colors, |
| 30 List<double> colorStops, | 41 [List<double> colorStops = null, |
| 31 [TileMode tileMode = TileMode.clamp]) | 42 TileMode tileMode = TileMode.clamp]) |
| 32 : super() { | 43 : super() { |
| 33 validateColorStops(colors, colorStops); | 44 validateColorStops(colors, colorStops); |
| 34 this._initRadial(center, radius, colors, colorStops, tileMode); | 45 this._initRadial(center, radius, colors, colorStops, tileMode); |
| 35 } | 46 } |
| 36 | 47 |
| 37 void validateColorStops(List<Color> colors, List<double> colorStops) { | 48 void validateColorStops(List<Color> colors, List<double> colorStops) { |
| 38 if (colorStops != null && colors.length != colorStops.length) { | 49 if (colorStops != null && colors.length != colorStops.length) { |
| 39 throw new ArgumentError( | 50 throw new ArgumentError( |
| 40 "[colors] and [colorStops] parameters must be equal length."); | 51 "[colors] and [colorStops] parameters must be equal length."); |
| 41 } | 52 } |
| 42 } | 53 } |
| 43 } | 54 } |
| OLD | NEW |