Get font info.

This commit is contained in:
jussi
2022-06-26 15:03:08 +03:00
parent 36baf4c122
commit 314d0412a5
24 changed files with 130 additions and 6 deletions

27
API.md
View File

@@ -3727,6 +3727,33 @@ Measure string size for Font
--- ---
> baseSize = RL_GetFontBaseSize( Font font )
Get font baseSize
- Failure return false
- Success return int
---
> glyphCount = RL_GetFontGlyphCount( Font font )
Get font glyphCount
- Failure return false
- Success return int
---
> glyphPadding = RL_GetFontGlyphPadding( Font font )
Get font glyphPadding
- Failure return false
- Success return int
---
## Models - Basic ## Models - Basic
--- ---

View File

@@ -25,6 +25,7 @@ List of some MISSING features that are planned to be included. For specific func
* LoadImageFromMemory * LoadImageFromMemory
* Text * Text
* LoadFontFromMemory * LoadFontFromMemory
* GlyphInfo
* Audio * Audio
* LoadWaveFromMemory * LoadWaveFromMemory
* LoadMusicStreamFromMemory * LoadMusicStreamFromMemory

View File

@@ -14,6 +14,7 @@ function init()
local winSize = RL_GetWindowSize() local winSize = RL_GetWindowSize()
RL_SetWindowState( FLAG_WINDOW_RESIZABLE ) RL_SetWindowState( FLAG_WINDOW_RESIZABLE )
RL_SetWindowState( FLAG_VSYNC_HINT )
RL_SetWindowPosition( { mPos[1] + mSize[1] / 2 - winSize[1] / 2, mPos[2] + mSize[2] / 2 - winSize[2] / 2 } ) RL_SetWindowPosition( { mPos[1] + mSize[1] / 2 - winSize[1] / 2, mPos[2] + mSize[2] / 2 - winSize[2] / 2 } )
RL_SetWindowTitle( "Camera 2D" ) RL_SetWindowTitle( "Camera 2D" )

View File

@@ -74,6 +74,7 @@ function init()
RL_SetExitKey( KEY_ESCAPE ) RL_SetExitKey( KEY_ESCAPE )
-- framebuffer = RL_LoadRenderTexture( res ) -- framebuffer = RL_LoadRenderTexture( res )
RL_SetWindowState( FLAG_WINDOW_RESIZABLE ) RL_SetWindowState( FLAG_WINDOW_RESIZABLE )
RL_SetWindowState( FLAG_VSYNC_HINT )
RL_SetWindowPosition( { mPos[1] + mSize[1] / 2 - winSize[1] / 2, mPos[2] + mSize[2] / 2 - winSize[2] / 2 } ) RL_SetWindowPosition( { mPos[1] + mSize[1] / 2 - winSize[1] / 2, mPos[2] + mSize[2] / 2 - winSize[2] / 2 } )
texture = RL_LoadTexture( RL_GetBasePath().."../resources/images/tiles.png" ) texture = RL_LoadTexture( RL_GetBasePath().."../resources/images/tiles.png" )

View File

@@ -28,6 +28,7 @@ function init()
RL_GuiSetFont( 0 ) RL_GuiSetFont( 0 )
RL_SetWindowState( FLAG_WINDOW_RESIZABLE ) RL_SetWindowState( FLAG_WINDOW_RESIZABLE )
RL_SetWindowState( FLAG_VSYNC_HINT )
RL_SetWindowPosition( { mPos[1] + mSize[1] / 2 - winSize[1] / 2, mPos[2] + mSize[2] / 2 - winSize[2] / 2 } ) RL_SetWindowPosition( { mPos[1] + mSize[1] / 2 - winSize[1] / 2, mPos[2] + mSize[2] / 2 - winSize[2] / 2 } )
end end

View File

@@ -24,6 +24,7 @@ function init()
local winSize = RL_GetWindowSize() local winSize = RL_GetWindowSize()
RL_SetWindowState( FLAG_WINDOW_RESIZABLE ) RL_SetWindowState( FLAG_WINDOW_RESIZABLE )
RL_SetWindowState( FLAG_VSYNC_HINT )
RL_SetWindowPosition( { mPos[1] + mSize[1] / 2 - winSize[1] / 2, mPos[2] + mSize[2] / 2 - winSize[2] / 2 } ) RL_SetWindowPosition( { mPos[1] + mSize[1] / 2 - winSize[1] / 2, mPos[2] + mSize[2] / 2 - winSize[2] / 2 } )
camera = RL_CreateCamera3D() camera = RL_CreateCamera3D()

View File

@@ -11,6 +11,7 @@ function init()
local winSize = RL_GetWindowSize() local winSize = RL_GetWindowSize()
RL_SetWindowState( FLAG_WINDOW_RESIZABLE ) RL_SetWindowState( FLAG_WINDOW_RESIZABLE )
RL_SetWindowState( FLAG_VSYNC_HINT )
RL_SetWindowPosition( { mPos[1] + mSize[1] / 2 - winSize[1] / 2, mPos[2] + mSize[2] / 2 - winSize[2] / 2 } ) RL_SetWindowPosition( { mPos[1] + mSize[1] / 2 - winSize[1] / 2, mPos[2] + mSize[2] / 2 - winSize[2] / 2 } )
image = RL_GenImageColor( winSize[1], winSize[2], WHITE ) image = RL_GenImageColor( winSize[1], winSize[2], WHITE )
-- Test changing working directory. -- Test changing working directory.

View File

@@ -18,6 +18,7 @@ function init()
local winSize = RL_GetWindowSize() local winSize = RL_GetWindowSize()
RL_SetWindowState( FLAG_WINDOW_RESIZABLE ) RL_SetWindowState( FLAG_WINDOW_RESIZABLE )
RL_SetWindowState( FLAG_VSYNC_HINT )
RL_SetWindowPosition( { mPos[1] + mSize[1] / 2 - winSize[1] / 2, mPos[2] + mSize[2] / 2 - winSize[2] / 2 } ) RL_SetWindowPosition( { mPos[1] + mSize[1] / 2 - winSize[1] / 2, mPos[2] + mSize[2] / 2 - winSize[2] / 2 } )
camera = RL_CreateCamera3D() camera = RL_CreateCamera3D()
RL_SetCamera3DPosition( camera, { 0, 2, 4 } ) RL_SetCamera3DPosition( camera, { 0, 2, 4 } )

View File

@@ -16,6 +16,7 @@ function init()
local winSize = RL_GetWindowSize() local winSize = RL_GetWindowSize()
RL_SetWindowState( FLAG_WINDOW_RESIZABLE ) RL_SetWindowState( FLAG_WINDOW_RESIZABLE )
RL_SetWindowState( FLAG_VSYNC_HINT )
RL_SetWindowPosition( { mPos[1] + mSize[1] / 2 - winSize[1] / 2, mPos[2] + mSize[2] / 2 - winSize[2] / 2 } ) RL_SetWindowPosition( { mPos[1] + mSize[1] / 2 - winSize[1] / 2, mPos[2] + mSize[2] / 2 - winSize[2] / 2 } )
camera = RL_CreateCamera3D() camera = RL_CreateCamera3D()

View File

@@ -12,6 +12,7 @@ local winSize = { res[1] * scale, res[2] * scale }
function init() function init()
RL_SetWindowState( FLAG_WINDOW_RESIZABLE ) RL_SetWindowState( FLAG_WINDOW_RESIZABLE )
RL_SetWindowState( FLAG_VSYNC_HINT )
RL_SetWindowPosition( { mPos[1] + mSize[1] / 2 - winSize[1] / 2, mPos[2] + mSize[2] / 2 - winSize[2] / 2 } ) RL_SetWindowPosition( { mPos[1] + mSize[1] / 2 - winSize[1] / 2, mPos[2] + mSize[2] / 2 - winSize[2] / 2 } )
RL_SetWindowSize( winSize ) RL_SetWindowSize( winSize )
tex = RL_LoadTexture( RL_GetBasePath().."../resources/images/cat.png" ) tex = RL_LoadTexture( RL_GetBasePath().."../resources/images/cat.png" )

View File

@@ -90,9 +90,9 @@ function init()
local monitorPos = Vec2:new( RL_GetMonitorPosition( monitor ) ) local monitorPos = Vec2:new( RL_GetMonitorPosition( monitor ) )
local monitorSize = Vec2:new( RL_GetMonitorSize( monitor ) ) local monitorSize = Vec2:new( RL_GetMonitorSize( monitor ) )
RL_SetConfigFlags( FLAG_VSYNC_HINT )
RL_SetWindowTitle( "Platformer" ) RL_SetWindowTitle( "Platformer" )
RL_SetWindowState( FLAG_WINDOW_RESIZABLE ) RL_SetWindowState( FLAG_WINDOW_RESIZABLE )
RL_SetWindowState( FLAG_VSYNC_HINT )
RL_SetWindowSize( winSize ) RL_SetWindowSize( winSize )
RL_SetWindowPosition( { monitorPos.x + monitorSize.x / 2 - winSize.x / 2, monitorPos.y + monitorSize.y / 2 - winSize.y / 2 } ) RL_SetWindowPosition( { monitorPos.x + monitorSize.x / 2 - winSize.x / 2, monitorPos.y + monitorSize.y / 2 - winSize.y / 2 } )

View File

@@ -34,9 +34,8 @@ function init()
local mSize = RL_GetMonitorSize( monitor ) local mSize = RL_GetMonitorSize( monitor )
local winSize = { 1920, 1080 } local winSize = { 1920, 1080 }
RL_SetConfigFlags( FLAG_VSYNC_HINT )
RL_SetWindowState( FLAG_WINDOW_RESIZABLE ) RL_SetWindowState( FLAG_WINDOW_RESIZABLE )
RL_SetWindowState( FLAG_VSYNC_HINT )
RL_SetWindowPosition( { mPos[1] + mSize[1] / 2 - winSize[1] / 2, mPos[2] + mSize[2] / 2 - winSize[2] / 2 } ) RL_SetWindowPosition( { mPos[1] + mSize[1] / 2 - winSize[1] / 2, mPos[2] + mSize[2] / 2 - winSize[2] / 2 } )
RL_SetWindowSize( winSize ) RL_SetWindowSize( winSize )
camera = RL_CreateCamera3D() camera = RL_CreateCamera3D()

View File

@@ -53,6 +53,7 @@ function init()
local mPos = RL_GetMonitorPosition( monitor ) local mPos = RL_GetMonitorPosition( monitor )
local mSize = RL_GetMonitorSize( monitor ) local mSize = RL_GetMonitorSize( monitor )
RL_SetWindowState( FLAG_VSYNC_HINT )
RL_SetWindowSize( winSize ) RL_SetWindowSize( winSize )
RL_SetWindowPosition( { mPos[1] + mSize[1] / 2 - winSize[1] / 2, mPos[2] + mSize[2] / 2 - winSize[2] / 2 } ) RL_SetWindowPosition( { mPos[1] + mSize[1] / 2 - winSize[1] / 2, mPos[2] + mSize[2] / 2 - winSize[2] / 2 } )
RL_SetWindowTitle( "Pong" ) RL_SetWindowTitle( "Pong" )

View File

@@ -9,6 +9,7 @@ local function setupWindow()
local winSize = RL_GetWindowSize() local winSize = RL_GetWindowSize()
RL_SetWindowState( FLAG_WINDOW_RESIZABLE ) RL_SetWindowState( FLAG_WINDOW_RESIZABLE )
RL_SetWindowState( FLAG_VSYNC_HINT )
RL_SetWindowPosition( { mPos[1] + mSize[1] / 2 - winSize[1] / 2, mPos[2] + mSize[2] / 2 - winSize[2] / 2 } ) RL_SetWindowPosition( { mPos[1] + mSize[1] / 2 - winSize[1] / 2, mPos[2] + mSize[2] / 2 - winSize[2] / 2 } )
end end

View File

@@ -13,7 +13,7 @@ function utillib.deepCopy( orig )
copy = {} copy = {}
for origKey, origValue in next, orig, nil do for origKey, origValue in next, orig, nil do
-- If object has clone method use that. Mainly for vector libraries. -- If object has clone method, use that.
if type( origValue ) == "table" and type( origValue.clone ) == "function" then if type( origValue ) == "table" and type( origValue.clone ) == "function" then
copy[ utillib.deepCopy( origKey ) ] = orig_value:clone() copy[ utillib.deepCopy( origKey ) ] = orig_value:clone()
else else

View File

@@ -14,6 +14,7 @@ function init()
local winSize = RL_GetWindowSize() local winSize = RL_GetWindowSize()
RL_SetWindowState( FLAG_WINDOW_RESIZABLE ) RL_SetWindowState( FLAG_WINDOW_RESIZABLE )
RL_SetWindowState( FLAG_VSYNC_HINT )
RL_SetWindowPosition( { mPos[1] + mSize[1] / 2 - winSize[1] / 2, mPos[2] + mSize[2] / 2 - winSize[2] / 2 } ) RL_SetWindowPosition( { mPos[1] + mSize[1] / 2 - winSize[1] / 2, mPos[2] + mSize[2] / 2 - winSize[2] / 2 } )
texture = RL_LoadTexture( RL_GetBasePath().."../resources/images/cat.png" ) texture = RL_LoadTexture( RL_GetBasePath().."../resources/images/cat.png" )

View File

@@ -66,6 +66,7 @@ end
function init() function init()
RL_SetWindowState( FLAG_WINDOW_RESIZABLE ) RL_SetWindowState( FLAG_WINDOW_RESIZABLE )
RL_SetWindowState( FLAG_VSYNC_HINT )
RL_SetWindowSize( winSize ) RL_SetWindowSize( winSize )
RL_SetWindowPosition( { monitorPos[1] + monitorSize[1] / 2 - winSize[1] / 2, monitorPos[2] + monitorSize[2] / 2 - winSize[2] / 2 } ) RL_SetWindowPosition( { monitorPos[1] + monitorSize[1] / 2 - winSize[1] / 2, monitorPos[2] + monitorSize[2] / 2 - winSize[2] / 2 } )
RL_SetWindowTitle( "Snake" ) RL_SetWindowTitle( "Snake" )

View File

@@ -17,6 +17,7 @@ function init()
RL_SetWindowTitle( "Waving cubes" ) RL_SetWindowTitle( "Waving cubes" )
RL_SetWindowState( FLAG_WINDOW_RESIZABLE ) RL_SetWindowState( FLAG_WINDOW_RESIZABLE )
RL_SetWindowState( FLAG_VSYNC_HINT )
RL_SetWindowPosition( { mPos[1] + mSize[1] / 2 - winSize[1] / 2, mPos[2] + mSize[2] / 2 - winSize[2] / 2 } ) RL_SetWindowPosition( { mPos[1] + mSize[1] / 2 - winSize[1] / 2, mPos[2] + mSize[2] / 2 - winSize[2] / 2 } )
camera = RL_CreateCamera3D() camera = RL_CreateCamera3D()

View File

@@ -5,6 +5,7 @@ local text = "Congrats! You created your first window!"
function init() function init()
RL_SetWindowTitle( "First window" ) RL_SetWindowTitle( "First window" )
RL_SetWindowState( FLAG_VSYNC_HINT )
end end
function process( delta ) function process( delta )

View File

@@ -78,5 +78,4 @@ typedef struct {
extern State *state; extern State *state;
bool stateInit( const char *exePath ); bool stateInit( const char *exePath );
// bool stateRun();
void stateFree(); void stateFree();

View File

@@ -12,3 +12,6 @@ int ltextDrawText( lua_State *L );
int ltextDrawTextPro( lua_State *L ); int ltextDrawTextPro( lua_State *L );
/* Misc. */ /* Misc. */
int ltextMeasureText( lua_State *L ); int ltextMeasureText( lua_State *L );
int ltextGetFontBaseSize( lua_State *L );
int ltextGetFontGlyphCount( lua_State *L );
int ltextGetFontGlyphPadding( lua_State *L );

View File

@@ -664,7 +664,7 @@ int lcoreSetConfigFlags( lua_State *L ) {
lua_pushboolean( L, false ); lua_pushboolean( L, false );
return 1; return 1;
} }
SetConfigFlags( lua_tointeger( L, -1 ) ); SetConfigFlags( (unsigned int)lua_tointeger( L, -1 ) );
lua_pushboolean( L, true ); lua_pushboolean( L, true );
return 1; return 1;

View File

@@ -529,6 +529,9 @@ bool luaInit() {
luaRegister(); luaRegister();
defineGlobals(); defineGlobals();
// SetConfigFlags( FLAG_VSYNC_HINT );
// SetWindowState( FLAG_VSYNC_HINT );
return luaCallMain(); return luaCallMain();
} }
@@ -1060,6 +1063,9 @@ void luaRegister() {
lua_register( L, "RL_DrawTextPro", ltextDrawTextPro ); lua_register( L, "RL_DrawTextPro", ltextDrawTextPro );
/* Misc. */ /* Misc. */
lua_register( L, "RL_MeasureText", ltextMeasureText ); 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. */
/* Audio device management. */ /* Audio device management. */

View File

@@ -261,3 +261,78 @@ int ltextMeasureText( lua_State *L ) {
return 1; 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;
}