viz1090/font.c
nathan 081ecda409 moving everything out of dump1090.h and interactive.c
Former-commit-id: 09fc0bec299442fa1ac44ee6e41f237134ab2b73
Former-commit-id: 0f3edc36d54876849854abd4ef5ab8531f374b38
2019-09-08 23:23:38 -05:00

89 lines
1.7 KiB
C
Executable file

#include "structs.h"
#include "SDL2/SDL2_rotozoom.h"
TTF_Font *loadFont(char *name, int size)
{
/* Use SDL_TTF to load the font at the specified size */
TTF_Font *font = TTF_OpenFont(name, size);
if (font == NULL)
{
printf("Failed to open Font %s: %s\n", name, TTF_GetError());
exit(1);
}
return font;
}
void closeFont(TTF_Font *font)
{
/* Close the font once we're done with it */
if (font != NULL)
{
TTF_CloseFont(font);
}
}
void drawString(char * text, int x, int y, TTF_Font *font, SDL_Color color)
{
if(!strlen(text)) {
return;
}
SDL_Surface *surface;
SDL_Rect dest;
surface = TTF_RenderUTF8_Solid(font, text, color);
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;
SDL_Texture *texture = SDL_CreateTextureFromSurface(appData.renderer, surface);
SDL_RenderCopy(appData.renderer, texture, NULL, &dest);
SDL_DestroyTexture(texture);
SDL_FreeSurface(surface);
}
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;
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;
SDL_Texture *texture = SDL_CreateTextureFromSurface(appData.renderer, surface);
SDL_RenderCopy(appData.renderer, texture, NULL, &dest);
SDL_DestroyTexture(texture);
SDL_FreeSurface(surface);
}