-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhudwriter.js
51 lines (42 loc) · 1.06 KB
/
hudwriter.js
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
// HUD text writer
function hudwrite(ctx, x, y, text, size, style)
{
ctx.save();
// Set fill style
ctx.fillStyle=style;
// Iterate through characters to write
for (var i=0; i<text.length; i++)
{
var offs=(text.charCodeAt(i)-32);
// Don't try to draw characters outside our font set
if ((offs<0) || (offs>94))
continue;
// Draw "pixels"
var px=0;
var py=0;
// Iterate through the 4 bytes used to define character
for (var j=0; j<4; j++)
{
var dual=font_8bit[(offs*4)+j]||0;
// Iterate through bits in byte
for (var k=0; k<8; k++)
{
if (dual&(1<<(8-k)))
ctx.fillRect(Math.floor(x+(i*4*size)+(px*size)), Math.floor(y+(size*py)), Math.ceil(size), Math.ceil(size));
px++;
if (px==4)
{
px=0;
py++;
}
}
ctx.stroke();
}
}
ctx.restore();
}
function hudshadowwrite(ctx, x, y, text, size, style)
{
hudwrite(ctx, x+(size/2), y+(size/2), text, size, "rgba(64,64,64,0.5)");
hudwrite(ctx, x, y, text, size, style);
}