Files
UwUGL/primatives/rectangle.cpp
T

47 lines
1.3 KiB
C++

#pragma once
#include <stdint.h>
#include "../datatypes.cpp"
#include "../helpers.cpp"
#include "../buffer.cpp"
#include "../shaders/shader.cpp"
#include "../shaders/colorshader.cpp"
// #include "../shaders/gradientshader.cpp"
#include "../shaders/hgradientshader.cpp"
#include "../shaders/vgradientshader.cpp"
// #include "../mapper.cpp"
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
template<typename ShaderType>
void draw (Buffer buffer, ShaderType& shader) {
// printf("color: %u, %u, %u, %u", shader.color().r, shader.color().g, shader.color().b, shader.color().a);
if (x0 > buffer.width || y0 > buffer.height || x1 > buffer.width || y1 > buffer.height) {return;};
// Coord2 uv = Coord2();
for (uint16_t y = y0; y < y1; y++) {
for (uint16_t x = x0; x < x1; x++) {
// uv = mapper.map(Coord2(x, y));
Color c = shader.color(x, y);
buffer.drawPixel(Coord2(x, y), c);
}
}
return;
}
};
}