openDrawEditor method

Future<void> openDrawEditor()

Opens the draw tool over the decoded image or the video's poster frame.

Implementation

Future<void> openDrawEditor() async {
  final ui.Image? source = switch (input) {
    VideoMedia() => await _ensureVideoPoster(),
    ImageMedia() => await ensureSource(),
    _ => null,
  };
  if (source == null) return;
  pauseVideo();
  drawLayer ??= DrawImageLayer(image: source);
  entityLayer ??= EntityLayer(imageSize: sourceSize!);
  // Pass the crop layer so the draw editor's canvas IS the cropped
  // preview (source × prior strokes → crop transform → clipped).
  // Pointer coords are converted source-space via DrawGestures'
  // crop-aware path so new strokes land at the right source pixel.
  final applied = await DrawScreen.borrowed(
    layer: drawLayer!,
    crop: cropLayer,
    entities: entityLayer,
    camera: camera,
    setFitRect: setFitRect,
  ).push();
  if (applied != true) return;
  if (input is VideoMedia) {
    await _snapshotDrawOverlay();
  } else {
    _invalidatePreview();
    await _renderPreview();
  }
}