- Funcions de pintat de text

This commit is contained in:
2023-06-06 10:03:18 +02:00
parent 7459390b0f
commit f7f6131a79
4 changed files with 61 additions and 4 deletions

View File

@@ -16,13 +16,16 @@ namespace draw
surface *screen = nullptr; // La superficie screen, que representa la pantalla. Se crea i destrueix internament
surface *destination = nullptr; // Punter a la actual superficie de destí
surface *source = nullptr; // Punter a la actual superficie de oritge
surface *source = nullptr; // Punter a la actual superficie d'oritge
surface *pushedSource = nullptr; // Punter a la superficie d'oritge que s'ha pushat
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
surface *textsurf = nullptr; // Surface on guardar el gif amb la font
// 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)
{
@@ -41,11 +44,15 @@ namespace draw
destination = screen;
sel_color = transparent = 0;
for (int i=0;i<256;++i) color_indices[i] = i;
textsurf = loadSurface("font.gif");
}
// Finalització del sistema
void quit()
{
if (textsurf) freeSurface(textsurf);
// Si la superficie "screen" existia, alliberem la seua memòria
if (screen != nullptr)
{
@@ -143,6 +150,16 @@ namespace draw
source = surf == nullptr ? screen : surf;
}
void pushSource()
{
pushedSource = source;
}
void popSource()
{
source = pushedSource;
}
// Estableix la paleta del sistema carregant-la d'un GIF
void loadPalette(const std::string &filename)
{
@@ -255,6 +272,11 @@ namespace draw
color_indices[c1] = c2;
}
void restorecol(const Uint8 c)
{
color_indices[c] = c;
}
void color(const Uint8 col)
{
sel_color = col;
@@ -283,6 +305,33 @@ namespace draw
vline(x+w-1,y,h);
}
void print(const char* text, const int x, const int y, const Uint8 color, const Uint8 borde)
{
surface* tmp = source;
source = textsurf;
swapcol(1, color);
const int len = strlen(text);
for (int i=0;i<len;++i)
{
char chr = text[i];
if (borde!=0)
{
swapcol(1, borde);
draw(-1+x+i*4, y-1, 4, 6, (chr&15)*4, (chr>>4)*6);
draw(x+i*4, y-1, 4, 6, (chr&15)*4, (chr>>4)*6);
draw(1+x+i*4, y-1, 4, 6, (chr&15)*4, (chr>>4)*6);
draw(-1+x+i*4, y, 4, 6, (chr&15)*4, (chr>>4)*6);
draw(1+x+i*4, y, 4, 6, (chr&15)*4, (chr>>4)*6);
draw(-1+x+i*4, y+1, 4, 6, (chr&15)*4, (chr>>4)*6);
draw(x+i*4, y+1, 4, 6, (chr&15)*4, (chr>>4)*6);
draw(1+x+i*4, y+1, 4, 6, (chr&15)*4, (chr>>4)*6);
swapcol(1, color);
}
draw(x+i*4, y, 4, 6, (chr&15)*4, (chr>>4)*6);
}
source = tmp;
}
// Refresca la pantalla
void render()
{
@@ -310,4 +359,5 @@ namespace draw
// I ho presentem
SDL_RenderPresent(sdl_renderer);
}
}