mirror of
https://github.com/ctruLua/ctruLua.git
synced 2025-10-27 16:39:29 +00:00
Documented the font library, Improved the news library (still unusable)
This commit is contained in:
parent
a3ab825365
commit
5d0e2a7d81
2 changed files with 50 additions and 7 deletions
|
|
@ -1,3 +1,9 @@
|
|||
/***
|
||||
The `font` module
|
||||
@module ctr.gfx.font
|
||||
@usage local font = require("ctr.gfx.font")
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
|
|
@ -9,6 +15,12 @@
|
|||
|
||||
#include "font.h"
|
||||
|
||||
/***
|
||||
Load a TTF font.
|
||||
@function load
|
||||
@tparam string path path to the file
|
||||
@treturn font the loaded font.
|
||||
*/
|
||||
static int font_load(lua_State *L) {
|
||||
const char *path = luaL_checkstring(L, 1);
|
||||
|
||||
|
|
@ -28,6 +40,11 @@ static int font_load(lua_State *L) {
|
|||
return 1;
|
||||
}
|
||||
|
||||
/***
|
||||
Set a font as the default one.
|
||||
@function setDefault
|
||||
@tparam font font the font to set as the default one.
|
||||
*/
|
||||
static int font_setDefault(lua_State *L) {
|
||||
if (luaL_testudata(L, 1, "LFont") == NULL) {
|
||||
font_userdata *font = lua_newuserdata(L, sizeof(*font));
|
||||
|
|
@ -42,12 +59,28 @@ static int font_setDefault(lua_State *L) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
/***
|
||||
Return the default font.
|
||||
@function getDefault
|
||||
@treturn font default font
|
||||
*/
|
||||
static int font_getDefault(lua_State *L) {
|
||||
lua_getfield(L, LUA_REGISTRYINDEX, "LFontDefault");
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/***
|
||||
font object
|
||||
@section Methods
|
||||
*/
|
||||
|
||||
/***
|
||||
Return the width of a string with a font.
|
||||
@function :object_width
|
||||
@tparam string text the text to test
|
||||
@treturn number the width of the text (in pixels)
|
||||
*/
|
||||
static int font_object_width(lua_State *L) {
|
||||
font_userdata *font = luaL_checkudata(L, 1, "LFont");
|
||||
if (font->font == NULL) luaL_error(L, "The font object was unloaded");
|
||||
|
|
@ -67,6 +100,10 @@ static int font_object_width(lua_State *L) {
|
|||
return 1;
|
||||
}
|
||||
|
||||
/***
|
||||
Unload a font.
|
||||
@function :unload
|
||||
*/
|
||||
static int font_object_unload(lua_State *L) {
|
||||
font_userdata *font = luaL_checkudata(L, 1, "LFont");
|
||||
if (font->font == NULL) return 0;
|
||||
|
|
@ -123,4 +160,4 @@ void unload_font_lib(lua_State *L) {
|
|||
|
||||
if (luaL_testudata(L, -1, "LFont") != NULL)
|
||||
sftd_free_font(((font_userdata *)lua_touserdata(L, -1))->font); // Unload current font
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,6 +10,8 @@ The `news` module.
|
|||
#include <lua.h>
|
||||
#include <lauxlib.h>
|
||||
|
||||
#include <string.h>
|
||||
|
||||
/***
|
||||
Initialize the news module.
|
||||
@function init
|
||||
|
|
@ -31,19 +33,23 @@ Send a notification to the user. WIP, do not use !!!
|
|||
static int news_notification(lua_State *L) {
|
||||
const char *title = luaL_checkstring(L, 1);
|
||||
const char *message = luaL_checkstring(L, 2);
|
||||
const void *imageData = luaL_checkstring(L, 3);
|
||||
const void *imageData = luaL_optstring(L, 3, NULL);
|
||||
bool jpeg = false;
|
||||
if (lua_isboolean(L, 4))
|
||||
jpeg = lua_toboolean(L, 4);
|
||||
lua_len(L, 3);
|
||||
u32 imageDataLength = luaL_checkinteger(L, -1);
|
||||
|
||||
|
||||
u32 imageDataLength = 0;
|
||||
if (imageData) {
|
||||
lua_len(L, 3);
|
||||
luaL_checkinteger(L, -1);
|
||||
}
|
||||
|
||||
const u16* cTitle = 0;
|
||||
const u16* cMessage = 0;
|
||||
u32 titleLength, messageLength;
|
||||
|
||||
titleLength = (u32) utf8_to_utf16((uint16_t*)cTitle, (uint8_t*)title, sizeof(title));
|
||||
messageLength = (u32) utf8_to_utf16((uint16_t*)cMessage, (uint8_t*)message, sizeof(message));
|
||||
titleLength = (u32) utf8_to_utf16((uint16_t*)cTitle, (uint8_t*)title, strlen(title));
|
||||
messageLength = (u32) utf8_to_utf16((uint16_t*)cMessage, (uint8_t*)message, strlen(message));
|
||||
|
||||
NEWSU_AddNotification(cTitle, titleLength, cMessage, messageLength, imageData, imageDataLength, jpeg);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue