#pragma once #include #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 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]; for (uint16_t x = x0; x < x1; x++) { 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); } } return; } } }; }