- swapcol(), color(), hline(), vline(), rect(), fillrect()

This commit is contained in:
2023-06-06 09:17:45 +02:00
parent 5cf871caed
commit 7459390b0f
2 changed files with 47 additions and 4 deletions

View File

@@ -18,8 +18,10 @@ namespace draw
surface *destination = nullptr; // Punter a la actual superficie de destí
surface *source = nullptr; // Punter a la actual superficie de oritge
uint32_t palette[256]; // La paleta de colors
uint8_t transparent = 0; // El color transparent
uint32_t palette[256]; // La paleta de colors
uint8_t color_indices[256]; // Indices dels colors per defecte
uint8_t sel_color = 0; // Color seleccionat per defecte
uint8_t transparent = 0; // El color transparent
// 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)
@@ -37,7 +39,8 @@ namespace draw
// Creem la superficie "screen" i la establim com a superficie destinació
screen = createSurface(width, height);
destination = screen;
transparent = 0;
sel_color = transparent = 0;
for (int i=0;i<256;++i) color_indices[i] = i;
}
// Finalització del sistema
@@ -185,7 +188,7 @@ namespace draw
// escriure el byte "color" on toca en el array de pixels de la superficie
if (color != transparent && x >= 0 && y >= 0 && x < surface->w && y < surface->h)
{
surface->pixels[x + y * surface->w] = color;
surface->pixels[x + y * surface->w] = color_indices[color];
}
}
@@ -247,6 +250,39 @@ namespace draw
}
}
void swapcol(const Uint8 c1, const Uint8 c2)
{
color_indices[c1] = c2;
}
void color(const Uint8 col)
{
sel_color = col;
}
void hline(const int x, const int y, const int w)
{
for (int i=x;i<x+w;++i) pset(destination, i, y, sel_color);
}
void vline(const int x, const int y, const int h)
{
for (int i=y;i<y+h;++i) pset(destination, x, i, sel_color);
}
void fillrect(const int x, const int y, const int w, const int h)
{
for (int j=y;j<y+h;++j) for (int i=x;i<x+w;++i) pset(destination, i, j, sel_color);
}
void rect(const int x, const int y, const int w, const int h)
{
hline(x,y,w);
hline(x,y+h-1,w);
vline(x,y,h);
vline(x+w-1,y,h);
}
// Refresca la pantalla
void render()
{

View File

@@ -73,6 +73,13 @@ namespace draw
/// @param flip si s'ha de fer flip en hortizontal o vertical (o ambdos)
void draw(const int dx, const int dy, const int w, const int h, const int sx, const int sy, const int flip = DRAW_FLIP_NONE);
void swapcol(const Uint8 c1, const Uint8 c2);
void color(const Uint8 col);
void hline(const int x, const int y, const int w);
void vline(const int x, const int y, const int h);
void fillrect(const int x, const int y, const int w, const int h);
void rect(const int x, const int y, const int w, const int h);
/// @brief Refresca la pantalla
void render();
}