- [NEW] implementat jdraw::stencil
This commit is contained in:
@@ -39,6 +39,40 @@ namespace draw
|
|||||||
surface* managed[50];
|
surface* managed[50];
|
||||||
int num_managed = 0;
|
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
|
// 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)
|
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
|
// Si pintem a "destination", mirem que estiga dins del "viewport" i sinó fora
|
||||||
if (surface == destination) {
|
if (surface == destination) {
|
||||||
if (x+viewport.x >= 0 && y+viewport.y >= 0 && x < viewport.w && y < viewport.h)
|
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];
|
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 {
|
} else {
|
||||||
// Si no es destinations, pintem i au
|
// Si no es destinations, pintem i au
|
||||||
surface->pixels[x + y * surface->w] = color_indices[color];
|
surface->pixels[x + y * surface->w] = color_indices[color];
|
||||||
|
|||||||
@@ -119,4 +119,14 @@ namespace draw
|
|||||||
|
|
||||||
/// @brief Refresca la pantalla
|
/// @brief Refresca la pantalla
|
||||||
void render();
|
void render();
|
||||||
|
|
||||||
|
namespace stencil
|
||||||
|
{
|
||||||
|
void init();
|
||||||
|
void enable();
|
||||||
|
void disable();
|
||||||
|
void clear(const uint8_t val);
|
||||||
|
void set(const uint8_t val);
|
||||||
|
const uint8_t query(const int x, const int y);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user