thickLineRgba function
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,
})
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 px = calloc<Int16>(4);
final py = calloc<Int16>(4);
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;
px[0] = (dx1 + ny).toInt();
px[1] = (dx1 - ny).toInt();
px[2] = (dx2 - ny).toInt();
px[3] = (dx2 + ny).toInt();
py[0] = (dy1 - nx).toInt();
py[1] = (dy1 + nx).toInt();
py[2] = (dy2 + nx).toInt();
py[3] = (dy2 - nx).toInt();
/* Draw polygon */
final result = filledPolygonRgba(
renderer,
px,
py,
4,
r,
g,
b,
a,
blendMode: blendMode,
);
calloc
..free(px)
..free(py);
return result;
}