hitTestInput method

  1. @override
DisplayObject? hitTestInput(
  1. num localX,
  2. num localY
)
override

Evaluates this display object to see if the coordinates localX and localY are inside this display object.

If the coordinates are inside, this display object is returned; null otherwise.

localX and localY are relative to to the origin (0,0) of this display object (local coordinates).

Implementation

@override
DisplayObject? hitTestInput(num localX, num localY) {
  localX = localX.toDouble();
  localY = localY.toDouble();

  DisplayObject? hit;

  for (var i = _children.length - 1; i >= 0; i--) {
    final child = _children[i];
    final mask = child.mask;
    final matrix = child.transformationMatrix;

    if (child.visible && child.off == false) {
      final deltaX = localX - matrix.tx;
      final deltaY = localY - matrix.ty;
      var childX = (matrix.d * deltaX - matrix.c * deltaY) / matrix.det;
      var childY = (matrix.a * deltaY - matrix.b * deltaX) / matrix.det;

      if (mask != null) {
        final maskX = mask.relativeToParent ? localX : childX;
        final maskY = mask.relativeToParent ? localY : childY;
        if (mask.hitTest(maskX, maskY) == false) continue;
      }

      if (child is DisplayObjectContainer3D) {
        final point = Point<num>(childX, childY);
        child.projectionMatrix3D.transformPointInverse(point, point);
        childX = point.x.toDouble();
        childY = point.y.toDouble();
      }

      final displayObject = child.hitTestInput(childX, childY);
      if (displayObject == null) continue;

      if (displayObject is InteractiveObject && displayObject.mouseEnabled) {
        return mouseChildren ? displayObject : this;
      }

      hit = this;
    }
  }

  return hit;
}