Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Improve style in lerp.dart and box_painter.dart #640

Merged
merged 2 commits into from
Aug 17, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions sky/packages/sky/lib/base/lerp.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ Color lerpColor(Color a, Color b, double t) {
if (b == null)
return _scaleAlpha(a, 1.0 - t);
return new Color.fromARGB(
lerpNum(a.alpha, b.alpha, t).toInt(),
lerpNum(a.red, b.red, t).toInt(),
lerpNum(a.green, b.green, t).toInt(),
lerpNum(a.blue, b.blue, t).toInt());
lerpNum(a.alpha, b.alpha, t).toInt(),
lerpNum(a.red, b.red, t).toInt(),
lerpNum(a.green, b.green, t).toInt(),
lerpNum(a.blue, b.blue, t).toInt()
);
}

Offset lerpOffset(Offset a, Offset b, double t) {
Expand All @@ -55,5 +56,6 @@ Rect lerpRect(Rect a, Rect b, double t) {
lerpNum(a.left, b.left, t),
lerpNum(a.top, b.top, t),
lerpNum(a.right, b.right, t),
lerpNum(a.bottom, b.bottom, t));
lerpNum(a.bottom, b.bottom, t)
);
}
42 changes: 23 additions & 19 deletions sky/packages/sky/lib/painting/box_painter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,10 @@ BoxShadow lerpBoxShadow(BoxShadow a, BoxShadow b, double t) {
if (b == null)
return a.scale(1.0 - t);
return new BoxShadow(
color: lerpColor(a.color, b.color, t),
offset: lerpOffset(a.offset, b.offset, t),
blur: lerpNum(a.blur, b.blur, t));
color: lerpColor(a.color, b.color, t),
offset: lerpOffset(a.offset, b.offset, t),
blur: lerpNum(a.blur, b.blur, t)
);
}

List<BoxShadow> lerpListBoxShadow(List<BoxShadow> a, List<BoxShadow> b, double t) {
Expand Down Expand Up @@ -126,18 +127,19 @@ class LinearGradient extends Gradient {
this.tileMode: sky.TileMode.clamp
});

String toString() =>
'LinearGradient($endPoints, $colors, $colorStops, $tileMode)';

sky.Shader createShader() {
return new sky.Gradient.linear(this.endPoints, this.colors, this.colorStops,
this.tileMode);
}

final List<Point> endPoints;
final List<Color> colors;
final List<double> colorStops;
final sky.TileMode tileMode;

sky.Shader createShader() {
return new sky.Gradient.linear(this.endPoints, this.colors,
this.colorStops, this.tileMode);
}

String toString() {
return 'LinearGradient($endPoints, $colors, $colorStops, $tileMode)';
}
}

class RadialGradient extends Gradient {
Expand All @@ -149,19 +151,20 @@ class RadialGradient extends Gradient {
this.tileMode: sky.TileMode.clamp
});

String toString() =>
'RadialGradient($center, $radius, $colors, $colorStops, $tileMode)';
final Point center;
final double radius;
final List<Color> colors;
final List<double> colorStops;
final sky.TileMode tileMode;

sky.Shader createShader() {
return new sky.Gradient.radial(this.center, this.radius, this.colors,
this.colorStops, this.tileMode);
}

final Point center;
final double radius;
final List<Color> colors;
final List<double> colorStops;
final sky.TileMode tileMode;
String toString() {
return 'RadialGradient($center, $radius, $colors, $colorStops, $tileMode)';
}
}

enum BackgroundFit { fill, contain, cover, none, scaleDown }
Expand Down Expand Up @@ -358,7 +361,8 @@ class BoxPainter {
}

void _paintBackgroundColor(sky.Canvas canvas, Rect rect) {
if (_decoration.backgroundColor != null || _decoration.boxShadow != null ||
if (_decoration.backgroundColor != null ||
_decoration.boxShadow != null ||
_decoration.gradient != null) {
switch (_decoration.shape) {
case Shape.circle:
Expand Down