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 |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 // true so that performResize()'s logic above does its thing. | 83 // true so that performResize()'s logic above does its thing. |
84 assert(sizedByParent); | 84 assert(sizedByParent); |
85 } | 85 } |
86 | 86 |
87 bool hitTest(HitTestResult result, { double radius, double theta }) { | 87 bool hitTest(HitTestResult result, { double radius, double theta }) { |
88 assert(parentData is SectorParentData); | 88 assert(parentData is SectorParentData); |
89 if (radius < parentData.radius || radius >= parentData.radius + deltaRadius
|| | 89 if (radius < parentData.radius || radius >= parentData.radius + deltaRadius
|| |
90 theta < parentData.theta || theta >= parentData.theta + deltaTheta) | 90 theta < parentData.theta || theta >= parentData.theta + deltaTheta) |
91 return false; | 91 return false; |
92 hitTestChildren(result, radius: radius, theta: theta); | 92 hitTestChildren(result, radius: radius, theta: theta); |
93 result.add(this); | 93 result.add(new HitTestData(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 class RenderDecoratedSector extends RenderSector { |
103 | 103 |
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
447 // convert to radius/theta | 447 // convert to radius/theta |
448 double radius = math.sqrt(x*x+y*y); | 448 double radius = math.sqrt(x*x+y*y); |
449 double theta = (math.atan2(x, -y) - math.PI/2.0) % kTwoPi; | 449 double theta = (math.atan2(x, -y) - math.PI/2.0) % kTwoPi; |
450 if (radius < innerRadius) | 450 if (radius < innerRadius) |
451 return false; | 451 return false; |
452 if (radius >= innerRadius + child.deltaRadius) | 452 if (radius >= innerRadius + child.deltaRadius) |
453 return false; | 453 return false; |
454 if (theta > child.deltaTheta) | 454 if (theta > child.deltaTheta) |
455 return false; | 455 return false; |
456 child.hitTest(result, radius: radius, theta: theta); | 456 child.hitTest(result, radius: radius, theta: theta); |
457 result.add(this); | 457 result.add(new BoxHitTestData(this, position)); |
458 return true; | 458 return true; |
459 } | 459 } |
460 | 460 |
461 } | 461 } |
462 | 462 |
463 class RenderSolidColor extends RenderDecoratedSector { | 463 class RenderSolidColor extends RenderDecoratedSector { |
464 RenderSolidColor(Color backgroundColor, { | 464 RenderSolidColor(Color backgroundColor, { |
465 this.desiredDeltaRadius: double.INFINITY, | 465 this.desiredDeltaRadius: double.INFINITY, |
466 this.desiredDeltaTheta: kTwoPi | 466 this.desiredDeltaTheta: kTwoPi |
467 }) : this.backgroundColor = backgroundColor, | 467 }) : this.backgroundColor = backgroundColor, |
468 super(new BoxDecoration(backgroundColor: backgroundColor)); | 468 super(new BoxDecoration(backgroundColor: backgroundColor)); |
469 | 469 |
470 double desiredDeltaRadius; | 470 double desiredDeltaRadius; |
471 double desiredDeltaTheta; | 471 double desiredDeltaTheta; |
472 final Color backgroundColor; | 472 final Color backgroundColor; |
473 | 473 |
474 SectorDimensions getIntrinsicDimensions(SectorConstraints constraints, double
radius) { | 474 SectorDimensions getIntrinsicDimensions(SectorConstraints constraints, double
radius) { |
475 return new SectorDimensions.withConstraints(constraints, deltaTheta: 1.0); /
/ 1.0 radians | 475 return new SectorDimensions.withConstraints(constraints, deltaTheta: 1.0); /
/ 1.0 radians |
476 } | 476 } |
477 | 477 |
478 void performLayout() { | 478 void performLayout() { |
479 deltaRadius = constraints.constrainDeltaRadius(desiredDeltaRadius); | 479 deltaRadius = constraints.constrainDeltaRadius(desiredDeltaRadius); |
480 deltaTheta = constraints.constrainDeltaTheta(desiredDeltaTheta); | 480 deltaTheta = constraints.constrainDeltaTheta(desiredDeltaTheta); |
481 } | 481 } |
482 | 482 |
483 void handleEvent(sky.Event event) { | 483 void handleEvent(sky.Event event, HitTestData data) { |
484 if (event.type == 'pointerdown') | 484 if (event.type == 'pointerdown') |
485 decoration = new BoxDecoration(backgroundColor: const Color(0xFFFF0000)); | 485 decoration = new BoxDecoration(backgroundColor: const Color(0xFFFF0000)); |
486 else if (event.type == 'pointerup') | 486 else if (event.type == 'pointerup') |
487 decoration = new BoxDecoration(backgroundColor: backgroundColor); | 487 decoration = new BoxDecoration(backgroundColor: backgroundColor); |
488 } | 488 } |
489 } | 489 } |
490 | 490 |
491 AppView app; | 491 AppView app; |
492 | 492 |
493 void main() { | 493 void main() { |
494 | 494 |
495 var rootCircle = new RenderSectorRing(padding: 20.0); | 495 var rootCircle = new RenderSectorRing(padding: 20.0); |
496 rootCircle.add(new RenderSolidColor(const Color(0xFF00FFFF), desiredDeltaTheta
: kTwoPi * 0.15)); | 496 rootCircle.add(new RenderSolidColor(const Color(0xFF00FFFF), desiredDeltaTheta
: kTwoPi * 0.15)); |
497 rootCircle.add(new RenderSolidColor(const Color(0xFF0000FF), desiredDeltaTheta
: kTwoPi * 0.4)); | 497 rootCircle.add(new RenderSolidColor(const Color(0xFF0000FF), desiredDeltaTheta
: kTwoPi * 0.4)); |
498 var stack = new RenderSectorSlice(padding: 2.0); | 498 var stack = new RenderSectorSlice(padding: 2.0); |
499 stack.add(new RenderSolidColor(const Color(0xFFFFFF00), desiredDeltaRadius: 20
.0)); | 499 stack.add(new RenderSolidColor(const Color(0xFFFFFF00), desiredDeltaRadius: 20
.0)); |
500 stack.add(new RenderSolidColor(const Color(0xFFFF9000), desiredDeltaRadius: 20
.0)); | 500 stack.add(new RenderSolidColor(const Color(0xFFFF9000), desiredDeltaRadius: 20
.0)); |
501 stack.add(new RenderSolidColor(const Color(0xFF00FF00))); | 501 stack.add(new RenderSolidColor(const Color(0xFF00FF00))); |
502 rootCircle.add(stack); | 502 rootCircle.add(stack); |
503 | 503 |
504 var root = new RenderBoxToRenderSectorAdapter(innerRadius: 50.0, child: rootCi
rcle); | 504 var root = new RenderBoxToRenderSectorAdapter(innerRadius: 50.0, child: rootCi
rcle); |
505 app = new AppView(root); | 505 app = new AppView(root); |
506 } | 506 } |
OLD | NEW |