-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmsdl_font.c
52 lines (45 loc) · 1.1 KB
/
msdl_font.c
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*
** msdl_font.c
** by bogard_t
*/
# include <stdlib.h>
# include "msdl.h"
# include "mconverter.h"
TTF_Font *msdl_load_font(const char *file,
size_t size)
{
TTF_Font *font;
if (!(font = TTF_OpenFont(file, size)))
{
fprintf(stderr, "->msdl font failure [%s] is not a good path\n", file);
return (NULL);
}
return (font);
}
void msdl_write_hexa_color(SDL_Surface **surface,
TTF_Font *font,
const char *str,
const unsigned int hexcode)
{
SDL_Color colorized_text;
unsigned int *rgb;
rgb = hex_to_rgb(hexcode);
colorized_text.r = rgb[0];
colorized_text.g = rgb[1];
colorized_text.b = rgb[2];
free(rgb);
*surface = TTF_RenderText_Solid(font, str, colorized_text);
TTF_CloseFont(font);
}
void msdl_write_rgb_color(SDL_Surface **surface,
TTF_Font *font,
const char *str,
const unsigned int *rgb)
{
SDL_Color colorized_text;
colorized_text.r = rgb[0];
colorized_text.g = rgb[1];
colorized_text.b = rgb[2];
*surface = TTF_RenderText_Solid(font, str, colorized_text);
TTF_CloseFont(font);
}