drawAssists method
Draws any assist lines that the object has on canvas
with size
.
Implementation
void drawAssists(Canvas canvas, Size size) {
// Draw the rotation assist line
//
// This assist line passes through the center point of the object
// and extends according to the object's rotation angle
if (assists.contains(ObjectDrawableAssist.rotation)) {
// Calculate the tangent of the angle
final angleTan = tan(rotationAngle);
// Calculate the points at which a line passing through the object's center
// with an angle tangent crosses the borders of the drawing size
final intersections =
_calculateBoxIntersections(position, angleTan, size);
if (intersections.length == 2) {
// Should be redundant, added for safety
// Draw the line between the two points on the size border
canvas.drawLine(
intersections[0],
intersections[1],
assistPaints[ObjectDrawableAssist.rotation] ??
defaultRotationAssistPaint,
);
}
}
// Draw the horizontal assist line
//
// This assist line passes through the center point of the object
// and extends horizontally (with a constant dy value)
if (assists.contains(ObjectDrawableAssist.horizontal)) {
canvas.drawLine(Offset(0, position.dy), Offset(size.width, position.dy),
assistPaints[ObjectDrawableAssist.horizontal] ?? defaultAssistPaint);
}
// Draw the vertical assist line
//
// This assist line passes through the center point of the object
// and extends vertically (with a constant dx value)
if (assists.contains(ObjectDrawableAssist.vertical)) {
canvas.drawLine(Offset(position.dx, 0), Offset(position.dx, size.height),
assistPaints[ObjectDrawableAssist.horizontal] ?? defaultAssistPaint);
}
}