From d3202073a72b4ff0f98c29cdb096e2747dbaaae8 Mon Sep 17 00:00:00 2001 From: jussi Date: Thu, 26 Sep 2024 23:02:13 +0300 Subject: FontCopy. --- API.md | 10 +++++++++- ReiLua_API.lua | 8 +++++++- changelog | 1 + include/state.h | 2 +- include/text.h | 1 + src/lua_core.c | 1 + src/rgui.c | 13 +++++++------ src/state.c | 2 +- src/text.c | 15 +++++++++++++++ 9 files changed, 43 insertions(+), 10 deletions(-) diff --git a/API.md b/API.md index 761ab4d..d98251d 100644 --- a/API.md +++ b/API.md @@ -6830,6 +6830,14 @@ Load Font from data --- +> font = RL.FontCopy( Font font ) + +Load font copy as new userdata + +- Success return Font + +--- + > isReady = RL.IsFontReady( Font font ) Check if a font is ready @@ -9395,7 +9403,7 @@ Set gui custom font (global state) > font = RL.GuiGetFont() -Get gui custom font (global state). Return as lightuserdata +Get gui font (global state). Return as lightuserdata - Success return Font diff --git a/ReiLua_API.lua b/ReiLua_API.lua index 383386d..db2c766 100644 --- a/ReiLua_API.lua +++ b/ReiLua_API.lua @@ -3992,6 +3992,12 @@ function RL.LoadFontFromMemory( fileType, fileData, fontSize, codepoints ) end ---@return any font function RL.LoadFontFromData( fontData ) end +---Load font copy as new userdata +---- Success return Font +---@param font any +---@return any font +function RL.FontCopy( font ) end + ---Check if a font is ready ---- Success return bool ---@param font any @@ -6326,7 +6332,7 @@ function RL.GuiGetState() end ---@return any RL.GuiSetFont function RL.GuiSetFont( font ) end ----Get gui custom font (global state). Return as lightuserdata +---Get gui font (global state). Return as lightuserdata ---- Success return Font ---@return any font function RL.GuiGetFont() end diff --git a/changelog b/changelog index 09e5648..0b2b60f 100644 --- a/changelog +++ b/changelog @@ -73,6 +73,7 @@ DETAILED CHANGES: - ADDED: GetBufferAsString. - FIXED: rlSetVertexAttribute takes pointer as Buffer. - CHANGE: UnloadMaterial can also optionally free textures and shader. + - ADDED: FontCopy. ------------------------------------------------------------------------ Release: ReiLua version 0.7.0 Using Raylib 5.0 and Forked Raygui 4.0 diff --git a/include/state.h b/include/state.h index 309a284..5fc3015 100644 --- a/include/state.h +++ b/include/state.h @@ -16,7 +16,7 @@ typedef struct { Vector2 resolution; int logLevelInvalid; Font defaultFont; - Font guiDefaultFont; + Font guiFont; Material defaultMaterial; Texture defaultTexture; int* RLGLcurrentShaderLocs; diff --git a/include/text.h b/include/text.h index 8834392..dd43956 100644 --- a/include/text.h +++ b/include/text.h @@ -8,6 +8,7 @@ int ltextLoadFontEx( lua_State* L ); int ltextLoadFontFromImage( lua_State* L ); int ltextLoadFontFromMemory( lua_State* L ); int ltextLoadFontFromData( lua_State* L ); +int ltextFontCopy( lua_State* L ); int ltextIsFontReady( lua_State* L ); int ltextLoadFontData( lua_State* L ); int ltextGenImageFontAtlas( lua_State* L ); diff --git a/src/lua_core.c b/src/lua_core.c index 7250cfc..508158d 100644 --- a/src/lua_core.c +++ b/src/lua_core.c @@ -1834,6 +1834,7 @@ void luaRegister() { assingGlobalFunction( "LoadFontFromImage", ltextLoadFontFromImage ); assingGlobalFunction( "LoadFontFromMemory", ltextLoadFontFromMemory ); assingGlobalFunction( "LoadFontFromData", ltextLoadFontFromData ); + assingGlobalFunction( "FontCopy", ltextFontCopy ); assingGlobalFunction( "IsFontReady", ltextIsFontReady ); assingGlobalFunction( "LoadFontData", ltextLoadFontData ); assingGlobalFunction( "GenImageFontAtlas", ltextGenImageFontAtlas ); diff --git a/src/rgui.c b/src/rgui.c index 0a4152d..106180e 100644 --- a/src/rgui.c +++ b/src/rgui.c @@ -129,7 +129,8 @@ int lguiGuiSetFont( lua_State* L ) { Font* font = uluaGetFont( L, 1 ); GuiSetFont( *font ); - state->guiDefaultFont = GuiGetFont(); + // state->guiFont = GuiGetFont(); + state->guiFont = *font; return 0; } @@ -137,12 +138,12 @@ int lguiGuiSetFont( lua_State* L ) { /* > font = RL.GuiGetFont() -Get gui custom font (global state). Return as lightuserdata +Get gui font (global state). Return as lightuserdata - Success return Font */ int lguiGuiGetFont( lua_State* L ) { - lua_pushlightuserdata( L, &state->guiDefaultFont ); + lua_pushlightuserdata( L, &state->guiFont ); return 1; } @@ -162,7 +163,6 @@ int lguiGuiSetStyle( lua_State* L ) { int value = luaL_checkinteger( L, 3 ); GuiSetStyle( control, property, value ); - state->guiDefaultFont = GuiGetFont(); return 0; } @@ -198,11 +198,12 @@ Load style file over global style variable (.rgs) int lguiGuiLoadStyle( lua_State* L ) { if ( FileExists( luaL_checkstring( L, 1 ) ) ) { GuiLoadStyle( lua_tostring( L, 1 ) ); + state->guiFont = GuiGetFont(); lua_pushboolean( L, true ); return 1; } - state->guiDefaultFont = GuiGetFont(); + // state->guiFont = GuiGetFont(); TraceLog( state->logLevelInvalid, "Invalid file '%s'", lua_tostring( L, 1 ) ); lua_pushnil( L ); @@ -216,7 +217,7 @@ Load style default over global style */ int lguiGuiLoadStyleDefault( lua_State* L ) { GuiLoadStyleDefault(); - state->guiDefaultFont = GuiGetFont(); + state->guiFont = GuiGetFont(); return 0; } diff --git a/src/state.c b/src/state.c index 0fed44e..70045de 100644 --- a/src/state.c +++ b/src/state.c @@ -32,7 +32,7 @@ bool stateInit( int argn, const char** argc, const char* basePath ) { state->run = luaInit( argn, argc ); } state->defaultFont = GetFontDefault(); - state->guiDefaultFont = GuiGetFont(); + state->guiFont = GuiGetFont(); state->defaultMaterial = LoadMaterialDefault(); state->defaultTexture = (Texture){ 1, 1, 1, 1, 7 }; state->RLGLcurrentShaderLocs = malloc( RL_MAX_SHADER_LOCATIONS * sizeof( int ) ); diff --git a/src/text.c b/src/text.c index 71bf14f..309f6da 100644 --- a/src/text.c +++ b/src/text.c @@ -279,6 +279,21 @@ int ltextLoadFontFromData( lua_State* L ) { return 1; } +/* +> font = RL.FontCopy( Font font ) + +Load font copy as new userdata + +- Success return Font +*/ +int ltextFontCopy( lua_State* L ) { + Font* font = uluaGetFont( L, 1 ); + + uluaPushFont( L, *font ); + + return 1; +} + /* > isReady = RL.IsFontReady( Font font ) -- cgit v1.2.3