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/app/view.dart'; | 7 import 'package:sky/app/view.dart'; |
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 | 10 |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 hitTestChildren(result, radius: radius, theta: theta); | 92 hitTestChildren(result, radius: radius, theta: theta); |
93 result.add(new HitTestEntry(this)); | 93 result.add(new HitTestEntry(this)); |
94 return true; | 94 return true; |
95 } | 95 } |
96 void hitTestChildren(HitTestResult result, { double radius, double theta }) {
} | 96 void hitTestChildren(HitTestResult result, { double radius, double theta }) {
} |
97 | 97 |
98 double deltaRadius; | 98 double deltaRadius; |
99 double deltaTheta; | 99 double deltaTheta; |
100 } | 100 } |
101 | 101 |
102 class RenderDecoratedSector extends RenderSector { | 102 abstract class RenderDecoratedSector extends RenderSector { |
103 | 103 |
104 RenderDecoratedSector(BoxDecoration decoration) : _decoration = decoration; | 104 RenderDecoratedSector(BoxDecoration decoration) : _decoration = decoration; |
105 | 105 |
106 BoxDecoration _decoration; | 106 BoxDecoration _decoration; |
107 BoxDecoration get decoration => _decoration; | 107 BoxDecoration get decoration => _decoration; |
108 void set decoration (BoxDecoration value) { | 108 void set decoration (BoxDecoration value) { |
109 if (value == _decoration) | 109 if (value == _decoration) |
110 return; | 110 return; |
111 _decoration = value; | 111 _decoration = value; |
112 markNeedsPaint(); | 112 markNeedsPaint(); |
(...skipping 14 matching lines...) Expand all Loading... |
127 double outerRadius = (parentData.radius + deltaRadius); | 127 double outerRadius = (parentData.radius + deltaRadius); |
128 Rect outerBounds = new Rect.fromLTRB(-outerRadius, -outerRadius, outerRadi
us, outerRadius); | 128 Rect outerBounds = new Rect.fromLTRB(-outerRadius, -outerRadius, outerRadi
us, outerRadius); |
129 path.arcTo(outerBounds, parentData.theta, deltaTheta, true); | 129 path.arcTo(outerBounds, parentData.theta, deltaTheta, true); |
130 double innerRadius = parentData.radius; | 130 double innerRadius = parentData.radius; |
131 Rect innerBounds = new Rect.fromLTRB(-innerRadius, -innerRadius, innerRadi
us, innerRadius); | 131 Rect innerBounds = new Rect.fromLTRB(-innerRadius, -innerRadius, innerRadi
us, innerRadius); |
132 path.arcTo(innerBounds, parentData.theta + deltaTheta, -deltaTheta, false)
; | 132 path.arcTo(innerBounds, parentData.theta + deltaTheta, -deltaTheta, false)
; |
133 path.close(); | 133 path.close(); |
134 canvas.drawPath(path, paint); | 134 canvas.drawPath(path, paint); |
135 } | 135 } |
136 } | 136 } |
| 137 |
137 } | 138 } |
138 | 139 |
139 class SectorChildListParentData extends SectorParentData with ContainerParentDat
aMixin<RenderSector> { } | 140 class SectorChildListParentData extends SectorParentData with ContainerParentDat
aMixin<RenderSector> { } |
140 | 141 |
141 class RenderSectorWithChildren extends RenderDecoratedSector with ContainerRende
rObjectMixin<RenderSector, SectorChildListParentData> { | 142 class RenderSectorWithChildren extends RenderDecoratedSector with ContainerRende
rObjectMixin<RenderSector, SectorChildListParentData> { |
142 RenderSectorWithChildren(BoxDecoration decoration) : super(decoration); | 143 RenderSectorWithChildren(BoxDecoration decoration) : super(decoration); |
143 | 144 |
144 void hitTestChildren(HitTestResult result, { double radius, double theta }) { | 145 void hitTestChildren(HitTestResult result, { double radius, double theta }) { |
145 RenderSector child = lastChild; | 146 RenderSector child = lastChild; |
146 while (child != null) { | 147 while (child != null) { |
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
390 _child = value; | 391 _child = value; |
391 adoptChild(_child); | 392 adoptChild(_child); |
392 markNeedsLayout(); | 393 markNeedsLayout(); |
393 } | 394 } |
394 | 395 |
395 void setParentData(RenderObject child) { | 396 void setParentData(RenderObject child) { |
396 if (child.parentData is! SectorParentData) | 397 if (child.parentData is! SectorParentData) |
397 child.parentData = new SectorParentData(); | 398 child.parentData = new SectorParentData(); |
398 } | 399 } |
399 | 400 |
| 401 double getMinIntrinsicWidth(BoxConstraints constraints) { |
| 402 if (child == null) |
| 403 return super.getMinIntrinsicWidth(constraints); |
| 404 return getIntrinsicDimensions(constraints).width; |
| 405 } |
| 406 |
| 407 double getMaxIntrinsicWidth(BoxConstraints constraints) { |
| 408 if (child == null) |
| 409 return super.getMaxIntrinsicWidth(constraints); |
| 410 return getIntrinsicDimensions(constraints).width; |
| 411 } |
| 412 |
| 413 double getMinIntrinsicHeight(BoxConstraints constraints) { |
| 414 if (child == null) |
| 415 return super.getMinIntrinsicHeight(constraints); |
| 416 return getIntrinsicDimensions(constraints).height; |
| 417 } |
| 418 |
| 419 double getMaxIntrinsicHeight(BoxConstraints constraints) { |
| 420 if (child == null) |
| 421 return super.getMaxIntrinsicHeight(constraints); |
| 422 return getIntrinsicDimensions(constraints).height; |
| 423 } |
| 424 |
400 Size getIntrinsicDimensions(BoxConstraints constraints) { | 425 Size getIntrinsicDimensions(BoxConstraints constraints) { |
401 if (child == null) | |
402 return constraints.constrain(Size.zero); | |
403 assert(child is RenderSector); | 426 assert(child is RenderSector); |
404 assert(child.parentData is SectorParentData); | 427 assert(child.parentData is SectorParentData); |
405 assert(!constraints.isInfinite); | 428 assert(!constraints.isInfinite); |
406 double maxChildDeltaRadius = math.min(constraints.maxWidth, constraints.maxH
eight) / 2.0 - innerRadius; | 429 double maxChildDeltaRadius = math.min(constraints.maxWidth, constraints.maxH
eight) / 2.0 - innerRadius; |
407 SectorDimensions childDimensions = child.getIntrinsicDimensions(new SectorCo
nstraints(maxDeltaRadius: maxChildDeltaRadius), innerRadius); | 430 SectorDimensions childDimensions = child.getIntrinsicDimensions(new SectorCo
nstraints(maxDeltaRadius: maxChildDeltaRadius), innerRadius); |
408 double dimension = (innerRadius + childDimensions.deltaRadius) * 2.0; | 431 double dimension = (innerRadius + childDimensions.deltaRadius) * 2.0; |
409 return constraints.constrain(new Size(dimension, dimension)); | 432 return constraints.constrain(new Size(dimension, dimension)); |
410 } | 433 } |
411 | 434 |
412 void performLayout() { | 435 void performLayout() { |
413 if (child == null) { | 436 if (child == null) { |
414 size = constraints.constrain(Size.zero); | 437 size = constraints.constrain(Size.zero); |
415 } else { | 438 } else { |
416 assert(child is RenderSector); | 439 assert(child is RenderSector); |
417 assert(!constraints.isInfinite); | 440 assert(!constraints.isInfinite); |
418 print("constraint maxes: ${constraints.maxWidth} and ${constraints.maxHeig
ht}"); | |
419 double maxChildDeltaRadius = math.min(constraints.maxWidth, constraints.ma
xHeight) / 2.0 - innerRadius; | 441 double maxChildDeltaRadius = math.min(constraints.maxWidth, constraints.ma
xHeight) / 2.0 - innerRadius; |
420 print("maxChildDeltaRadius = $maxChildDeltaRadius"); | |
421 assert(child.parentData is SectorParentData); | 442 assert(child.parentData is SectorParentData); |
422 child.parentData.radius = innerRadius; | 443 child.parentData.radius = innerRadius; |
423 child.parentData.theta = 0.0; | 444 child.parentData.theta = 0.0; |
424 child.layout(new SectorConstraints(maxDeltaRadius: maxChildDeltaRadius), p
arentUsesSize: true); | 445 child.layout(new SectorConstraints(maxDeltaRadius: maxChildDeltaRadius), p
arentUsesSize: true); |
425 double dimension = (innerRadius + child.deltaRadius) * 2.0; | 446 double dimension = (innerRadius + child.deltaRadius) * 2.0; |
426 size = constraints.constrain(new Size(dimension, dimension)); | 447 size = constraints.constrain(new Size(dimension, dimension)); |
427 } | 448 } |
428 } | 449 } |
429 | 450 |
430 // paint origin is 0,0 of our circle | 451 // paint origin is 0,0 of our circle |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
465 this.desiredDeltaRadius: double.INFINITY, | 486 this.desiredDeltaRadius: double.INFINITY, |
466 this.desiredDeltaTheta: kTwoPi | 487 this.desiredDeltaTheta: kTwoPi |
467 }) : this.backgroundColor = backgroundColor, | 488 }) : this.backgroundColor = backgroundColor, |
468 super(new BoxDecoration(backgroundColor: backgroundColor)); | 489 super(new BoxDecoration(backgroundColor: backgroundColor)); |
469 | 490 |
470 double desiredDeltaRadius; | 491 double desiredDeltaRadius; |
471 double desiredDeltaTheta; | 492 double desiredDeltaTheta; |
472 final Color backgroundColor; | 493 final Color backgroundColor; |
473 | 494 |
474 SectorDimensions getIntrinsicDimensions(SectorConstraints constraints, double
radius) { | 495 SectorDimensions getIntrinsicDimensions(SectorConstraints constraints, double
radius) { |
475 return new SectorDimensions.withConstraints(constraints, deltaTheta: 1.0); /
/ 1.0 radians | 496 return new SectorDimensions.withConstraints(constraints, deltaTheta: desired
DeltaTheta); |
476 } | 497 } |
477 | 498 |
478 void performLayout() { | 499 void performLayout() { |
479 deltaRadius = constraints.constrainDeltaRadius(desiredDeltaRadius); | 500 deltaRadius = constraints.constrainDeltaRadius(desiredDeltaRadius); |
480 deltaTheta = constraints.constrainDeltaTheta(desiredDeltaTheta); | 501 deltaTheta = constraints.constrainDeltaTheta(desiredDeltaTheta); |
481 } | 502 } |
482 | 503 |
483 void handleEvent(sky.Event event, HitTestEntry entry) { | 504 void handleEvent(sky.Event event, HitTestEntry entry) { |
484 if (event.type == 'pointerdown') | 505 if (event.type == 'pointerdown') |
485 decoration = new BoxDecoration(backgroundColor: const Color(0xFFFF0000)); | 506 decoration = new BoxDecoration(backgroundColor: const Color(0xFFFF0000)); |
486 else if (event.type == 'pointerup') | 507 else if (event.type == 'pointerup') |
487 decoration = new BoxDecoration(backgroundColor: backgroundColor); | 508 decoration = new BoxDecoration(backgroundColor: backgroundColor); |
488 } | 509 } |
489 } | 510 } |
490 | 511 |
491 AppView app; | 512 RenderBox buildSectorExample() { |
492 | 513 RenderSectorRing rootCircle = new RenderSectorRing(padding: 20.0); |
493 void main() { | |
494 | |
495 var rootCircle = new RenderSectorRing(padding: 20.0); | |
496 rootCircle.add(new RenderSolidColor(const Color(0xFF00FFFF), desiredDeltaTheta
: kTwoPi * 0.15)); | 514 rootCircle.add(new RenderSolidColor(const Color(0xFF00FFFF), desiredDeltaTheta
: kTwoPi * 0.15)); |
497 rootCircle.add(new RenderSolidColor(const Color(0xFF0000FF), desiredDeltaTheta
: kTwoPi * 0.4)); | 515 rootCircle.add(new RenderSolidColor(const Color(0xFF0000FF), desiredDeltaTheta
: kTwoPi * 0.4)); |
498 var stack = new RenderSectorSlice(padding: 2.0); | 516 RenderSectorSlice stack = new RenderSectorSlice(padding: 2.0); |
499 stack.add(new RenderSolidColor(const Color(0xFFFFFF00), desiredDeltaRadius: 20
.0)); | 517 stack.add(new RenderSolidColor(const Color(0xFFFFFF00), desiredDeltaRadius: 20
.0)); |
500 stack.add(new RenderSolidColor(const Color(0xFFFF9000), desiredDeltaRadius: 20
.0)); | 518 stack.add(new RenderSolidColor(const Color(0xFFFF9000), desiredDeltaRadius: 20
.0)); |
501 stack.add(new RenderSolidColor(const Color(0xFF00FF00))); | 519 stack.add(new RenderSolidColor(const Color(0xFF00FF00))); |
502 rootCircle.add(stack); | 520 rootCircle.add(stack); |
| 521 return new RenderBoxToRenderSectorAdapter(innerRadius: 50.0, child: rootCircle
); |
| 522 } |
503 | 523 |
504 var root = new RenderBoxToRenderSectorAdapter(innerRadius: 50.0, child: rootCi
rcle); | 524 void main() { |
505 app = new AppView(root: root); | 525 new AppView(root: buildSectorExample()); |
506 } | 526 } |
OLD | NEW |