blob: f221f3d7e280b878c08ccb95dd0f8e9415d7db08 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
#include "SDL.h"
#include "SDL_ttf.h"
#include <stdlib.h>
#include "text.h"
Text_t * CreateText(TTF_Font * Font, const char * text, SDL_Color * components) {
Text_t * newtext;
newtext = malloc(sizeof(Text_t));
newtext->Surface = NULL;
UpdateText(newtext, Font, text, components);
return newtext;
}
void UpdateText(Text_t * tobeupdated, TTF_Font * Font, const char * text, SDL_Color * components) {
SDL_Surface * Temp = NULL;
Temp = TTF_RenderText_Blended(Font, text, *components);
if (tobeupdated->Surface) {
SDL_FreeSurface(tobeupdated->Surface);
}
tobeupdated->Surface = SDL_DisplayFormatAlpha(Temp);
SDL_FreeSurface(Temp);
tobeupdated->Rect.w = tobeupdated->Surface->w;
tobeupdated->Rect.h = tobeupdated->Surface->h;
}
void DeleteText(Text_t * Text) {
SDL_FreeSurface(Text->Surface);
free(Text);
}
|