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

Side by Side Diff: sky/examples/game/lib/node_with_size.dart

Issue 1190123003: Decouple Canvas from DisplayList and map Picture and PictureRecorder more directly to their Skia co… (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Rebased version of previous patch 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 part of sprites; 1 part of sprites;
2 2
3 /// The super class of any [Node] that has a size. 3 /// The super class of any [Node] that has a size.
4 /// 4 ///
5 /// NodeWithSize adds the ability for a node to have a size and a pivot point. 5 /// NodeWithSize adds the ability for a node to have a size and a pivot point.
6 abstract class NodeWithSize extends Node { 6 abstract class NodeWithSize extends Node {
7 7
8 /// Changing the size will affect the size of the rendering of the node. 8 /// Changing the size will affect the size of the rendering of the node.
9 /// 9 ///
10 /// myNode.size = new Size(1024.0, 1024.0); 10 /// myNode.size = new Size(1024.0, 1024.0);
(...skipping 14 matching lines...) Expand all
25 if (size == null) size = Size.zero; 25 if (size == null) size = Size.zero;
26 if (pivot == null) pivot = Point.origin; 26 if (pivot == null) pivot = Point.origin;
27 } 27 }
28 28
29 /// Call this method in your [paint] method if you want the origin of your dra wing to be the top left corner of the 29 /// Call this method in your [paint] method if you want the origin of your dra wing to be the top left corner of the
30 /// node's bounding box. 30 /// node's bounding box.
31 /// 31 ///
32 /// If you use this method you will need to save and restore your canvas at th e beginning and 32 /// If you use this method you will need to save and restore your canvas at th e beginning and
33 /// end of your [paint] method. 33 /// end of your [paint] method.
34 /// 34 ///
35 /// void paint(PictureRecorder canvas) { 35 /// void paint(RenderCanvas canvas) {
36 /// canvas.save(); 36 /// canvas.save();
37 /// applyTransformForPivot(canvas); 37 /// applyTransformForPivot(canvas);
38 /// 38 ///
39 /// // Do painting here 39 /// // Do painting here
40 /// 40 ///
41 /// canvas.restore(); 41 /// canvas.restore();
42 /// } 42 /// }
43 void applyTransformForPivot(PictureRecorder canvas) { 43 void applyTransformForPivot(RenderCanvas canvas) {
44 if (pivot.x != 0 || pivot.y != 0) { 44 if (pivot.x != 0 || pivot.y != 0) {
45 double pivotInPointsX = size.width * pivot.x; 45 double pivotInPointsX = size.width * pivot.x;
46 double pivotInPointsY = size.height * pivot.y; 46 double pivotInPointsY = size.height * pivot.y;
47 canvas.translate(-pivotInPointsX, -pivotInPointsY); 47 canvas.translate(-pivotInPointsX, -pivotInPointsY);
48 } 48 }
49 } 49 }
50 50
51 bool isPointInside (Point nodePoint) { 51 bool isPointInside (Point nodePoint) {
52 52
53 double minX = -size.width * pivot.x; 53 double minX = -size.width * pivot.x;
54 double minY = -size.height * pivot.y; 54 double minY = -size.height * pivot.y;
55 double maxX = minX + size.width; 55 double maxX = minX + size.width;
56 double maxY = minY + size.height; 56 double maxY = minY + size.height;
57 return (nodePoint.x >= minX && nodePoint.x < maxX && 57 return (nodePoint.x >= minX && nodePoint.x < maxX &&
58 nodePoint.y >= minY && nodePoint.y < maxY); 58 nodePoint.y >= minY && nodePoint.y < maxY);
59 } 59 }
60 } 60 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698