- swapcol(), color(), hline(), vline(), rect(), fillrect()
This commit is contained in:
@@ -19,6 +19,8 @@ namespace draw
|
|||||||
surface *source = nullptr; // Punter a la actual superficie de oritge
|
surface *source = nullptr; // Punter a la actual superficie de oritge
|
||||||
|
|
||||||
uint32_t palette[256]; // La paleta de colors
|
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
|
uint8_t transparent = 0; // El color transparent
|
||||||
|
|
||||||
// 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
|
||||||
@@ -37,7 +39,8 @@ namespace draw
|
|||||||
// Creem la superficie "screen" i la establim com a superficie destinació
|
// Creem la superficie "screen" i la establim com a superficie destinació
|
||||||
screen = createSurface(width, height);
|
screen = createSurface(width, height);
|
||||||
destination = screen;
|
destination = screen;
|
||||||
transparent = 0;
|
sel_color = transparent = 0;
|
||||||
|
for (int i=0;i<256;++i) color_indices[i] = i;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Finalització del sistema
|
// Finalització del sistema
|
||||||
@@ -185,7 +188,7 @@ namespace draw
|
|||||||
// escriure el byte "color" on toca en el array de pixels de la superficie
|
// 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)
|
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
|
// Refresca la pantalla
|
||||||
void render()
|
void render()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -73,6 +73,13 @@ namespace draw
|
|||||||
/// @param flip si s'ha de fer flip en hortizontal o vertical (o ambdos)
|
/// @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 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
|
/// @brief Refresca la pantalla
|
||||||
void render();
|
void render();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user