aboutsummaryrefslogtreecommitdiff
path: root/src/sysbin
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2017-05-03 20:37:59 +0200
committerAlex Auvolat <alex@adnab.me>2017-05-03 20:37:59 +0200
commit1161e1d8be014945266017cb0ce735537a287677 (patch)
tree118f2201a5e12f79aefb404295794eed0d52cd6d /src/sysbin
parent0b583122fb6cfcff991c54836d37cb3958c343b1 (diff)
downloadkogata-1161e1d8be014945266017cb0ce735537a287677.tar.gz
kogata-1161e1d8be014945266017cb0ce735537a287677.zip
Truetype fonts
Diffstat (limited to 'src/sysbin')
-rw-r--r--src/sysbin/lx/lua_cmsgpack.c1
-rw-r--r--src/sysbin/lx/lxdrawlib.c29
-rw-r--r--src/sysbin/terminal/main.c4
3 files changed, 27 insertions, 7 deletions
diff --git a/src/sysbin/lx/lua_cmsgpack.c b/src/sysbin/lx/lua_cmsgpack.c
index 57c378e..8eb15fc 100644
--- a/src/sysbin/lx/lua_cmsgpack.c
+++ b/src/sysbin/lx/lua_cmsgpack.c
@@ -19,6 +19,7 @@
#endif
/* Check if float or double can be an integer without loss of precision */
+#define isinf(x) (false)
#define IS_INT_TYPE_EQUIVALENT(x, T) (!isinf(x) && (T)(x) == (x))
#define IS_INT64_EQUIVALENT(x) IS_INT_TYPE_EQUIVALENT(x, int64_t)
diff --git a/src/sysbin/lx/lxdrawlib.c b/src/sysbin/lx/lxdrawlib.c
index 68da1d6..22c6a3b 100644
--- a/src/sysbin/lx/lxdrawlib.c
+++ b/src/sysbin/lx/lxdrawlib.c
@@ -41,9 +41,26 @@ typedef struct {
// ====================================================================
// FONTS
-static int draw_loadfont(lua_State *L) {
+static int draw_load_bitmap_font(lua_State *L) {
const char* name = luaL_checkstring(L, 1);
- font_t *f = g_load_font(name);
+ font_t *f = g_load_ascii_bitmap_font(name);
+ if (f == NULL) {
+ lua_pushnil(L);
+ return 1;
+ }
+
+ drawlib_font *ff = (drawlib_font*)lua_newuserdata(L, sizeof(drawlib_font));
+ luaL_getmetatable(L, FONT);
+ lua_setmetatable(L, -2);
+
+ ff->font = f;
+
+ return 1;
+}
+
+static int draw_load_ttf_font(lua_State *L) {
+ const char* name = luaL_checkstring(L, 1);
+ font_t *f = g_load_ttf_font(name);
if (f == NULL) {
lua_pushnil(L);
return 1;
@@ -384,10 +401,11 @@ static int surface_write(lua_State *L) {
int y = luaL_checkinteger(L, 3);
const char *text = luaL_checkstring(L, 4);
drawlib_font *f = (drawlib_font*)luaL_checkudata(L, 5, FONT);
- color_t c = (color_t)lx_checklightudata(L, 6);
+ int size = luaL_checkinteger(L, 6);
+ color_t c = (color_t)lx_checklightudata(L, 7);
// TODO: relative to subregion!
- g_write(s->fb, x, y, text, f->font, c);
+ g_write(s->fb, x, y, text, f->font, size, c);
return 0;
}
@@ -397,7 +415,8 @@ static const luaL_Reg drawlib[] = {
{"surface_from_fd",draw_surface_from_fd},
{"new_surface", draw_new_surface},
{"load_image", draw_load_image},
- {"load_font", draw_loadfont},
+ {"load_bitmap_font",draw_load_bitmap_font},
+ {"load_ttf_font",draw_load_ttf_font},
{NULL, NULL}
};
diff --git a/src/sysbin/terminal/main.c b/src/sysbin/terminal/main.c
index 13f39ca..4805f9d 100644
--- a/src/sysbin/terminal/main.c
+++ b/src/sysbin/terminal/main.c
@@ -101,7 +101,7 @@ int main(int argc, char **argv) {
term.kb = init_keyboard();
ASSERT(term.kb != 0);
- term.font = g_load_font("sys:/fonts/default.bf");
+ term.font = g_load_ascii_bitmap_font("sys:/fonts/default.bf");
ASSERT(term.font != 0);
term.cw = g_text_width(term.font, "#");
term.ch = g_text_height(term.font, "#");
@@ -138,7 +138,7 @@ void term_draw_c(term_t *t, int l, int c) {
if (t->fb) {
g_fillrect(t->fb, c * t->cw, l * t->ch, t->cw, t->ch, bg);
- g_write(t->fb, c * t->cw, l * t->ch, ss, t->font, t->fg);
+ g_write(t->fb, c * t->cw, l * t->ch, ss, t->font, 16, t->fg);
}
}