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 // Extends the generated _Gradient interface via the PrivateDart attribute. | 7 // Extends the generated _Gradient interface via the PrivateDart attribute. |
8 class Gradient extends _Gradient { | 8 class Gradient extends _Gradient { |
9 // TODO(mpcomplete): Support other gradient types. | |
10 // TODO(mpcomplete): Maybe pass a list of (color, colorStop) pairs instead? | 9 // TODO(mpcomplete): Maybe pass a list of (color, colorStop) pairs instead? |
11 Gradient.Linear(List<Point> endPoints, | 10 Gradient.Linear(List<Point> endPoints, |
12 List<Color> colors, | 11 List<Color> colors, |
13 List<double> colorStops) | 12 List<double> colorStops) |
14 : super(0, endPoints, colors, _validate(colorStops, colors)); | 13 : super() { |
| 14 if (endPoints == null || endPoints.length != 2) |
| 15 throw new ArgumentError("Expected exactly 2 [endPoints]."); |
| 16 validateColorStops(colors, colorStops); |
| 17 this._initLinear(endPoints, colors, colorStops); |
| 18 } |
15 | 19 |
16 // TODO(mpcomplete): Figure out a good way to validate arguments. | 20 Gradient.Radial(Point center, |
17 static List<double> _validate(colorStops, colors) { | 21 double radius, |
| 22 List<Color> colors, |
| 23 List<double> colorStops) |
| 24 : super() { |
| 25 validateColorStops(colors, colorStops); |
| 26 this._initRadial(center, radius, colors, colorStops); |
| 27 } |
| 28 |
| 29 void validateColorStops(List<Color> colors, List<double> colorStops) { |
18 if (colorStops != null && colors.length != colorStops.length) { | 30 if (colorStops != null && colors.length != colorStops.length) { |
19 throw new ArgumentError( | 31 throw new ArgumentError( |
20 "[colors] and [colorStops] parameters must be equal length."); | 32 "[colors] and [colorStops] parameters must be equal length."); |
21 } | 33 } |
22 return colorStops; | |
23 } | 34 } |
24 } | 35 } |
OLD | NEW |