paint method
(Internal usage) Paints the graphics onto the given Canvas. If isMask is true, it clips the canvas to the path of each GraphicsDrawingData in the _drawingQueue, allowing for masking effects. Otherwise, it iterates over each GraphicsDrawingData in the _drawingQueue and draws its path or picture onto the canvas, filling it with the corresponding Paint. If the GraphicsDrawingData contains a gradient, it calculates the gradient's bounds and creates a shader from the gradient to fill the shape. If the GraphicsDrawingData contains vertices, it draws them onto the canvas using the corresponding Paint. If the GraphicsDrawingData contains a picture, it draws the picture onto the canvas.
Implementation
@override
void paint(Canvas canvas) {
// TODO : add mask support.
if (isMask) {
for (var graph in _drawingQueue) {
canvas.clipPath(graph!.path!, doAntiAlias: false);
}
return;
}
_constrainAlpha();
if (!_isVisible) return;
for (var graph in _drawingQueue) {
if (graph!.hasPicture) {
canvas.drawPicture(graph.picture!);
break;
}
final fill = graph.fill!;
final baseColor = fill.color;
// FIX: causes flickering on rendering.
// if (baseColor.alpha == 0) break;
/// calculate gradient.
if (graph.hasGradient) {
Rect? graphBounds;
if (graph.hasVertices) {
graphBounds = graph.vertices!.getBounds();
} else {
graphBounds = graph.path!.getBounds();
}
/// TODO: try if this works to change the gradient
/// opacity from the Shape.
fill.color = baseColor.withOpacity(alpha);
fill.shader = graph.gradient!.createShader(graphBounds!);
} else {
if (alpha != 1) {
fill.color = baseColor.withOpacity(baseColor.opacity * alpha);
}
}
if (graph.hasVertices) {
if (graph.vertices!.uvtData != null && graph.shaderTexture != null) {
graph.vertices!.calculateUvt(graph.shaderTexture);
}
if (fill.style == PaintingStyle.stroke) {
canvas.drawRawPoints(
ui.PointMode.lines,
graph.vertices!.rawPoints!,
fill,
);
} else {
canvas.drawVertices(
graph.vertices!.rawData!,
graph.vertices!.blendMode!,
fill,
);
}
} else {
canvas.drawPath(graph.path!, fill);
}
fill.color = baseColor;
}
}