- [NEW] implementat jdraw::stencil

This commit is contained in:
2024-07-11 08:25:27 +02:00
parent 7365d72360
commit b794ebe608
2 changed files with 47 additions and 0 deletions

View File

@@ -39,6 +39,40 @@ namespace draw
surface* managed[50];
int num_managed = 0;
namespace stencil
{
static bool enabled = false;
static uint8_t value = 0;
static surface *stencil = nullptr;
void init()
{
if (stencil) freeSurface(stencil);
stencil = createSurface(screen->w, screen->h);
}
void enable() { enabled = true; }
void disable() { enabled = false; }
void clear(const uint8_t val)
{
if (!stencil) return;
memset(stencil->pixels, val, stencil->w*stencil->h);
}
void set(const uint8_t val)
{
if (!stencil) return;
value = val;
}
const uint8_t query(const int x, const int y)
{
if (!stencil) return 0;
return stencil->pixels[x+y*stencil->w];
}
}
// Inicialització de tot el que fa falta per a carregar gràfics i pintar en pantalla
void init(const std::string &titol, const uint16_t width, const uint16_t height, const int zoom, const bool fullscreen)
{
@@ -362,7 +396,10 @@ namespace draw
// Si pintem a "destination", mirem que estiga dins del "viewport" i sinó fora
if (surface == destination) {
if (x+viewport.x >= 0 && y+viewport.y >= 0 && x < viewport.w && y < viewport.h)
{
surface->pixels[(viewport.x+x) + (y+viewport.y) * surface->w] = color_indices[color];
if (stencil::stencil && stencil::enabled) stencil::stencil->pixels[(viewport.x+x) + (y+viewport.y) * stencil::stencil->w] = stencil::value;
}
} else {
// Si no es destinations, pintem i au
surface->pixels[x + y * surface->w] = color_indices[color];