createBannerPath method

Path createBannerPath({
  1. required Offset bannerBoundingBoxTopLeft,
  2. required Size contentSize,
})

Creates the path for a banner that fits into the corner of this SBannerPosition.

bannerBoundingBoxTopLeft is the global screen-space offset for the top left corner of the banner's bounding box.

Implementation

Path createBannerPath({
  required Offset bannerBoundingBoxTopLeft,
  required Size contentSize,
}) {
  final distanceToNearEdge = calculateDistanceToNearBannerEdge(contentSize);
  final distanceToFarEdge = calculateDistanceToFarBannerEdge(contentSize);

  late Path relativePath;

  switch (_corner) {
    case _Corner.topLeft:
      relativePath = Path()
        ..moveTo(0, distanceToNearEdge)
        ..lineTo(distanceToNearEdge, 0)
        ..lineTo(distanceToFarEdge, 0)
        ..lineTo(0, distanceToFarEdge)
        ..close();
      break;
    case _Corner.topRight:
      relativePath = Path()
        ..moveTo(0, 0)
        ..lineTo(distanceToFarEdge - distanceToNearEdge, 0)
        ..lineTo(distanceToFarEdge, distanceToNearEdge)
        ..lineTo(distanceToFarEdge, distanceToFarEdge)
        ..close();
      break;
    case _Corner.bottomLeft:
      relativePath = Path()
        ..moveTo(0, 0)
        ..lineTo(distanceToFarEdge, distanceToFarEdge)
        ..lineTo(distanceToNearEdge, distanceToFarEdge)
        ..lineTo(0, distanceToFarEdge - distanceToNearEdge)
        ..close();
      break;
    case _Corner.bottomRight:
      relativePath = Path()
        ..moveTo(0, distanceToFarEdge)
        ..lineTo(distanceToFarEdge, 0)
        ..lineTo(distanceToFarEdge, distanceToFarEdge - distanceToNearEdge)
        ..lineTo(distanceToFarEdge - distanceToNearEdge, distanceToFarEdge)
        ..close();
      break;
  }

  return relativePath.shift(bannerBoundingBoxTopLeft);
}