From 314d0412a53b8e012ec183c503a69cc32e24ab34 Mon Sep 17 00:00:00 2001 From: jussi Date: Sun, 26 Jun 2022 15:03:08 +0300 Subject: Get font info. --- src/core.c | 2 +- src/lua_core.c | 6 +++++ src/text.c | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 82 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/core.c b/src/core.c index d549eb0..8e48c0a 100644 --- a/src/core.c +++ b/src/core.c @@ -664,7 +664,7 @@ int lcoreSetConfigFlags( lua_State *L ) { lua_pushboolean( L, false ); return 1; } - SetConfigFlags( lua_tointeger( L, -1 ) ); + SetConfigFlags( (unsigned int)lua_tointeger( L, -1 ) ); lua_pushboolean( L, true ); return 1; diff --git a/src/lua_core.c b/src/lua_core.c index f17872e..23f6534 100644 --- a/src/lua_core.c +++ b/src/lua_core.c @@ -529,6 +529,9 @@ bool luaInit() { luaRegister(); defineGlobals(); + // SetConfigFlags( FLAG_VSYNC_HINT ); + // SetWindowState( FLAG_VSYNC_HINT ); + return luaCallMain(); } @@ -1060,6 +1063,9 @@ void luaRegister() { lua_register( L, "RL_DrawTextPro", ltextDrawTextPro ); /* Misc. */ lua_register( L, "RL_MeasureText", ltextMeasureText ); + lua_register( L, "RL_GetFontBaseSize", ltextGetFontBaseSize ); + lua_register( L, "RL_GetFontGlyphCount", ltextGetFontGlyphCount ); + lua_register( L, "RL_GetFontGlyphPadding", ltextGetFontGlyphPadding ); /* Audio. */ /* Audio device management. */ diff --git a/src/text.c b/src/text.c index ace5e20..564204d 100644 --- a/src/text.c +++ b/src/text.c @@ -261,3 +261,78 @@ int ltextMeasureText( lua_State *L ) { return 1; } + +/* +> baseSize = RL_GetFontBaseSize( Font font ) + +Get font baseSize + +- Failure return false +- Success return int +*/ +int ltextGetFontBaseSize( lua_State *L ) { + if ( !lua_isnumber( L, -1 ) ) { + TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_GetFontBaseSize( Font font )" ); + lua_pushboolean( L, false ); + return 1; + } + size_t fontId = lua_tointeger( L, -1 ); + + if ( !validFont( fontId ) ) { + lua_pushboolean( L, false ); + return 1; + } + lua_pushinteger( L, state->fonts[ fontId ]->baseSize ); + + return 1; +} + +/* +> glyphCount = RL_GetFontGlyphCount( Font font ) + +Get font glyphCount + +- Failure return false +- Success return int +*/ +int ltextGetFontGlyphCount( lua_State *L ) { + if ( !lua_isnumber( L, -1 ) ) { + TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_GetFontGlyphCount( Font font )" ); + lua_pushboolean( L, false ); + return 1; + } + size_t fontId = lua_tointeger( L, -1 ); + + if ( !validFont( fontId ) ) { + lua_pushboolean( L, false ); + return 1; + } + lua_pushinteger( L, state->fonts[ fontId ]->glyphCount ); + + return 1; +} + +/* +> glyphPadding = RL_GetFontGlyphPadding( Font font ) + +Get font glyphPadding + +- Failure return false +- Success return int +*/ +int ltextGetFontGlyphPadding( lua_State *L ) { + if ( !lua_isnumber( L, -1 ) ) { + TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_GetFontGlyphPadding( Font font )" ); + lua_pushboolean( L, false ); + return 1; + } + size_t fontId = lua_tointeger( L, -1 ); + + if ( !validFont( fontId ) ) { + lua_pushboolean( L, false ); + return 1; + } + lua_pushinteger( L, state->fonts[ fontId ]->glyphPadding ); + + return 1; +} -- cgit v1.2.3