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 'package:sky/framework/app.dart'; | 7 import 'package:sky/framework/app.dart'; |
8 import 'package:sky/framework/rendering/box.dart'; | 8 import 'package:sky/framework/rendering/box.dart'; |
9 import 'package:sky/framework/rendering/object.dart'; | 9 import 'package:sky/framework/rendering/object.dart'; |
10 | 10 |
11 const double kTwoPi = 2 * math.PI; | 11 const double kTwoPi = 2 * math.PI; |
12 | 12 |
13 double deg(double radians) => radians * 180.0 / math.PI; | |
14 | |
15 class SectorConstraints { | 13 class SectorConstraints { |
16 const SectorConstraints({ | 14 const SectorConstraints({ |
17 this.minDeltaRadius: 0.0, | 15 this.minDeltaRadius: 0.0, |
18 this.maxDeltaRadius: double.INFINITY, | 16 this.maxDeltaRadius: double.INFINITY, |
19 this.minDeltaTheta: 0.0, | 17 this.minDeltaTheta: 0.0, |
20 this.maxDeltaTheta: kTwoPi | 18 this.maxDeltaTheta: kTwoPi |
21 }); | 19 }); |
22 | 20 |
23 const SectorConstraints.tight({ double deltaRadius: 0.0, double deltaTheta: 0.
0 }) | 21 const SectorConstraints.tight({ double deltaRadius: 0.0, double deltaTheta: 0.
0 }) |
24 : minDeltaRadius = deltaRadius, | 22 : minDeltaRadius = deltaRadius, |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 assert(parentData is SectorParentData); | 119 assert(parentData is SectorParentData); |
122 | 120 |
123 if (_decoration == null) | 121 if (_decoration == null) |
124 return; | 122 return; |
125 | 123 |
126 if (_decoration.backgroundColor != null) { | 124 if (_decoration.backgroundColor != null) { |
127 Paint paint = new Paint()..color = _decoration.backgroundColor; | 125 Paint paint = new Paint()..color = _decoration.backgroundColor; |
128 Path path = new Path(); | 126 Path path = new Path(); |
129 double outerRadius = (parentData.radius + deltaRadius); | 127 double outerRadius = (parentData.radius + deltaRadius); |
130 Rect outerBounds = new Rect.fromLTRB(-outerRadius, -outerRadius, outerRadi
us, outerRadius); | 128 Rect outerBounds = new Rect.fromLTRB(-outerRadius, -outerRadius, outerRadi
us, outerRadius); |
131 path.arcTo(outerBounds, deg(parentData.theta), deg(deltaTheta), true); | 129 path.arcTo(outerBounds, parentData.theta, deltaTheta, true); |
132 double innerRadius = parentData.radius; | 130 double innerRadius = parentData.radius; |
133 Rect innerBounds = new Rect.fromLTRB(-innerRadius, -innerRadius, innerRadi
us, innerRadius); | 131 Rect innerBounds = new Rect.fromLTRB(-innerRadius, -innerRadius, innerRadi
us, innerRadius); |
134 path.arcTo(innerBounds, deg(parentData.theta + deltaTheta), deg(-deltaThet
a), false); | 132 path.arcTo(innerBounds, parentData.theta + deltaTheta, -deltaTheta, false)
; |
135 path.close(); | 133 path.close(); |
136 canvas.drawPath(path, paint); | 134 canvas.drawPath(path, paint); |
137 } | 135 } |
138 } | 136 } |
139 } | 137 } |
140 | 138 |
141 class SectorChildListParentData extends SectorParentData with ContainerParentDat
aMixin<RenderSector> { } | 139 class SectorChildListParentData extends SectorParentData with ContainerParentDat
aMixin<RenderSector> { } |
142 | 140 |
143 class RenderSectorWithChildren extends RenderDecoratedSector with ContainerRende
rObjectMixin<RenderSector, SectorChildListParentData> { | 141 class RenderSectorWithChildren extends RenderDecoratedSector with ContainerRende
rObjectMixin<RenderSector, SectorChildListParentData> { |
144 RenderSectorWithChildren(BoxDecoration decoration) : super(decoration); | 142 RenderSectorWithChildren(BoxDecoration decoration) : super(decoration); |
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
499 rootCircle.add(new RenderSolidColor(const Color(0xFF0000FF), desiredDeltaTheta
: kTwoPi * 0.4)); | 497 rootCircle.add(new RenderSolidColor(const Color(0xFF0000FF), desiredDeltaTheta
: kTwoPi * 0.4)); |
500 var stack = new RenderSectorSlice(padding: 2.0); | 498 var stack = new RenderSectorSlice(padding: 2.0); |
501 stack.add(new RenderSolidColor(const Color(0xFFFFFF00), desiredDeltaRadius: 20
.0)); | 499 stack.add(new RenderSolidColor(const Color(0xFFFFFF00), desiredDeltaRadius: 20
.0)); |
502 stack.add(new RenderSolidColor(const Color(0xFFFF9000), desiredDeltaRadius: 20
.0)); | 500 stack.add(new RenderSolidColor(const Color(0xFFFF9000), desiredDeltaRadius: 20
.0)); |
503 stack.add(new RenderSolidColor(const Color(0xFF00FF00))); | 501 stack.add(new RenderSolidColor(const Color(0xFF00FF00))); |
504 rootCircle.add(stack); | 502 rootCircle.add(stack); |
505 | 503 |
506 var root = new RenderBoxToRenderSectorAdapter(innerRadius: 50.0, child: rootCi
rcle); | 504 var root = new RenderBoxToRenderSectorAdapter(innerRadius: 50.0, child: rootCi
rcle); |
507 app = new AppView(root); | 505 app = new AppView(root); |
508 } | 506 } |
OLD | NEW |