draw method
Implementation
void draw(Canvas canvas) {
// The highlighted column is filled first so the grid lines and events draw
// on top of it (it emphasizes the column without obscuring its content).
_drawHighlight(canvas);
// vertical lines can be drawn instantly
for (var line in vLines) {
line.draw(canvas, vPaint);
}
// The 30-minute lines fade in past zoom 1, the 15/45-minute lines past
// zoom 2. These thresholds are cheap to recompute each frame and also gate
// line visibility below.
final double zoom = manager.controller.zoom;
final double color2 = (zoom - 1).clamp(0.0, 1.0).toDouble();
final double color3 = (zoom - 2).clamp(0.0, 1.0).toDouble();
// Recolour the cached paints only when the zoom actually changed, reusing
// the same Paint objects across frames instead of allocating two per frame
// (#25 / D7).
if (zoom != _cachedZoom) {
div2Paint.color = Color.fromARGB((color2 * 60).toInt(), 255, 255, 255);
div3Paint.color = Color.fromARGB((color3 * 30).toInt(), 255, 255, 255);
_cachedZoom = zoom;
}
// draw lines
for (int i = 0; i < hLines.length; i++) {
if ((i + 1) % 4 == 0) {
// hour
hLines[i].draw(canvas, vPaint);
} else if ((i + 1) % 2 == 0 && color2 != 0) {
// half an hour
hLines[i].draw(canvas, div2Paint);
} else if (color3 != 0) {
// 15 and 45 minutes
hLines[i].draw(canvas, div3Paint);
}
}
}