-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathtools.dart
92 lines (79 loc) · 2.38 KB
/
tools.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import 'package:blobs/src/config.dart';
import 'package:blobs/src/models.dart';
import 'package:flutter/material.dart';
circle(Canvas canvas, Size size, double radius) {
var paint = Paint()
..color = const Color(0xffef5777)
..strokeWidth = 3
..style = PaintingStyle.stroke;
var path = Path();
path.addOval(Rect.fromCircle(
center: Offset(size.width / 2, size.height / 2),
radius: radius,
));
canvas.drawPath(path, paint);
}
label(Canvas canvas, String text, Offset offset) {
final textSpan = TextSpan(
text: text,
style: TextStyle(color: Colors.black, fontSize: 16),
);
final textPainter =
TextPainter(text: textSpan, textDirection: TextDirection.ltr);
textPainter.layout(
minWidth: 0,
maxWidth: 100,
);
textPainter.paint(canvas, offset + Offset(0, -20));
}
line(Canvas canvas, Offset start, Offset end) {
var paint = Paint()
..color = Color(0xff596275).withOpacity(0.5)
..strokeWidth = 3
..style = PaintingStyle.stroke
..strokeCap = StrokeCap.round;
canvas.drawLine(start, end, paint);
}
point(Canvas canvas, Offset center) {
var paint = Paint()
..color = const Color(0xff1e272e)
..strokeWidth = 1
..style = PaintingStyle.fill
..strokeCap = StrokeCap.round;
var path = Path();
path.addOval(Rect.fromCircle(
center: center,
radius: 3,
));
canvas.drawPath(path, paint);
}
Paint createPaint(BlobStyles? styles) {
Map<BlobFillType, PaintingStyle> fillType = {
BlobFillType.fill: PaintingStyle.fill,
BlobFillType.stroke: PaintingStyle.stroke
};
if (styles == null) styles = BlobStyles();
var paint = Paint();
paint.color = styles.color ?? BlobConfig.color;
paint.shader = styles.gradient;
paint.strokeWidth = (styles.strokeWidth ?? BlobConfig.strokeWidth).toDouble();
paint.style = fillType[styles.fillType ?? BlobConfig.fillType]!;
if (styles.blendMode != null) {
paint.blendMode = styles.blendMode!;
}
return paint;
}
Path connectPoints(BlobCurves curves) {
var path = Path();
path.moveTo(curves.start.dx, curves.start.dy);
curves.curves.forEach((curve) {
path.quadraticBezierTo(curve[0], curve[1], curve[2], curve[3]);
});
path.close();
return path;
}
void drawBlob(Canvas canvas, Path path, BlobStyles? styles) {
Paint paint = createPaint(styles);
// canvas.drawShadow(path, Colors.red.withOpacity(0.8), 10, true);
canvas.drawPath(path, paint);
}