paintCropRotationDial function

void paintCropRotationDial(
  1. Canvas canvas, {
  2. required Rect crop,
  3. required double rotate,
  4. required Rect viewport,
  5. required double scale,
})

Paints the rotation dial's guides in image space: a tick circle whose lowest point marks rotate and a fixed needle under it.

viewport is the camera-mapped visible rect in image space and scale the inverse camera scale, so every screen-px metric above lands on screen at its literal size. rotate is the render angle — the ticks turn with the image, not with the data state.

Implementation

void paintCropRotationDial(
  Canvas canvas, {
  required Rect crop,
  required double rotate,
  required Rect viewport,
  required double scale,
}) {
  final r = viewport.width * .5;
  final center = crop.bottomCenter - Offset(0, r - kCropDialTickInset * scale);

  canvas.save();
  canvas.clipRect(
    Rect.fromLTRB(viewport.left, crop.bottom, viewport.right, viewport.bottom),
  );

  final dotBig = Paint()
    ..color = colors.onMedia
    ..style = PaintingStyle.stroke
    ..strokeWidth = 5 * scale
    ..strokeCap = StrokeCap.round;
  final dotSmall = Paint()
    ..color = colors.onMedia
    ..style = PaintingStyle.stroke
    ..strokeWidth = 2 * scale
    ..strokeCap = StrokeCap.round;

  for (int angle = 0; angle < 180; angle += 2) {
    final a1 = rotate + angle * vmath.degrees2Radians;
    final a2 = rotate - angle * vmath.degrees2Radians;
    final p1 = center + _onCircle(r, a1);
    final p2 = center + _onCircle(r, a2);
    final labelled = angle % 10 == 0;

    canvas.drawPoints(ui.PointMode.points, [
      p1,
      p2,
    ], labelled ? dotBig : dotSmall);
    if (labelled) {
      _drawAngleLabel(canvas, '${-angle}', a1, center, p1, scale);
      _drawAngleLabel(canvas, '$angle', a2, center, p2, scale);
    }
  }

  _drawNeedle(
    canvas,
    Offset(center.dx, center.dy + r + kCropDialNeedleGap * scale),
    scale,
  );

  canvas.restore();
}