paintLines method
Draw grid lines inside the crop area
Implementation
void paintLines(
Canvas canvas, Size size, ExtendedImageCropLayerPainter painter) {
final Color lineColor = painter.lineColor;
final double lineHeight = painter.lineHeight;
final Rect cropRect = painter.cropRect;
final bool pointerDown = painter.pointerDown;
final Paint linePainter = Paint()
..color = lineColor
..strokeWidth = lineHeight
..style = PaintingStyle.stroke;
// Draw the crop rectangle's border
canvas.drawRect(cropRect, linePainter);
// If pointer is down, draw additional grid lines inside the crop area
if (pointerDown) {
// Vertical lines
canvas.drawLine(
Offset((cropRect.right - cropRect.left) / 3.0 + cropRect.left,
cropRect.top),
Offset((cropRect.right - cropRect.left) / 3.0 + cropRect.left,
cropRect.bottom),
linePainter);
canvas.drawLine(
Offset((cropRect.right - cropRect.left) / 3.0 * 2.0 + cropRect.left,
cropRect.top),
Offset((cropRect.right - cropRect.left) / 3.0 * 2.0 + cropRect.left,
cropRect.bottom),
linePainter);
// Horizontal lines
canvas.drawLine(
Offset(
cropRect.left,
(cropRect.bottom - cropRect.top) / 3.0 + cropRect.top,
),
Offset(
cropRect.right,
(cropRect.bottom - cropRect.top) / 3.0 + cropRect.top,
),
linePainter);
canvas.drawLine(
Offset(cropRect.left,
(cropRect.bottom - cropRect.top) / 3.0 * 2.0 + cropRect.top),
Offset(
cropRect.right,
(cropRect.bottom - cropRect.top) / 3.0 * 2.0 + cropRect.top,
),
linePainter);
}
}