2026-06-21 23:41:01 +08:00
|
|
|
// lib/editor/render/live_ink_painter.dart
|
|
|
|
|
//
|
|
|
|
|
// CustomPainter for the in-progress stroke (live) layer.
|
|
|
|
|
//
|
|
|
|
|
// Paints only the single EditorStroke? currently being drawn, with
|
|
|
|
|
// isComplete:false so perfect_freehand tapers the trailing end correctly.
|
|
|
|
|
// Kept in a separate RepaintBoundary so committed strokes are never
|
|
|
|
|
// re-rasterized on pointer-move events.
|
|
|
|
|
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
|
|
|
|
|
import '../engine/stroke_geometry.dart';
|
|
|
|
|
import '../engine/stroke_model.dart';
|
|
|
|
|
|
|
|
|
|
/// Paints the single in-progress [EditorStroke] (or nothing when [live] is
|
|
|
|
|
/// null / empty). Use alongside [StaticInkPainter] in stacked [CustomPaint]s.
|
|
|
|
|
class LiveInkPainter extends CustomPainter {
|
|
|
|
|
const LiveInkPainter({
|
|
|
|
|
required this.live,
|
|
|
|
|
required this.pageSize,
|
2026-06-23 02:59:30 +08:00
|
|
|
this.thinning = kDefaultPenThinning,
|
2026-06-21 23:41:01 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
/// The stroke currently being drawn, or null when idle.
|
|
|
|
|
final EditorStroke? live;
|
|
|
|
|
final Size pageSize;
|
|
|
|
|
|
2026-06-23 02:59:30 +08:00
|
|
|
/// perfect_freehand pressure→width response (from `PenConfig.pressureSensitivity`),
|
|
|
|
|
/// kept consistent with the static layer so the stroke doesn't change width
|
|
|
|
|
/// the instant it commits.
|
|
|
|
|
final double thinning;
|
|
|
|
|
|
2026-06-21 23:41:01 +08:00
|
|
|
@override
|
|
|
|
|
void paint(Canvas canvas, Size size) {
|
|
|
|
|
final stroke = live;
|
|
|
|
|
if (stroke == null || stroke.points.isEmpty) return;
|
|
|
|
|
|
2026-06-23 02:59:30 +08:00
|
|
|
final path = buildStrokeOutline(stroke, pageSize,
|
|
|
|
|
isComplete: false, thinning: thinning);
|
2026-06-21 23:41:01 +08:00
|
|
|
if (path.getBounds().isEmpty) return;
|
|
|
|
|
|
2026-06-24 23:27:11 +08:00
|
|
|
canvas.drawPath(path, paintForEditorStroke(stroke));
|
2026-06-21 23:41:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
bool shouldRepaint(LiveInkPainter old) =>
|
2026-06-23 02:59:30 +08:00
|
|
|
!identical(old.live, live) ||
|
|
|
|
|
old.pageSize != pageSize ||
|
|
|
|
|
old.thinning != thinning;
|
2026-06-21 23:41:01 +08:00
|
|
|
}
|