| 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 | 7 |
| 8 import 'package:sky/rendering/box.dart'; | 8 import 'package:sky/rendering/box.dart'; |
| 9 import 'package:sky/rendering/object.dart'; | 9 import 'package:sky/rendering/object.dart'; |
| 10 import 'package:sky/rendering/sky_binding.dart'; | 10 import 'package:sky/rendering/sky_binding.dart'; |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 | 119 |
| 120 BoxDecoration _decoration; | 120 BoxDecoration _decoration; |
| 121 BoxDecoration get decoration => _decoration; | 121 BoxDecoration get decoration => _decoration; |
| 122 void set decoration (BoxDecoration value) { | 122 void set decoration (BoxDecoration value) { |
| 123 if (value == _decoration) | 123 if (value == _decoration) |
| 124 return; | 124 return; |
| 125 _decoration = value; | 125 _decoration = value; |
| 126 markNeedsPaint(); | 126 markNeedsPaint(); |
| 127 } | 127 } |
| 128 | 128 |
| 129 // origin must be set to the center of the circle | 129 // offset must point to the center of the circle |
| 130 void paint(RenderCanvas canvas) { | 130 void paint(RenderCanvas canvas, Offset offset) { |
| 131 assert(deltaRadius != null); | 131 assert(deltaRadius != null); |
| 132 assert(deltaTheta != null); | 132 assert(deltaTheta != null); |
| 133 assert(parentData is SectorParentData); | 133 assert(parentData is SectorParentData); |
| 134 | 134 |
| 135 if (_decoration == null) | 135 if (_decoration == null) |
| 136 return; | 136 return; |
| 137 | 137 |
| 138 if (_decoration.backgroundColor != null) { | 138 if (_decoration.backgroundColor != null) { |
| 139 Paint paint = new Paint()..color = _decoration.backgroundColor; | 139 Paint paint = new Paint()..color = _decoration.backgroundColor; |
| 140 Path path = new Path(); | 140 Path path = new Path(); |
| 141 double outerRadius = (parentData.radius + deltaRadius); | 141 double outerRadius = (parentData.radius + deltaRadius); |
| 142 Rect outerBounds = new Rect.fromLTRB(-outerRadius, -outerRadius, outerRadi
us, outerRadius); | 142 Rect outerBounds = new Rect.fromLTRB(offset.dx-outerRadius, offset.dy-oute
rRadius, offset.dx+outerRadius, offset.dy+outerRadius); |
| 143 path.arcTo(outerBounds, parentData.theta, deltaTheta, true); | 143 path.arcTo(outerBounds, parentData.theta, deltaTheta, true); |
| 144 double innerRadius = parentData.radius; | 144 double innerRadius = parentData.radius; |
| 145 Rect innerBounds = new Rect.fromLTRB(-innerRadius, -innerRadius, innerRadi
us, innerRadius); | 145 Rect innerBounds = new Rect.fromLTRB(offset.dx-innerRadius, offset.dy-inne
rRadius, offset.dx+innerRadius, offset.dy+innerRadius); |
| 146 path.arcTo(innerBounds, parentData.theta + deltaTheta, -deltaTheta, false)
; | 146 path.arcTo(innerBounds, parentData.theta + deltaTheta, -deltaTheta, false)
; |
| 147 path.close(); | 147 path.close(); |
| 148 canvas.drawPath(path, paint); | 148 canvas.drawPath(path, paint); |
| 149 } | 149 } |
| 150 } | 150 } |
| 151 | 151 |
| 152 } | 152 } |
| 153 | 153 |
| 154 class SectorChildListParentData extends SectorParentData with ContainerParentDat
aMixin<RenderSector> { } | 154 class SectorChildListParentData extends SectorParentData with ContainerParentDat
aMixin<RenderSector> { } |
| 155 | 155 |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 assert(child.parentData is SectorChildListParentData); | 255 assert(child.parentData is SectorChildListParentData); |
| 256 child = child.parentData.nextSibling; | 256 child = child.parentData.nextSibling; |
| 257 if (child != null) { | 257 if (child != null) { |
| 258 innerTheta += paddingTheta; | 258 innerTheta += paddingTheta; |
| 259 remainingDeltaTheta -= paddingTheta; | 259 remainingDeltaTheta -= paddingTheta; |
| 260 } | 260 } |
| 261 } | 261 } |
| 262 deltaTheta = innerTheta; | 262 deltaTheta = innerTheta; |
| 263 } | 263 } |
| 264 | 264 |
| 265 // paint origin is 0,0 of our circle | 265 // offset must point to the center of our circle |
| 266 // each sector then knows how to paint itself at its location | 266 // each sector then knows how to paint itself at its location |
| 267 void paint(RenderCanvas canvas) { | 267 void paint(RenderCanvas canvas, Offset offset) { |
| 268 // TODO(ianh): avoid code duplication | 268 // TODO(ianh): avoid code duplication |
| 269 super.paint(canvas); | 269 super.paint(canvas, offset); |
| 270 RenderSector child = firstChild; | 270 RenderSector child = firstChild; |
| 271 while (child != null) { | 271 while (child != null) { |
| 272 assert(child.parentData is SectorChildListParentData); | 272 assert(child.parentData is SectorChildListParentData); |
| 273 canvas.paintChild(child, Point.origin); | 273 canvas.paintChild(child, offset.toPoint()); |
| 274 child = child.parentData.nextSibling; | 274 child = child.parentData.nextSibling; |
| 275 } | 275 } |
| 276 } | 276 } |
| 277 | 277 |
| 278 } | 278 } |
| 279 | 279 |
| 280 class RenderSectorSlice extends RenderSectorWithChildren { | 280 class RenderSectorSlice extends RenderSectorWithChildren { |
| 281 // lays out RenderSector children in a stack | 281 // lays out RenderSector children in a stack |
| 282 | 282 |
| 283 RenderSectorSlice({ | 283 RenderSectorSlice({ |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 360 childRadius += child.deltaRadius; | 360 childRadius += child.deltaRadius; |
| 361 remainingDeltaRadius -= child.deltaRadius; | 361 remainingDeltaRadius -= child.deltaRadius; |
| 362 assert(child.parentData is SectorChildListParentData); | 362 assert(child.parentData is SectorChildListParentData); |
| 363 child = child.parentData.nextSibling; | 363 child = child.parentData.nextSibling; |
| 364 childRadius += padding; | 364 childRadius += padding; |
| 365 remainingDeltaRadius -= padding; | 365 remainingDeltaRadius -= padding; |
| 366 } | 366 } |
| 367 deltaRadius = childRadius - this.parentData.radius; | 367 deltaRadius = childRadius - this.parentData.radius; |
| 368 } | 368 } |
| 369 | 369 |
| 370 // paint origin is 0,0 of our circle | 370 // offset must point to the center of our circle |
| 371 // each sector then knows how to paint itself at its location | 371 // each sector then knows how to paint itself at its location |
| 372 void paint(RenderCanvas canvas) { | 372 void paint(RenderCanvas canvas, Offset offset) { |
| 373 // TODO(ianh): avoid code duplication | 373 // TODO(ianh): avoid code duplication |
| 374 super.paint(canvas); | 374 super.paint(canvas, offset); |
| 375 RenderSector child = firstChild; | 375 RenderSector child = firstChild; |
| 376 while (child != null) { | 376 while (child != null) { |
| 377 assert(child.parentData is SectorChildListParentData); | 377 assert(child.parentData is SectorChildListParentData); |
| 378 canvas.paintChild(child, Point.origin); | 378 canvas.paintChild(child, offset.toPoint()); |
| 379 child = child.parentData.nextSibling; | 379 child = child.parentData.nextSibling; |
| 380 } | 380 } |
| 381 } | 381 } |
| 382 | 382 |
| 383 } | 383 } |
| 384 | 384 |
| 385 class RenderBoxToRenderSectorAdapter extends RenderBox { | 385 class RenderBoxToRenderSectorAdapter extends RenderBox { |
| 386 | 386 |
| 387 RenderBoxToRenderSectorAdapter({ double innerRadius: 0.0, RenderSector child }
) : | 387 RenderBoxToRenderSectorAdapter({ double innerRadius: 0.0, RenderSector child }
) : |
| 388 _innerRadius = innerRadius { | 388 _innerRadius = innerRadius { |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 455 double maxChildDeltaRadius = math.min(constraints.maxWidth, constraints.ma
xHeight) / 2.0 - innerRadius; | 455 double maxChildDeltaRadius = math.min(constraints.maxWidth, constraints.ma
xHeight) / 2.0 - innerRadius; |
| 456 assert(child.parentData is SectorParentData); | 456 assert(child.parentData is SectorParentData); |
| 457 child.parentData.radius = innerRadius; | 457 child.parentData.radius = innerRadius; |
| 458 child.parentData.theta = 0.0; | 458 child.parentData.theta = 0.0; |
| 459 child.layout(new SectorConstraints(maxDeltaRadius: maxChildDeltaRadius), p
arentUsesSize: true); | 459 child.layout(new SectorConstraints(maxDeltaRadius: maxChildDeltaRadius), p
arentUsesSize: true); |
| 460 double dimension = (innerRadius + child.deltaRadius) * 2.0; | 460 double dimension = (innerRadius + child.deltaRadius) * 2.0; |
| 461 size = constraints.constrain(new Size(dimension, dimension)); | 461 size = constraints.constrain(new Size(dimension, dimension)); |
| 462 } | 462 } |
| 463 } | 463 } |
| 464 | 464 |
| 465 // paint origin is 0,0 of our circle | 465 void paint(RenderCanvas canvas, Offset offset) { |
| 466 void paint(RenderCanvas canvas) { | 466 super.paint(canvas, offset); |
| 467 super.paint(canvas); | |
| 468 if (child != null) { | 467 if (child != null) { |
| 469 Rect bounds = new Rect.fromSize(size); | 468 Rect bounds = offset + size; |
| 469 // we move the offset to the center of the circle for the RenderSectors |
| 470 canvas.paintChild(child, bounds.center); | 470 canvas.paintChild(child, bounds.center); |
| 471 } | 471 } |
| 472 } | 472 } |
| 473 | 473 |
| 474 bool hitTest(HitTestResult result, { Point position }) { | 474 bool hitTest(HitTestResult result, { Point position }) { |
| 475 double x = position.x; | 475 double x = position.x; |
| 476 double y = position.y; | 476 double y = position.y; |
| 477 if (child == null) | 477 if (child == null) |
| 478 return false; | 478 return false; |
| 479 // translate to our origin | 479 // translate to our origin |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 531 stack.add(new RenderSolidColor(const Color(0xFFFFFF00), desiredDeltaRadius: 20
.0)); | 531 stack.add(new RenderSolidColor(const Color(0xFFFFFF00), desiredDeltaRadius: 20
.0)); |
| 532 stack.add(new RenderSolidColor(const Color(0xFFFF9000), desiredDeltaRadius: 20
.0)); | 532 stack.add(new RenderSolidColor(const Color(0xFFFF9000), desiredDeltaRadius: 20
.0)); |
| 533 stack.add(new RenderSolidColor(const Color(0xFF00FF00))); | 533 stack.add(new RenderSolidColor(const Color(0xFF00FF00))); |
| 534 rootCircle.add(stack); | 534 rootCircle.add(stack); |
| 535 return new RenderBoxToRenderSectorAdapter(innerRadius: 50.0, child: rootCircle
); | 535 return new RenderBoxToRenderSectorAdapter(innerRadius: 50.0, child: rootCircle
); |
| 536 } | 536 } |
| 537 | 537 |
| 538 void main() { | 538 void main() { |
| 539 new SkyBinding(root: buildSectorExample()); | 539 new SkyBinding(root: buildSectorExample()); |
| 540 } | 540 } |
| OLD | NEW |