TransformData.fromRect constructor

TransformData.fromRect(
  1. Rect rect,
  2. Size layout,
  3. Size maxSize,
  4. VideoEditorController? controller,
)

Implementation

factory TransformData.fromRect(
  // the selected crop rect area
  Rect rect,
  // the maximum size of the crop area
  Size layout,
  // the maximum size to display
  Size maxSize,
  // if controller is not provided, rotation is set to default (0)
  VideoEditorController? controller,
) {
  if (controller != null && controller.isRotated) {
    maxSize = maxSize.flipped;
  }

  final double scale = scaleToSize(maxSize, rect);
  final double rotation = -(controller?.cacheRotation ?? 0) * (pi / 180.0);
  final Offset translate = Offset(
    ((layout.width - rect.width) / 2) - rect.left,
    ((layout.height - rect.height) / 2) - rect.top,
  );

  return TransformData(
    rotation: rotation,
    scale: scale,
    translate: translate,
  );
}