rectangleRgba function
bool
rectangleRgba(
- Pointer<SdlRenderer> renderer,
- double x1,
- double y1,
- double x2,
- double y2,
- int r,
- int g,
- int b,
- int a, {
- int blendMode = SDL_BLENDMODE_BLEND,
})
Implementation
bool rectangleRgba(
Pointer<SdlRenderer> renderer,
double x1,
double y1,
double x2,
double y2,
int r,
int g,
int b,
int a, {
int blendMode = SDL_BLENDMODE_BLEND,
}) {
var x10 = x1;
var y10 = y1;
var x20 = x2;
var y20 = y2;
var result = true;
double tmp;
/*
* Test for special cases of straight lines or single point
*/
if (x10 == x20) {
if (y10 == y20) {
return pixelRgba(renderer, x10, y10, r, g, b, a, blendMode: blendMode);
} else {
return vlineRgba(
renderer,
x10,
y10,
y20,
r,
g,
b,
a,
blendMode: blendMode,
);
}
} else {
if (y10 == y20) {
return hlineRgba(
renderer,
x10,
x20,
y10,
r,
g,
b,
a,
blendMode: blendMode,
);
}
}
/*
* Swap x10, x20 if required
*/
if (x10 > x20) {
tmp = x10;
x10 = x20;
x20 = tmp;
}
/*
* Swap y10, y20 if required
*/
if (y10 > y20) {
tmp = y10;
y10 = y20;
y20 = tmp;
}
/*
* Create destination rect
*/
final rect = calloc<SdlFRect>();
rect.ref.x = x10;
rect.ref.y = y10;
rect.ref.w = x20 - x10;
rect.ref.h = y20 - y10;
/*
* Draw
*/
result = true;
if (result) {
result = sdlSetRenderDrawBlendMode(renderer, blendMode);
}
if (result) {
result = sdlSetRenderDrawColor(renderer, r, g, b, a);
}
if (result) {
result = sdlRenderRect(renderer, rect);
}
calloc.free(rect);
return result;
}