Draw: Add Draw_DrawBox and Draw_DrawBoxFilled.

This commit is contained in:
2024-10-06 15:10:47 +02:00
parent 6114e885d0
commit ef2ab33824
2 changed files with 67 additions and 0 deletions

View File

@@ -732,6 +732,61 @@ int Draw_GetFlip(DrawImg img) {
return image->flip;
}
/////////////////////////////
// Draw_DrawBoxFilled
//
//
DrawImg Draw_DrawBoxFilled(DrawImg img, const int x1, const int y1, const int x2, const int y2, ColorRgba color) {
const DrawImage image = img;
for (int y = y1; y < y2; y++) {
for (int x = x1; x < x2; x++) {
const int offset = (x + y * image->w) * 4;
image->data[offset + 0] = color[0];
image->data[offset + 1] = color[1];
image->data[offset + 2] = color[2];
image->data[offset + 3] = color[3];
}
}
return (img);
}
/////////////////////////////
// Draw_DrawBox
//
//
DrawImg Draw_DrawBox(DrawImg img, const int x1, const int y1, const int x2, const int y2, ColorRgba color) {
const DrawImage image = img;
for (int x = x1; x < x2; x++) {
const int offset1 = (x + y1 * image->w) * 4;
image->data[offset1 + 0] = color[0];
image->data[offset1 + 1] = color[1];
image->data[offset1 + 2] = color[2];
image->data[offset1 + 3] = color[3];
const int offset2 = (x + (y2 - 1) * image->w) * 4;
image->data[offset2 + 0] = color[0];
image->data[offset2 + 1] = color[1];
image->data[offset2 + 2] = color[2];
image->data[offset2 + 3] = color[3];
}
for (int y = y1 + 1; y < y2 - 1; y++) {
const int offset1 = (x1 + y * image->w) * 4;
image->data[offset1 + 0] = color[0];
image->data[offset1 + 1] = color[1];
image->data[offset1 + 2] = color[2];
image->data[offset1 + 3] = color[3];
const int offset2 = ((x2 - 1) + y * image->w) * 4;
image->data[offset2 + 0] = color[0];
image->data[offset2 + 1] = color[1];
image->data[offset2 + 2] = color[2];
image->data[offset2 + 3] = color[3];
}
return (img);
}
/////////////////////////////
// Draw_DrawImg
//