containsPoint method
- Vector2 point
override
Whether this node's hit area contains point.
The default implementation always returns false, so plain nodes are invisible to hitTest. Override to opt a node into hit-testing.
Implementation
@override
bool containsPoint(Vector2 point) {
final local = toLocal(point);
final adjusted = Vector2(
local.x + anchor.x * width,
local.y + anchor.y * height,
);
switch (shape) {
case Rectangle(:final size):
return adjusted.x >= 0 && //
adjusted.x <= size.x &&
adjusted.y >= 0 &&
adjusted.y <= size.y;
case Circle(:final radius):
final dx = adjusted.x - radius;
final dy = adjusted.y - radius;
return dx * dx + dy * dy <= radius * radius;
}
}