| 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/node.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; | 13 double deg(double radians) => radians * 180.0 / math.PI; |
| 14 | 14 |
| 15 class SectorConstraints { | 15 class SectorConstraints { |
| 16 const SectorConstraints({ | 16 const SectorConstraints({ |
| 17 this.minDeltaRadius: 0.0, | 17 this.minDeltaRadius: 0.0, |
| 18 this.maxDeltaRadius: double.INFINITY, | 18 this.maxDeltaRadius: double.INFINITY, |
| 19 this.minDeltaTheta: 0.0, | 19 this.minDeltaTheta: 0.0, |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 | 55 |
| 56 final double deltaRadius; | 56 final double deltaRadius; |
| 57 final double deltaTheta; | 57 final double deltaTheta; |
| 58 } | 58 } |
| 59 | 59 |
| 60 class SectorParentData extends ParentData { | 60 class SectorParentData extends ParentData { |
| 61 double radius = 0.0; | 61 double radius = 0.0; |
| 62 double theta = 0.0; | 62 double theta = 0.0; |
| 63 } | 63 } |
| 64 | 64 |
| 65 abstract class RenderSector extends RenderNode { | 65 abstract class RenderSector extends RenderObject { |
| 66 | 66 |
| 67 void setParentData(RenderNode child) { | 67 void setParentData(RenderObject child) { |
| 68 if (child.parentData is! SectorParentData) | 68 if (child.parentData is! SectorParentData) |
| 69 child.parentData = new SectorParentData(); | 69 child.parentData = new SectorParentData(); |
| 70 } | 70 } |
| 71 | 71 |
| 72 SectorDimensions getIntrinsicDimensions(SectorConstraints constraints, double
radius) { | 72 SectorDimensions getIntrinsicDimensions(SectorConstraints constraints, double
radius) { |
| 73 return new SectorDimensions.withConstraints(constraints); | 73 return new SectorDimensions.withConstraints(constraints); |
| 74 } | 74 } |
| 75 | 75 |
| 76 SectorConstraints get constraints => super.constraints as SectorConstraints; | 76 SectorConstraints get constraints => super.constraints as SectorConstraints; |
| 77 void performResize() { | 77 void performResize() { |
| (...skipping 30 matching lines...) Expand all Loading... |
| 108 BoxDecoration _decoration; | 108 BoxDecoration _decoration; |
| 109 BoxDecoration get decoration => _decoration; | 109 BoxDecoration get decoration => _decoration; |
| 110 void set decoration (BoxDecoration value) { | 110 void set decoration (BoxDecoration value) { |
| 111 if (value == _decoration) | 111 if (value == _decoration) |
| 112 return; | 112 return; |
| 113 _decoration = value; | 113 _decoration = value; |
| 114 markNeedsPaint(); | 114 markNeedsPaint(); |
| 115 } | 115 } |
| 116 | 116 |
| 117 // origin must be set to the center of the circle | 117 // origin must be set to the center of the circle |
| 118 void paint(RenderNodeDisplayList canvas) { | 118 void paint(RenderObjectDisplayList canvas) { |
| 119 assert(deltaRadius != null); | 119 assert(deltaRadius != null); |
| 120 assert(deltaTheta != null); | 120 assert(deltaTheta != null); |
| 121 assert(parentData is SectorParentData); | 121 assert(parentData is SectorParentData); |
| 122 | 122 |
| 123 if (_decoration == null) | 123 if (_decoration == null) |
| 124 return; | 124 return; |
| 125 | 125 |
| 126 if (_decoration.backgroundColor != null) { | 126 if (_decoration.backgroundColor != null) { |
| 127 sky.Paint paint = new sky.Paint()..color = _decoration.backgroundColor; | 127 sky.Paint paint = new sky.Paint()..color = _decoration.backgroundColor; |
| 128 sky.Path path = new sky.Path(); | 128 sky.Path path = new sky.Path(); |
| 129 double outerRadius = (parentData.radius + deltaRadius); | 129 double outerRadius = (parentData.radius + deltaRadius); |
| 130 sky.Rect outerBounds = new sky.Rect.fromLTRB(-outerRadius, -outerRadius, o
uterRadius, outerRadius); | 130 sky.Rect outerBounds = new sky.Rect.fromLTRB(-outerRadius, -outerRadius, o
uterRadius, outerRadius); |
| 131 path.arcTo(outerBounds, deg(parentData.theta), deg(deltaTheta), true); | 131 path.arcTo(outerBounds, deg(parentData.theta), deg(deltaTheta), true); |
| 132 double innerRadius = parentData.radius; | 132 double innerRadius = parentData.radius; |
| 133 sky.Rect innerBounds = new sky.Rect.fromLTRB(-innerRadius, -innerRadius, i
nnerRadius, innerRadius); | 133 sky.Rect innerBounds = new sky.Rect.fromLTRB(-innerRadius, -innerRadius, i
nnerRadius, innerRadius); |
| 134 path.arcTo(innerBounds, deg(parentData.theta + deltaTheta), deg(-deltaThet
a), false); | 134 path.arcTo(innerBounds, deg(parentData.theta + deltaTheta), deg(-deltaThet
a), false); |
| 135 path.close(); | 135 path.close(); |
| 136 canvas.drawPath(path, paint); | 136 canvas.drawPath(path, paint); |
| 137 } | 137 } |
| 138 } | 138 } |
| 139 } | 139 } |
| 140 | 140 |
| 141 class SectorChildListParentData extends SectorParentData with ContainerParentDat
aMixin<RenderSector> { } | 141 class SectorChildListParentData extends SectorParentData with ContainerParentDat
aMixin<RenderSector> { } |
| 142 | 142 |
| 143 class RenderSectorWithChildren extends RenderDecoratedSector with ContainerRende
rNodeMixin<RenderSector, SectorChildListParentData> { | 143 class RenderSectorWithChildren extends RenderDecoratedSector with ContainerRende
rObjectMixin<RenderSector, SectorChildListParentData> { |
| 144 RenderSectorWithChildren(BoxDecoration decoration) : super(decoration); | 144 RenderSectorWithChildren(BoxDecoration decoration) : super(decoration); |
| 145 | 145 |
| 146 void hitTestChildren(HitTestResult result, { double radius, double theta }) { | 146 void hitTestChildren(HitTestResult result, { double radius, double theta }) { |
| 147 RenderSector child = lastChild; | 147 RenderSector child = lastChild; |
| 148 while (child != null) { | 148 while (child != null) { |
| 149 assert(child.parentData is SectorChildListParentData); | 149 assert(child.parentData is SectorChildListParentData); |
| 150 if (child.hitTest(result, radius: radius, theta: theta)) | 150 if (child.hitTest(result, radius: radius, theta: theta)) |
| 151 return; | 151 return; |
| 152 child = child.parentData.previousSibling; | 152 child = child.parentData.previousSibling; |
| 153 } | 153 } |
| (...skipping 23 matching lines...) Expand all Loading... |
| 177 double get padding => _padding; | 177 double get padding => _padding; |
| 178 void set padding(double value) { | 178 void set padding(double value) { |
| 179 // TODO(ianh): avoid code duplication | 179 // TODO(ianh): avoid code duplication |
| 180 assert(value != null); | 180 assert(value != null); |
| 181 if (_padding != value) { | 181 if (_padding != value) { |
| 182 _padding = value; | 182 _padding = value; |
| 183 markNeedsLayout(); | 183 markNeedsLayout(); |
| 184 } | 184 } |
| 185 } | 185 } |
| 186 | 186 |
| 187 void setParentData(RenderNode child) { | 187 void setParentData(RenderObject child) { |
| 188 // TODO(ianh): avoid code duplication | 188 // TODO(ianh): avoid code duplication |
| 189 if (child.parentData is! SectorChildListParentData) | 189 if (child.parentData is! SectorChildListParentData) |
| 190 child.parentData = new SectorChildListParentData(); | 190 child.parentData = new SectorChildListParentData(); |
| 191 } | 191 } |
| 192 | 192 |
| 193 SectorDimensions getIntrinsicDimensions(SectorConstraints constraints, double
radius) { | 193 SectorDimensions getIntrinsicDimensions(SectorConstraints constraints, double
radius) { |
| 194 double outerDeltaRadius = constraints.constrainDeltaRadius(desiredDeltaRadiu
s); | 194 double outerDeltaRadius = constraints.constrainDeltaRadius(desiredDeltaRadiu
s); |
| 195 double innerDeltaRadius = outerDeltaRadius - padding * 2.0; | 195 double innerDeltaRadius = outerDeltaRadius - padding * 2.0; |
| 196 double childRadius = radius + padding; | 196 double childRadius = radius + padding; |
| 197 double paddingTheta = math.atan(padding / (radius + outerDeltaRadius)); | 197 double paddingTheta = math.atan(padding / (radius + outerDeltaRadius)); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 if (child != null) { | 244 if (child != null) { |
| 245 innerTheta += paddingTheta; | 245 innerTheta += paddingTheta; |
| 246 remainingDeltaTheta -= paddingTheta; | 246 remainingDeltaTheta -= paddingTheta; |
| 247 } | 247 } |
| 248 } | 248 } |
| 249 deltaTheta = innerTheta; | 249 deltaTheta = innerTheta; |
| 250 } | 250 } |
| 251 | 251 |
| 252 // paint origin is 0,0 of our circle | 252 // paint origin is 0,0 of our circle |
| 253 // each sector then knows how to paint itself at its location | 253 // each sector then knows how to paint itself at its location |
| 254 void paint(RenderNodeDisplayList canvas) { | 254 void paint(RenderObjectDisplayList canvas) { |
| 255 // TODO(ianh): avoid code duplication | 255 // TODO(ianh): avoid code duplication |
| 256 super.paint(canvas); | 256 super.paint(canvas); |
| 257 RenderSector child = firstChild; | 257 RenderSector child = firstChild; |
| 258 while (child != null) { | 258 while (child != null) { |
| 259 assert(child.parentData is SectorChildListParentData); | 259 assert(child.parentData is SectorChildListParentData); |
| 260 canvas.paintChild(child, new sky.Point(0.0, 0.0)); | 260 canvas.paintChild(child, new sky.Point(0.0, 0.0)); |
| 261 child = child.parentData.nextSibling; | 261 child = child.parentData.nextSibling; |
| 262 } | 262 } |
| 263 } | 263 } |
| 264 | 264 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 287 double get padding => _padding; | 287 double get padding => _padding; |
| 288 void set padding(double value) { | 288 void set padding(double value) { |
| 289 // TODO(ianh): avoid code duplication | 289 // TODO(ianh): avoid code duplication |
| 290 assert(value != null); | 290 assert(value != null); |
| 291 if (_padding != value) { | 291 if (_padding != value) { |
| 292 _padding = value; | 292 _padding = value; |
| 293 markNeedsLayout(); | 293 markNeedsLayout(); |
| 294 } | 294 } |
| 295 } | 295 } |
| 296 | 296 |
| 297 void setParentData(RenderNode child) { | 297 void setParentData(RenderObject child) { |
| 298 // TODO(ianh): avoid code duplication | 298 // TODO(ianh): avoid code duplication |
| 299 if (child.parentData is! SectorChildListParentData) | 299 if (child.parentData is! SectorChildListParentData) |
| 300 child.parentData = new SectorChildListParentData(); | 300 child.parentData = new SectorChildListParentData(); |
| 301 } | 301 } |
| 302 | 302 |
| 303 SectorDimensions getIntrinsicDimensions(SectorConstraints constraints, double
radius) { | 303 SectorDimensions getIntrinsicDimensions(SectorConstraints constraints, double
radius) { |
| 304 assert(this.parentData is SectorParentData); | 304 assert(this.parentData is SectorParentData); |
| 305 double paddingTheta = math.atan(padding / this.parentData.radius); | 305 double paddingTheta = math.atan(padding / this.parentData.radius); |
| 306 double outerDeltaTheta = constraints.constrainDeltaTheta(desiredDeltaTheta); | 306 double outerDeltaTheta = constraints.constrainDeltaTheta(desiredDeltaTheta); |
| 307 double innerDeltaTheta = outerDeltaTheta - paddingTheta * 2.0; | 307 double innerDeltaTheta = outerDeltaTheta - paddingTheta * 2.0; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 349 assert(child.parentData is SectorChildListParentData); | 349 assert(child.parentData is SectorChildListParentData); |
| 350 child = child.parentData.nextSibling; | 350 child = child.parentData.nextSibling; |
| 351 childRadius += padding; | 351 childRadius += padding; |
| 352 remainingDeltaRadius -= padding; | 352 remainingDeltaRadius -= padding; |
| 353 } | 353 } |
| 354 deltaRadius = childRadius - this.parentData.radius; | 354 deltaRadius = childRadius - this.parentData.radius; |
| 355 } | 355 } |
| 356 | 356 |
| 357 // paint origin is 0,0 of our circle | 357 // paint origin is 0,0 of our circle |
| 358 // each sector then knows how to paint itself at its location | 358 // each sector then knows how to paint itself at its location |
| 359 void paint(RenderNodeDisplayList canvas) { | 359 void paint(RenderObjectDisplayList canvas) { |
| 360 // TODO(ianh): avoid code duplication | 360 // TODO(ianh): avoid code duplication |
| 361 super.paint(canvas); | 361 super.paint(canvas); |
| 362 RenderSector child = firstChild; | 362 RenderSector child = firstChild; |
| 363 while (child != null) { | 363 while (child != null) { |
| 364 assert(child.parentData is SectorChildListParentData); | 364 assert(child.parentData is SectorChildListParentData); |
| 365 canvas.paintChild(child, new sky.Point(0.0, 0.0)); | 365 canvas.paintChild(child, new sky.Point(0.0, 0.0)); |
| 366 child = child.parentData.nextSibling; | 366 child = child.parentData.nextSibling; |
| 367 } | 367 } |
| 368 } | 368 } |
| 369 | 369 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 387 RenderSector _child; | 387 RenderSector _child; |
| 388 RenderSector get child => _child; | 388 RenderSector get child => _child; |
| 389 void set child(RenderSector value) { | 389 void set child(RenderSector value) { |
| 390 if (_child != null) | 390 if (_child != null) |
| 391 dropChild(_child); | 391 dropChild(_child); |
| 392 _child = value; | 392 _child = value; |
| 393 adoptChild(_child); | 393 adoptChild(_child); |
| 394 markNeedsLayout(); | 394 markNeedsLayout(); |
| 395 } | 395 } |
| 396 | 396 |
| 397 void setParentData(RenderNode child) { | 397 void setParentData(RenderObject child) { |
| 398 if (child.parentData is! SectorParentData) | 398 if (child.parentData is! SectorParentData) |
| 399 child.parentData = new SectorParentData(); | 399 child.parentData = new SectorParentData(); |
| 400 } | 400 } |
| 401 | 401 |
| 402 sky.Size getIntrinsicDimensions(BoxConstraints constraints) { | 402 sky.Size getIntrinsicDimensions(BoxConstraints constraints) { |
| 403 if (child == null) | 403 if (child == null) |
| 404 return constraints.constrain(new sky.Size(0.0, 0.0)); | 404 return constraints.constrain(new sky.Size(0.0, 0.0)); |
| 405 assert(child is RenderSector); | 405 assert(child is RenderSector); |
| 406 assert(child.parentData is SectorParentData); | 406 assert(child.parentData is SectorParentData); |
| 407 assert(!constraints.isInfinite); | 407 assert(!constraints.isInfinite); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 423 assert(child.parentData is SectorParentData); | 423 assert(child.parentData is SectorParentData); |
| 424 child.parentData.radius = innerRadius; | 424 child.parentData.radius = innerRadius; |
| 425 child.parentData.theta = 0.0; | 425 child.parentData.theta = 0.0; |
| 426 child.layout(new SectorConstraints(maxDeltaRadius: maxChildDeltaRadius), p
arentUsesSize: true); | 426 child.layout(new SectorConstraints(maxDeltaRadius: maxChildDeltaRadius), p
arentUsesSize: true); |
| 427 double dimension = (innerRadius + child.deltaRadius) * 2.0; | 427 double dimension = (innerRadius + child.deltaRadius) * 2.0; |
| 428 size = constraints.constrain(new sky.Size(dimension, dimension)); | 428 size = constraints.constrain(new sky.Size(dimension, dimension)); |
| 429 } | 429 } |
| 430 } | 430 } |
| 431 | 431 |
| 432 // paint origin is 0,0 of our circle | 432 // paint origin is 0,0 of our circle |
| 433 void paint(RenderNodeDisplayList canvas) { | 433 void paint(RenderObjectDisplayList canvas) { |
| 434 super.paint(canvas); | 434 super.paint(canvas); |
| 435 if (child != null) { | 435 if (child != null) { |
| 436 sky.Rect bounds = new sky.Rect.fromSize(size); | 436 sky.Rect bounds = new sky.Rect.fromSize(size); |
| 437 canvas.paintChild(child, bounds.center); | 437 canvas.paintChild(child, bounds.center); |
| 438 } | 438 } |
| 439 } | 439 } |
| 440 | 440 |
| 441 bool hitTest(HitTestResult result, { sky.Point position }) { | 441 bool hitTest(HitTestResult result, { sky.Point position }) { |
| 442 double x = position.x; | 442 double x = position.x; |
| 443 double y = position.y; | 443 double y = position.y; |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 499 rootCircle.add(new RenderSolidColor(const sky.Color(0xFF0000FF), desiredDeltaT
heta: kTwoPi * 0.4)); | 499 rootCircle.add(new RenderSolidColor(const sky.Color(0xFF0000FF), desiredDeltaT
heta: kTwoPi * 0.4)); |
| 500 var stack = new RenderSectorSlice(padding: 2.0); | 500 var stack = new RenderSectorSlice(padding: 2.0); |
| 501 stack.add(new RenderSolidColor(const sky.Color(0xFFFFFF00), desiredDeltaRadius
: 20.0)); | 501 stack.add(new RenderSolidColor(const sky.Color(0xFFFFFF00), desiredDeltaRadius
: 20.0)); |
| 502 stack.add(new RenderSolidColor(const sky.Color(0xFFFF9000), desiredDeltaRadius
: 20.0)); | 502 stack.add(new RenderSolidColor(const sky.Color(0xFFFF9000), desiredDeltaRadius
: 20.0)); |
| 503 stack.add(new RenderSolidColor(const sky.Color(0xFF00FF00))); | 503 stack.add(new RenderSolidColor(const sky.Color(0xFF00FF00))); |
| 504 rootCircle.add(stack); | 504 rootCircle.add(stack); |
| 505 | 505 |
| 506 var root = new RenderBoxToRenderSectorAdapter(innerRadius: 50.0, child: rootCi
rcle); | 506 var root = new RenderBoxToRenderSectorAdapter(innerRadius: 50.0, child: rootCi
rcle); |
| 507 app = new AppView(root); | 507 app = new AppView(root); |
| 508 } | 508 } |
| OLD | NEW |