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"
|
|
|
|
|
#include "../shaders/shader.cpp"
|
2026-07-08 13:33:43 -07:00
|
|
|
// #include "../shaders/colorshader.cpp"
|
2026-07-07 17:57:25 -07:00
|
|
|
// #include "../shaders/gradientshader.cpp"
|
2026-07-08 13:33:43 -07:00
|
|
|
// #include "../shaders/hgradientshader.cpp"
|
|
|
|
|
// #include "../shaders/vgradientshader.cpp"
|
2026-07-07 17:57:25 -07:00
|
|
|
// #include "../mapper.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) {
|
|
|
|
|
if (shader.shaderType == COLOR) {
|
|
|
|
|
if (x0 > buffer.width || y0 > buffer.height || x1 > buffer.width || y1 > buffer.height) {return;};
|
|
|
|
|
Color c = shader.c0;
|
|
|
|
|
uint8_t r = c.r;
|
|
|
|
|
uint8_t g = c.g;
|
|
|
|
|
uint8_t b = c.b;
|
|
|
|
|
size_t stride = buffer.stride;
|
|
|
|
|
size_t i = (size_t)y0 * buffer.stride + (size_t)x0 * 4;
|
|
|
|
|
for (uint16_t y = y0; y < y1; y++) {
|
|
|
|
|
for (uint16_t x = x0; x < x1; x++) {
|
|
|
|
|
// buffer.drawPixel(Coord2(x, y), shader.c0);
|
|
|
|
|
buffer.pixels[i + 0] = b;
|
|
|
|
|
buffer.pixels[i + 1] = g;
|
|
|
|
|
buffer.pixels[i + 2] = r;
|
|
|
|
|
buffer.pixels[i + 3] = 255;
|
|
|
|
|
i += 4;
|
|
|
|
|
}
|
|
|
|
|
i += stride - ((x1 - x0) * 4);
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
} else if (shader.shaderType == HGRADIENT) {
|
|
|
|
|
if (x0 > buffer.width || y0 > buffer.height || x1 > buffer.width || y1 > buffer.height) {return;};
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
for (uint16_t y = y0; y < y1; y++) {
|
|
|
|
|
for (uint16_t x = x0; x < x1; x++) {
|
|
|
|
|
buffer.drawPixel(Coord2(x, y), cols[x - x0]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
} else if (shader.shaderType == VGRADIENT) {
|
|
|
|
|
if (x0 > buffer.width || y0 > buffer.height || x1 > buffer.width || y1 > buffer.height) {return;};
|
|
|
|
|
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++) {
|
|
|
|
|
buffer.drawPixel(Coord2(x, y), c);
|
|
|
|
|
}
|
2026-07-07 06:47:24 -07:00
|
|
|
}
|
2026-07-08 13:33:43 -07:00
|
|
|
return;
|
2026-07-07 06:47:24 -07:00
|
|
|
}
|
2026-07-08 13:33:43 -07:00
|
|
|
|
2026-07-07 06:47:24 -07:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|