2019-09-09 06:23:38 +02:00
|
|
|
#include "structs.h"
|
2019-09-08 01:11:20 +02:00
|
|
|
#include "SDL2/SDL2_rotozoom.h"
|
2017-09-14 05:21:36 +02:00
|
|
|
|
|
|
|
TTF_Font *loadFont(char *name, int size)
|
|
|
|
{
|
|
|
|
TTF_Font *font = TTF_OpenFont(name, size);
|
|
|
|
|
|
|
|
if (font == NULL)
|
|
|
|
{
|
|
|
|
printf("Failed to open Font %s: %s\n", name, TTF_GetError());
|
|
|
|
|
|
|
|
exit(1);
|
|
|
|
}
|
2019-09-08 01:11:20 +02:00
|
|
|
|
2017-09-14 05:21:36 +02:00
|
|
|
return font;
|
|
|
|
}
|
|
|
|
|
|
|
|
void closeFont(TTF_Font *font)
|
2020-03-03 07:22:35 +01:00
|
|
|
{
|
2017-09-14 05:21:36 +02:00
|
|
|
if (font != NULL)
|
|
|
|
{
|
|
|
|
TTF_CloseFont(font);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void drawString(char * text, int x, int y, TTF_Font *font, SDL_Color color)
|
|
|
|
{
|
2017-09-17 17:38:22 +02:00
|
|
|
if(!strlen(text)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-09-14 05:21:36 +02:00
|
|
|
SDL_Surface *surface;
|
2017-09-15 04:13:02 +02:00
|
|
|
SDL_Rect dest;
|
|
|
|
|
2019-09-08 01:11:20 +02:00
|
|
|
surface = TTF_RenderUTF8_Solid(font, text, color);
|
2017-10-06 18:34:36 +02:00
|
|
|
|
|
|
|
if (surface == NULL)
|
|
|
|
{
|
|
|
|
printf("Couldn't create String %s: %s\n", text, SDL_GetError());
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
dest.x = x;
|
|
|
|
dest.y = y;
|
|
|
|
dest.w = surface->w;
|
|
|
|
dest.h = surface->h;
|
|
|
|
|
2019-09-09 06:23:38 +02:00
|
|
|
SDL_Texture *texture = SDL_CreateTextureFromSurface(appData.renderer, surface);
|
|
|
|
SDL_RenderCopy(appData.renderer, texture, NULL, &dest);
|
2019-09-08 01:11:20 +02:00
|
|
|
SDL_DestroyTexture(texture);
|
2017-10-06 18:34:36 +02:00
|
|
|
SDL_FreeSurface(surface);
|
|
|
|
}
|
|
|
|
|
2017-09-17 17:38:22 +02:00
|
|
|
void drawStringBG(char * text, int x, int y, TTF_Font *font, SDL_Color color, SDL_Color bgColor) {
|
|
|
|
if(!strlen(text)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SDL_Surface *surface;
|
|
|
|
SDL_Rect dest;
|
2017-09-14 05:21:36 +02:00
|
|
|
|
2017-09-17 17:38:22 +02:00
|
|
|
surface = TTF_RenderUTF8_Shaded(font, text, color, bgColor);
|
|
|
|
|
|
|
|
if (surface == NULL)
|
|
|
|
{
|
|
|
|
printf("Couldn't create String %s: %s\n", text, SDL_GetError());
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Blit the entire surface to the screen */
|
|
|
|
|
|
|
|
dest.x = x;
|
|
|
|
dest.y = y;
|
|
|
|
dest.w = surface->w;
|
|
|
|
dest.h = surface->h;
|
|
|
|
|
2019-09-09 06:23:38 +02:00
|
|
|
SDL_Texture *texture = SDL_CreateTextureFromSurface(appData.renderer, surface);
|
|
|
|
SDL_RenderCopy(appData.renderer, texture, NULL, &dest);
|
2019-09-08 01:11:20 +02:00
|
|
|
SDL_DestroyTexture(texture);
|
2017-09-17 17:38:22 +02:00
|
|
|
SDL_FreeSurface(surface);
|
|
|
|
}
|