Implement unicode character replacements
Useful to draw whitespaces with alternate characters and colors without slowing down the text rendering. A new API is implemented. A renderer.replacements object can be created to list the replacements. In turns the function renderer.draw_text and draw_text_subpixel now accept two optional arguments for replacements.
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
#include "api.h"
|
||||
#include "renderer.h"
|
||||
|
||||
|
||||
static int f_new(lua_State *L) {
|
||||
CPReplaceTable *rep_table = lua_newuserdata(L, sizeof(CPReplaceTable));
|
||||
luaL_setmetatable(L, API_TYPE_REPLACE);
|
||||
ren_cp_replace_init(rep_table);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
static int f_gc(lua_State *L) {
|
||||
CPReplaceTable *rep_table = luaL_checkudata(L, 1, API_TYPE_REPLACE);
|
||||
ren_cp_replace_free(rep_table);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int f_add(lua_State *L) {
|
||||
CPReplaceTable *rep_table = luaL_checkudata(L, 1, API_TYPE_REPLACE);
|
||||
const char *src = luaL_checkstring(L, 2);
|
||||
const char *dst = luaL_checkstring(L, 3);
|
||||
ren_cp_replace_add(rep_table, src, dst);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static const luaL_Reg lib[] = {
|
||||
{ "__gc", f_gc },
|
||||
{ "new", f_new },
|
||||
{ "add", f_add },
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
int luaopen_renderer_replacements(lua_State *L) {
|
||||
luaL_newmetatable(L, API_TYPE_REPLACE);
|
||||
luaL_setfuncs(L, lib, 0);
|
||||
lua_pushvalue(L, -1);
|
||||
lua_setfield(L, -2, "__index");
|
||||
return 1;
|
||||
}
|
||||
Reference in New Issue
Block a user