import 'package:flutter/material.dart'; import '../layout/layout_models.dart'; import '../routing/route_models.dart'; import 'graph_edge_layer.dart'; /// Paints one highlighted edge over the other routes and behind the nodes: a /// soft glow under the two endpoint stages, then the route in [color] at a /// heavier stroke with its arrow, on a translucent halo. /// /// Passive like the other edge layers: it never takes a hit. class EdgeHighlightPainter extends CustomPainter { EdgeHighlightPainter({ required this.route, required this.endpoints, required this.color, required this.strokeWidth, this.glowRadius = 14, }); final EdgeRoute route; /// The source and target node boxes (one for a self loop). final List endpoints; final Color color; /// The highlighted stroke; the halo is wider. final double strokeWidth; /// The corner radius of the glow around each endpoint stage: the stage /// card's own corners plus the glow's spread. final double glowRadius; @override void paint(Canvas canvas, Size size) { final glow = Paint()..color = color.withValues(alpha: 0.18); for (final box in endpoints) { final rect = Rect.fromLTWH(box.x, box.y, box.width, box.height); canvas.drawRRect( RRect.fromRectAndRadius(rect.inflate(5), Radius.circular(glowRadius)), glow, ); } if (route.points.length < 2) return; final geometry = GraphEdgePainter( routes: [route], color: color, strokeWidth: strokeWidth, ); final line = geometry.linePath(route); canvas.drawPath( line, Paint() ..color = color.withValues(alpha: 0.22) ..strokeWidth = strokeWidth * 3 ..style = PaintingStyle.stroke ..strokeJoin = StrokeJoin.round ..strokeCap = StrokeCap.round, ); canvas.drawPath( line, Paint() ..color = color ..strokeWidth = strokeWidth ..style = PaintingStyle.stroke ..strokeJoin = StrokeJoin.round, ); canvas.drawPath( GraphEdgePainter( routes: [route], color: color, // The arrow scales with the stroke; keep it near the plain arrow. strokeWidth: strokeWidth / 1.5, ).arrowPath(route), Paint()..color = color, ); } @override bool hitTest(Offset position) => false; @override bool shouldRepaint(EdgeHighlightPainter oldDelegate) => oldDelegate.route != route || oldDelegate.color != color || oldDelegate.strokeWidth != strokeWidth || oldDelegate.glowRadius != glowRadius || oldDelegate.endpoints.length != endpoints.length || !_sameBoxes(oldDelegate.endpoints, endpoints); static bool _sameBoxes(List a, List b) { for (var index = 0; index < a.length; index += 1) { if (a[index] != b[index]) return false; } return true; } }