提交 b9738108 编写于 作者: M Matt Perry

Sky: Small fixes to Gradient interface. Added comments and renamed constructors.

R=abarth@chromium.org

Review URL: https://codereview.chromium.org/1180873003.
上级 7d788ecf
......@@ -4,19 +4,26 @@
part of dart.sky;
/// Defines what happens at the edge of the gradient.
enum TileMode {
/// Edge is clamped to the final color.
clamp,
/// Edge is repeated from first color to last.
repeated,
/// Edge is mirrored from last color to first.
mirror
}
// Extends the generated _Gradient interface via the PrivateDart attribute.
/// Extends the generated _Gradient interface via the PrivateDart attribute.
class Gradient extends _Gradient {
/// Creates a linear gradient from [endPoint[0]] to [endPoint[1]]. If
/// [colorStops] is provided, [colorStops[i]] is a number from 0 to 1 that
/// specifies where [color[i]] begins in the gradient.
// TODO(mpcomplete): Maybe pass a list of (color, colorStop) pairs instead?
Gradient.Linear(List<Point> endPoints,
Gradient.linear(List<Point> endPoints,
List<Color> colors,
List<double> colorStops,
[TileMode tileMode = TileMode.clamp])
[List<double> colorStops = null,
TileMode tileMode = TileMode.clamp])
: super() {
if (endPoints == null || endPoints.length != 2)
throw new ArgumentError("Expected exactly 2 [endPoints].");
......@@ -24,11 +31,15 @@ class Gradient extends _Gradient {
this._initLinear(endPoints, colors, colorStops, tileMode);
}
Gradient.Radial(Point center,
/// Creates a radial gradient centered at [center] that ends at [radius]
/// distance from the center. If [colorStops] is provided, [colorStops[i]] is
/// a number from 0 to 1 that specifies where [color[i]] begins in the
/// gradient.
Gradient.radial(Point center,
double radius,
List<Color> colors,
List<double> colorStops,
[TileMode tileMode = TileMode.clamp])
[List<double> colorStops = null,
TileMode tileMode = TileMode.clamp])
: super() {
validateColorStops(colors, colorStops);
this._initRadial(center, radius, colors, colorStops, tileMode);
......
......@@ -26,10 +26,9 @@ void main() {
paint.color = const Color.fromARGB(128, 255, 0, 255);
context.rotate(math.PI/4.0);
Gradient yellowBlue = new Gradient.Linear(
Gradient yellowBlue = new Gradient.linear(
[new Point(-radius, -radius), new Point(0.0, 0.0)],
[const Color(0xFFFFFF00), const Color(0xFF0000FF)],
null);
[const Color(0xFFFFFF00), const Color(0xFF0000FF)]);
context.drawRect(new Rect.fromLTRB(-radius, -radius, radius, radius),
new Paint()..setShader(yellowBlue));
......@@ -67,7 +66,7 @@ void main() {
..setColorMode(TransferMode.srcMode)
..setPaintBits(-1),
(Paint layerPaint) {
Gradient redYellow = new Gradient.Radial(
Gradient redYellow = new Gradient.radial(
new Point(0.0, 0.0), radius/3.0,
[const Color(0xFFFFFF00), const Color(0xFFFF0000)],
null, TileMode.mirror);
......
......@@ -85,7 +85,7 @@ class LinearGradient extends Gradient {
'LinearGradient($endPoints, $colors, $colorStops, $tileMode)';
sky.Shader createShader() {
return new sky.Gradient.Linear(this.endPoints, this.colors, this.colorStops,
return new sky.Gradient.linear(this.endPoints, this.colors, this.colorStops,
this.tileMode);
}
......@@ -108,7 +108,7 @@ class RadialGradient extends Gradient {
'RadialGradient($center, $radius, $colors, $colorStops, $tileMode)';
sky.Shader createShader() {
return new sky.Gradient.Radial(this.center, this.radius, this.colors,
return new sky.Gradient.radial(this.center, this.radius, this.colors,
this.colorStops, this.tileMode);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册