New object type Font.

This commit is contained in:
jussi
2023-10-28 14:15:20 +03:00
parent 23935aefca
commit af03c7364e
12 changed files with 179 additions and 362 deletions

59
API.md
View File

@@ -3853,21 +3853,27 @@ Get pixel data size in bytes for certain format
--- ---
> RL.GetFontDefault()
Get the default Font
---
> font = RL.LoadFont( string fileName ) > font = RL.LoadFont( string fileName )
Load font from file into GPU memory (VRAM) Load font from file into GPU memory (VRAM)
- Failure return -1 - Failure return nil
- Success return int - Success return Font
--- ---
> font = RL.LoadFontEx( string fileName, int fontSize ) > font = RL.LoadFontEx( string fileName, int fontSize, int fontChars{} )
Load font from file with extended parameters. Loading the default character set Load font from file with extended parameters. Loading the default character set
- Failure return -1 - Failure return nil
- Success return int - Success return Font
--- ---
@@ -3875,17 +3881,7 @@ Load font from file with extended parameters. Loading the default character set
Load font from Image ( XNA style ) Load font from Image ( XNA style )
- Failure return -1 - Success return Font
- Success return int
---
> success = RL.UnloadFont( Font font )
Unload Font from GPU memory ( VRAM )
- Failure return false
- Success return true
--- ---
@@ -3893,31 +3889,22 @@ Unload Font from GPU memory ( VRAM )
--- ---
> success = RL.DrawFPS( Vector2 pos ) > RL.DrawFPS( Vector2 pos )
Draw current FPS Draw current FPS
- Failure return false
- Success return true
--- ---
> success = RL.DrawText( Font font, string text, Vector2 position, float fontSize, float spacing, Color tint ) > RL.DrawText( Font font, string text, Vector2 position, float fontSize, float spacing, Color tint )
Draw text using font and additional parameters Draw text using font and additional parameters
- Failure return false
- Success return true
--- ---
> success = RL.DrawTextPro( Font font, string text, Vector2 position, Vector2 origin, float rotation, float fontSize, float spacing, Color tint ) > RL.DrawTextPro( Font font, string text, Vector2 position, Vector2 origin, float rotation, float fontSize, float spacing, Color tint )
Draw text using Font and pro parameters (rotation) Draw text using Font and pro parameters (rotation)
- Failure return false
- Success return true
--- ---
## Text - Misc ## Text - Misc
@@ -3928,7 +3915,6 @@ Draw text using Font and pro parameters ( rotation )
Measure string size for Font Measure string size for Font
- Failure return false
- Success return Vector2 - Success return Vector2
--- ---
@@ -3937,7 +3923,6 @@ Measure string size for Font
Get font base size (default chars height) Get font base size (default chars height)
- Failure return false
- Success return int - Success return int
--- ---
@@ -3946,7 +3931,6 @@ Get font base size ( default chars height )
Get font number of glyph characters Get font number of glyph characters
- Failure return false
- Success return int - Success return int
--- ---
@@ -3955,17 +3939,15 @@ Get font number of glyph characters
Get font padding around the glyph characters Get font padding around the glyph characters
- Failure return false
- Success return int - Success return int
--- ---
> textureTable = RL.GetFontTexture( Font font ) > texture = RL.GetFontTexture( Font font )
Get font texture atlas containing the glyphs. NOTE! Texture in table form. Get font texture atlas containing the glyphs.
- Failure return false - Success return Texture
- Success return table
--- ---
@@ -6067,13 +6049,10 @@ Get gui state ( global state )
--- ---
> success = RL.GuiSetFont( Font font ) > RL.GuiSetFont( Font font )
Set gui custom font (global state) Set gui custom font (global state)
- Failure return false
- Success return true
--- ---
> font = RL.GuiGetFont() > font = RL.GuiGetFont()

View File

@@ -2794,61 +2794,52 @@ function RL.GetPixelDataSize( width, height, format ) end
-- Text - Loading -- Text - Loading
---Get the default Font
---@return any RL.GetFontDefault
function RL.GetFontDefault() end
---Load font from file into GPU memory (VRAM) ---Load font from file into GPU memory (VRAM)
---- Failure return -1 ---- Failure return nil
---- Success return int ---- Success return Font
---@param fileName string ---@param fileName string
---@return any font ---@return any font
function RL.LoadFont( fileName ) end function RL.LoadFont( fileName ) end
---Load font from file with extended parameters. Loading the default character set ---Load font from file with extended parameters. Loading the default character set
---- Failure return -1 ---- Failure return nil
---- Success return int ---- Success return Font
---@param fileName string ---@param fileName string
---@param fontSize integer ---@param fontSize integer
---@param fontChars{} integer
---@return any font ---@return any font
function RL.LoadFontEx( fileName, fontSize ) end function RL.LoadFontEx( fileName, fontSize, fontChars{} ) end
---Load font from Image ( XNA style ) ---Load font from Image ( XNA style )
---- Failure return -1 ---- Success return Font
---- Success return int
---@param image any ---@param image any
---@param key table ---@param key table
---@param firstChar integer ---@param firstChar integer
---@return any font ---@return any font
function RL.LoadFontFromImage( image, key, firstChar ) end function RL.LoadFontFromImage( image, key, firstChar ) end
---Unload Font from GPU memory ( VRAM )
---- Failure return false
---- Success return true
---@param font any
---@return any success
function RL.UnloadFont( font ) end
-- Text - Draw -- Text - Draw
---Draw current FPS ---Draw current FPS
---- Failure return false
---- Success return true
---@param pos table ---@param pos table
---@return any success ---@return any RL.DrawFPS
function RL.DrawFPS( pos ) end function RL.DrawFPS( pos ) end
---Draw text using font and additional parameters ---Draw text using font and additional parameters
---- Failure return false
---- Success return true
---@param font any ---@param font any
---@param text string ---@param text string
---@param position table ---@param position table
---@param fontSize number ---@param fontSize number
---@param spacing number ---@param spacing number
---@param tint table ---@param tint table
---@return any success ---@return any RL.DrawText
function RL.DrawText( font, text, position, fontSize, spacing, tint ) end function RL.DrawText( font, text, position, fontSize, spacing, tint ) end
---Draw text using Font and pro parameters (rotation) ---Draw text using Font and pro parameters (rotation)
---- Failure return false
---- Success return true
---@param font any ---@param font any
---@param text string ---@param text string
---@param position table ---@param position table
@@ -2857,13 +2848,12 @@ function RL.DrawText( font, text, position, fontSize, spacing, tint ) end
---@param fontSize number ---@param fontSize number
---@param spacing number ---@param spacing number
---@param tint table ---@param tint table
---@return any success ---@return any RL.DrawTextPro
function RL.DrawTextPro( font, text, position, origin, rotation, fontSize, spacing, tint ) end function RL.DrawTextPro( font, text, position, origin, rotation, fontSize, spacing, tint ) end
-- Text - Misc -- Text - Misc
---Measure string size for Font ---Measure string size for Font
---- Failure return false
---- Success return Vector2 ---- Success return Vector2
---@param font any ---@param font any
---@param text string ---@param text string
@@ -2873,31 +2863,27 @@ function RL.DrawTextPro( font, text, position, origin, rotation, fontSize, spaci
function RL.MeasureText( font, text, fontSize, spacing ) end function RL.MeasureText( font, text, fontSize, spacing ) end
---Get font base size (default chars height) ---Get font base size (default chars height)
---- Failure return false
---- Success return int ---- Success return int
---@param font any ---@param font any
---@return any baseSize ---@return any baseSize
function RL.GetFontBaseSize( font ) end function RL.GetFontBaseSize( font ) end
---Get font number of glyph characters ---Get font number of glyph characters
---- Failure return false
---- Success return int ---- Success return int
---@param font any ---@param font any
---@return any glyphCount ---@return any glyphCount
function RL.GetFontGlyphCount( font ) end function RL.GetFontGlyphCount( font ) end
---Get font padding around the glyph characters ---Get font padding around the glyph characters
---- Failure return false
---- Success return int ---- Success return int
---@param font any ---@param font any
---@return any glyphPadding ---@return any glyphPadding
function RL.GetFontGlyphPadding( font ) end function RL.GetFontGlyphPadding( font ) end
---Get font texture atlas containing the glyphs. NOTE! Texture in table form. ---Get font texture atlas containing the glyphs.
---- Failure return false ---- Success return Texture
---- Success return table
---@param font any ---@param font any
---@return any textureTable ---@return any texture
function RL.GetFontTexture( font ) end function RL.GetFontTexture( font ) end
-- Models - Basic -- Models - Basic
@@ -4785,10 +4771,8 @@ function RL.GuiGetState() end
-- Gui - Font -- Gui - Font
---Set gui custom font (global state) ---Set gui custom font (global state)
---- Failure return false
---- Success return true
---@param font any ---@param font any
---@return any success ---@return any RL.GuiSetFont
function RL.GuiSetFont( font ) end function RL.GuiSetFont( font ) end
---Get gui custom font ( global state ) ---Get gui custom font ( global state )

View File

@@ -14,6 +14,7 @@ DETAILED CHANGES:
- ADDED: GetRenderTextureTexture and GetRenderTextureDepthTexture. - ADDED: GetRenderTextureTexture and GetRenderTextureDepthTexture.
- REMOVED: UnloadCamera2D and UnloadCamera3D. - REMOVED: UnloadCamera2D and UnloadCamera3D.
- REMOVED: UnloadShader. - REMOVED: UnloadShader.
- ADDED: LoadFontEx takes also fontChars.
------------------------------------------------------------------------ ------------------------------------------------------------------------
Release: ReiLua version 0.5.0 Using Raylib 4.5 Release: ReiLua version 0.5.0 Using Raylib 4.5

View File

@@ -11,7 +11,6 @@ function RL.init()
print( "path", path ) print( "path", path )
texture = RL.LoadTexture( path ) texture = RL.LoadTexture( path )
print( "texture", texture ) print( "texture", texture )
end end
@@ -33,5 +32,5 @@ end
function RL.draw() function RL.draw()
RL.ClearBackground( RL.RAYWHITE ) RL.ClearBackground( RL.RAYWHITE )
RL.DrawTexture( texture, { 20, 20 }, RL.WHITE ) RL.DrawTexture( texture, { 20, 20 }, RL.WHITE )
RL.DrawText( 0, text, textPos, 20, 2, textColor ) RL.DrawText( RL.fontDefault, text, textPos, 20, 2, textColor )
end end

View File

@@ -74,6 +74,7 @@ void uluaPushRenderTexture( lua_State *L, RenderTexture renderTexture );
void uluaPushCamera2D( lua_State *L, Camera2D camera ); void uluaPushCamera2D( lua_State *L, Camera2D camera );
void uluaPushCamera3D( lua_State *L, Camera3D camera ); void uluaPushCamera3D( lua_State *L, Camera3D camera );
void uluaPushShader( lua_State *L, Shader shader ); void uluaPushShader( lua_State *L, Shader shader );
void uluaPushFont( lua_State *L, Font font );
int uluaGetTableLen( lua_State *L ); int uluaGetTableLen( lua_State *L );
int uluaGetTableLenIndex( lua_State *L, int index ); int uluaGetTableLenIndex( lua_State *L, int index );

View File

@@ -13,13 +13,8 @@ typedef struct {
bool run; bool run;
lua_State *luaState; lua_State *luaState;
Vector2 resolution; Vector2 resolution;
size_t guiFont;
int logLevelInvalid; int logLevelInvalid;
/* Resources. */ /* Resources. */
/* Fonts. */
Font **fonts;
size_t fontCount;
size_t fontAlloc;
/* Sounds. */ /* Sounds. */
Wave **waves; Wave **waves;
size_t waveCount; size_t waveCount;

View File

@@ -1,12 +1,10 @@
#pragma once #pragma once
/* Validators. */
bool validFont( size_t id );
/* Loading. */ /* Loading. */
int ltextGetFontDefault( lua_State *L );
int ltextLoadFont( lua_State *L ); int ltextLoadFont( lua_State *L );
int ltextLoadFontEx( lua_State *L ); int ltextLoadFontEx( lua_State *L );
int ltextLoadFontFromImage( lua_State *L ); int ltextLoadFontFromImage( lua_State *L );
int ltextUnloadFont( lua_State *L );
/* Drawing. */ /* Drawing. */
int ltextDrawFPS( lua_State *L ); int ltextDrawFPS( lua_State *L );
int ltextDrawText( lua_State *L ); int ltextDrawText( lua_State *L );

View File

@@ -122,6 +122,24 @@ static void defineShader() {
lua_setfield( L, -2, "__gc" ); lua_setfield( L, -2, "__gc" );
} }
/* Font. */
static int gcFont( lua_State *L ) {
Font *font = luaL_checkudata ( L, 1, "Font" );
printf( "gcFont\n" );
UnloadFont( *font );
}
static void defineFont() {
lua_State *L = state->luaState;
luaL_newmetatable( L, "Font" );
lua_pushvalue( L, -1 );
lua_setfield( L, -2, "__index" );
lua_pushcfunction( L, gcFont );
lua_setfield( L, -2, "__gc" );
}
/* Assing globals. */ /* Assing globals. */
static void assignGlobalInt( int value, const char *name ) { static void assignGlobalInt( int value, const char *name ) {
@@ -161,6 +179,9 @@ static void defineGlobals() {
lua_setglobal( L, "RL" ); lua_setglobal( L, "RL" );
lua_getglobal( L, "RL" ); lua_getglobal( L, "RL" );
uluaPushFont( L, GetFontDefault() );
lua_setfield( L, -2, "fontDefault" );
/*DOC_START*/ /*DOC_START*/
/* ConfigFlags */ /* ConfigFlags */
assignGlobalInt( FLAG_VSYNC_HINT, "FLAG_VSYNC_HINT" ); assignGlobalInt( FLAG_VSYNC_HINT, "FLAG_VSYNC_HINT" );
@@ -1130,10 +1151,8 @@ bool luaInit( int argn, const char **argc ) {
if ( L == NULL ) { if ( L == NULL ) {
TraceLog( LOG_WARNING, "%s", "Failed to init Lua" ); TraceLog( LOG_WARNING, "%s", "Failed to init Lua" );
return false; return false;
} }
defineGlobals();
/* Define object types. */ /* Define object types. */
defineBuffer(); defineBuffer();
defineImage(); defineImage();
@@ -1142,6 +1161,9 @@ bool luaInit( int argn, const char **argc ) {
defineCamera2D(); defineCamera2D();
defineCamera3D(); defineCamera3D();
defineShader(); defineShader();
defineFont();
/* Define globals. */
defineGlobals();
/* Set arguments. */ /* Set arguments. */
lua_getglobal( L, "RL" ); lua_getglobal( L, "RL" );
@@ -1733,10 +1755,10 @@ void luaRegister() {
/* Text. */ /* Text. */
/* Loading. */ /* Loading. */
assingGlobalFunction( "GetFontDefault", ltextGetFontDefault );
assingGlobalFunction( "LoadFont", ltextLoadFont ); assingGlobalFunction( "LoadFont", ltextLoadFont );
assingGlobalFunction( "LoadFontEx", ltextLoadFontEx ); assingGlobalFunction( "LoadFontEx", ltextLoadFontEx );
assingGlobalFunction( "LoadFontFromImage", ltextLoadFontFromImage ); assingGlobalFunction( "LoadFontFromImage", ltextLoadFontFromImage );
assingGlobalFunction( "UnloadFont", ltextUnloadFont );
/* Drawing. */ /* Drawing. */
assingGlobalFunction( "DrawFPS", ltextDrawFPS ); assingGlobalFunction( "DrawFPS", ltextDrawFPS );
assingGlobalFunction( "DrawText", ltextDrawText ); assingGlobalFunction( "DrawText", ltextDrawText );
@@ -2871,6 +2893,12 @@ void uluaPushShader( lua_State *L, Shader shader ) {
luaL_setmetatable( L, "Shader" ); luaL_setmetatable( L, "Shader" );
} }
void uluaPushFont( lua_State *L, Font font ) {
Font *fontP = lua_newuserdata( L, sizeof( Font ) );
*fontP = font;
luaL_setmetatable( L, "Font" );
}
int uluaGetTableLen( lua_State *L ) { int uluaGetTableLen( lua_State *L ) {
return uluaGetTableLenIndex( L, lua_gettop( L ) ); return uluaGetTableLenIndex( L, lua_gettop( L ) );
} }

View File

@@ -129,26 +129,16 @@ int lguiGuiGetState( lua_State *L ) {
*/ */
/* /*
> success = RL.GuiSetFont( Font font ) > RL.GuiSetFont( Font font )
Set gui custom font (global state) Set gui custom font (global state)
- Failure return false
- Success return true
*/ */
int lguiGuiSetFont( lua_State *L ) { int lguiGuiSetFont( lua_State *L ) {
if ( !lua_isnumber( L, 1 ) ) { Font *font = luaL_checkudata( L, 1, "Font" );
TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GuiSetFont( Font font )" );
lua_pushboolean( L, false );
return 1;
}
size_t fontId = lua_tointeger( L, 1 );
state->guiFont = fontId;
GuiSetFont( *state->fonts[ fontId ] ); GuiSetFont( *font );
lua_pushboolean( L, true );
return 1; return 0;
} }
/* /*
@@ -159,7 +149,7 @@ Get gui custom font ( global state )
- Success return int - Success return int
*/ */
int lguiGuiGetFont( lua_State *L ) { int lguiGuiGetFont( lua_State *L ) {
lua_pushinteger( L, state->guiFont ); uluaPushFont( L, GuiGetFont() );
return 1; return 1;
} }

View File

@@ -16,12 +16,7 @@ bool stateInit( int argn, const char **argc, const char *exePath ) {
state->run = true; state->run = true;
state->resolution = (Vector2){ 800, 600 }; state->resolution = (Vector2){ 800, 600 };
state->luaState = NULL; state->luaState = NULL;
state->guiFont = 0;
state->logLevelInvalid = LOG_ERROR; state->logLevelInvalid = LOG_ERROR;
/* Fonts. */
state->fontAlloc = ALLOC_PAGE_SIZE;
state->fontCount = 1;
state->fonts = malloc( state->fontAlloc * sizeof( Font* ) );
/* Waves. */ /* Waves. */
state->waveAlloc = ALLOC_PAGE_SIZE; state->waveAlloc = ALLOC_PAGE_SIZE;
state->waveCount = 0; state->waveCount = 0;
@@ -65,7 +60,6 @@ bool stateInit( int argn, const char **argc, const char *exePath ) {
/* The ones we want to save the first. */ /* The ones we want to save the first. */
if ( 0 < i ) { if ( 0 < i ) {
state->fonts[i] = NULL;
state->materials[i] = NULL; state->materials[i] = NULL;
} }
} }
@@ -73,8 +67,6 @@ bool stateInit( int argn, const char **argc, const char *exePath ) {
/* Has to be after InitWindod where opengl context is created. */ /* Has to be after InitWindod where opengl context is created. */
state->materials[0] = malloc( sizeof( Material ) ); state->materials[0] = malloc( sizeof( Material ) );
*state->materials[0] = LoadMaterialDefault(); *state->materials[0] = LoadMaterialDefault();
state->fonts[0] = malloc( sizeof( Font ) );
*state->fonts[0] = GetFontDefault();
if ( !IsWindowReady() ) { if ( !IsWindowReady() ) {
state->hasWindow = false; state->hasWindow = false;
@@ -94,12 +86,6 @@ void stateInitInterpret( int argn, const char **argc ) {
} }
void stateFree() { void stateFree() {
for ( int i = 0; i < state->fontCount; ++i ) {
if ( state->fonts[i] != NULL ) {
UnloadFont( *state->fonts[i] );
free( state->fonts[i] );
}
}
for ( int i = 0; i < state->waveCount; ++i ) { for ( int i = 0; i < state->waveCount; ++i ) {
if ( state->waves[i] != NULL ) { if ( state->waves[i] != NULL ) {
UnloadWave( *state->waves[i] ); UnloadWave( *state->waves[i] );
@@ -165,7 +151,6 @@ void stateFree() {
if ( state->hasWindow ) { if ( state->hasWindow ) {
CloseWindow(); CloseWindow();
} }
free( state->fonts );
free( state->waves ); free( state->waves );
free( state->sounds ); free( state->sounds );
free( state->musics ); free( state->musics );

View File

@@ -4,103 +4,77 @@
#include "textures.h" #include "textures.h"
#include "lua_core.h" #include "lua_core.h"
static void checkFontRealloc( int i ) {
if ( i == state->fontCount ) {
state->fontCount++;
}
if ( state->fontCount == state->fontAlloc ) {
state->fontAlloc += ALLOC_PAGE_SIZE;
state->fonts = realloc( state->fonts, state->fontAlloc * sizeof( Font* ) );
for ( i = state->fontCount; i < state->fontAlloc; i++ ) {
state->fonts[i] = NULL;
}
}
}
bool validFont( size_t id ) {
if ( id < 0 || state->fontCount < id || state->fonts[ id ] == NULL ) {
TraceLog( state->logLevelInvalid, "%s %d", "Invalid font", id );
return false;
}
else {
return true;
}
}
static int newFont() {
int i = 0;
for ( i = 0; i < state->fontCount; i++ ) {
if ( state->fonts[i] == NULL ) {
break;
}
}
state->fonts[i] = malloc( sizeof( Font ) );
checkFontRealloc( i );
return i;
}
/* /*
## Text - Loading ## Text - Loading
*/ */
/*
> RL.GetFontDefault()
Get the default Font
*/
int ltextGetFontDefault( lua_State *L ) {
uluaPushFont( L, GetFontDefault() );
return 1;
}
/* /*
> font = RL.LoadFont( string fileName ) > font = RL.LoadFont( string fileName )
Load font from file into GPU memory (VRAM) Load font from file into GPU memory (VRAM)
- Failure return -1 - Failure return nil
- Success return int - Success return Font
*/ */
int ltextLoadFont( lua_State *L ) { int ltextLoadFont( lua_State *L ) {
if ( !lua_isstring( L, 1 ) ) { if ( FileExists( luaL_checkstring( L, 1 ) ) ) {
TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.LoadFont( string fileName )" ); uluaPushFont( L, LoadFont( lua_tostring( L, 1 ) ) );
lua_pushinteger( L, -1 );
return 1;
}
if ( FileExists( lua_tostring( L, 1 ) ) ) {
int i = newFont();
*state->fonts[i] = LoadFont( lua_tostring( L, 1 ) );
lua_pushinteger( L, i );
return 1;
}
else {
lua_pushinteger( L, -1 );
return 1; return 1;
} }
TraceLog( state->logLevelInvalid, "Invalid file path '%s'", lua_tostring( L, 1 ) );
lua_pushnil( L );
return 1; return 1;
} }
/* /*
> font = RL.LoadFontEx( string fileName, int fontSize ) > font = RL.LoadFontEx( string fileName, int fontSize, int fontChars{} )
Load font from file with extended parameters. Loading the default character set Load font from file with extended parameters. Loading the default character set
- Failure return -1 - Failure return nil
- Success return int - Success return Font
*/ */
int ltextLoadFontEx( lua_State *L ) { int ltextLoadFontEx( lua_State *L ) {
if ( !lua_isstring( L, 1 ) || !lua_isnumber( L, 2 ) ) { int fontSize = luaL_checkinteger( L, 2 );
TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.LoadFontEx( string fileName, int fontSize )" );
lua_pushinteger( L, -1 ); if ( FileExists( luaL_checkstring( L, 1 ) ) ) {
return 1; if ( lua_istable( L, 3 ) ) {
} int glyphCount = uluaGetTableLenIndex( L, 3 );
int fontSize = lua_tointeger( L, 2 ); int fontChars[ glyphCount ];
int t = lua_gettop( L );
int i = 0;
lua_pushnil( L );
while ( lua_next( L, t ) != 0 ) {
fontChars[i] = lua_tointeger( L, -1 );
i++;
lua_pop( L, 1 );
}
uluaPushFont( L, LoadFontEx( lua_tostring( L, 1 ), fontSize, fontChars, glyphCount ) );
return 0;
}
uluaPushFont( L, LoadFontEx( lua_tostring( L, 1 ), fontSize, NULL, 0 ) );
if ( FileExists( lua_tostring( L, 1 ) ) ) {
int i = newFont();
*state->fonts[i] = LoadFontEx( lua_tostring( L, 1 ), fontSize, NULL, 0 );
lua_pushinteger( L, i );
return 1;
}
else {
lua_pushinteger( L, -1 );
return 1; return 1;
} }
TraceLog( state->logLevelInvalid, "Invalid file path '%s'", lua_tostring( L, 1 ) );
lua_pushnil( L );
return 1; return 1;
} }
@@ -110,44 +84,14 @@ int ltextLoadFontEx( lua_State *L ) {
Load font from Image ( XNA style ) Load font from Image ( XNA style )
- Failure return -1 - Success return Font
- Success return int
*/ */
int ltextLoadFontFromImage( lua_State *L ) { int ltextLoadFontFromImage( lua_State *L ) {
Image *image = luaL_checkudata( L, 1, "Image" ); Image *image = luaL_checkudata( L, 1, "Image" );
Color key = uluaGetColorIndex( L, 2 ); Color key = uluaGetColorIndex( L, 2 );
int firstChar = lua_tointeger( L, 3 ); int firstChar = luaL_checkinteger( L, 3 );
int i = newFont(); uluaPushFont( L, LoadFontFromImage( *image, key, firstChar ) );
*state->fonts[i] = LoadFontFromImage( *image, key, firstChar );
lua_pushinteger( L, i );
return 1;
}
/*
> success = RL.UnloadFont( Font font )
Unload Font from GPU memory ( VRAM )
- Failure return false
- Success return true
*/
int ltextUnloadFont( lua_State *L ) {
if ( !lua_isnumber( L, 1 ) ) {
TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.UnloadFont( Font font )" );
lua_pushboolean( L, false );
return 1;
}
size_t FontId = lua_tointeger( L, 1 );
if ( !validFont( FontId ) ) {
lua_pushboolean( L, false );
return 1;
}
UnloadFont( *state->fonts[ FontId ] );
state->fonts[ FontId ] = NULL;
lua_pushboolean( L, true );
return 1; return 1;
} }
@@ -157,89 +101,52 @@ int ltextUnloadFont( lua_State *L ) {
*/ */
/* /*
> success = RL.DrawFPS( Vector2 pos ) > RL.DrawFPS( Vector2 pos )
Draw current FPS Draw current FPS
- Failure return false
- Success return true
*/ */
int ltextDrawFPS( lua_State *L ) { int ltextDrawFPS( lua_State *L ) {
if ( !lua_istable( L, 1 ) ) {
TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.DrawFPS( Vector2 pos )" );
lua_pushboolean( L, false );
return 1;
}
Vector2 pos = uluaGetVector2Index( L, 1 ); Vector2 pos = uluaGetVector2Index( L, 1 );
DrawFPS( pos.x, pos.y ); DrawFPS( pos.x, pos.y );
lua_pushboolean( L, true );
return 1; return 0;
} }
/* /*
> success = RL.DrawText( Font font, string text, Vector2 position, float fontSize, float spacing, Color tint ) > RL.DrawText( Font font, string text, Vector2 position, float fontSize, float spacing, Color tint )
Draw text using font and additional parameters Draw text using font and additional parameters
- Failure return false
- Success return true
*/ */
int ltextDrawText( lua_State *L ) { int ltextDrawText( lua_State *L ) {
if ( !lua_isnumber( L, 1 ) || !lua_isstring( L, 2 ) || !lua_istable( L, 3 ) Font *font = luaL_checkudata( L, 1, "Font" );
|| !lua_isnumber( L, 4 ) || !lua_isnumber( L, 5 ) || !lua_istable( L, 6 ) ) {
TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.DrawText( Font font, string text, Vector2 position, float fontSize, float spacing, Color tint )" );
lua_pushboolean( L, false );
return 1;
}
size_t fontId = lua_tointeger( L, 1 );
Vector2 position = uluaGetVector2Index( L, 3 ); Vector2 position = uluaGetVector2Index( L, 3 );
float fontSize = lua_tonumber( L, 4 ); float fontSize = luaL_checknumber( L, 4 );
float spacing = lua_tonumber( L, 5 ); float spacing = luaL_checknumber( L, 5 );
Color tint = uluaGetColorIndex( L, 6 ); Color tint = uluaGetColorIndex( L, 6 );
if ( !validFont( fontId ) ) { DrawTextEx( *font, luaL_checkstring( L, 2 ), position, fontSize, spacing, tint );
lua_pushboolean( L, false );
return 1;
}
DrawTextEx( *state->fonts[ fontId ], lua_tostring( L, 2 ), position, fontSize, spacing, tint );
lua_pushboolean( L, true );
return 1; return 0;
} }
/* /*
> success = RL.DrawTextPro( Font font, string text, Vector2 position, Vector2 origin, float rotation, float fontSize, float spacing, Color tint ) > RL.DrawTextPro( Font font, string text, Vector2 position, Vector2 origin, float rotation, float fontSize, float spacing, Color tint )
Draw text using Font and pro parameters (rotation) Draw text using Font and pro parameters (rotation)
- Failure return false
- Success return true
*/ */
int ltextDrawTextPro( lua_State *L ) { int ltextDrawTextPro( lua_State *L ) {
if ( !lua_isnumber( L, 1 ) || !lua_isstring( L, 2 ) || !lua_istable( L, 3 ) || !lua_istable( L, 4 ) Font *font = luaL_checkudata( L, 1, "Font" );
|| !lua_isnumber( L, 5 ) || !lua_isnumber( L, 6 ) || !lua_isnumber( L, 7 ) || !lua_istable( L, 8 ) ) {
TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.DrawTextPro( Font font, string text, Vector2 position, Vector2 origin, float rotation, float fontSize, float spacing, Color tint )" );
lua_pushboolean( L, false );
return 1;
}
size_t fontId = lua_tointeger( L, 1 );
Vector2 position = uluaGetVector2Index( L, 3 ); Vector2 position = uluaGetVector2Index( L, 3 );
Vector2 origin = uluaGetVector2Index( L, 4 ); Vector2 origin = uluaGetVector2Index( L, 4 );
float rotation = lua_tonumber( L, 5 ); float rotation = luaL_checknumber( L, 5 );
float fontSize = lua_tonumber( L, 6 ); float fontSize = luaL_checknumber( L, 6 );
float spacing = lua_tonumber( L, 7 ); float spacing = luaL_checknumber( L, 7 );
Color tint = uluaGetColorIndex( L, 8 ); Color tint = uluaGetColorIndex( L, 8 );
if ( !validFont( fontId ) ) { DrawTextPro( *font, luaL_checkstring( L, 2 ), position, origin, rotation, fontSize, spacing, tint );
lua_pushboolean( L, false );
return 1;
}
DrawTextPro( *state->fonts[ fontId ], lua_tostring( L, 2 ), position, origin, rotation, fontSize, spacing, tint );
lua_pushboolean( L, true );
return 1; return 0;
} }
/* /*
@@ -251,24 +158,14 @@ int ltextDrawTextPro( lua_State *L ) {
Measure string size for Font Measure string size for Font
- Failure return false
- Success return Vector2 - Success return Vector2
*/ */
int ltextMeasureText( lua_State *L ) { int ltextMeasureText( lua_State *L ) {
if ( !lua_isnumber( L, 1 ) || !lua_isstring( L, 2 ) || !lua_isnumber( L, 3 ) || !lua_isnumber( L, 4 ) ) { Font *font = luaL_checkudata( L, 1, "Font" );
TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.MeasureText( Font font, string text, float fontSize, float spacing )" ); float fontSize = luaL_checknumber( L, 3 );
lua_pushboolean( L, false ); float spacing = luaL_checknumber( L, 4 );
return 1;
}
size_t fontId = lua_tointeger( L, 1 );
float fontSize = lua_tonumber( L, 3 );
float spacing = lua_tonumber( L, 4 );
if ( !validFont( fontId ) ) { uluaPushVector2( L, MeasureTextEx( *font, luaL_checkstring( L, 2 ), fontSize, spacing ) );
lua_pushboolean( L, false );
return 1;
}
uluaPushVector2( L, MeasureTextEx( *state->fonts[ fontId ], lua_tostring( L, 2 ), fontSize, spacing ) );
return 1; return 1;
} }
@@ -278,22 +175,12 @@ int ltextMeasureText( lua_State *L ) {
Get font base size (default chars height) Get font base size (default chars height)
- Failure return false
- Success return int - Success return int
*/ */
int ltextGetFontBaseSize( lua_State *L ) { int ltextGetFontBaseSize( lua_State *L ) {
if ( !lua_isnumber( L, 1 ) ) { Font *font = luaL_checkudata( L, 1, "Font" );
TraceLog( state->logLevelInvalid, "%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_pushinteger( L, font->baseSize );
lua_pushboolean( L, false );
return 1;
}
lua_pushinteger( L, state->fonts[ fontId ]->baseSize );
return 1; return 1;
} }
@@ -303,22 +190,12 @@ int ltextGetFontBaseSize( lua_State *L ) {
Get font number of glyph characters Get font number of glyph characters
- Failure return false
- Success return int - Success return int
*/ */
int ltextGetFontGlyphCount( lua_State *L ) { int ltextGetFontGlyphCount( lua_State *L ) {
if ( !lua_isnumber( L, 1 ) ) { Font *font = luaL_checkudata( L, 1, "Font" );
TraceLog( state->logLevelInvalid, "%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_pushinteger( L, font->glyphCount );
lua_pushboolean( L, false );
return 1;
}
lua_pushinteger( L, state->fonts[ fontId ]->glyphCount );
return 1; return 1;
} }
@@ -328,47 +205,27 @@ int ltextGetFontGlyphCount( lua_State *L ) {
Get font padding around the glyph characters Get font padding around the glyph characters
- Failure return false
- Success return int - Success return int
*/ */
int ltextGetFontGlyphPadding( lua_State *L ) { int ltextGetFontGlyphPadding( lua_State *L ) {
if ( !lua_isnumber( L, 1 ) ) { Font *font = luaL_checkudata( L, 1, "Font" );
TraceLog( state->logLevelInvalid, "%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_pushinteger( L, font->glyphPadding );
lua_pushboolean( L, false );
return 1;
}
lua_pushinteger( L, state->fonts[ fontId ]->glyphPadding );
return 1; return 1;
} }
/* /*
> textureTable = RL.GetFontTexture( Font font ) > texture = RL.GetFontTexture( Font font )
Get font texture atlas containing the glyphs. NOTE! Texture in table form. Get font texture atlas containing the glyphs.
- Failure return false - Success return Texture
- Success return table
*/ */
int ltextGetFontTexture( lua_State *L ) { int ltextGetFontTexture( lua_State *L ) {
if ( !lua_isnumber( L, 1 ) ) { Font *font = luaL_checkudata( L, 1, "Font" );
TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GetFontTexture( Font font )" );
lua_pushboolean( L, false );
return 1;
}
size_t fontId = lua_tointeger( L, 1 );
if ( !validFont( fontId ) ) { uluaPushTexture( L, font->texture );
lua_pushboolean( L, false );
return 1;
}
uluaPushTexture( L, state->fonts[ fontId ]->texture );
return 1; return 1;
} }

View File

@@ -924,7 +924,7 @@ Load texture from file into GPU memory ( VRAM )
- Success return Texture - Success return Texture
*/ */
int ltexturesLoadTexture( lua_State *L ) { int ltexturesLoadTexture( lua_State *L ) {
if ( FileExists( lua_tostring( L, 1 ) ) ) { if ( FileExists( luaL_checkstring( L, 1 ) ) ) {
uluaPushTexture( L, LoadTexture( lua_tostring( L, 1 ) ) ); uluaPushTexture( L, LoadTexture( lua_tostring( L, 1 ) ) );
return 1; return 1;