-
Notifications
You must be signed in to change notification settings - Fork 0
/
text_rendering.c
88 lines (79 loc) · 2.34 KB
/
text_rendering.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/* ************************************************************************** */
/* */
/* :::::::: */
/* text_rendering.c :+: :+: */
/* +:+ */
/* By: cschuijt <[email protected]> +#+ */
/* +#+ */
/* Created: 2022/12/26 19:02:50 by cschuijt #+# #+# */
/* Updated: 2022/12/26 19:02:50 by cschuijt ######## odam.nl */
/* */
/* ************************************************************************** */
#include "so_long.h"
void string_to_image(char *str, mlx_image_t *image, \
uint8_t **charset, size_t xy[2])
{
size_t i;
i = 0;
while (str[i])
{
if (ft_isprint(str[i]))
char_to_image(charset[(int)(str[i])], image, xy, TEXT_COLOR);
else
char_to_image(charset['?'], image, xy, TEXT_COLOR);
xy[0] += FONT_W;
i++;
}
}
void string_to_image_right(char *str, mlx_image_t *image, \
uint8_t **charset, size_t xy[2])
{
size_t i;
size_t len;
len = ft_strlen(str);
i = 1;
while (i <= len)
{
if (ft_isprint(str[len - i]))
char_to_image(charset[(int)(str[len - i])], image, xy, TEXT_COLOR);
else
char_to_image(charset['?'], image, xy, TEXT_COLOR);
xy[0] -= FONT_W;
i++;
}
}
void string_to_image_center(char *str, mlx_image_t *image, \
uint8_t **charset, size_t y)
{
size_t i;
size_t xy[2];
size_t len;
len = ft_strlen(str);
xy[0] = (image->width / 2) - ((len * FONT_W) / 2);
xy[1] = y;
i = 0;
while (str[i])
{
if (ft_isprint(str[i]))
char_to_image(charset[(int)(str[i])], image, xy, TEXT_COLOR);
else
char_to_image(charset['?'], image, xy, TEXT_COLOR);
xy[0] += FONT_W;
i++;
}
}
void char_to_image(uint8_t *chr, mlx_image_t *image, \
size_t xy[2], uint32_t color)
{
size_t i;
uint32_t *src;
i = 0;
src = (uint32_t *) chr;
while (i < FONT_SPRITE_DIMS * FONT_SPRITE_DIMS)
{
if (src[i] == 0xFFFFFFFF)
mlx_put_pixel(image, xy[0] + (i % FONT_SPRITE_DIMS), \
xy[1] + (i / FONT_SPRITE_DIMS), color);
i++;
}
}