forked from mifki/df-twbt
-
Notifications
You must be signed in to change notification settings - Fork 4
/
tileupdate_text.hpp
120 lines (104 loc) · 3.4 KB
/
tileupdate_text.hpp
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
static void screen_to_texid_text(renderer_cool *r, int tile, struct texture_fullid &ret)
{
const unsigned char *s = r->screen + tile*4;
int bold = (s[3] != 0) * 8;
int fg = (s[1] + bold) % 16;
int bg = s[2] % 16;
const long texpos = ((long*)r->screentexpos)[tile];
if (!texpos)
{
ret.texpos = text_texpos[s[0]];
ret.r = enabler->ccolor[fg][0];
ret.g = enabler->ccolor[fg][1];
ret.b = enabler->ccolor[fg][2];
ret.br = enabler->ccolor[bg][0];
ret.bg = enabler->ccolor[bg][1];
ret.bb = enabler->ccolor[bg][2];
return;
}
ret.texpos = texpos;
if (r->screentexpos_grayscale[tile])
{
const unsigned char cf = r->screentexpos_cf[tile];
const unsigned char cbr = r->screentexpos_cbr[tile];
ret.r = enabler->ccolor[cf][0];
ret.g = enabler->ccolor[cf][1];
ret.b = enabler->ccolor[cf][2];
ret.br = enabler->ccolor[cbr][0];
ret.bg = enabler->ccolor[cbr][1];
ret.bb = enabler->ccolor[cbr][2];
}
else if (r->screentexpos_addcolor[tile])
{
ret.r = enabler->ccolor[fg][0];
ret.g = enabler->ccolor[fg][1];
ret.b = enabler->ccolor[fg][2];
ret.br = enabler->ccolor[bg][0];
ret.bg = enabler->ccolor[bg][1];
ret.bb = enabler->ccolor[bg][2];
}
else
{
ret.r = ret.g = ret.b = 1;
ret.br = ret.bg = ret.bb = 0;
}
}
static void write_tile_arrays_text(renderer_cool *r, int x, int y, GLfloat *fg, GLfloat *bg, GLfloat *tex)
{
const int tile = x * tdimy + y;
// Fast path for transparent area where we render the map
if (screen_map_type == 1 && x > 0 && y > 0 && y < tdimy-1 && x < tdimx-gmenu_w-1)
{
const unsigned char *s = r->screen + tile*4;
if (s[0] == 0)
{
fg[11] = fg[23] = 0;
bg[11] = bg[23] = 0;
return;
}
}
else if (screen_map_type == 2)
{
int m = df::global::ui_advmode->menu;
bool tmode = advmode_needs_map(m);
if (y < tdimy-2 && tmode)
{
const unsigned char *s = r->screen + tile*4;
if (s[0] == 0)
{
fg[11] = fg[23] = 0;
bg[11] = bg[23] = 0;
return;
}
}
}
struct texture_fullid ret;
screen_to_texid_text(r, tile, ret);
for (int i = 0; i < 2; i++) {
fg += 8;
*(fg++) = ret.r;
*(fg++) = ret.g;
*(fg++) = ret.b;
*(fg++) = 1;
bg += 8;
*(bg++) = ret.br;
*(bg++) = ret.bg;
*(bg++) = ret.bb;
*(bg++) = 1;
}
//TODO: handle special cases of graphics tiles outside of the map here with is_text_tile as before (+aux font)
// Set texture coordinates
gl_texpos *txt = (gl_texpos*) enabler->textures.gl_texpos;
*(tex++) = txt[ret.texpos].left; // Upper left
*(tex++) = txt[ret.texpos].bottom;
*(tex++) = txt[ret.texpos].right; // Upper right
*(tex++) = txt[ret.texpos].bottom;
*(tex++) = txt[ret.texpos].left; // Lower left
*(tex++) = txt[ret.texpos].top;
*(tex++) = txt[ret.texpos].left; // Lower left
*(tex++) = txt[ret.texpos].top;
*(tex++) = txt[ret.texpos].right; // Upper right
*(tex++) = txt[ret.texpos].bottom;
*(tex++) = txt[ret.texpos].right; // Lower right
*(tex++) = txt[ret.texpos].top;
}