Files
BadNote/lib/editor/render/live_ink_painter.dart

48 lines
1.4 KiB
Dart
Raw Normal View History

// 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,
});
/// The stroke currently being drawn, or null when idle.
final EditorStroke? live;
final Size pageSize;
@override
void paint(Canvas canvas, Size size) {
final stroke = live;
if (stroke == null || stroke.points.isEmpty) return;
final path = buildStrokeOutline(stroke, pageSize, isComplete: false);
if (path.getBounds().isEmpty) return;
canvas.drawPath(
path,
Paint()
..color = Color(stroke.color)
..style = PaintingStyle.fill
..isAntiAlias = true,
);
}
@override
bool shouldRepaint(LiveInkPainter old) =>
!identical(old.live, live) || old.pageSize != pageSize;
}