paintBorder method
void
paintBorder({})
Paint the border of the NeoPopTiltedButton
The border is painted as a polygon with the following points: a, b, c, d. Theta is the angle of the tilt of the button.
Implementation
void paintBorder({
required Border border,
required Canvas canvas,
required Offset a,
required Offset b,
required Offset c,
required Offset d,
required double tanTheta,
required double sinTheta,
}) {
final Path borderPath = Path();
final Paint borderPaint = Paint()..strokeWidth = 0.0;
switch (border.top.style) {
case BorderStyle.solid:
borderPaint.color = border.top.color;
borderPath.reset();
borderPath.moveTo(a.dx, a.dy);
borderPath.lineTo(b.dx, b.dy);
final borderWidth = border.top.width;
if (borderWidth == 0) {
borderPaint.style = PaintingStyle.stroke;
} else {
borderPaint.style = PaintingStyle.fill;
borderPath.lineTo(
b.dx - (borderWidth / tanTheta), b.dy + borderWidth);
borderPath.lineTo(
a.dx + (borderWidth / tanTheta), a.dy + borderWidth);
}
canvas.drawPath(borderPath, borderPaint);
break;
default:
break;
}
switch (border.right.style) {
case BorderStyle.solid:
borderPaint.color = border.right.color;
borderPath.reset();
borderPath.moveTo(b.dx, b.dy);
borderPath.lineTo(c.dx, c.dy);
final borderWidth = border.right.width;
if (borderWidth == 0) {
borderPaint.style = PaintingStyle.stroke;
} else {
borderPaint.style = PaintingStyle.fill;
borderPath.lineTo(c.dx - (borderWidth / sinTheta), c.dy);
borderPath.lineTo(b.dx - (borderWidth / sinTheta), b.dy);
}
canvas.drawPath(borderPath, borderPaint);
break;
default:
break;
}
switch (border.bottom.style) {
case BorderStyle.solid:
borderPaint.color = border.bottom.color;
borderPath.reset();
borderPath.moveTo(c.dx, c.dy);
borderPath.lineTo(d.dx, d.dy);
final borderWidth = border.bottom.width;
if (borderWidth == 0) {
borderPaint.style = PaintingStyle.stroke;
} else {
borderPaint.style = PaintingStyle.fill;
borderPath.lineTo(
d.dx + (borderWidth / tanTheta), d.dy - borderWidth);
borderPath.lineTo(
c.dx - (borderWidth / tanTheta), c.dy - borderWidth);
}
canvas.drawPath(borderPath, borderPaint);
break;
default:
break;
}
switch (border.left.style) {
case BorderStyle.solid:
borderPaint.color = border.left.color;
borderPath.reset();
borderPath.moveTo(d.dx, d.dy);
borderPath.lineTo(a.dx, a.dy);
final borderWidth = border.left.width;
if (borderWidth == 0) {
borderPaint.style = PaintingStyle.stroke;
} else {
borderPaint.style = PaintingStyle.fill;
borderPath.lineTo(a.dx + (borderWidth / sinTheta), a.dy);
borderPath.lineTo(d.dx + (borderWidth / sinTheta), d.dy);
}
canvas.drawPath(borderPath, borderPaint);
break;
default:
break;
}
}