Some checks failed
CI / Windows build (push) Has been cancelled
Honor each brush's opacity/blend so the brushes feel distinct (closes TODO(brush-opacity)). - Shared paint resolver: a stroke's color alpha is multiplied by its brush opacity; ballpoint/pencil opacity is tied to pressure (per-stroke average this increment) so a ballpoint reads lighter than a solid fountain pen. - Highlighter paints with BlendMode.multiply and draws once, so cross-stroke overlap darkens like a real marker while self-overlap doesn't. - Applied across BOTH render paths (PenCanvas static/live painters and the PDF _PageOverlayPainter). Pencil paper-grain texture still deferred (TODO brush-texture); brush kind is not yet serialized (TODO brush-persist — next). analyze clean, tests green.
51 lines
1.6 KiB
Dart
51 lines
1.6 KiB
Dart
// 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,
|
|
this.thinning = kDefaultPenThinning,
|
|
});
|
|
|
|
/// The stroke currently being drawn, or null when idle.
|
|
final EditorStroke? live;
|
|
final Size pageSize;
|
|
|
|
/// 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;
|
|
|
|
@override
|
|
void paint(Canvas canvas, Size size) {
|
|
final stroke = live;
|
|
if (stroke == null || stroke.points.isEmpty) return;
|
|
|
|
final path = buildStrokeOutline(stroke, pageSize,
|
|
isComplete: false, thinning: thinning);
|
|
if (path.getBounds().isEmpty) return;
|
|
|
|
canvas.drawPath(path, paintForEditorStroke(stroke));
|
|
}
|
|
|
|
@override
|
|
bool shouldRepaint(LiveInkPainter old) =>
|
|
!identical(old.live, live) ||
|
|
old.pageSize != pageSize ||
|
|
old.thinning != thinning;
|
|
}
|