40 lines
1.0 KiB
C++
40 lines
1.0 KiB
C++
#pragma once
|
|
|
|
#include <stdint.h>
|
|
|
|
#include "../datatypes.cpp"
|
|
#include "../helpers.cpp"
|
|
#include "../buffer.cpp"
|
|
#include "../mappers/mappers.h"
|
|
#include "../textures/textures.h"
|
|
|
|
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 <class MapperT, class TextureT>
|
|
void draw (Buffer buffer, MapperBase<MapperT>& mapper, TextureBase<TextureT>& texture) {
|
|
if (x0 > buffer.width || y0 > buffer.height || x1 > buffer.width || y1 > buffer.height) {return;};
|
|
for (uint16_t y = y0; y <= y1; y++) {
|
|
for (uint16_t x = x0; x <= x1; x++) {
|
|
Coord2 uv = mapper.map(x0, y0, x, y);
|
|
buffer.drawPixel(x, y, texture.texel(uv.x, uv.y));
|
|
}
|
|
}
|
|
return;
|
|
}
|
|
};
|
|
} |