hitTest method
Determines if the display object or any of its children intersect with a
localPoint
. If useShape
is set to true, the hit test will take the
shape of the object into account. If mouseChildren is false, only the
current display object will be tested.
Returns the top-most display object that intersects with the localPoint
.
If there's no intersection, returns null.
If the useShape
is set to true, the shape of the display object is used
to determine the hit. Otherwise, the bounding box of the object is used.
If the mouseChildren is set to false, only the current display object
will be tested. If it is true, the hit test will continue on its children.
Implementation
@override
GDisplayObject? hitTest(GPoint localPoint, [bool useShape = false]) {
if (!$hasTouchableArea || !mouseEnabled || !hitTestMask(localPoint)) {
return null;
}
/// optimization.
if (!mouseChildren) {
return super.hitTest(localPoint, useShape);
}
final numChild = children.length;
for (var i = numChild - 1; i >= 0; --i) {
var child = children[i];
if (child.isMask) continue;
_sHitTestMatrix.copyFrom(child.transformationMatrix);
_sHitTestMatrix.invert();
_sHitTestMatrix.transformCoords(
localPoint.x,
localPoint.y,
_sHitTestPoint,
);
final target = child.hitTest(_sHitTestPoint);
if (target != null) {
return mouseChildren ? this : target;
}
}
return null;
}