-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfgui_text.c
90 lines (75 loc) · 1.98 KB
/
fgui_text.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
89
90
/*
FemtoGUI
fgui_text.c:
Text functions
copyright:
Copyright (c) 2006-2008 Bastiaan van Kesteren <[email protected]>
This program comes with ABSOLUTELY NO WARRANTY; for details see the file LICENSE.
This program is free software; you can redistribute it and/or modify it under the terms
of the GNU General Public License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
remarks:
*/
#include "fgui.h"
#define FGUI_CODE
#include "fgui_helper.h"
extern fgui_t fgui;
void fgui_setfont(const unsigned char *newfont)
/*
Select the font to use. Must be called before using any of the other text
functions.
'newfont' must point to a valid font array. Elements in the array are:
0 char width in bits (pixels)
1 char height in bits (pixels)
2-n The actual pixel data
*/
{
fgui.font.w = newfont[0];
fgui.font.bytew = bitstobytesup(newfont[0]);
fgui.font.h = newfont[1];
fgui.font.pixeldata = (unsigned char *)&newfont[2];
}
unsigned char fgui_charheight()
/*
Height of active font, in pixels
*/
{
return fgui.font.h;
}
unsigned char fgui_charwidth()
/*
Width of a single character from the active font, in pixels
*/
{
return fgui.font.w;
}
unsigned int fgui_strlen(char *s)
/*
Get length of given string, in pixels
*/
{
int length=0;
while(*s) {
s++;
length++;
}
return length * fgui.font.w;
}
void fgui_char(const int x, const int y, const char c)
/*
Place a single character at given location
*/
{
copypixeldata(x, y, &fgui.font.pixeldata[(c-32) * (fgui.font.h * fgui.font.bytew)], fgui.font.w, fgui.font.h, fgui.font.bytew, fgui.fgcolor);
}
void fgui_text(int x, const int y, const char *str)
/*
Place a NULL terminated string at the given location
*/
{
while(*str) {
fgui_char(x,y,*str);
x += fgui.font.w;
str++;
}
}