Files
BadNote/lib/editor/canvas/pen_stroke.dart

48 lines
1.3 KiB
Dart
Raw Normal View History

// lib/editor/canvas/pen_stroke.dart
//
// Pen-first canvas stroke model. Points are stored in NORMALIZED page
// coordinates ([0,1] x [0,1] relative to the page rectangle) so strokes stay
// pinned to the page regardless of zoom/pan or the on-screen page size.
import 'package:flutter/foundation.dart';
/// A single captured sample of a stroke.
///
/// [x]/[y] are normalized to the page rectangle ([0,1]).
/// [pressure] is the normalized stylus pressure ([0,1]) or null when the
/// device reported no usable pressure (perfect_freehand then simulates it).
@immutable
class PenPoint {
const PenPoint(this.x, this.y, this.pressure);
final double x;
final double y;
final double? pressure;
}
/// Which kind of mark a stroke is.
enum PenStrokeKind { pen, highlighter }
/// A committed stroke for a single page, in normalized page coordinates.
@immutable
class PenStroke {
const PenStroke({
required this.points,
required this.color,
required this.width,
required this.kind,
});
/// Normalized points (see [PenPoint]).
final List<PenPoint> points;
/// ARGB color value.
final int color;
/// Stroke width expressed as a fraction of the page width, so it scales with
/// the page when zoomed. Multiply by the on-screen page width to get pixels.
final double width;
final PenStrokeKind kind;
}