summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjussi2023-10-31 15:24:11 +0200
committerjussi2023-10-31 15:24:11 +0200
commitbe39fd96344ee1f4f85ac5c63b4e5f9daf6e5171 (patch)
treef0612052c4fe78ad2b6c2e7e8fc695a18d1d961e
parentd351b7b025f95983e49afaecb2fafef7802996a0 (diff)
downloadreilua-enhanced-be39fd96344ee1f4f85ac5c63b4e5f9daf6e5171.tar.gz
reilua-enhanced-be39fd96344ee1f4f85ac5c63b4e5f9daf6e5171.tar.bz2
reilua-enhanced-be39fd96344ee1f4f85ac5c63b4e5f9daf6e5171.zip
GlyphInfo type. Some new text and core functions.
-rw-r--r--API.md77
-rw-r--r--ReiLua_API.lua74
-rw-r--r--changelog6
-rw-r--r--devnotes4
-rw-r--r--docgen.lua2
-rw-r--r--examples/basic_lighting/main.lua2
-rw-r--r--examples/bunnymark/main.lua4
-rw-r--r--examples/events/main.lua2
-rw-r--r--examples/free_camera3d/main.lua2
-rw-r--r--examples/iqm_test/main.lua4
-rw-r--r--examples/pong/main.lua4
-rw-r--r--examples/resources/lib/utillib.lua2
-rw-r--r--examples/snake/main.lua2
-rw-r--r--examples/window/main.lua2
-rw-r--r--include/core.h3
-rw-r--r--include/lua_core.h1
-rw-r--r--include/text.h8
-rw-r--r--src/core.c50
-rw-r--r--src/lua_core.c25
-rw-r--r--src/state.c1
-rw-r--r--src/text.c124
21 files changed, 367 insertions, 32 deletions
diff --git a/API.md b/API.md
index 1dc0fdc..253f9b5 100644
--- a/API.md
+++ b/API.md
@@ -211,6 +211,12 @@ BoundingBox
---
+> GlyphInfo = { value = int, offsetX = int, offsetY = int, advanceX = int, image = Image }
+
+GlyphInfo, font characters glyphs info
+
+---
+
> Wave = Userdata
Wave, audio wave data
@@ -1556,6 +1562,20 @@ Set window dimensions
---
+> RL.SetWindowOpacity( float opacity )
+
+Set window opacity [0.0f..1.0f] (only PLATFORM_DESKTOP)
+
+---
+
+> windowHandle = RL.GetWindowHandle()
+
+Get native window handle. Return as lightuserdata
+
+- Success return lightuserdata
+
+---
+
> RL.SetWindowMinSize( Vector2 size )
Set window minimum dimensions (for FLAG_WINDOW_RESIZABLE)
@@ -1630,6 +1650,12 @@ Set icon for window (Only PLATFORM_DESKTOP)
---
+> RL.SetWindowIcons( Image{} images )
+
+Set icon for window (multiple images, RGBA 32bit, only PLATFORM_DESKTOP)
+
+---
+
> RL.SetWindowTitle( string title )
Set title for window (Only PLATFORM_DESKTOP)
@@ -3868,7 +3894,7 @@ Load font from file into GPU memory (VRAM)
> 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, use NULL for fontChars to load the default character set
- Failure return nil
- Success return Font
@@ -3907,7 +3933,13 @@ Draw current FPS
---
-> RL.DrawText( Font font, string text, Vector2 position, float fontSize, float spacing, Color tint )
+> RL.DrawText( string text, Vector2 position, float fontSize, Color tint )
+
+Draw text (using default font)
+
+---
+
+> RL.DrawTextEx( Font font, string text, Vector2 position, float fontSize, float spacing, Color tint )
Draw text using font and additional parameters
@@ -3919,7 +3951,19 @@ Draw text using Font and pro parameters (rotation)
---
-## Text - Misc
+> RL.DrawTextCodepoint( Font font, int codepoint, Vector2 position, float fontSize, Color tint )
+
+Draw one character (codepoint)
+
+---
+
+> RL.DrawTextCodepoints( Font font, int{} codepoints, Vector2 position, float fontSize, float spacing, Color tint )
+
+Draw multiple character (codepoint)
+
+---
+
+## Text - Font info functions
---
@@ -3931,6 +3975,31 @@ Measure string size for Font
---
+> index = RL.GetGlyphIndex( Font font, int codepoint )
+
+Get glyph index position in font for a codepoint (unicode character), fallback to '?' if not found
+
+- Success return int
+
+---
+
+> glyphInfo = RL.GetGlyphInfo( Font font, int codepoint )
+
+Get glyph font info data for a codepoint (unicode character), fallback to '?' if not found.
+Return Image as lightuserdata
+
+- Success return GlyphInfo
+
+---
+
+> rect = RL.GetGlyphAtlasRec( Font font, int codepoint )
+
+Get glyph rectangle in font atlas for a codepoint (unicode character), fallback to '?' if not found
+
+- Success return Rectangle
+
+---
+
> baseSize = RL.GetFontBaseSize( Font font )
Get font base size (default chars height)
@@ -3957,7 +4026,7 @@ Get font padding around the glyph characters
> texture = RL.GetFontTexture( Font font )
-Get font texture atlas containing the glyphs. Returns as lightuserdata
+Get font texture atlas containing the glyphs. Return as lightuserdata
- Success return Texture
diff --git a/ReiLua_API.lua b/ReiLua_API.lua
index e03e8e0..c1768cf 100644
--- a/ReiLua_API.lua
+++ b/ReiLua_API.lua
@@ -772,6 +772,16 @@ function RL.SetWindowPosition( pos ) end
---@return any RL.SetWindowSize
function RL.SetWindowSize( size ) end
+---Set window opacity [0.0f..1.0f] (only PLATFORM_DESKTOP)
+---@param opacity number
+---@return any RL.SetWindowOpacity
+function RL.SetWindowOpacity( opacity ) end
+
+---Get native window handle. Return as lightuserdata
+---- Success return lightuserdata
+---@return any windowHandle
+function RL.GetWindowHandle() end
+
---Set window minimum dimensions (for FLAG_WINDOW_RESIZABLE)
---@param size table
---@return any RL.SetWindowMinSize
@@ -826,6 +836,11 @@ function RL.IsWindowResized() end
---@return any RL.SetWindowIcon
function RL.SetWindowIcon( image ) end
+---Set icon for window (multiple images, RGBA 32bit, only PLATFORM_DESKTOP)
+---@param images any
+---@return any RL.SetWindowIcons
+function RL.SetWindowIcons( images ) end
+
---Set title for window (Only PLATFORM_DESKTOP)
---@param title string
---@return any RL.SetWindowTitle
@@ -2790,7 +2805,7 @@ function RL.GetFontDefault() end
---@return any font
function RL.LoadFont( fileName ) end
----Load font from file with extended parameters. Loading the default character set
+---Load font from file with extended parameters, use NULL for fontChars to load the default character set
---- Failure return nil
---- Success return Font
---@param fileName string
@@ -2825,6 +2840,14 @@ function RL.UnloadFont( font ) end
---@return any RL.DrawFPS
function RL.DrawFPS( pos ) end
+---Draw text (using default font)
+---@param text string
+---@param position table
+---@param fontSize number
+---@param tint table
+---@return any RL.DrawText
+function RL.DrawText( text, position, fontSize, tint ) end
+
---Draw text using font and additional parameters
---@param font any
---@param text string
@@ -2832,8 +2855,8 @@ function RL.DrawFPS( pos ) end
---@param fontSize number
---@param spacing number
---@param tint table
----@return any RL.DrawText
-function RL.DrawText( font, text, position, fontSize, spacing, tint ) end
+---@return any RL.DrawTextEx
+function RL.DrawTextEx( font, text, position, fontSize, spacing, tint ) end
---Draw text using Font and pro parameters (rotation)
---@param font any
@@ -2847,7 +2870,26 @@ function RL.DrawText( font, text, position, fontSize, spacing, tint ) end
---@return any RL.DrawTextPro
function RL.DrawTextPro( font, text, position, origin, rotation, fontSize, spacing, tint ) end
--- Text - Misc
+---Draw one character (codepoint)
+---@param font any
+---@param codepoint integer
+---@param position table
+---@param fontSize number
+---@param tint table
+---@return any RL.DrawTextCodepoint
+function RL.DrawTextCodepoint( font, codepoint, position, fontSize, tint ) end
+
+---Draw multiple character (codepoint)
+---@param font any
+---@param codepoints any
+---@param position table
+---@param fontSize number
+---@param spacing number
+---@param tint table
+---@return any RL.DrawTextCodepoints
+function RL.DrawTextCodepoints( font, codepoints, position, fontSize, spacing, tint ) end
+
+-- Text - Font info functions
---Measure string size for Font
---- Success return Vector2
@@ -2858,6 +2900,28 @@ function RL.DrawTextPro( font, text, position, origin, rotation, fontSize, spac
---@return any size
function RL.MeasureText( font, text, fontSize, spacing ) end
+---Get glyph index position in font for a codepoint (unicode character), fallback to '?' if not found
+---- Success return int
+---@param font any
+---@param codepoint integer
+---@return any index
+function RL.GetGlyphIndex( font, codepoint ) end
+
+---Get glyph font info data for a codepoint (unicode character), fallback to '?' if not found.
+---Return Image as lightuserdata
+---- Success return GlyphInfo
+---@param font any
+---@param codepoint integer
+---@return any glyphInfo
+function RL.GetGlyphInfo( font, codepoint ) end
+
+---Get glyph rectangle in font atlas for a codepoint (unicode character), fallback to '?' if not found
+---- Success return Rectangle
+---@param font any
+---@param codepoint integer
+---@return any rect
+function RL.GetGlyphAtlasRec( font, codepoint ) end
+
---Get font base size (default chars height)
---- Success return int
---@param font any
@@ -2876,7 +2940,7 @@ function RL.GetFontGlyphCount( font ) end
---@return any glyphPadding
function RL.GetFontGlyphPadding( font ) end
----Get font texture atlas containing the glyphs. Returns as lightuserdata
+---Get font texture atlas containing the glyphs. Return as lightuserdata
---- Success return Texture
---@param font any
---@return any texture
diff --git a/changelog b/changelog
index 3aa2b08..1afa553 100644
--- a/changelog
+++ b/changelog
@@ -12,6 +12,9 @@ KEY CHANGES:
- ADDED: Shaders management functions.
- ADDED: Compute shader management and Buffer management.
- ADDED: More RLGL Initialization functions.
+ - ADDED: GlyphInfo type.
+ - ADDED: DrawTextEx.
+ - CHANGED: DrawText is now DrawTextEx like in Raylib.
DETAILED CHANGES:
- CHANGED: GenImageColor now takes Vector2 as size.
@@ -26,6 +29,9 @@ DETAILED CHANGES:
- ADDED: UnloadBuffer.
- ADDED: GetMaterialDefault returns lightuserdata reference to default material.
- REMOVED: Some examples.
+ - ADDED: DrawTextCodepoint and DrawTextCodepoints.
+ - ADDED: GetGlyphIndex, GetGlyphInfo and GetGlyphAtlasRec.
+ - ADDED: SetWindowIcons, SetWindowOpacity and GetWindowHandle.
------------------------------------------------------------------------
Release: ReiLua version 0.5.0 Using Raylib 4.5
diff --git a/devnotes b/devnotes
index e4a99cd..eba7761 100644
--- a/devnotes
+++ b/devnotes
@@ -3,12 +3,12 @@ Current {
Backlog {
* Text
- * Codepoints?
+ * Text codepoints management functions (unicode characters)?
+ * Some of the Text strings management functions could be easier to use than the Lua ones.
* Audio
* AudioStream.
* Core.
* Compression/Encoding functionality.
- * SetWindowIcons.
* Models
* LoadMaterials (Load materials from model file).
* LoadMaterialsFromModel (Could then for example edit and set back to model).
diff --git a/docgen.lua b/docgen.lua
index 1aeaaa4..16c0005 100644
--- a/docgen.lua
+++ b/docgen.lua
@@ -212,6 +212,8 @@ apiFile:write( "\n> RayCollision = { hit = true, distance = 1.0, point = { 0.0,
RayCollision, ray hit information\n\n---\n" )
apiFile:write( "\n> BoundingBox = { { 0.0, 0.0, 0.0 }, { 1.0, 1.0, 1.0 } } or { min = { 0.0, 0.0, 0.0 }, max = { 1.0, 1.0, 1.0 } }\n\
BoundingBox\n\n---\n" )
+apiFile:write( "\n> GlyphInfo = { value = int, offsetX = int, offsetY = int, advanceX = int, image = Image }\n\
+GlyphInfo, font characters glyphs info\n\n---\n" )
apiFile:write( "\n> Wave = Userdata\n\
Wave, audio wave data\n\n---\n" )
apiFile:write( "\n> Sound = Userdata\n\
diff --git a/examples/basic_lighting/main.lua b/examples/basic_lighting/main.lua
index 0d7b77c..29104f2 100644
--- a/examples/basic_lighting/main.lua
+++ b/examples/basic_lighting/main.lua
@@ -136,5 +136,5 @@ function RL.draw()
camera:endMode3D()
- RL.DrawText( RL.GetFontDefault(), "Use keys [Y][R][G][B] to toggle lights", { 10, 10 }, 20, 4, RL.DARKGRAY )
+ RL.DrawText( "Use keys [Y][R][G][B] to toggle lights", { 10, 10 }, 20, RL.DARKGRAY )
end
diff --git a/examples/bunnymark/main.lua b/examples/bunnymark/main.lua
index 03f53ad..7b1820e 100644
--- a/examples/bunnymark/main.lua
+++ b/examples/bunnymark/main.lua
@@ -83,7 +83,7 @@ function RL.draw()
end
RL.DrawRectangle( { 0, 0, screenWidth, 40 }, RL.BLACK)
- RL.DrawText( RL.GetFontDefault(), "bunnies: " .. #bunnies, { 120, 10 }, 20, 2, RL.GREEN )
- RL.DrawText( RL.GetFontDefault(), "batched draw calls: " .. math.ceil( 1 + #bunnies / MAX_BATCH_ELEMENTS ), { 320, 10 }, 20, 2, RL.RED )
+ RL.DrawText( "bunnies: " .. #bunnies, { 120, 10 }, 20, RL.GREEN )
+ RL.DrawText( "batched draw calls: " .. math.ceil( 1 + #bunnies / MAX_BATCH_ELEMENTS ), { 320, 10 }, 20, RL.RED )
RL.DrawFPS( { 10, 10 } )
end
diff --git a/examples/events/main.lua b/examples/events/main.lua
index 052edc1..3a042f1 100644
--- a/examples/events/main.lua
+++ b/examples/events/main.lua
@@ -100,5 +100,5 @@ function RL.draw()
RL.ClearBackground( RL.RED )
end
- RL.DrawText( RL.GetFontDefault(), text, textPos, 20, 2, RL.BLACK )
+ RL.DrawText( text, textPos, 20, RL.BLACK )
end
diff --git a/examples/free_camera3d/main.lua b/examples/free_camera3d/main.lua
index 4881cc5..30cee08 100644
--- a/examples/free_camera3d/main.lua
+++ b/examples/free_camera3d/main.lua
@@ -69,5 +69,5 @@ function RL.draw()
text = text.."\nPress T to toggle target visible.\nVisible: "..tostring( targetVisible )
-- RL.DrawText( RL.defaultFont, text, { 16, 16 }, 30, 4, RL.WHITE )
- RL.DrawText( RL.GetFontDefault(), text, { 16, 16 }, 30, 4, RL.WHITE )
+ RL.DrawText( text, { 16, 16 }, 30, RL.WHITE )
end
diff --git a/examples/iqm_test/main.lua b/examples/iqm_test/main.lua
index 22341a4..ef1549c 100644
--- a/examples/iqm_test/main.lua
+++ b/examples/iqm_test/main.lua
@@ -80,10 +80,10 @@ function RL.draw()
RL.DrawModelEx( model, { 0, 0, 0 }, { 1.0, 0.0, 0.0 }, -90.0, { 1.0, 1.0, 1.0 }, RL.WHITE )
RL.EndMode3D()
- RL.DrawText( RL.GetFontDefault(),
+ RL.DrawText(
"Enter: Change animation\
Space: Play animation\
Up arrow: Inreace animation speed\
Down arrow: Decreace animation speed",
- { 10, 10 }, 30, 5, RL.WHITE )
+ { 10, 10 }, 30, RL.WHITE )
end
diff --git a/examples/pong/main.lua b/examples/pong/main.lua
index 4dd3462..635b355 100644
--- a/examples/pong/main.lua
+++ b/examples/pong/main.lua
@@ -126,7 +126,7 @@ function RL.draw()
RL.DrawCircle( ball.pos, ball.radius, RL.WHITE )
-- Draw score.
- RL.DrawText( RL.GetFontDefault(), tostring( playerLeft.score ), { 50, 10 }, 40, 2, RL.WHITE )
+ RL.DrawText( tostring( playerLeft.score ), { 50, 10 }, 40, RL.WHITE )
local rightTextSize = Vec2:new( RL.MeasureText( RL.GetFontDefault(), tostring( playerRight.score ), 40, 2 ) )
- RL.DrawText( RL.GetFontDefault(), tostring( playerRight.score ), { winSize.x - 50 - rightTextSize.x, 10 }, 40, 2, RL.WHITE )
+ RL.DrawText( tostring( playerRight.score ), { winSize.x - 50 - rightTextSize.x, 10 }, 40, RL.WHITE )
end
diff --git a/examples/resources/lib/utillib.lua b/examples/resources/lib/utillib.lua
index ed4e787..94e33f9 100644
--- a/examples/resources/lib/utillib.lua
+++ b/examples/resources/lib/utillib.lua
@@ -131,7 +131,7 @@ function utillib.toBoolean( v )
return false
end
-function utillib.boo2Number( bool )
+function utillib.bool2Number( bool )
return bool and 1 or 0
end
diff --git a/examples/snake/main.lua b/examples/snake/main.lua
index 5aa22b3..4ae88d1 100644
--- a/examples/snake/main.lua
+++ b/examples/snake/main.lua
@@ -213,7 +213,7 @@ function RL.draw()
drawApple()
if gameState == STATE.OVER then
- RL.DrawText( RL.GetFontDefault(), "Press Enter to\nrestart", { 10, 10 }, 10, 2, RL.WHITE )
+ RL.DrawText( "Press Enter to\nrestart", { 10, 10 }, 10, RL.WHITE )
end
RL.EndTextureMode()
diff --git a/examples/window/main.lua b/examples/window/main.lua
index c6161e9..3e10f34 100644
--- a/examples/window/main.lua
+++ b/examples/window/main.lua
@@ -24,5 +24,5 @@ end
function RL.draw()
RL.ClearBackground( RL.RAYWHITE )
- RL.DrawText( RL.GetFontDefault(), text, textPos, 20, 2, textColor )
+ RL.DrawText( text, textPos, 20, textColor )
end
diff --git a/include/core.h b/include/core.h
index f9b26bd..0a4cd2b 100644
--- a/include/core.h
+++ b/include/core.h
@@ -10,6 +10,8 @@ int lcoreIsWindowFocused( lua_State *L );
int lcoreSetWindowMonitor( lua_State *L );
int lcoreSetWindowPosition( lua_State *L );
int lcoreSetWindowSize( lua_State *L );
+int lcoreSetWindowOpacity( lua_State *L );
+int lcoreGetWindowHandle( lua_State *L );
int lcoreSetWindowMinSize( lua_State *L );
int lcoreGetMonitorPosition( lua_State *L );
int lcoreGetMonitorSize( lua_State *L );
@@ -20,6 +22,7 @@ int lcoreIsWindowState( lua_State *L );
int lcoreClearWindowState( lua_State *L );
int lcoreIsWindowResized( lua_State *L );
int lcoreSetWindowIcon( lua_State *L );
+int lcoreSetWindowIcons( lua_State *L );
int lcoreSetWindowTitle( lua_State *L );
int lcoreGetMonitorCount( lua_State *L );
int lcoreGetCurrentMonitor( lua_State *L );
diff --git a/include/lua_core.h b/include/lua_core.h
index 5fe539f..9090040 100644
--- a/include/lua_core.h
+++ b/include/lua_core.h
@@ -84,6 +84,7 @@ void uluaPushMatrix( lua_State *L, Matrix matrix );
void uluaPushRay( lua_State *L, Ray ray );
void uluaPushRayCollision( lua_State *L, RayCollision rayCol );
void uluaPushBoundingBox( lua_State *L, BoundingBox box );
+void uluaPushGlyphInfo( lua_State *L, GlyphInfo glyphInfo, Image *image );
void uluaPushBuffer( lua_State *L, Buffer buffer );
void uluaPushImage( lua_State *L, Image image );
void uluaPushTexture( lua_State *L, Texture texture );
diff --git a/include/text.h b/include/text.h
index 1cfe4e8..ddf782e 100644
--- a/include/text.h
+++ b/include/text.h
@@ -10,9 +10,15 @@ int ltextUnloadFont( lua_State *L );
/* Drawing. */
int ltextDrawFPS( lua_State *L );
int ltextDrawText( lua_State *L );
+int ltextDrawTextEx( lua_State *L );
int ltextDrawTextPro( lua_State *L );
-/* Misc. */
+int ltextDrawTextCodepoint( lua_State *L );
+int ltextDrawTextCodepoints( lua_State *L );
+/* Font info functions. */
int ltextMeasureText( lua_State *L );
+int ltextGetGlyphIndex( lua_State *L );
+int ltextGetGlyphInfo( lua_State *L );
+int ltextGetGlyphAtlasRec( lua_State *L );
int ltextGetFontBaseSize( lua_State *L );
int ltextGetFontGlyphCount( lua_State *L );
int ltextGetFontGlyphPadding( lua_State *L );
diff --git a/src/core.c b/src/core.c
index bd1ffe0..28b531d 100644
--- a/src/core.c
+++ b/src/core.c
@@ -126,6 +126,32 @@ int lcoreSetWindowSize( lua_State *L ) {
}
/*
+> RL.SetWindowOpacity( float opacity )
+
+Set window opacity [0.0f..1.0f] (only PLATFORM_DESKTOP)
+*/
+int lcoreSetWindowOpacity( lua_State *L ) {
+ float opacity = luaL_checknumber( L, 1 );
+
+ SetWindowOpacity( opacity );
+
+ return 0;
+}
+
+/*
+> windowHandle = RL.GetWindowHandle()
+
+Get native window handle. Return as lightuserdata
+
+- Success return lightuserdata
+*/
+int lcoreGetWindowHandle( lua_State *L ) {
+ lua_pushlightuserdata( L, GetWindowHandle() );
+
+ return 1;
+}
+
+/*
> RL.SetWindowMinSize( Vector2 size )
Set window minimum dimensions (for FLAG_WINDOW_RESIZABLE)
@@ -266,6 +292,30 @@ int lcoreSetWindowIcon( lua_State *L ) {
}
/*
+> RL.SetWindowIcons( Image{} images )
+
+Set icon for window (multiple images, RGBA 32bit, only PLATFORM_DESKTOP)
+*/
+int lcoreSetWindowIcons( lua_State *L ) {
+ int count = uluaGetTableLenIndex( L, 1 );
+ Image images[ count ];
+
+ int t = 1;
+ int i = 0;
+ lua_pushnil( L );
+
+ while ( lua_next( L, t ) != 0 ) {
+ images[i] = *uluaGetImage( L, lua_gettop( L ) );
+
+ i++;
+ lua_pop( L, 1 );
+ }
+ SetWindowIcons( images, count );
+
+ return 0;
+}
+
+/*
> RL.SetWindowTitle( string title )
Set title for window (Only PLATFORM_DESKTOP)
diff --git a/src/lua_core.c b/src/lua_core.c
index cb91583..90ed9ba 100644
--- a/src/lua_core.c
+++ b/src/lua_core.c
@@ -1504,6 +1504,8 @@ void luaRegister() {
assingGlobalFunction( "SetWindowMonitor", lcoreSetWindowMonitor );
assingGlobalFunction( "SetWindowPosition", lcoreSetWindowPosition );
assingGlobalFunction( "SetWindowSize", lcoreSetWindowSize );
+ assingGlobalFunction( "SetWindowOpacity", lcoreSetWindowOpacity );
+ assingGlobalFunction( "GetWindowHandle", lcoreGetWindowHandle );
assingGlobalFunction( "SetWindowMinSize", lcoreSetWindowMinSize );
assingGlobalFunction( "GetMonitorPosition", lcoreGetMonitorPosition );
assingGlobalFunction( "GetMonitorSize", lcoreGetMonitorSize );
@@ -1514,6 +1516,7 @@ void luaRegister() {
assingGlobalFunction( "ClearWindowState", lcoreClearWindowState );
assingGlobalFunction( "IsWindowResized", lcoreIsWindowResized );
assingGlobalFunction( "SetWindowIcon", lcoreSetWindowIcon );
+ assingGlobalFunction( "SetWindowIcons", lcoreSetWindowIcons );
assingGlobalFunction( "SetWindowTitle", lcoreSetWindowTitle );
assingGlobalFunction( "GetMonitorCount", lcoreGetMonitorCount );
assingGlobalFunction( "GetCurrentMonitor", lcoreGetCurrentMonitor );
@@ -1936,9 +1939,15 @@ void luaRegister() {
/* Drawing. */
assingGlobalFunction( "DrawFPS", ltextDrawFPS );
assingGlobalFunction( "DrawText", ltextDrawText );
+ assingGlobalFunction( "DrawTextEx", ltextDrawTextEx );
assingGlobalFunction( "DrawTextPro", ltextDrawTextPro );
- /* Misc. */
+ assingGlobalFunction( "DrawTextCodepoint", ltextDrawTextCodepoint );
+ assingGlobalFunction( "DrawTextCodepoints", ltextDrawTextCodepoints );
+ /* Font info functions. */
assingGlobalFunction( "MeasureText", ltextMeasureText );
+ assingGlobalFunction( "GetGlyphIndex", ltextGetGlyphIndex );
+ assingGlobalFunction( "GetGlyphInfo", ltextGetGlyphInfo );
+ assingGlobalFunction( "GetGlyphAtlasRec", ltextGetGlyphAtlasRec );
assingGlobalFunction( "GetFontBaseSize", ltextGetFontBaseSize );
assingGlobalFunction( "GetFontGlyphCount", ltextGetFontGlyphCount );
assingGlobalFunction( "GetFontGlyphPadding", ltextGetFontGlyphPadding );
@@ -3129,6 +3138,20 @@ void uluaPushBoundingBox( lua_State *L, BoundingBox box ) {
lua_rawseti( L, -2, 2 );
}
+void uluaPushGlyphInfo( lua_State *L, GlyphInfo glyphInfo, Image *image ) {
+ lua_createtable( L, 4, 0 );
+ lua_pushinteger( L, glyphInfo.value );
+ lua_setfield( L, -2, "value" );
+ lua_pushinteger( L, glyphInfo.offsetX );
+ lua_setfield( L, -2, "offsetX" );
+ lua_pushinteger( L, glyphInfo.offsetY );
+ lua_setfield( L, -2, "offsetY" );
+ lua_pushinteger( L, glyphInfo.advanceX );
+ lua_setfield( L, -2, "advanceX" );
+ lua_pushlightuserdata( L, image );
+ lua_setfield( L, -2, "image" );
+}
+
void uluaPushBuffer( lua_State *L, Buffer buffer ) {
Buffer *bufferP = lua_newuserdata( L, sizeof( Buffer ) );
*bufferP = buffer;
diff --git a/src/state.c b/src/state.c
index 3706561..228cbce 100644
--- a/src/state.c
+++ b/src/state.c
@@ -41,7 +41,6 @@ bool stateInit( int argn, const char **argc, const char *exePath ) {
for ( int i = 0; i < RL_MAX_SHADER_LOCATIONS; i++ ) {
state->RLGLcurrentShaderLocs[i] = defaultShaderLocs[i];
- printf( "defaultShaderLocs[%d] %d\n", i, defaultShaderLocs[i] );
}
return state->run;
diff --git a/src/text.c b/src/text.c
index e2135d1..c127ccf 100644
--- a/src/text.c
+++ b/src/text.c
@@ -42,7 +42,7 @@ int ltextLoadFont( lua_State *L ) {
/*
> 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, use NULL for fontChars to load the default character set
- Failure return nil
- Success return Font
@@ -67,7 +67,7 @@ int ltextLoadFontEx( lua_State *L ) {
}
uluaPushFont( L, LoadFontEx( lua_tostring( L, 1 ), fontSize, fontChars, glyphCount ) );
- return 0;
+ return 1;
}
uluaPushFont( L, LoadFontEx( lua_tostring( L, 1 ), fontSize, NULL, 0 ) );
@@ -142,11 +142,26 @@ int ltextDrawFPS( lua_State *L ) {
}
/*
-> RL.DrawText( Font font, string text, Vector2 position, float fontSize, float spacing, Color tint )
+> RL.DrawText( string text, Vector2 position, float fontSize, Color tint )
-Draw text using font and additional parameters
+Draw text (using default font)
*/
int ltextDrawText( lua_State *L ) {
+ Vector2 position = uluaGetVector2Index( L, 2 );
+ float fontSize = luaL_checknumber( L, 3 );
+ Color tint = uluaGetColorIndex( L, 4 );
+
+ DrawText( luaL_checkstring( L, 1 ), position.x, position.y, fontSize, tint );
+
+ return 0;
+}
+
+/*
+> RL.DrawTextEx( Font font, string text, Vector2 position, float fontSize, float spacing, Color tint )
+
+Draw text using font and additional parameters
+*/
+int ltextDrawTextEx( lua_State *L ) {
Font *font = uluaGetFont( L, 1 );
Vector2 position = uluaGetVector2Index( L, 3 );
float fontSize = luaL_checknumber( L, 4 );
@@ -178,7 +193,54 @@ int ltextDrawTextPro( lua_State *L ) {
}
/*
-## Text - Misc
+> RL.DrawTextCodepoint( Font font, int codepoint, Vector2 position, float fontSize, Color tint )
+
+Draw one character (codepoint)
+*/
+int ltextDrawTextCodepoint( lua_State *L ) {
+ Font *font = uluaGetFont( L, 1 );
+ int codepoint = luaL_checkinteger( L, 2 );
+ Vector2 position = uluaGetVector2Index( L, 3 );
+ float fontSize = luaL_checknumber( L, 4 );
+ Color tint = uluaGetColorIndex( L, 5 );
+
+ DrawTextCodepoint( *font, codepoint, position, fontSize, tint );
+
+ return 0;
+}
+
+/*
+> RL.DrawTextCodepoints( Font font, int{} codepoints, Vector2 position, float fontSize, float spacing, Color tint )
+
+Draw multiple character (codepoint)
+*/
+int ltextDrawTextCodepoints( lua_State *L ) {
+ Font *font = uluaGetFont( L, 1 );
+ Vector2 position = uluaGetVector2Index( L, 3 );
+ float fontSize = luaL_checknumber( L, 4 );
+ float spacing = luaL_checknumber( L, 5 );
+ Color tint = uluaGetColorIndex( L, 6 );
+
+ int count = uluaGetTableLenIndex( L, 2 );
+ int codepoints[ count ];
+
+ int t = 2;
+ int i = 0;
+ lua_pushnil( L );
+
+ while ( lua_next( L, t ) != 0 ) {
+ codepoints[i] = lua_tointeger( L, -1 );
+
+ i++;
+ lua_pop( L, 1 );
+ }
+ DrawTextCodepoints( *font, codepoints, count, position, fontSize, spacing, tint );
+
+ return 0;
+}
+
+/*
+## Text - Font info functions
*/
/*
@@ -199,6 +261,56 @@ int ltextMeasureText( lua_State *L ) {
}
/*
+> index = RL.GetGlyphIndex( Font font, int codepoint )
+
+Get glyph index position in font for a codepoint (unicode character), fallback to '?' if not found
+
+- Success return int
+*/
+int ltextGetGlyphIndex( lua_State *L ) {
+ Font *font = uluaGetFont( L, 1 );
+ int codepoint = luaL_checkinteger( L, 2 );
+
+ lua_pushinteger( L, GetGlyphIndex( *font, codepoint ) );
+
+ return 1;
+}
+
+/*
+> glyphInfo = RL.GetGlyphInfo( Font font, int codepoint )
+
+Get glyph font info data for a codepoint (unicode character), fallback to '?' if not found.
+Return Image as lightuserdata
+
+- Success return GlyphInfo
+*/
+int ltextGetGlyphInfo( lua_State *L ) {
+ Font *font = uluaGetFont( L, 1 );
+ int codepoint = luaL_checkinteger( L, 2 );
+
+ int id = GetGlyphIndex( *font, codepoint );
+ uluaPushGlyphInfo( L, font->glyphs[id], &font->glyphs[id].image );
+
+ return 1;
+}
+
+/*
+> rect = RL.GetGlyphAtlasRec( Font font, int codepoint )
+
+Get glyph rectangle in font atlas for a codepoint (unicode character), fallback to '?' if not found
+
+- Success return Rectangle
+*/
+int ltextGetGlyphAtlasRec( lua_State *L ) {
+ Font *font = uluaGetFont( L, 1 );
+ int codepoint = luaL_checkinteger( L, 2 );
+
+ uluaPushRectangle( L, GetGlyphAtlasRec( *font, codepoint ) );
+
+ return 1;
+}
+
+/*
> baseSize = RL.GetFontBaseSize( Font font )
Get font base size (default chars height)
@@ -246,7 +358,7 @@ int ltextGetFontGlyphPadding( lua_State *L ) {
/*
> texture = RL.GetFontTexture( Font font )
-Get font texture atlas containing the glyphs. Returns as lightuserdata
+Get font texture atlas containing the glyphs. Return as lightuserdata
- Success return Texture
*/