-
Notifications
You must be signed in to change notification settings - Fork 30
/
gui_hooks.hpp
98 lines (82 loc) · 2.8 KB
/
gui_hooks.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
namespace twbt_gui_hooks {
using namespace DFHack;
using df::global::enabler;
bool read_map_tile(Screen::Pen &pen, int x, int y)
{
renderer_cool *r = (renderer_cool*)enabler->renderer;
if (!r->is_twbt())
return false;
if (x < 1 || x > r->gdimx || y < 1 || y > r->gdimy)
{
// invalidate
pen.tile = -1;
return true;
}
const int tile = (x-1) * r->gdimy + (y-1);
unsigned char *s = r->gscreen + tile*4;
pen.ch = s[0];
pen.fg = s[1] % 8;
pen.bg = s[2];
pen.bold = s[3] & 0x1; // check?
return true;
}
bool write_map_tile(const Screen::Pen &pen, int x, int y)
{
renderer_cool *r = (renderer_cool*)enabler->renderer;
if (!r->is_twbt())
return false;
if (x < 1 || x > r->gdimx || y < 1 || y > r->gdimy)
return false;
const int tile = (x-1) * r->gdimy + (y-1);
unsigned char *s = r->gscreen + tile*4;
s[0] = pen.ch;
s[1] = pen.fg % 8;
s[2] = pen.bg;
s[3] = (pen.fg / 8 | pen.bold) | (s[3]&0xf0);
r->gscreentexpos[tile] = 0;
return true;
}
Screen::Pen get_tile(int x, int y, bool map);
GUI_HOOK_CALLBACK(Screen::Hooks::get_tile, get_tile_hook, get_tile);
Screen::Pen get_tile(int x, int y, bool map)
{
Screen::Pen pen;
if (map && read_map_tile(pen, x, y))
return pen;
return get_tile_hook.next()(x, y, map);
}
bool set_tile(const Screen::Pen &pen, int x, int y, bool map);
GUI_HOOK_CALLBACK(Screen::Hooks::set_tile, set_tile_hook, set_tile);
bool set_tile(const Screen::Pen &pen, int x, int y, bool map)
{
if (map && write_map_tile(pen, x, y))
return true;
return set_tile_hook.next()(pen, x, y, map);
}
Gui::DwarfmodeDims get_dwarfmode_dims();
GUI_HOOK_CALLBACK(Gui::Hooks::dwarfmode_view_dims, get_dwarfmode_dims_hook, get_dwarfmode_dims);
Gui::DwarfmodeDims get_dwarfmode_dims()
{
auto dims = get_dwarfmode_dims_hook.next()();
auto r = (renderer_cool*)enabler->renderer;
if (r->is_twbt())
{
dims.map_x2 = r->gdimx;
dims.map_y2 = r->gdimy;
}
return dims;
}
int get_depth_at(int32_t x, int32_t y);
GUI_HOOK_CALLBACK(Gui::Hooks::depth_at, get_depth_at_hook, get_depth_at);
int get_depth_at(int32_t x, int32_t y)
{
auto r = (renderer_cool*)enabler->renderer;
if (r->is_twbt() && x >= 1 && x <= r->gdimx && y >= 1 && y <= r->gdimy)
{
const int tile = (x-1) * r->gdimy + (y-1);
unsigned char *s = r->gscreen + tile*4;
return ((s[3]&0xf0)>>4);
}
return get_depth_at_hook.next()(x, y);
}
}