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:math' as math; | 5 import 'dart:math' as math; |
6 import 'dart:sky' as sky; | 6 import 'dart:sky' as sky; |
7 import 'dart:typed_data'; | 7 import 'dart:typed_data'; |
8 import 'object.dart'; | 8 import 'object.dart'; |
9 import '../painting/shadows.dart'; | 9 import '../painting/shadows.dart'; |
10 import 'package:vector_math/vector_math.dart'; | 10 import 'package:vector_math/vector_math.dart'; |
(...skipping 637 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
648 this.blur | 648 this.blur |
649 }); | 649 }); |
650 | 650 |
651 final Color color; | 651 final Color color; |
652 final Size offset; | 652 final Size offset; |
653 final double blur; | 653 final double blur; |
654 | 654 |
655 String toString() => 'BoxShadow($color, $offset, $blur)'; | 655 String toString() => 'BoxShadow($color, $offset, $blur)'; |
656 } | 656 } |
657 | 657 |
658 abstract class BoxGradient { | |
659 String toString(); | |
abarth-chromium
2015/06/09 21:23:39
You can skip this declaration. It's declared alre
Matt Perry
2015/06/09 21:38:28
Done.
| |
660 sky.Shader createShader(); | |
661 } | |
662 | |
663 class LinearBoxGradient extends BoxGradient { | |
664 LinearBoxGradient({ | |
665 this.endPoints, | |
666 this.colors, | |
667 this.colorStops, | |
668 this.tileMode: sky.TileMode.clamp | |
669 }); | |
670 | |
671 String toString() => | |
672 'LinearBoxGradient($endPoints, $colors, $colorStops, $tileMode)'; | |
673 | |
674 sky.Shader createShader() { | |
675 return new sky.Gradient.Linear(this.endPoints, this.colors, this.colorStops, | |
676 this.tileMode); | |
677 } | |
678 | |
679 final List<Point> endPoints; | |
680 final List<Color> colors; | |
681 final List<double> colorStops; | |
682 final sky.TileMode tileMode; | |
683 } | |
684 | |
685 class RadialBoxGradient extends BoxGradient { | |
686 RadialBoxGradient({ | |
687 this.center, | |
688 this.radius, | |
689 this.colors, | |
690 this.colorStops, | |
691 this.tileMode: sky.TileMode.clamp | |
692 }); | |
693 | |
694 String toString() => | |
695 'RadialBoxGradient($center, $radius, $colors, $colorStops, $tileMode)'; | |
696 | |
697 sky.Shader createShader() { | |
698 return new sky.Gradient.Radial(this.center, this.radius, this.colors, | |
699 this.colorStops, this.tileMode); | |
700 } | |
701 | |
702 final Point center; | |
703 final double radius; | |
704 final List<Color> colors; | |
705 final List<double> colorStops; | |
706 final sky.TileMode tileMode; | |
707 } | |
708 | |
658 // This must be immutable, because we won't notice when it changes | 709 // This must be immutable, because we won't notice when it changes |
659 class BoxDecoration { | 710 class BoxDecoration { |
660 const BoxDecoration({ | 711 const BoxDecoration({ |
661 this.backgroundColor, | 712 this.backgroundColor, |
662 this.border, | 713 this.border, |
663 this.borderRadius, | 714 this.borderRadius, |
664 this.boxShadow | 715 this.boxShadow, |
716 this.boxGradient | |
665 }); | 717 }); |
666 | 718 |
667 final Color backgroundColor; | 719 final Color backgroundColor; |
668 final double borderRadius; | 720 final double borderRadius; |
669 final Border border; | 721 final Border border; |
670 final List<BoxShadow> boxShadow; | 722 final List<BoxShadow> boxShadow; |
723 final BoxGradient boxGradient; | |
abarth-chromium
2015/06/09 21:23:40
boxGradient -> gradient
We should probably rename
Matt Perry
2015/06/09 21:38:28
Done.
| |
671 | 724 |
672 String toString([String prefix = '']) { | 725 String toString([String prefix = '']) { |
673 List<String> result = []; | 726 List<String> result = []; |
674 if (backgroundColor != null) | 727 if (backgroundColor != null) |
675 result.add('${prefix}backgroundColor: $backgroundColor'); | 728 result.add('${prefix}backgroundColor: $backgroundColor'); |
676 if (border != null) | 729 if (border != null) |
677 result.add('${prefix}border: $border'); | 730 result.add('${prefix}border: $border'); |
678 if (borderRadius != null) | 731 if (borderRadius != null) |
679 result.add('${prefix}borderRadius: $borderRadius'); | 732 result.add('${prefix}borderRadius: $borderRadius'); |
680 if (boxShadow != null) | 733 if (boxShadow != null) |
681 result.add('${prefix}boxShadow: ${boxShadow.map((shadow) => shadow.toStrin g())}'); | 734 result.add('${prefix}boxShadow: ${boxShadow.map((shadow) => shadow.toStrin g())}'); |
735 if (boxGradient != null) | |
736 result.add('${prefix}boxGradient: $boxGradient'); | |
682 if (result.isEmpty) | 737 if (result.isEmpty) |
683 return '${prefix}<no decorations specified>'; | 738 return '${prefix}<no decorations specified>'; |
684 return result.join('\n'); | 739 return result.join('\n'); |
685 } | 740 } |
686 } | 741 } |
687 | 742 |
688 class RenderDecoratedBox extends RenderProxyBox { | 743 class RenderDecoratedBox extends RenderProxyBox { |
689 | 744 |
690 RenderDecoratedBox({ | 745 RenderDecoratedBox({ |
691 BoxDecoration decoration, | 746 BoxDecoration decoration, |
(...skipping 21 matching lines...) Expand all Loading... | |
713 if (_decoration.backgroundColor != null) | 768 if (_decoration.backgroundColor != null) |
714 paint.color = _decoration.backgroundColor; | 769 paint.color = _decoration.backgroundColor; |
715 | 770 |
716 if (_decoration.boxShadow != null) { | 771 if (_decoration.boxShadow != null) { |
717 var builder = new ShadowDrawLooperBuilder(); | 772 var builder = new ShadowDrawLooperBuilder(); |
718 for (BoxShadow boxShadow in _decoration.boxShadow) | 773 for (BoxShadow boxShadow in _decoration.boxShadow) |
719 builder.addShadow(boxShadow.offset, boxShadow.color, boxShadow.blur); | 774 builder.addShadow(boxShadow.offset, boxShadow.color, boxShadow.blur); |
720 paint.setDrawLooper(builder.build()); | 775 paint.setDrawLooper(builder.build()); |
721 } | 776 } |
722 | 777 |
778 if (_decoration.boxGradient != null) | |
779 paint.setShader(_decoration.boxGradient.createShader()); | |
780 | |
723 _cachedBackgroundPaint = paint; | 781 _cachedBackgroundPaint = paint; |
724 } | 782 } |
725 | 783 |
726 return _cachedBackgroundPaint; | 784 return _cachedBackgroundPaint; |
727 } | 785 } |
728 | 786 |
729 void paint(RenderObjectDisplayList canvas) { | 787 void paint(RenderObjectDisplayList canvas) { |
730 assert(size.width != null); | 788 assert(size.width != null); |
731 assert(size.height != null); | 789 assert(size.height != null); |
732 | 790 |
733 if (_decoration.backgroundColor != null || _decoration.boxShadow != null) { | 791 if (_decoration.backgroundColor != null || _decoration.boxShadow != null || |
792 _deocration.boxGradient != null) { | |
734 Rect rect = new Rect.fromLTRB(0.0, 0.0, size.width, size.height); | 793 Rect rect = new Rect.fromLTRB(0.0, 0.0, size.width, size.height); |
735 if (_decoration.borderRadius == null) | 794 if (_decoration.borderRadius == null) |
736 canvas.drawRect(rect, _backgroundPaint); | 795 canvas.drawRect(rect, _backgroundPaint); |
737 else | 796 else |
738 canvas.drawRRect(new sky.RRect()..setRectXY(rect, _decoration.borderRadi us, _decoration.borderRadius), _backgroundPaint); | 797 canvas.drawRRect(new sky.RRect()..setRectXY(rect, _decoration.borderRadi us, _decoration.borderRadius), _backgroundPaint); |
739 } | 798 } |
740 | 799 |
741 if (_decoration.border != null) { | 800 if (_decoration.border != null) { |
742 assert(_decoration.borderRadius == null); // TODO(abarth): Implement borde rs with border radius. | 801 assert(_decoration.borderRadius == null); // TODO(abarth): Implement borde rs with border radius. |
743 | 802 |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1016 | 1075 |
1017 void defaultPaint(RenderObjectDisplayList canvas) { | 1076 void defaultPaint(RenderObjectDisplayList canvas) { |
1018 RenderBox child = firstChild; | 1077 RenderBox child = firstChild; |
1019 while (child != null) { | 1078 while (child != null) { |
1020 assert(child.parentData is ParentDataType); | 1079 assert(child.parentData is ParentDataType); |
1021 canvas.paintChild(child, child.parentData.position); | 1080 canvas.paintChild(child, child.parentData.position); |
1022 child = child.parentData.nextSibling; | 1081 child = child.parentData.nextSibling; |
1023 } | 1082 } |
1024 } | 1083 } |
1025 } | 1084 } |
OLD | NEW |