| 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/layout2.dart'; | 8 import 'package:sky/framework/layout2.dart'; | 
| 9 | 9 | 
| 10 const double kTwoPi = 2 * math.PI; | 10 const double kTwoPi = 2 * math.PI; | 
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 249   } | 249   } | 
| 250 | 250 | 
| 251   // paint origin is 0,0 of our circle | 251   // paint origin is 0,0 of our circle | 
| 252   // each sector then knows how to paint itself at its location | 252   // each sector then knows how to paint itself at its location | 
| 253   void paint(RenderNodeDisplayList canvas) { | 253   void paint(RenderNodeDisplayList canvas) { | 
| 254     // TODO(ianh): avoid code duplication | 254     // TODO(ianh): avoid code duplication | 
| 255     super.paint(canvas); | 255     super.paint(canvas); | 
| 256     RenderSector child = firstChild; | 256     RenderSector child = firstChild; | 
| 257     while (child != null) { | 257     while (child != null) { | 
| 258       assert(child.parentData is SectorChildListParentData); | 258       assert(child.parentData is SectorChildListParentData); | 
| 259       canvas.paintChild(child, 0.0, 0.0); | 259       canvas.paintChild(child, new sky.Point(0.0, 0.0)); | 
| 260       child = child.parentData.nextSibling; | 260       child = child.parentData.nextSibling; | 
| 261     } | 261     } | 
| 262   } | 262   } | 
| 263 | 263 | 
| 264 } | 264 } | 
| 265 | 265 | 
| 266 class RenderSectorSlice extends RenderSectorWithChildren { | 266 class RenderSectorSlice extends RenderSectorWithChildren { | 
| 267   // lays out RenderSector children in a stack | 267   // lays out RenderSector children in a stack | 
| 268 | 268 | 
| 269   RenderSectorSlice({ | 269   RenderSectorSlice({ | 
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 354   } | 354   } | 
| 355 | 355 | 
| 356   // paint origin is 0,0 of our circle | 356   // paint origin is 0,0 of our circle | 
| 357   // each sector then knows how to paint itself at its location | 357   // each sector then knows how to paint itself at its location | 
| 358   void paint(RenderNodeDisplayList canvas) { | 358   void paint(RenderNodeDisplayList canvas) { | 
| 359     // TODO(ianh): avoid code duplication | 359     // TODO(ianh): avoid code duplication | 
| 360     super.paint(canvas); | 360     super.paint(canvas); | 
| 361     RenderSector child = firstChild; | 361     RenderSector child = firstChild; | 
| 362     while (child != null) { | 362     while (child != null) { | 
| 363       assert(child.parentData is SectorChildListParentData); | 363       assert(child.parentData is SectorChildListParentData); | 
| 364       canvas.paintChild(child, 0.0, 0.0); | 364       canvas.paintChild(child, new sky.Point(0.0, 0.0)); | 
| 365       child = child.parentData.nextSibling; | 365       child = child.parentData.nextSibling; | 
| 366     } | 366     } | 
| 367   } | 367   } | 
| 368 | 368 | 
| 369 } | 369 } | 
| 370 | 370 | 
| 371 class RenderBoxToRenderSectorAdapter extends RenderBox { | 371 class RenderBoxToRenderSectorAdapter extends RenderBox { | 
| 372 | 372 | 
| 373   RenderBoxToRenderSectorAdapter({ double innerRadius: 0.0, RenderSector child }
     ) : | 373   RenderBoxToRenderSectorAdapter({ double innerRadius: 0.0, RenderSector child }
     ) : | 
| 374     _innerRadius = innerRadius { | 374     _innerRadius = innerRadius { | 
| (...skipping 29 matching lines...) Expand all  Loading... | 
| 404     assert(child is RenderSector); | 404     assert(child is RenderSector); | 
| 405     assert(child.parentData is SectorParentData); | 405     assert(child.parentData is SectorParentData); | 
| 406     assert(!constraints.isInfinite); | 406     assert(!constraints.isInfinite); | 
| 407     double maxChildDeltaRadius = math.min(constraints.maxWidth, constraints.maxH
     eight) / 2.0 - innerRadius; | 407     double maxChildDeltaRadius = math.min(constraints.maxWidth, constraints.maxH
     eight) / 2.0 - innerRadius; | 
| 408     SectorDimensions childDimensions = child.getIntrinsicDimensions(new SectorCo
     nstraints(maxDeltaRadius: maxChildDeltaRadius), innerRadius); | 408     SectorDimensions childDimensions = child.getIntrinsicDimensions(new SectorCo
     nstraints(maxDeltaRadius: maxChildDeltaRadius), innerRadius); | 
| 409     double dimension = (innerRadius + childDimensions.deltaRadius) * 2.0; | 409     double dimension = (innerRadius + childDimensions.deltaRadius) * 2.0; | 
| 410     return new BoxDimensions.withConstraints(constraints, width: dimension, heig
     ht: dimension); | 410     return new BoxDimensions.withConstraints(constraints, width: dimension, heig
     ht: dimension); | 
| 411   } | 411   } | 
| 412 | 412 | 
| 413   void performLayout() { | 413   void performLayout() { | 
| 414     BoxDimensions ourDimensions; |  | 
| 415     if (child == null) { | 414     if (child == null) { | 
| 416       ourDimensions = new BoxDimensions.withConstraints(constraints, width: 0.0,
      height: 0.0); | 415       size = constraints.constrain(new sky.Size(0.0, 0.0)); | 
| 417     } else { | 416     } else { | 
| 418       assert(child is RenderSector); | 417       assert(child is RenderSector); | 
| 419       assert(!constraints.isInfinite); | 418       assert(!constraints.isInfinite); | 
| 420       double maxChildDeltaRadius = math.min(constraints.maxWidth, constraints.ma
     xHeight) / 2.0 - innerRadius; | 419       double maxChildDeltaRadius = math.min(constraints.maxWidth, constraints.ma
     xHeight) / 2.0 - innerRadius; | 
| 421       assert(child.parentData is SectorParentData); | 420       assert(child.parentData is SectorParentData); | 
| 422       child.parentData.radius = innerRadius; | 421       child.parentData.radius = innerRadius; | 
| 423       child.parentData.theta = 0.0; | 422       child.parentData.theta = 0.0; | 
| 424       child.layout(new SectorConstraints(maxDeltaRadius: maxChildDeltaRadius), p
     arentUsesSize: true); | 423       child.layout(new SectorConstraints(maxDeltaRadius: maxChildDeltaRadius), p
     arentUsesSize: true); | 
| 425       double dimension = (innerRadius + child.deltaRadius) * 2.0; | 424       double dimension = (innerRadius + child.deltaRadius) * 2.0; | 
| 426       ourDimensions = new BoxDimensions.withConstraints(constraints, width: dime
     nsion, height: dimension); | 425       size = constraints.constrain(new sky.Size(dimension, dimension)); | 
| 427     } | 426     } | 
| 428     width = ourDimensions.width; |  | 
| 429     height = ourDimensions.height; |  | 
| 430   } | 427   } | 
| 431 | 428 | 
| 432   double width; |  | 
| 433   double height; |  | 
| 434 |  | 
| 435   // paint origin is 0,0 of our circle | 429   // paint origin is 0,0 of our circle | 
| 436   void paint(RenderNodeDisplayList canvas) { | 430   void paint(RenderNodeDisplayList canvas) { | 
| 437     super.paint(canvas); | 431     super.paint(canvas); | 
| 438     if (child != null) | 432     if (child != null) { | 
| 439       canvas.paintChild(child, width/2.0, height/2.0); | 433       sky.Rect bounds = new sky.Rect.fromSize(size); | 
|  | 434       canvas.paintChild(child, bounds.center); | 
|  | 435     } | 
| 440   } | 436   } | 
| 441 | 437 | 
| 442   bool hitTest(HitTestResult result, { double x, double y }) { | 438   bool hitTest(HitTestResult result, { sky.Point position }) { | 
|  | 439     double x = position.x; | 
|  | 440     double y = position.y; | 
| 443     if (child == null) | 441     if (child == null) | 
| 444       return false; | 442       return false; | 
| 445     // translate to our origin | 443     // translate to our origin | 
| 446     x -= width/2.0; | 444     x -= size.width/2.0; | 
| 447     y -= height/2.0; | 445     y -= size.height/2.0; | 
| 448     // convert to radius/theta | 446     // convert to radius/theta | 
| 449     double radius = math.sqrt(x*x+y*y); | 447     double radius = math.sqrt(x*x+y*y); | 
| 450     double theta = (math.atan2(x, -y) - math.PI/2.0) % kTwoPi; | 448     double theta = (math.atan2(x, -y) - math.PI/2.0) % kTwoPi; | 
| 451     if (radius < innerRadius) | 449     if (radius < innerRadius) | 
| 452       return false; | 450       return false; | 
| 453     if (radius >= innerRadius + child.deltaRadius) | 451     if (radius >= innerRadius + child.deltaRadius) | 
| 454       return false; | 452       return false; | 
| 455     if (theta > child.deltaTheta) | 453     if (theta > child.deltaTheta) | 
| 456       return false; | 454       return false; | 
| 457     child.hitTest(result, radius: radius, theta: theta); | 455     child.hitTest(result, radius: radius, theta: theta); | 
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 498   rootCircle.add(new RenderSolidColor(0xFF0000FF, desiredDeltaTheta: kTwoPi * 0.
     4)); | 496   rootCircle.add(new RenderSolidColor(0xFF0000FF, desiredDeltaTheta: kTwoPi * 0.
     4)); | 
| 499   var stack = new RenderSectorSlice(padding: 2.0); | 497   var stack = new RenderSectorSlice(padding: 2.0); | 
| 500   stack.add(new RenderSolidColor(0xFFFFFF00, desiredDeltaRadius: 20.0)); | 498   stack.add(new RenderSolidColor(0xFFFFFF00, desiredDeltaRadius: 20.0)); | 
| 501   stack.add(new RenderSolidColor(0xFFFF9000, desiredDeltaRadius: 20.0)); | 499   stack.add(new RenderSolidColor(0xFFFF9000, desiredDeltaRadius: 20.0)); | 
| 502   stack.add(new RenderSolidColor(0xFF00FF00)); | 500   stack.add(new RenderSolidColor(0xFF00FF00)); | 
| 503   rootCircle.add(stack); | 501   rootCircle.add(stack); | 
| 504 | 502 | 
| 505   var root = new RenderBoxToRenderSectorAdapter(innerRadius: 50.0, child: rootCi
     rcle); | 503   var root = new RenderBoxToRenderSectorAdapter(innerRadius: 50.0, child: rootCi
     rcle); | 
| 506   app = new AppView(root); | 504   app = new AppView(root); | 
| 507 } | 505 } | 
| OLD | NEW | 
|---|