drawShape method
Implementation
void drawShape(Canvas canvas, List<ShapeEntity> shapes, int frameAlpha) {
if (shapes.isEmpty) return;
for (var shape in shapes) {
final path = buildPath(shape);
if (shape.hasTransform()) {
canvas.save();
canvas.transform(Float64List.fromList(<double>[
shape.transform.a,
shape.transform.b,
0.0,
0.0,
shape.transform.c,
shape.transform.d,
0.0,
0.0,
0.0,
0.0,
1.0,
0.0,
shape.transform.tx,
shape.transform.ty,
0.0,
1.0
]));
}
final fill = shape.styles.fill;
if (fill.isInitialized()) {
final paint = Paint();
paint.isAntiAlias = true;
paint.style = PaintingStyle.fill;
paint.color = Color.fromARGB(
(fill.a * frameAlpha).toInt(),
(fill.r * 255).toInt(),
(fill.g * 255).toInt(),
(fill.b * 255).toInt(),
);
canvas.drawPath(path, paint);
}
final strokeWidth = shape.styles.strokeWidth;
if (strokeWidth > 0) {
final paint = Paint();
paint.style = PaintingStyle.stroke;
if (shape.styles.stroke.isInitialized()) {
paint.color = Color.fromARGB(
(shape.styles.stroke.a * frameAlpha).toInt(),
(shape.styles.stroke.r * 255).toInt(),
(shape.styles.stroke.g * 255).toInt(),
(shape.styles.stroke.b * 255).toInt(),
);
}
paint.strokeWidth = strokeWidth;
final lineCap = shape.styles.lineCap;
switch (lineCap) {
case ShapeEntityStyleLineCap.LineCap_BUTT:
paint.strokeCap = StrokeCap.butt;
break;
case ShapeEntityStyleLineCap.LineCap_ROUND:
paint.strokeCap = StrokeCap.round;
break;
case ShapeEntityStyleLineCap.LineCap_SQUARE:
paint.strokeCap = StrokeCap.square;
break;
default:
}
final lineJoin = shape.styles.lineJoin;
switch (lineJoin) {
case ShapeEntityStyleLineJoin.LineJoin_MITER:
paint.strokeJoin = StrokeJoin.miter;
break;
case ShapeEntityStyleLineJoin.LineJoin_ROUND:
paint.strokeJoin = StrokeJoin.round;
break;
case ShapeEntityStyleLineJoin.LineJoin_BEVEL:
paint.strokeJoin = StrokeJoin.bevel;
break;
default:
}
paint.strokeMiterLimit = shape.styles.miterLimit;
List<double> lineDash = [
shape.styles.lineDashI,
shape.styles.lineDashII,
shape.styles.lineDashIII
];
if (lineDash[0] > 0 || lineDash[1] > 0) {
canvas.drawPath(
DashPath(
path,
dashArray: CircularIntervalList([
lineDash[0] < 1.0 ? 1.0 : lineDash[0],
lineDash[1] < 0.1 ? 0.1 : lineDash[1],
]),
dashOffset: DashOffset.absolute(lineDash[2]),
),
paint);
} else {
canvas.drawPath(path, paint);
}
}
if (shape.hasTransform()) {
canvas.restore();
}
}
}