-
Notifications
You must be signed in to change notification settings - Fork 1
/
font.cpp
46 lines (45 loc) · 1.62 KB
/
font.cpp
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
//=============================================================================
// ■ Font
//-----------------------------------------------------------------------------
// A Lua class for handling fonts.
//=============================================================================
namespace Font {
//-------------------------------------------------------------------------
// ● check_font
//-------------------------------------------------------------------------
TTF_Font* check_font(lua_State* L, int index) {
return *((TTF_Font**) luaL_checkudata(L, index, "Font"));
}
//-------------------------------------------------------------------------
// ● ~Font()
//-------------------------------------------------------------------------
int lua_gc(lua_State* L) {
TTF_Font* font = check_font(L, 1);
TTF_CloseFont(font);
return 0;
}
//-------------------------------------------------------------------------
// ● init_load_assets
//-------------------------------------------------------------------------
void init_load_assets() {
for (int i = 0; i < 1; i++) {
char filename[16];
sprintf(filename, "fon%d.ttf", i);
$font[i] = TTF_OpenFontIndex(Util::rtp(filename), 20, 0);
TTF_SetFontHinting($font[i], TTF_HINTING_NONE);
}
}
//-------------------------------------------------------------------------
// ● init
//-------------------------------------------------------------------------
void init() {
init_load_assets();
const luaL_reg reg[] = {
{"__gc", lua_gc},
{NULL, NULL}
};
luaL_newmetatable(L, "Font");
luaL_register(L, NULL, reg);
lua_setfield(L, -1, "__index");
}
}