Chromium Code Reviews| Index: sky/examples/game/lib/node_with_size.dart |
| diff --git a/sky/examples/game/lib/node_with_size.dart b/sky/examples/game/lib/node_with_size.dart |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..1e7c65729c90c1f9060a30690531a67c2a52f040 |
| --- /dev/null |
| +++ b/sky/examples/game/lib/node_with_size.dart |
| @@ -0,0 +1,31 @@ |
| +part of sprites; |
| + |
| +abstract class NodeWithSize extends Node { |
| + Size size; |
| + Point pivot; |
| + |
| + NodeWithSize() { |
| + size = new Size(0.0, 0.0); |
| + pivot = new Point(0.0, 0.0); |
|
abarth-chromium
2015/06/11 00:20:20
Size.zero
Point.origin
|
| + } |
| + |
| + NodeWithSize.withSize(Size size, [Point pivot]); |
| + |
| + void applyTransformForPivot(PictureRecorder canvas) { |
| + if (pivot.x != 0 || pivot.y != 0) { |
| + double pivotInPointsX = size.width * pivot.x; |
| + double pivotInPointsY = size.height * pivot.y; |
| + canvas.translate(-pivotInPointsX, -pivotInPointsY); |
| + } |
| + } |
| + |
| + bool hitTest (Point nodePoint) { |
| + |
| + double minX = -size.width * pivot.x; |
| + double minY = -size.height * pivot.y; |
| + double maxX = minX + size.width; |
| + double maxY = minY + size.height; |
| + return (nodePoint.x >= minX && nodePoint.x < maxX && |
| + nodePoint.y >= minY && nodePoint.y < maxY); |
| + } |
| +} |