created point and rectangle drawing methods

This commit is contained in:
2026-07-04 01:28:13 -07:00
parent 24cae3d544
commit 18ce6a039d
2 changed files with 48 additions and 6 deletions
BIN
View File
Binary file not shown.
+47 -5
View File
@@ -44,6 +44,16 @@ namespace UwU {
// Draw a rectangle (duh)
void rectangle(uint32_t x0, uint32_t y0, uint32_t x1, uint32_t y1, uint8_t r, uint8_t g, uint8_t b) {
if (x0 > this->width || y0 > this->height || x1 > this->width || y1 > this->height) {return;};
for (uint32_t y = y0; y < y1; y++) {
for (uint32_t x = x0; x < x1; x++) {
size_t i = (size_t)y * waymini_get_stride(this->wm) + (size_t)x * 4;
this->pixels[i + 0] = b; // B
this->pixels[i + 1] = g; // G
this->pixels[i + 2] = r; // R
this->pixels[i + 3] = 0xFF; // A
}
}
return;
}
@@ -52,13 +62,44 @@ namespace UwU {
for (uint32_t y = 0; y < this->height; y++) {
for (uint32_t x = 0; x < this->width; x++) {
size_t i = (size_t)y * waymini_get_stride(this->wm) + (size_t)x * 4;
this->pixels[i + 0] = (uint8_t)(y * 255 / this->height); /* B */
this->pixels[i + 1] = 0x00; /* G */
this->pixels[i + 2] = (uint8_t)(x * 255 / this->width); /* R */
this->pixels[i + 3] = 0xFF; /* A (ignored for XRGB) */
this->pixels[i + 0] = (uint8_t)(y * 255 / this->height); // B
this->pixels[i + 1] = 0x00; // G
this->pixels[i + 2] = (uint8_t)(x * 255 / this->width); // R
this->pixels[i + 3] = 0xFF; // A
}
}
}
void point (uint32_t x, uint32_t y, uint8_t r, uint8_t g, uint8_t b) {
if (x > this->width || y > this->height) {return;};
size_t i = (size_t)y * waymini_get_stride(this->wm) + (size_t)x * 4;
this->pixels[i + 0] = b; // B
this->pixels[i + 1] = g; // G
this->pixels[i + 2] = r; // R
this->pixels[i + 3] = 0xFF; // A
}
// // Uses Bresenham's line algorithm to draw line of any slope
// void line (uint32_t x0, uint32_t y0, uint32_t x1, uint32_t y1, uint8_t r, uint8_t g, uint8_t b) {
// if (x0 > this->width || y0 > this->height || x1 > this->width || y1 > this->height) {return;};
// int32_t dx = (int32_t)x1 - (int32_t)x0;
// int32_t dy = (int32_t)y1 - (int32_t)y1;
// int32_t yi = 1;
// if (dy < 0) {
// yi = -1;
// dy = -dy;
// }
// int32_t d = (2 * dy) - dx;
// int32_t y = y0
// for (uint32_t x = x0; x < x1; x++) {
// }
// size_t i = (size_t)y * waymini_get_stride(this->wm) + (size_t)x * 4;
// this->pixels[i + 0] = b; // B
// this->pixels[i + 1] = g; // G
// this->pixels[i + 2] = r; // R
// this->pixels[i + 3] = 0xFF; // A
// }
};
}
@@ -71,7 +112,8 @@ int main(void) {
draw.rainbow();
waymini_present(draw.wm);
draw.pixels[200001] = 255;
draw.rectangle(69, 69, 420, 420, 0xB0, 0x0B, 0x69);
draw.point(387, 43, 0x00, 0xff, 0x00);
while (!waymini_should_close(draw.wm)) {
if (waymini_dispatch(draw.wm) < 0) break;