summaryrefslogtreecommitdiff
path: root/font.c
blob: 90acaee6386c1f1bd22743fe98c8ac1e27977bda (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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include "font.h"
#include "TZR.h"

static TZR_Uint ___font_spr = 0;

int font_init(const char *path)
{
	___font_spr = TZR_LoadResourceTyped(TZR_RES_IMAGE, path);
	if (___font_spr == 0)
		return 1;
	return 0;
}

void font_draw(int x, int y, const char *s, int size)
{
	const int ox = x;
	TZR_DrawSetColor(1, 1, 1, 1);
	for (; *s != '\0' && size > 0; s++, size--) {
		const char c = toupper(*s);
		const int ix = c % 16 * FONT_W;
		const int iy = c / 16 * FONT_H;
		switch (*s) {
		case '\n':
			y += 1;
			x = ox;
			break;
		case 'R':
			TZR_DrawSetColor(1, 0, 0);
			break;
		case 'G':
			TZR_DrawSetColor(0, 1, 0);
			break;
		case 'B':
			TZR_DrawSetColor(0, 0, 1);
			break;
		case 'W':
			TZR_DrawSetColor(1, 1, 1);
			break;
		case 'D':
			TZR_DrawSetColor(0.5, 0.5, 0.5);
			break;
		default:
			TZR_DrawImage(___font_spr, x*FONT_W, y*FONT_H, ix, iy,
			              FONT_W, FONT_H);
			x += 1;
			break;
		}
	}
	TZR_DrawSetColor(1, 1, 1);
	if (TZR_GetTick() / 30 % 2)
		TZR_DrawRectangle(true, x*FONT_W, y*FONT_H+1, 1, FONT_H-2);
}