Improve things

This commit is contained in:
2025-02-05 22:32:31 +01:00
parent 9837729656
commit 2a2313dff7
6 changed files with 296 additions and 12 deletions

View File

@@ -12,21 +12,19 @@ prepText(SDL_Renderer *renderer, unsigned char pxSize, const char *file, uint8_t
out.size = pxSize;
out.color = (SDL_Color) {r, g, b, a};
unsigned char i = 0;
SDL_Surface *fontTempSurf = NULL;
do {
char tmpOut[2] = {i, 0};
fontTempSurf = TTF_RenderText_Solid(gFont, tmpOut, out.color);
out.surface[i] = TTF_RenderText_Solid(gFont, tmpOut, out.color);
SDL_Rect dstRect;
dstRect.x = 0;
dstRect.y = 0;
dstRect.w = pxSize;
dstRect.h = pxSize;
out.texture[i] = SDL_CreateTextureFromSurface(renderer, fontTempSurf);
out.texture[i] = SDL_CreateTextureFromSurface(renderer, out.surface[i]);
i++;
} while (i < 255);
SDL_FreeSurface(fontTempSurf);
TTF_CloseFont(gFont);
return out;
}
@@ -42,6 +40,12 @@ void renderText(SDL_Renderer *renderer, BitmapFont font, char *string, uint16_t
outRect.y = y;
while (*string) {
if (*string == '\n') {
outRect.x = x;
outRect.y += charRect.h + 4;
string++;
continue;
}
SDL_RenderCopy(renderer, font.texture[*string], &charRect, &outRect);
outRect.x += charRect.w + 1;
string++;