globalToLocal method

  1. @override
Offset globalToLocal(
  1. Offset point,
  2. RenderView view
)
override

Convert the given point from the global coordinate space of the provided RenderView to its local one.

This method operates in logical pixels for both coordinate spaces. It does not apply the device pixel ratio (used to translate to/from physical pixels).

For definitions for coordinate spaces, see TestWidgetsFlutterBinding.

Implementation

@override
Offset globalToLocal(Offset point, RenderView view) {
  // The method is expected to translate the given point expressed in logical
  // pixels in the global coordinate space to the local coordinate space (also
  // expressed in logical pixels).
  // The inverted transform translates from the global coordinate space in
  // physical pixels to the local coordinate space in logical pixels.
  final Matrix4 transform = view.configuration.toMatrix();
  final double det = transform.invert();
  assert(det != 0.0);
  // In order to use the transform, we need to translate the point first into
  // the physical coordinate space by applying the device pixel ratio.
  return MatrixUtils.transformPoint(
    transform,
    point * view.configuration.devicePixelRatio,
  );
}