Skip to content

Commit

Permalink
added the move threshold
Browse files Browse the repository at this point in the history
  • Loading branch information
featzima committed Mar 11, 2021
1 parent 0ef1a13 commit 5adb6ca
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions lib/src/ui/reactive_painter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import 'package:sketcher/src/models/stroke_style.dart';
import 'package:sketcher/src/ui/bezier_path.dart';

class ReactivePainter extends ChangeNotifier implements CustomPainter {
static const _moveThreshold = 2.0;

// Color strokeColor;
final _strokes = <Stroke>[];

Expand All @@ -19,17 +21,21 @@ class ReactivePainter extends ChangeNotifier implements CustomPainter {
bool? hitTest(Offset position) => null;

void startStroke(Offset position) {
_strokes.add(Stroke(
[position],
strokeStyle!.color.withOpacity(strokeStyle!.opacity),
strokeStyle!.weight));
_strokes.add(Stroke([position], strokeStyle!.color.withOpacity(strokeStyle!.opacity), strokeStyle!.weight));
notifyListeners();
}

void appendStroke(Offset position) {
final stroke = _strokes.last;
stroke.points.add(position);
notifyListeners();
if (stroke.points.isEmpty) {
stroke.points.add(position);
notifyListeners();
} else {
if ((stroke.points.last - position).distance >= _moveThreshold) {
stroke.points.add(position);
notifyListeners();
}
}
}

Stroke endStroke() {
Expand Down

0 comments on commit 5adb6ca

Please sign in to comment.