| 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 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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(); |
| 113 } | 113 } |
| 114 | 114 |
| 115 // origin must be set to the center of the circle | 115 // origin must be set to the center of the circle |
| 116 void paint(RenderObjectDisplayList canvas) { | 116 void paint(sky.Canvas canvas) { |
| 117 assert(deltaRadius != null); | 117 assert(deltaRadius != null); |
| 118 assert(deltaTheta != null); | 118 assert(deltaTheta != null); |
| 119 assert(parentData is SectorParentData); | 119 assert(parentData is SectorParentData); |
| 120 | 120 |
| 121 if (_decoration == null) | 121 if (_decoration == null) |
| 122 return; | 122 return; |
| 123 | 123 |
| 124 if (_decoration.backgroundColor != null) { | 124 if (_decoration.backgroundColor != null) { |
| 125 Paint paint = new Paint()..color = _decoration.backgroundColor; | 125 Paint paint = new Paint()..color = _decoration.backgroundColor; |
| 126 Path path = new Path(); | 126 Path path = new Path(); |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 if (child != null) { | 242 if (child != null) { |
| 243 innerTheta += paddingTheta; | 243 innerTheta += paddingTheta; |
| 244 remainingDeltaTheta -= paddingTheta; | 244 remainingDeltaTheta -= paddingTheta; |
| 245 } | 245 } |
| 246 } | 246 } |
| 247 deltaTheta = innerTheta; | 247 deltaTheta = innerTheta; |
| 248 } | 248 } |
| 249 | 249 |
| 250 // paint origin is 0,0 of our circle | 250 // paint origin is 0,0 of our circle |
| 251 // each sector then knows how to paint itself at its location | 251 // each sector then knows how to paint itself at its location |
| 252 void paint(RenderObjectDisplayList canvas) { | 252 void paint(sky.Canvas canvas) { |
| 253 // TODO(ianh): avoid code duplication | 253 // TODO(ianh): avoid code duplication |
| 254 super.paint(canvas); | 254 super.paint(canvas); |
| 255 RenderSector child = firstChild; | 255 RenderSector child = firstChild; |
| 256 while (child != null) { | 256 while (child != null) { |
| 257 assert(child.parentData is SectorChildListParentData); | 257 assert(child.parentData is SectorChildListParentData); |
| 258 canvas.paintChild(child, Point.origin); | 258 paintChild(canvas, child, Point.origin); |
| 259 child = child.parentData.nextSibling; | 259 child = child.parentData.nextSibling; |
| 260 } | 260 } |
| 261 } | 261 } |
| 262 | 262 |
| 263 } | 263 } |
| 264 | 264 |
| 265 class RenderSectorSlice extends RenderSectorWithChildren { | 265 class RenderSectorSlice extends RenderSectorWithChildren { |
| 266 // lays out RenderSector children in a stack | 266 // lays out RenderSector children in a stack |
| 267 | 267 |
| 268 RenderSectorSlice({ | 268 RenderSectorSlice({ |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 347 assert(child.parentData is SectorChildListParentData); | 347 assert(child.parentData is SectorChildListParentData); |
| 348 child = child.parentData.nextSibling; | 348 child = child.parentData.nextSibling; |
| 349 childRadius += padding; | 349 childRadius += padding; |
| 350 remainingDeltaRadius -= padding; | 350 remainingDeltaRadius -= padding; |
| 351 } | 351 } |
| 352 deltaRadius = childRadius - this.parentData.radius; | 352 deltaRadius = childRadius - this.parentData.radius; |
| 353 } | 353 } |
| 354 | 354 |
| 355 // paint origin is 0,0 of our circle | 355 // paint origin is 0,0 of our circle |
| 356 // each sector then knows how to paint itself at its location | 356 // each sector then knows how to paint itself at its location |
| 357 void paint(RenderObjectDisplayList canvas) { | 357 void paint(sky.Canvas canvas) { |
| 358 // TODO(ianh): avoid code duplication | 358 // TODO(ianh): avoid code duplication |
| 359 super.paint(canvas); | 359 super.paint(canvas); |
| 360 RenderSector child = firstChild; | 360 RenderSector child = firstChild; |
| 361 while (child != null) { | 361 while (child != null) { |
| 362 assert(child.parentData is SectorChildListParentData); | 362 assert(child.parentData is SectorChildListParentData); |
| 363 canvas.paintChild(child, Point.origin); | 363 paintChild(canvas, child, Point.origin); |
| 364 child = child.parentData.nextSibling; | 364 child = child.parentData.nextSibling; |
| 365 } | 365 } |
| 366 } | 366 } |
| 367 | 367 |
| 368 } | 368 } |
| 369 | 369 |
| 370 class RenderBoxToRenderSectorAdapter extends RenderBox { | 370 class RenderBoxToRenderSectorAdapter extends RenderBox { |
| 371 | 371 |
| 372 RenderBoxToRenderSectorAdapter({ double innerRadius: 0.0, RenderSector child }
) : | 372 RenderBoxToRenderSectorAdapter({ double innerRadius: 0.0, RenderSector child }
) : |
| 373 _innerRadius = innerRadius { | 373 _innerRadius = innerRadius { |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 421 assert(child.parentData is SectorParentData); | 421 assert(child.parentData is SectorParentData); |
| 422 child.parentData.radius = innerRadius; | 422 child.parentData.radius = innerRadius; |
| 423 child.parentData.theta = 0.0; | 423 child.parentData.theta = 0.0; |
| 424 child.layout(new SectorConstraints(maxDeltaRadius: maxChildDeltaRadius), p
arentUsesSize: true); | 424 child.layout(new SectorConstraints(maxDeltaRadius: maxChildDeltaRadius), p
arentUsesSize: true); |
| 425 double dimension = (innerRadius + child.deltaRadius) * 2.0; | 425 double dimension = (innerRadius + child.deltaRadius) * 2.0; |
| 426 size = constraints.constrain(new Size(dimension, dimension)); | 426 size = constraints.constrain(new Size(dimension, dimension)); |
| 427 } | 427 } |
| 428 } | 428 } |
| 429 | 429 |
| 430 // paint origin is 0,0 of our circle | 430 // paint origin is 0,0 of our circle |
| 431 void paint(RenderObjectDisplayList canvas) { | 431 void paint(sky.Canvas canvas) { |
| 432 super.paint(canvas); | 432 super.paint(canvas); |
| 433 if (child != null) { | 433 if (child != null) { |
| 434 Rect bounds = new Rect.fromSize(size); | 434 Rect bounds = new Rect.fromSize(size); |
| 435 canvas.paintChild(child, bounds.center); | 435 paintChild(canvas, child, bounds.center); |
| 436 } | 436 } |
| 437 } | 437 } |
| 438 | 438 |
| 439 bool hitTest(HitTestResult result, { Point position }) { | 439 bool hitTest(HitTestResult result, { Point position }) { |
| 440 double x = position.x; | 440 double x = position.x; |
| 441 double y = position.y; | 441 double y = position.y; |
| 442 if (child == null) | 442 if (child == null) |
| 443 return false; | 443 return false; |
| 444 // translate to our origin | 444 // translate to our origin |
| 445 x -= size.width/2.0; | 445 x -= size.width/2.0; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 |