1
0
Fork 0
mirror of https://github.com/ctruLua/ctruLua.git synced 2025-10-27 16:39:29 +00:00

Added ctr.gfx.text and the Bitsream Vera font

This commit is contained in:
Reuh 2015-08-19 14:32:53 +02:00
parent 2dcb9c6aa0
commit 7edb1e2f7b
19 changed files with 385 additions and 4 deletions

23
source/font.c Normal file
View file

@ -0,0 +1,23 @@
#include <sftd.h>
#include "vera_ttf.h"
#include <lua.h>
#include <lauxlib.h>
sftd_font *font_default;
static const struct luaL_Reg font_lib[] = {
{ NULL, NULL }
};
int luaopen_font_lib(lua_State *L) {
luaL_newlib(L, font_lib);
font_default = sftd_load_font_mem(vera_ttf, vera_ttf_size); // Load default font
return 1;
}
void load_font_lib(lua_State *L) {
luaL_requiref(L, "ctr.gfx.font", luaopen_font_lib, false);
}

View file

@ -1,11 +1,14 @@
#include <sf2d.h>
#include <sftd.h>
#include <lua.h>
#include <lauxlib.h>
int load_color_lib(lua_State *L);
int load_font_lib(lua_State *L);
u32 color_default;
sftd_font *font_default;
static int gfx_startFrame(lua_State *L) {
u8 screen = luaL_checkinteger(L, 1);
@ -81,6 +84,20 @@ static int gfx_circle(lua_State *L) {
return 0;
}
static int gfx_text(lua_State *L) {
int x = luaL_checkinteger(L, 1);
int y = luaL_checkinteger(L, 2);
const char *text = luaL_checkstring(L, 3);
int size = luaL_optinteger(L, 4, 9);
u32 color = luaL_optinteger(L, 5, color_default);
// todo : font selection
sftd_draw_text(font_default, x, y, color, size, text);
return 0;
}
static const struct luaL_Reg gfx_lib[] = {
{ "startFrame", gfx_startFrame},
{ "endFrame", gfx_endFrame },
@ -89,6 +106,7 @@ static const struct luaL_Reg gfx_lib[] = {
{ "point", gfx_point },
{ "rectangle", gfx_rectangle },
{ "circle", gfx_circle },
{ "text", gfx_text },
{ NULL, NULL }
};
@ -107,6 +125,7 @@ struct { char *name; int value; } gfx_constants[] = {
struct { char *name; int (*load)(lua_State *L); } gfx_libs[] = {
{ "color", load_color_lib },
{ "font", load_font_lib },
{ NULL, NULL }
};

View file

@ -47,11 +47,13 @@ int main() {
// Do the actual thing
if(luaL_dofile(L, BOOT_FILE)) error("Can open "BOOT_FILE);
// Un-init (?)
sftd_fini();
sf2d_fini();
// Disable needed things
// Disable accel/gyro
HIDUSER_DisableAccelerometer();
HIDUSER_DisableGyroscope();
// Uninit GFX
sftd_fini();
sf2d_fini();
return 0;
}