thickLineRgba function

bool thickLineRgba(
  1. Pointer<SdlRenderer> renderer,
  2. double x1,
  3. double y1,
  4. double x2,
  5. double y2,
  6. double width,
  7. int r,
  8. int g,
  9. int b,
  10. int a, {
  11. int blendMode = SDL_BLENDMODE_BLEND,
})

Implementation

bool thickLineRgba(
  Pointer<SdlRenderer> renderer,
  double x1,
  double y1,
  double x2,
  double y2,
  double width,
  int r,
  int g,
  int b,
  int a, {
  int blendMode = SDL_BLENDMODE_BLEND,
}) {
  int wh;
  double dx;
  double dy;
  double dx1;
  double dy1;
  double dx2;
  double dy2;
  double l;
  double wl2;
  double nx;
  double ny;
  double ang;
  double adj;
  final points = List<SdlxFPoint>.generate(4, (index) => SdlxFPoint(0, 0));

  if (renderer == nullptr) {
    return false;
  }

  if (width < 1) {
    return false;
  }

  /* Special case: thick "point" */
  if ((x1 == x2) && (y1 == y2)) {
    wh = width ~/ 2;
    return boxRgba(
      renderer,
      x1 - wh,
      y1 - wh,
      x2 + width,
      y2 + width,
      r,
      g,
      b,
      a,
    );
  }

  /* Special case: width == 1 */
  if (width == 1) {
    return lineRgba(renderer, x1, y1, x2, y2, r, g, b, a, blendMode: blendMode);
  }

  /* Calculate offsets for sides */
  dx = x2 - x1;
  dy = y2 - y1;
  l = sdlSqrt(dx * dx + dy * dy);
  ang = sdlAtan2(dx, dy);
  adj = 0.1 + 0.9 * sdlFabs(sdlCos(2.0 * ang));
  wl2 = (width - adj) / (2.0 * l);
  nx = dx * wl2;
  ny = dy * wl2;

  /* Build polygon */
  dx1 = x1;
  dy1 = y1;
  dx2 = x2;
  dy2 = y2;
  points[0].x = dx1 + ny;
  points[1].x = dx1 - ny;
  points[2].x = dx2 - ny;
  points[3].x = dx2 + ny;
  points[0].y = dy1 - nx;
  points[1].y = dy1 + nx;
  points[2].y = dy2 + nx;
  points[3].y = dy2 - nx;

  /* Draw polygon */
  final result = filledPolygonRgba(
    renderer,
    points,
    r,
    g,
    b,
    a,
    blendMode: blendMode,
  );
  return result;
}