OLD | NEW |
1 part of sprites; | 1 part of sprites; |
2 | 2 |
3 abstract class NodeWithSize extends Node { | 3 abstract class NodeWithSize extends Node { |
4 Size size; | 4 Size size; |
5 Point pivot; | 5 Point pivot; |
6 | 6 |
7 NodeWithSize() { | 7 NodeWithSize() { |
8 size = Size.zero; | 8 size = Size.zero; |
9 pivot = Point.origin; | 9 pivot = Point.origin; |
10 } | 10 } |
11 | 11 |
12 NodeWithSize.withSize(Size this.size, [Point this.pivot]); | 12 NodeWithSize.withSize(Size this.size, [Point this.pivot]) { |
| 13 if (pivot == null) pivot = Point.origin; |
| 14 } |
13 | 15 |
14 void applyTransformForPivot(PictureRecorder canvas) { | 16 void applyTransformForPivot(PictureRecorder canvas) { |
15 if (pivot.x != 0 || pivot.y != 0) { | 17 if (pivot.x != 0 || pivot.y != 0) { |
16 double pivotInPointsX = size.width * pivot.x; | 18 double pivotInPointsX = size.width * pivot.x; |
17 double pivotInPointsY = size.height * pivot.y; | 19 double pivotInPointsY = size.height * pivot.y; |
18 canvas.translate(-pivotInPointsX, -pivotInPointsY); | 20 canvas.translate(-pivotInPointsX, -pivotInPointsY); |
19 } | 21 } |
20 } | 22 } |
21 | 23 |
22 bool hitTest (Point nodePoint) { | 24 bool hitTest (Point nodePoint) { |
23 | 25 |
24 double minX = -size.width * pivot.x; | 26 double minX = -size.width * pivot.x; |
25 double minY = -size.height * pivot.y; | 27 double minY = -size.height * pivot.y; |
26 double maxX = minX + size.width; | 28 double maxX = minX + size.width; |
27 double maxY = minY + size.height; | 29 double maxY = minY + size.height; |
28 return (nodePoint.x >= minX && nodePoint.x < maxX && | 30 return (nodePoint.x >= minX && nodePoint.x < maxX && |
29 nodePoint.y >= minY && nodePoint.y < maxY); | 31 nodePoint.y >= minY && nodePoint.y < maxY); |
30 } | 32 } |
31 } | 33 } |
OLD | NEW |