2026-07-07 06:47:24 -07:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
2026-07-07 08:09:54 -07:00
|
|
|
#include "../datatypes.cpp"
|
|
|
|
|
#include "../helpers.cpp"
|
|
|
|
|
#include "../buffer.cpp"
|
2026-07-08 14:05:42 -07:00
|
|
|
#include "../shader.cpp"
|
2026-07-07 06:47:24 -07:00
|
|
|
|
|
|
|
|
namespace UwU {
|
|
|
|
|
// rectangle
|
|
|
|
|
class Rectangle {
|
|
|
|
|
public:
|
|
|
|
|
Rectangle(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1) {
|
|
|
|
|
this->x0 = x0;
|
|
|
|
|
this->y0 = y0;
|
|
|
|
|
this->x1 = x1;
|
|
|
|
|
this->y1 = y1;
|
|
|
|
|
}
|
|
|
|
|
Rectangle() {}
|
|
|
|
|
uint16_t x0;
|
|
|
|
|
uint16_t y0;
|
|
|
|
|
uint16_t x1;
|
|
|
|
|
uint16_t y1;
|
|
|
|
|
|
|
|
|
|
// Draw a rectangle
|
2026-07-08 13:33:43 -07:00
|
|
|
void draw (Buffer buffer, Shader shader) {
|
2026-07-08 16:50:17 -07:00
|
|
|
if (x0 > buffer.width || y0 > buffer.height || x1 > buffer.width || y1 > buffer.height) {return;};
|
2026-07-08 13:33:43 -07:00
|
|
|
if (shader.shaderType == COLOR) {
|
|
|
|
|
for (uint16_t y = y0; y < y1; y++) {
|
|
|
|
|
for (uint16_t x = x0; x < x1; x++) {
|
2026-07-08 14:34:55 -07:00
|
|
|
buffer.drawPixel(x, y, shader.c0);
|
2026-07-08 13:33:43 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
} else if (shader.shaderType == HGRADIENT) {
|
2026-07-08 14:34:55 -07:00
|
|
|
|
|
|
|
|
// Precompute gradient LUT
|
2026-07-08 13:33:43 -07:00
|
|
|
Color cols[x1 - x0];
|
2026-07-07 06:47:24 -07:00
|
|
|
for (uint16_t x = x0; x < x1; x++) {
|
2026-07-08 13:33:43 -07:00
|
|
|
cols[x - x0] = ShaderMethods::gradient(shader.u0, shader.scale, shader.c0, shader.c1, x);
|
|
|
|
|
}
|
2026-07-08 16:50:17 -07:00
|
|
|
|
2026-07-08 13:33:43 -07:00
|
|
|
for (uint16_t y = y0; y < y1; y++) {
|
|
|
|
|
for (uint16_t x = x0; x < x1; x++) {
|
2026-07-08 14:34:55 -07:00
|
|
|
buffer.drawPixel(x, y, cols[x - x0]);
|
2026-07-08 13:33:43 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
} else if (shader.shaderType == VGRADIENT) {
|
|
|
|
|
for (uint16_t y = y0; y < y1; y++) {
|
|
|
|
|
Color c = ShaderMethods::gradient(shader.v0, shader.scale, shader.c0, shader.c1, y);
|
|
|
|
|
for (uint16_t x = x0; x < x1; x++) {
|
2026-07-08 14:34:55 -07:00
|
|
|
buffer.drawPixel(x, y, c);
|
2026-07-08 13:33:43 -07:00
|
|
|
}
|
2026-07-07 06:47:24 -07:00
|
|
|
}
|
2026-07-08 13:33:43 -07:00
|
|
|
return;
|
2026-07-08 16:50:17 -07:00
|
|
|
|
|
|
|
|
} else if (shader.shaderType == BUFFER) {
|
|
|
|
|
for (uint16_t y = y0; y < y1; y++) {
|
|
|
|
|
for (uint16_t x = x0; x < x1; x++) {
|
|
|
|
|
buffer.drawPixel(x, y, ShaderMethods::buffer(shader.u0, shader.v0, shader.buffer, x, y));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return;
|
2026-07-07 06:47:24 -07:00
|
|
|
}
|
2026-07-08 16:50:17 -07:00
|
|
|
return;
|
2026-07-07 06:47:24 -07:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|