Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(98)

Side by Side Diff: sky/examples/raw/sector-layout.dart

Issue 1156303004: Use Point, Size, and Rect in layout2.dart (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 } 257 }
258 258
259 // paint origin is 0,0 of our circle 259 // paint origin is 0,0 of our circle
260 // each sector then knows how to paint itself at its location 260 // each sector then knows how to paint itself at its location
261 void paint(RenderNodeDisplayList canvas) { 261 void paint(RenderNodeDisplayList canvas) {
262 // TODO(ianh): avoid code duplication 262 // TODO(ianh): avoid code duplication
263 super.paint(canvas); 263 super.paint(canvas);
264 RenderSector child = firstChild; 264 RenderSector child = firstChild;
265 while (child != null) { 265 while (child != null) {
266 assert(child.parentData is SectorChildListParentData); 266 assert(child.parentData is SectorChildListParentData);
267 canvas.paintChild(child, 0.0, 0.0); 267 canvas.paintChild(child, new sky.Point());
Hixie 2015/05/28 18:45:22 I don't like the way this looks. It's not obvious
268 child = child.parentData.nextSibling; 268 child = child.parentData.nextSibling;
269 } 269 }
270 } 270 }
271 271
272 } 272 }
273 273
274 class RenderSectorSlice extends RenderSectorWithChildren { 274 class RenderSectorSlice extends RenderSectorWithChildren {
275 // lays out RenderSector children in a stack 275 // lays out RenderSector children in a stack
276 276
277 RenderSectorSlice({ 277 RenderSectorSlice({
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 } 377 }
378 378
379 // paint origin is 0,0 of our circle 379 // paint origin is 0,0 of our circle
380 // each sector then knows how to paint itself at its location 380 // each sector then knows how to paint itself at its location
381 void paint(RenderNodeDisplayList canvas) { 381 void paint(RenderNodeDisplayList canvas) {
382 // TODO(ianh): avoid code duplication 382 // TODO(ianh): avoid code duplication
383 super.paint(canvas); 383 super.paint(canvas);
384 RenderSector child = firstChild; 384 RenderSector child = firstChild;
385 while (child != null) { 385 while (child != null) {
386 assert(child.parentData is SectorChildListParentData); 386 assert(child.parentData is SectorChildListParentData);
387 canvas.paintChild(child, 0.0, 0.0); 387 canvas.paintChild(child, new sky.Point());
388 child = child.parentData.nextSibling; 388 child = child.parentData.nextSibling;
389 } 389 }
390 } 390 }
391 391
392 } 392 }
393 393
394 class RenderBoxToRenderSectorAdapter extends RenderBox { 394 class RenderBoxToRenderSectorAdapter extends RenderBox {
395 395
396 RenderBoxToRenderSectorAdapter({ double innerRadius: 0.0, RenderSector child } ) : 396 RenderBoxToRenderSectorAdapter({ double innerRadius: 0.0, RenderSector child } ) :
397 _innerRadius = innerRadius { 397 _innerRadius = innerRadius {
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
456 layoutDone(); 456 layoutDone();
457 } 457 }
458 458
459 double width; 459 double width;
460 double height; 460 double height;
461 461
462 // paint origin is 0,0 of our circle 462 // paint origin is 0,0 of our circle
463 void paint(RenderNodeDisplayList canvas) { 463 void paint(RenderNodeDisplayList canvas) {
464 super.paint(canvas); 464 super.paint(canvas);
465 if (child != null) 465 if (child != null)
466 canvas.paintChild(child, width/2.0, height/2.0); 466 canvas.paintChild(child, new sky.Point(width/2.0, height/2.0));
Hixie 2015/05/28 18:45:22 We could replace width/height with a Rect and then
467 } 467 }
468 468
469 bool hitTest(HitTestResult result, { double x, double y }) { 469 bool hitTest(HitTestResult result, { sky.Point position }) {
470 double x = position.x;
471 double y = position.y;
470 if (child == null) 472 if (child == null)
471 return false; 473 return false;
472 // translate to our origin 474 // translate to our origin
473 x -= width/2.0; 475 x -= width/2.0;
474 y -= height/2.0; 476 y -= height/2.0;
475 // convert to radius/theta 477 // convert to radius/theta
476 double radius = math.sqrt(x*x+y*y); 478 double radius = math.sqrt(x*x+y*y);
477 double theta = (math.atan2(x, -y) - math.PI/2.0) % kTwoPi; 479 double theta = (math.atan2(x, -y) - math.PI/2.0) % kTwoPi;
478 if (radius < innerRadius) 480 if (radius < innerRadius)
479 return false; 481 return false;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
526 rootCircle.add(new RenderSolidColor(0xFF0000FF, desiredDeltaTheta: kTwoPi * 0. 4)); 528 rootCircle.add(new RenderSolidColor(0xFF0000FF, desiredDeltaTheta: kTwoPi * 0. 4));
527 var stack = new RenderSectorSlice(padding: 2.0); 529 var stack = new RenderSectorSlice(padding: 2.0);
528 stack.add(new RenderSolidColor(0xFFFFFF00, desiredDeltaRadius: 20.0)); 530 stack.add(new RenderSolidColor(0xFFFFFF00, desiredDeltaRadius: 20.0));
529 stack.add(new RenderSolidColor(0xFFFF9000, desiredDeltaRadius: 20.0)); 531 stack.add(new RenderSolidColor(0xFFFF9000, desiredDeltaRadius: 20.0));
530 stack.add(new RenderSolidColor(0xFF00FF00)); 532 stack.add(new RenderSolidColor(0xFF00FF00));
531 rootCircle.add(stack); 533 rootCircle.add(stack);
532 534
533 var root = new RenderBoxToRenderSectorAdapter(innerRadius: 50.0, child: rootCi rcle); 535 var root = new RenderBoxToRenderSectorAdapter(innerRadius: 50.0, child: rootCi rcle);
534 app = new AppView(root); 536 app = new AppView(root);
535 } 537 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698