| 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 import 'dart:async'; | 5 import 'dart:async'; |
| 6 import 'dart:math' as math; | 6 import 'dart:math' as math; |
| 7 import 'dart:sky' as sky; | 7 import 'dart:sky' as sky; |
| 8 import 'dart:sky' show Point, Offset, Size, Rect, Color, Paint, Path; | 8 import 'dart:sky' show Point, Offset, Size, Rect, Color, Paint, Path; |
| 9 | 9 |
| 10 import '../base/lerp.dart'; | 10 import '../base/lerp.dart'; |
| 11 import 'shadows.dart'; | 11 import 'shadows.dart'; |
| 12 | 12 |
| 13 class BorderSide { | 13 class BorderSide { |
| 14 const BorderSide({ | 14 const BorderSide({ |
| 15 this.color: const Color(0xFF000000), | 15 this.color: const Color(0xFF000000), |
| 16 this.width: 1.0 | 16 this.width: 1.0 |
| 17 }); | 17 }); |
| 18 final Color color; | 18 final Color color; |
| 19 final double width; | 19 final double width; |
| 20 | 20 |
| 21 static const none = const BorderSide(width: 0.0); | 21 static const none = const BorderSide(width: 0.0); |
| 22 | 22 |
| 23 @override |
| 23 int get hashCode { | 24 int get hashCode { |
| 24 int value = 373; | 25 int value = 373; |
| 25 value = 37 * value * color.hashCode; | 26 value = 37 * value * color.hashCode; |
| 26 value = 37 * value * width.hashCode; | 27 value = 37 * value * width.hashCode; |
| 27 return value; | 28 return value; |
| 28 } | 29 } |
| 30 |
| 31 @override |
| 29 String toString() => 'BorderSide($color, $width)'; | 32 String toString() => 'BorderSide($color, $width)'; |
| 30 } | 33 } |
| 31 | 34 |
| 32 class Border { | 35 class Border { |
| 33 const Border({ | 36 const Border({ |
| 34 this.top: BorderSide.none, | 37 this.top: BorderSide.none, |
| 35 this.right: BorderSide.none, | 38 this.right: BorderSide.none, |
| 36 this.bottom: BorderSide.none, | 39 this.bottom: BorderSide.none, |
| 37 this.left: BorderSide.none | 40 this.left: BorderSide.none |
| 38 }); | 41 }); |
| 39 | 42 |
| 40 const Border.all(BorderSide side) : | 43 const Border.all(BorderSide side) : |
| 41 top = side, | 44 top = side, |
| 42 right = side, | 45 right = side, |
| 43 bottom = side, | 46 bottom = side, |
| 44 left = side; | 47 left = side; |
| 45 | 48 |
| 46 final BorderSide top; | 49 final BorderSide top; |
| 47 final BorderSide right; | 50 final BorderSide right; |
| 48 final BorderSide bottom; | 51 final BorderSide bottom; |
| 49 final BorderSide left; | 52 final BorderSide left; |
| 50 | 53 |
| 54 @override |
| 51 int get hashCode { | 55 int get hashCode { |
| 52 int value = 373; | 56 int value = 373; |
| 53 value = 37 * value * top.hashCode; | 57 value = 37 * value * top.hashCode; |
| 54 value = 37 * value * right.hashCode; | 58 value = 37 * value * right.hashCode; |
| 55 value = 37 * value * bottom.hashCode; | 59 value = 37 * value * bottom.hashCode; |
| 56 value = 37 * value * left.hashCode; | 60 value = 37 * value * left.hashCode; |
| 57 return value; | 61 return value; |
| 58 } | 62 } |
| 63 |
| 64 @override |
| 59 String toString() => 'Border($top, $right, $bottom, $left)'; | 65 String toString() => 'Border($top, $right, $bottom, $left)'; |
| 60 } | 66 } |
| 61 | 67 |
| 62 class BoxShadow { | 68 class BoxShadow { |
| 63 const BoxShadow({ | 69 const BoxShadow({ |
| 64 this.color, | 70 this.color, |
| 65 this.offset, | 71 this.offset, |
| 66 this.blur | 72 this.blur |
| 67 }); | 73 }); |
| 68 | 74 |
| 69 final Color color; | 75 final Color color; |
| 70 final Offset offset; | 76 final Offset offset; |
| 71 final double blur; | 77 final double blur; |
| 72 | 78 |
| 79 @override |
| 73 String toString() => 'BoxShadow($color, $offset, $blur)'; | 80 String toString() => 'BoxShadow($color, $offset, $blur)'; |
| 74 } | 81 } |
| 75 | 82 |
| 76 BoxShadow lerpBoxShadow(BoxShadow a, BoxShadow b, double t) { | 83 BoxShadow lerpBoxShadow(BoxShadow a, BoxShadow b, double t) { |
| 77 return new BoxShadow( | 84 return new BoxShadow( |
| 78 color: lerpColor(a.color, b.color, t), | 85 color: lerpColor(a.color, b.color, t), |
| 79 offset: lerpOffset(a.offset, b.offset, t), | 86 offset: lerpOffset(a.offset, b.offset, t), |
| 80 blur: lerpNum(a.blur, b.blur, t)); | 87 blur: lerpNum(a.blur, b.blur, t)); |
| 81 } | 88 } |
| 82 | 89 |
| 83 abstract class Gradient { | 90 abstract class Gradient { |
| 84 sky.Shader createShader(); | 91 sky.Shader createShader(); |
| 85 } | 92 } |
| 86 | 93 |
| 87 class LinearGradient extends Gradient { | 94 class LinearGradient extends Gradient { |
| 88 LinearGradient({ | 95 LinearGradient({ |
| 89 this.endPoints, | 96 this.endPoints, |
| 90 this.colors, | 97 this.colors, |
| 91 this.colorStops, | 98 this.colorStops, |
| 92 this.tileMode: sky.TileMode.clamp | 99 this.tileMode: sky.TileMode.clamp |
| 93 }); | 100 }); |
| 94 | 101 |
| 102 @override |
| 95 String toString() => | 103 String toString() => |
| 96 'LinearGradient($endPoints, $colors, $colorStops, $tileMode)'; | 104 'LinearGradient($endPoints, $colors, $colorStops, $tileMode)'; |
| 97 | 105 |
| 106 @override |
| 98 sky.Shader createShader() { | 107 sky.Shader createShader() { |
| 99 return new sky.Gradient.linear(this.endPoints, this.colors, this.colorStops, | 108 return new sky.Gradient.linear(this.endPoints, this.colors, this.colorStops, |
| 100 this.tileMode); | 109 this.tileMode); |
| 101 } | 110 } |
| 102 | 111 |
| 103 final List<Point> endPoints; | 112 final List<Point> endPoints; |
| 104 final List<Color> colors; | 113 final List<Color> colors; |
| 105 final List<double> colorStops; | 114 final List<double> colorStops; |
| 106 final sky.TileMode tileMode; | 115 final sky.TileMode tileMode; |
| 107 } | 116 } |
| 108 | 117 |
| 109 class RadialGradient extends Gradient { | 118 class RadialGradient extends Gradient { |
| 110 RadialGradient({ | 119 RadialGradient({ |
| 111 this.center, | 120 this.center, |
| 112 this.radius, | 121 this.radius, |
| 113 this.colors, | 122 this.colors, |
| 114 this.colorStops, | 123 this.colorStops, |
| 115 this.tileMode: sky.TileMode.clamp | 124 this.tileMode: sky.TileMode.clamp |
| 116 }); | 125 }); |
| 117 | 126 |
| 127 @override |
| 118 String toString() => | 128 String toString() => |
| 119 'RadialGradient($center, $radius, $colors, $colorStops, $tileMode)'; | 129 'RadialGradient($center, $radius, $colors, $colorStops, $tileMode)'; |
| 120 | 130 |
| 131 @override |
| 121 sky.Shader createShader() { | 132 sky.Shader createShader() { |
| 122 return new sky.Gradient.radial(this.center, this.radius, this.colors, | 133 return new sky.Gradient.radial(this.center, this.radius, this.colors, |
| 123 this.colorStops, this.tileMode); | 134 this.colorStops, this.tileMode); |
| 124 } | 135 } |
| 125 | 136 |
| 126 final Point center; | 137 final Point center; |
| 127 final double radius; | 138 final double radius; |
| 128 final List<Color> colors; | 139 final List<Color> colors; |
| 129 final List<double> colorStops; | 140 final List<double> colorStops; |
| 130 final sky.TileMode tileMode; | 141 final sky.TileMode tileMode; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 final List<Function> _listeners = new List<Function>(); | 177 final List<Function> _listeners = new List<Function>(); |
| 167 | 178 |
| 168 void addChangeListener(Function listener) { | 179 void addChangeListener(Function listener) { |
| 169 _listeners.add(listener); | 180 _listeners.add(listener); |
| 170 } | 181 } |
| 171 | 182 |
| 172 void removeChangeListener(Function listener) { | 183 void removeChangeListener(Function listener) { |
| 173 _listeners.remove(listener); | 184 _listeners.remove(listener); |
| 174 } | 185 } |
| 175 | 186 |
| 187 @override |
| 176 String toString() => 'BackgroundImage($fit, $repeat)'; | 188 String toString() => 'BackgroundImage($fit, $repeat)'; |
| 177 } | 189 } |
| 178 | 190 |
| 179 enum Shape { rectangle, circle } | 191 enum Shape { rectangle, circle } |
| 180 | 192 |
| 181 // This must be immutable, because we won't notice when it changes | 193 // This must be immutable, because we won't notice when it changes |
| 182 class BoxDecoration { | 194 class BoxDecoration { |
| 183 const BoxDecoration({ | 195 const BoxDecoration({ |
| 184 this.backgroundColor, // null = don't draw background color | 196 this.backgroundColor, // null = don't draw background color |
| 185 this.backgroundImage, // null = don't draw background image | 197 this.backgroundImage, // null = don't draw background image |
| 186 this.border, // null = don't draw border | 198 this.border, // null = don't draw border |
| 187 this.borderRadius, // null = use more efficient background drawing; note tha
t this must be null for circles | 199 this.borderRadius, // null = use more efficient background drawing; note tha
t this must be null for circles |
| 188 this.boxShadow, // null = don't draw shadows | 200 this.boxShadow, // null = don't draw shadows |
| 189 this.gradient, // null = don't allocate gradient objects | 201 this.gradient, // null = don't allocate gradient objects |
| 190 this.shape: Shape.rectangle | 202 this.shape: Shape.rectangle |
| 191 }); | 203 }); |
| 192 | 204 |
| 193 final Color backgroundColor; | 205 final Color backgroundColor; |
| 194 final BackgroundImage backgroundImage; | 206 final BackgroundImage backgroundImage; |
| 195 final double borderRadius; | 207 final double borderRadius; |
| 196 final Border border; | 208 final Border border; |
| 197 final List<BoxShadow> boxShadow; | 209 final List<BoxShadow> boxShadow; |
| 198 final Gradient gradient; | 210 final Gradient gradient; |
| 199 final Shape shape; | 211 final Shape shape; |
| 200 | 212 |
| 213 @override |
| 201 String toString([String prefix = '']) { | 214 String toString([String prefix = '']) { |
| 202 List<String> result = []; | 215 List<String> result = []; |
| 203 if (backgroundColor != null) | 216 if (backgroundColor != null) |
| 204 result.add('${prefix}backgroundColor: $backgroundColor'); | 217 result.add('${prefix}backgroundColor: $backgroundColor'); |
| 205 if (backgroundImage != null) | 218 if (backgroundImage != null) |
| 206 result.add('${prefix}backgroundImage: $backgroundImage'); | 219 result.add('${prefix}backgroundImage: $backgroundImage'); |
| 207 if (border != null) | 220 if (border != null) |
| 208 result.add('${prefix}border: $border'); | 221 result.add('${prefix}border: $border'); |
| 209 if (borderRadius != null) | 222 if (borderRadius != null) |
| 210 result.add('${prefix}borderRadius: $borderRadius'); | 223 result.add('${prefix}borderRadius: $borderRadius'); |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 380 path.close(); | 393 path.close(); |
| 381 canvas.drawPath(path, paint); | 394 canvas.drawPath(path, paint); |
| 382 } | 395 } |
| 383 | 396 |
| 384 void paint(sky.Canvas canvas, Rect rect) { | 397 void paint(sky.Canvas canvas, Rect rect) { |
| 385 _paintBackgroundColor(canvas, rect); | 398 _paintBackgroundColor(canvas, rect); |
| 386 _paintBackgroundImage(canvas, rect); | 399 _paintBackgroundImage(canvas, rect); |
| 387 _paintBorder(canvas, rect); | 400 _paintBorder(canvas, rect); |
| 388 } | 401 } |
| 389 } | 402 } |
| OLD | NEW |