summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjussi2024-01-03 18:23:19 +0200
committerjussi2024-01-03 18:23:19 +0200
commit70a2bcba18aa9855380c132f89e26b61bfd2cb40 (patch)
tree7f5d18d0d82afc352b5c75c68b136f4e2f6850d0
parent192d471fb3caaa6d73796185e5cadc62075743f7 (diff)
downloadreilua-enhanced-70a2bcba18aa9855380c132f89e26b61bfd2cb40.tar.gz
reilua-enhanced-70a2bcba18aa9855380c132f89e26b61bfd2cb40.tar.bz2
reilua-enhanced-70a2bcba18aa9855380c132f89e26b61bfd2cb40.zip
Rest of font loading/unloading functions. GlyphInfo type to userdata. GlyphInfo management functions.
-rw-r--r--API.md165
-rw-r--r--ReiLua_API.lua133
-rw-r--r--changelog4
-rw-r--r--devnotes3
-rw-r--r--docgen.lua13
-rw-r--r--examples/2D_lights/main.lua24
-rw-r--r--examples/free_camera3d/main.lua1
-rw-r--r--examples/raygui_custom/main.lua89
-rw-r--r--examples/raygui_custom/spriteButton.lua54
-rw-r--r--examples/resources/images/LICENCE1
-rw-r--r--examples/resources/images/button.pngbin0 -> 1130 bytes
-rw-r--r--examples/resources/lib/rectangle.lua3
-rw-r--r--examples/window/main.lua2
-rw-r--r--include/lua_core.h4
-rw-r--r--include/text.h19
-rw-r--r--src/lights.c2
-rw-r--r--src/lua_core.c120
-rw-r--r--src/models.c10
-rw-r--r--src/platforms/core_desktop.c6
-rw-r--r--src/rlgl.c2
-rw-r--r--src/text.c433
-rw-r--r--src/textures.c8
22 files changed, 957 insertions, 139 deletions
diff --git a/API.md b/API.md
index 06aa7ef..049a202 100644
--- a/API.md
+++ b/API.md
@@ -215,10 +215,20 @@ BoundingBox
---
-> GlyphInfo = { value = int, offsetX = int, offsetY = int, advanceX = int, image = Image }
+> GlyphInfo = Userdata
GlyphInfo, font characters glyphs info
+```
+glyphInfoData = {
+ value = int, --Character value (Unicode)
+ offsetX = int, --Character offset X when drawing
+ offsetY = int, --Character offset Y when drawing
+ advanceX = int, --Character advance position X
+ image = Image, --Character image data
+}
+```
+
---
> BoneInfo = { name = string[32], parent = int }
@@ -6313,6 +6323,22 @@ Load font from Image (XNA style)
---
+> font = RL.LoadFontFromMemory( string fileType, Buffer fileData, int fontSize, int{} codepoints )
+
+Load font from memory buffer, fileType refers to extension: i.e. '.ttf'. NOTE: FileData type should be unsigned char
+
+- Success return Font
+
+---
+
+> font = RL.LoadFontFromData( Font{} fontData )
+
+Load Font from data
+
+- Success return Font
+
+---
+
> isReady = RL.IsFontReady( Font font )
Check if a font is ready
@@ -6321,12 +6347,36 @@ Check if a font is ready
---
+> glyphs = RL.LoadFontData( Buffer fileData, int fontSize, int{} codepoints, int type )
+
+Load font data for further use. NOTE: FileData type should be unsigned char
+
+- Success return GlyphInfo{}
+
+---
+
+> image, rectangles = RL.GenImageFontAtlas( GlyphInfo{} glyphs, int fontSize, int padding, int packMethod )
+
+Generate image font atlas using chars info. NOTE: Packing method: 0-Default, 1-Skyline
+
+- Success Image, Rectangle{}
+
+---
+
> RL.UnloadFont( Font font )
Unload font from GPU memory (VRAM)
---
+> RL.ExportFontAsCode( Font font, string fileName )
+
+Export font as code file, returns true on success
+
+- Success return bool
+
+---
+
## Text - Text drawing functions
---
@@ -6411,13 +6461,21 @@ Get glyph index position in font for a codepoint (unicode character), fallback t
> 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
+Get glyph font info data for a codepoint (unicode character), fallback to '?' if not found
- Success return GlyphInfo
---
+> glyphInfo = RL.GetGlyphInfoByIndex( Font font, int index )
+
+Get glyph font info data by index
+
+- Failure return nil
+- 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
@@ -6426,6 +6484,15 @@ Get glyph rectangle in font atlas for a codepoint (unicode character), fallback
---
+> rect = RL.GetGlyphAtlasRecByIndex( Font font, int index )
+
+Get glyph rectangle in font atlas by index
+
+- Failure return nil
+- Success return Rectangle
+
+---
+
> baseSize = RL.GetFontBaseSize( Font font )
Get font base size (default chars height)
@@ -6458,6 +6525,80 @@ Get font texture atlas containing the glyphs. Return as lightuserdata
---
+## Text - GlyphInfo management functions
+
+---
+
+> glyphInfo = RL.LoadGlyphInfo( GlyphInfo{} glyphInfoData )
+
+Load GlyphInfo from data
+
+- Success return GlyphInfo
+
+---
+
+> RL.UnloadGlyphInfo( GlyphInfo glyphInfo )
+
+Unload glyphInfo image from CPU memory (RAM)
+
+---
+
+> RL.SetGlyphInfoValue( GlyphInfo glyphInfo, int value )
+
+Set glyphInfo character value (Unicode)
+
+---
+
+> RL.SetGlyphInfoOffset( GlyphInfo glyphInfo, Vector2 offset )
+
+Set glyphInfo character offset when drawing
+
+---
+
+> RL.SetGlyphInfoAdvanceX( GlyphInfo glyphInfo, int advanceX )
+
+Set glyphInfo character advance position X
+
+---
+
+> RL.SetGlyphInfoImage( GlyphInfo glyphInfo, Image image )
+
+Set glyphInfo character image data
+
+---
+
+> value = RL.GetGlyphInfoValue( GlyphInfo glyphInfo )
+
+Get glyphInfo character value (Unicode)
+
+- Success return int
+
+---
+
+> offset = RL.GetGlyphInfoOffset( GlyphInfo glyphInfo )
+
+Get glyphInfo character offset when drawing
+
+- Success return Vector2
+
+---
+
+> advanceX = RL.GetGlyphInfoAdvanceX( GlyphInfo glyphInfo )
+
+Get glyphInfo character advance position X
+
+- Success return int
+
+---
+
+> image = RL.GetGlyphInfoImage( GlyphInfo glyphInfo )
+
+Get glyphInfo character image data. Return as lightuserdata
+
+- Success return Image
+
+---
+
## Models - Basic geometric 3D shapes drawing functions
---
@@ -6794,7 +6935,7 @@ Draw a billboard texture defined by source and rotation
> RL.UpdateMesh( Mesh mesh, Mesh{} meshData )
Update mesh vertex data in GPU.
-Note! Mainly intented to be used with custom meshes.
+NOTE: Mainly intented to be used with custom meshes.
---
@@ -7022,7 +7163,7 @@ Set material generic parameters (if required)
> texture = RL.GetMaterialTexture( Material material, int mapType )
-Get texture from material map type. Returns -1 if no texture
+Get texture from material map type. Return as lightuserdata
- Success return Texture
@@ -7046,9 +7187,9 @@ Get color from material map type
> shader = RL.GetMaterialShader( Material material )
-Get material shader
+Get material shader. Return as lightuserdata
-- Success return Shader. Return as lightuserdata
+- Success return Shader
---
@@ -9017,7 +9158,7 @@ Get light color
Get light enabled
-- Success return boolean
+- Success return bool
---
@@ -9629,7 +9770,7 @@ Unload vertex buffer (VBO)
> RL.rlSetVertexAttribute( int index, int compSize, int type, bool normalized, int stride, int pointer )
-Set vertex attribute. Note! Pointer should be given in size of bytes
+Set vertex attribute. NOTE: Pointer should be given in size of bytes
---
@@ -10358,20 +10499,20 @@ Called when a joystick is connected or disconnected. Type GLFW_JOYSTICK_EVENT
> GLFWpentabletdataEvent = { int type, float x, float y, float z, float pressure, float pitch, float yaw, float roll }
Called when the pen tablet data is updated. Type GLFW_PEN_TABLET_DATA_EVENT
-NOTE! Experimental. Needs glfw PR https://github.com/glfw/glfw/pull/1445
+NOTE: Experimental. Needs glfw PR https://github.com/glfw/glfw/pull/1445
---
> GLFWpentabletcursorEvent = { int type, int identifier }
Called when the pen tablet cursor has changed. Type GLFW_PEN_TABLET_CURSOR_EVENT
-NOTE! Experimental. Needs glfw PR https://github.com/glfw/glfw/pull/1445
+NOTE: Experimental. Needs glfw PR https://github.com/glfw/glfw/pull/1445
---
> GLFWpentabletproximityEvent = { int type, int proxState }
Called when the pen tablet proximity has changed. Type GLFW_PEN_TABLET_PROXIMITY_EVENT
-NOTE! Experimental. Needs glfw PR https://github.com/glfw/glfw/pull/1445
+NOTE: Experimental. Needs glfw PR https://github.com/glfw/glfw/pull/1445
---
diff --git a/ReiLua_API.lua b/ReiLua_API.lua
index 9e8b678..04de577 100644
--- a/ReiLua_API.lua
+++ b/ReiLua_API.lua
@@ -3673,17 +3673,58 @@ function RL.LoadFontEx( fileName, fontSize, codepoints ) end
---@return any font
function RL.LoadFontFromImage( image, key, firstChar ) end
+---Load font from memory buffer, fileType refers to extension: i.e. '.ttf'. NOTE: FileData type should be unsigned char
+---- Success return Font
+---@param fileType string
+---@param fileData any
+---@param fontSize integer
+---@param codepoints table
+---@return any font
+function RL.LoadFontFromMemory( fileType, fileData, fontSize, codepoints ) end
+
+---Load Font from data
+---- Success return Font
+---@param fontData table
+---@return any font
+function RL.LoadFontFromData( fontData ) end
+
---Check if a font is ready
---- Success return bool
---@param font any
---@return any isReady
function RL.IsFontReady( font ) end
+---Load font data for further use. NOTE: FileData type should be unsigned char
+---- Success return GlyphInfo{}
+---@param fileData any
+---@param fontSize integer
+---@param codepoints table
+---@param type integer
+---@return any glyphs
+function RL.LoadFontData( fileData, fontSize, codepoints, type ) end
+
+---Generate image font atlas using chars info. NOTE: Packing method: 0-Default, 1-Skyline
+---- Success Image, Rectangle{}
+---@param glyphs table
+---@param fontSize integer
+---@param padding integer
+---@param packMethod integer
+---@return any image
+---@return any rectangles
+function RL.GenImageFontAtlas( glyphs, fontSize, padding, packMethod ) end
+
---Unload font from GPU memory (VRAM)
---@param font any
---@return any RL.UnloadFont
function RL.UnloadFont( font ) end
+---Export font as code file, returns true on success
+---- Success return bool
+---@param font any
+---@param fileName string
+---@return any RL.ExportFontAsCode
+function RL.ExportFontAsCode( font, fileName ) end
+
-- Text - Text drawing functions
---Draw current FPS
@@ -3788,14 +3829,21 @@ function RL.MeasureText( font, text, fontSize, spacing ) end
---@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
+---Get glyph font info data for a codepoint (unicode character), fallback to '?' if not found
---- Success return GlyphInfo
---@param font any
---@param codepoint integer
---@return any glyphInfo
function RL.GetGlyphInfo( font, codepoint ) end
+---Get glyph font info data by index
+---- Failure return nil
+---- Success return GlyphInfo
+---@param font any
+---@param index integer
+---@return any glyphInfo
+function RL.GetGlyphInfoByIndex( font, index ) end
+
---Get glyph rectangle in font atlas for a codepoint (unicode character), fallback to '?' if not found
---- Success return Rectangle
---@param font any
@@ -3803,6 +3851,14 @@ function RL.GetGlyphInfo( font, codepoint ) end
---@return any rect
function RL.GetGlyphAtlasRec( font, codepoint ) end
+---Get glyph rectangle in font atlas by index
+---- Failure return nil
+---- Success return Rectangle
+---@param font any
+---@param index integer
+---@return any rect
+function RL.GetGlyphAtlasRecByIndex( font, index ) end
+
---Get font base size (default chars height)
---- Success return int
---@param font any
@@ -3827,6 +3883,67 @@ function RL.GetFontGlyphPadding( font ) end
---@return any texture
function RL.GetFontTexture( font ) end
+-- Text - GlyphInfo management functions
+
+---Load GlyphInfo from data
+---- Success return GlyphInfo
+---@param glyphInfoData table
+---@return any glyphInfo
+function RL.LoadGlyphInfo( glyphInfoData ) end
+
+---Unload glyphInfo image from CPU memory (RAM)
+---@param glyphInfo any
+---@return any RL.UnloadGlyphInfo
+function RL.UnloadGlyphInfo( glyphInfo ) end
+
+---Set glyphInfo character value (Unicode)
+---@param glyphInfo any
+---@param value integer
+---@return any RL.SetGlyphInfoValue
+function RL.SetGlyphInfoValue( glyphInfo, value ) end
+
+---Set glyphInfo character offset when drawing
+---@param glyphInfo any
+---@param offset table
+---@return any RL.SetGlyphInfoOffset
+function RL.SetGlyphInfoOffset( glyphInfo, offset ) end
+
+---Set glyphInfo character advance position X
+---@param glyphInfo any
+---@param advanceX integer
+---@return any RL.SetGlyphInfoAdvanceX
+function RL.SetGlyphInfoAdvanceX( glyphInfo, advanceX ) end
+
+---Set glyphInfo character image data
+---@param glyphInfo any
+---@param image any
+---@return any RL.SetGlyphInfoImage
+function RL.SetGlyphInfoImage( glyphInfo, image ) end
+
+---Get glyphInfo character value (Unicode)
+---- Success return int
+---@param glyphInfo any
+---@return any value
+function RL.GetGlyphInfoValue( glyphInfo ) end
+
+---Get glyphInfo character offset when drawing
+---- Success return Vector2
+---@param glyphInfo any
+---@return any offset
+function RL.GetGlyphInfoOffset( glyphInfo ) end
+
+---Get glyphInfo character advance position X
+---- Success return int
+---@param glyphInfo any
+---@return any advanceX
+function RL.GetGlyphInfoAdvanceX( glyphInfo ) end
+
+---Get glyphInfo character image data. Return as lightuserdata
+---- Success return Image
+---@param glyphInfo any
+---@return any image
+function RL.GetGlyphInfoImage( glyphInfo ) end
+
-- Models - Basic geometric 3D shapes drawing functions
---Draw a line in 3D world space
@@ -4201,7 +4318,7 @@ function RL.DrawBillboardPro( camera, texture, source, position, up, size, orig
-- Models - Mesh management functions
---Update mesh vertex data in GPU.
----Note! Mainly intented to be used with custom meshes.
+---NOTE: Mainly intented to be used with custom meshes.
---@param mesh any
---@param meshData table
---@return any RL.UpdateMesh
@@ -4409,7 +4526,7 @@ function RL.SetMaterialShader( material, shader ) end
---@return any RL.SetMaterialParams
function RL.SetMaterialParams( material, params ) end
----Get texture from material map type. Returns -1 if no texture
+---Get texture from material map type. Return as lightuserdata
---- Success return Texture
---@param material any
---@param mapType integer
@@ -4430,8 +4547,8 @@ function RL.GetMaterialColor( material, mapType ) end
---@return any value
function RL.GetMaterialValue( material, mapType ) end
----Get material shader
----- Success return Shader. Return as lightuserdata
+---Get material shader. Return as lightuserdata
+---- Success return Shader
---@param material any
---@return any shader
function RL.GetMaterialShader( material ) end
@@ -6191,7 +6308,7 @@ function RL.GetLightTarget( light ) end
function RL.GetLightColor( light ) end
---Get light enabled
----- Success return boolean
+---- Success return bool
---@param light any
---@return any enabled
function RL.IsLightEnabled( light ) end
@@ -6668,7 +6785,7 @@ function RL.rlUnloadVertexArray( vaoId ) end
---@return any RL.rlUnloadVertexBuffer
function RL.rlUnloadVertexBuffer( vboId ) end
----Set vertex attribute. Note! Pointer should be given in size of bytes
+---Set vertex attribute. NOTE: Pointer should be given in size of bytes
---@param index integer
---@param compSize integer
---@param type integer
diff --git a/changelog b/changelog
index 418aa66..1b9410a 100644
--- a/changelog
+++ b/changelog
@@ -27,6 +27,9 @@ KEY CHANGES:
- ADDED: Rest of rlRenderBatch functions.
- ADDED: DrawTextureNPatchRepeat.
- ADDED: GuiScrollBar and made it puplic in raygui.h.
+ - ADDED: Rest of font loading/unloading functions.
+ - CHANGE: GlyphInfo type to userdata.
+ - ADDED: GlyphInfo management functions.
DETAILED CHANGES:
- REMOVED: DrawLineBezierQuad, DrawLineBezierCubic.
@@ -52,6 +55,7 @@ DETAILED CHANGES:
- FIXED: rlSetVertexAttribute pointer offset.
- ADDED: GetImageData.
- FIXED: CameraLib. Slow lateral movement.
+ - ADDED: GetGlyphInfoByIndex and GetGlyphAtlasRecByIndex.
------------------------------------------------------------------------
Release: ReiLua version 0.6.0 Using Raylib 4.5
diff --git a/devnotes b/devnotes
index c72df1e..407cae9 100644
--- a/devnotes
+++ b/devnotes
@@ -11,9 +11,6 @@ Backlog {
* Text
* Text codepoints management functions (unicode characters)? Could be usefull for luajit.
* Some of the Text strings management functions could be easier to use than the Lua ones.
- * LoadFontFromMemory.
- * LoadFontData.
- * GenImageFontAtlas.
* Audio
* AudioStream.
* Core
diff --git a/docgen.lua b/docgen.lua
index f152463..625cbee 100644
--- a/docgen.lua
+++ b/docgen.lua
@@ -221,8 +221,17 @@ 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> GlyphInfo = Userdata\n\
+GlyphInfo, font characters glyphs info\n\
+```\
+glyphInfoData = {\
+ value = int, --Character value (Unicode)\
+ offsetX = int, --Character offset X when drawing\
+ offsetY = int, --Character offset Y when drawing\
+ advanceX = int, --Character advance position X\
+ image = Image, --Character image data\
+}\
+```\n\n---\n" )
apiFile:write( "\n> BoneInfo = { name = string[32], parent = int }\n\
Bone, skeletal animation bone\n\n---\n" )
apiFile:write( "\n> Transform = { translation = Vector3, rotation = Quaternion, scale = Vector3 }\n\
diff --git a/examples/2D_lights/main.lua b/examples/2D_lights/main.lua
index 9c033eb..d3aa4e9 100644
--- a/examples/2D_lights/main.lua
+++ b/examples/2D_lights/main.lua
@@ -103,21 +103,21 @@ function RL.init()
createShadowMesh()
- addLight( Vector2:new( 230, 480 ), Color:new( RL.ORANGE ), 512 )
- addLight( Vector2:new( 600, 200 ), Color:new( RL.RED ), 512 )
- addLight( Vector2:new( 384, 520 ), Color:new( RL.GREEN ), 400 )
- addLight( Vector2:new( 880, 750 ), Color:new( RL.BLUE ), 300 )
- addLight( Vector2:new( 800, 500 ), Color:new( RL.PURPLE ), 512 )
- addLight( Vector2:new( 200, 760 ), Color:new( RL.WHITE ), 400 )
+ -- addLight( Vector2:new( 230, 480 ), Color:new( RL.ORANGE ), 512 )
+ -- addLight( Vector2:new( 600, 200 ), Color:new( RL.RED ), 512 )
+ -- addLight( Vector2:new( 384, 520 ), Color:new( RL.GREEN ), 400 )
+ -- addLight( Vector2:new( 880, 750 ), Color:new( RL.BLUE ), 300 )
+ -- addLight( Vector2:new( 800, 500 ), Color:new( RL.PURPLE ), 512 )
+ -- addLight( Vector2:new( 200, 760 ), Color:new( RL.WHITE ), 400 )
-- Stress test
- -- for i = 1, 300 do
- -- addLight( Vector2:new( math.random( 20, RESOLUTION.x - 20 ), math.random( 20, RESOLUTION.y - 20 ) ),
- -- Color:new( { math.random( 40, 255 ), math.random( 40, 255 ), math.random( 40, 255 ), 255 } ),
- -- 128
- -- )
- -- end
+ for i = 1, 300 do
+ addLight( Vector2:new( math.random( 20, RESOLUTION.x - 20 ), math.random( 20, RESOLUTION.y - 20 ) ),
+ Color:new( { math.random( 40, 255 ), math.random( 40, 255 ), math.random( 40, 255 ), 255 } ),
+ 128
+ )
+ end
-- Camera for shadow rendering.
camera = RL.CreateCamera3D()
diff --git a/examples/free_camera3d/main.lua b/examples/free_camera3d/main.lua
index 30cee08..f1f11ee 100644
--- a/examples/free_camera3d/main.lua
+++ b/examples/free_camera3d/main.lua
@@ -19,6 +19,7 @@ function RL.init()
RL.SetWindowState( RL.FLAG_VSYNC_HINT )
RL.SetWindowSize( winSize )
RL.SetWindowPosition( { mPos.x + mSize.x / 2 - winSize.x / 2, mPos.y + mSize.y / 2 - winSize.y / 2 } )
+ RL.SetTextLineSpacing( 26 )
camera = Cam3D:new()
diff --git a/examples/raygui_custom/main.lua b/examples/raygui_custom/main.lua
new file mode 100644
index 0000000..c11d321
--- /dev/null
+++ b/examples/raygui_custom/main.lua
@@ -0,0 +1,89 @@
+package.path = package.path..";"..RL.GetBasePath().."?.lua"
+package.path = package.path..";"..RL.GetBasePath().."../resources/lib/?.lua"
+
+Util = require( "utillib" )
+Rect = require( "rectangle" )
+Vec2 = require( "vector2" )
+Color = require( "color" )
+Rect = require( "rectangle" )
+Raygui = require( "raygui" )
+
+Gui = Raygui:new()
+SpriteButton = require( "spriteButton" )
+SpriteButton:register( Gui )
+local buttonTexture = nil
+
+local resolution = Vec2:new( 640, 480 )
+local winSize = Vec2:new()
+local framebuffer = nil
+
+local function addButton( bounds, text, callback )
+ local button = Gui:SpriteButton(
+ bounds,
+ text,
+ buttonTexture,
+ { source = { 0, 0, 48, 48 }, left = 16, top = 16, right = 16, bottom = 16, layout = RL.NPATCH_NINE_PATCH },
+ { source = { 48, 0, 48, 48 }, left = 16, top = 16, right = 16, bottom = 16, layout = RL.NPATCH_NINE_PATCH },
+ callback
+ )
+ button.styles = {
+ { RL.LABEL, RL.TEXT_ALIGNMENT, RL.TEXT_ALIGN_CENTER },
+ { RL.LABEL, RL.TEXT_COLOR_NORMAL, RL.ColorToInt( { 84, 59, 22 } ) },
+ { RL.LABEL, RL.TEXT_COLOR_PRESSED, RL.ColorToInt( { 84/2, 59/2, 22/2 } ) },
+ { RL.LABEL, RL.TEXT_COLOR_FOCUSED, RL.ColorToInt( RL.GREEN ) },
+ }
+end
+
+function RL.init()
+ local monitor = 0
+ local mPos = Vec2:new( RL.GetMonitorPosition( monitor ) )
+ local mSize = Vec2:new( RL.GetMonitorSize( monitor ) )
+ local winScale = 2
+ winSize = resolution:scale( winScale )
+
+ framebuffer = RL.LoadRenderTexture( resolution )
+
+ RL.SetWindowState( RL.FLAG_WINDOW_RESIZABLE )
+ RL.SetWindowState( RL.FLAG_VSYNC_HINT )
+ RL.SetWindowSize( resolution:scale( winScale ) )
+ RL.SetWindowPosition( { mPos.x + mSize.x / 2 - winSize.x / 2, mPos.y + mSize.y / 2 - winSize.y / 2 } )
+
+ RL.SetMouseScale( { 1/winScale, 1/winScale } )
+
+ RL.GuiSetStyle( RL.DEFAULT, RL.TEXT_SIZE, 20 )
+ RL.GuiSetStyle( RL.DEFAULT, RL.TEXT_SPACING, 4 )
+
+ buttonTexture = RL.LoadTexture( RL.GetBasePath().."../resources/images/button.png" )
+
+ local buttonSize = Vec2:new( 216, 32 )
+ local bounds = Rect:new( resolution.x / 2 - buttonSize.x / 2, 200, buttonSize.x, buttonSize.y )
+ local gap = buttonSize.y + 2
+ addButton( bounds, "Start New Game", function() print( "New Game!" ) end )
+ bounds.y = bounds.y + gap
+ addButton( bounds, "Load Game", function() print( "Load Game!" ) end )
+ bounds.y = bounds.y + gap
+ addButton( bounds, "Options", function() print( "Options!" ) end )
+ bounds.y = bounds.y + gap
+ addButton( bounds, "Quit", function() RL.CloseWindow() end )
+end
+
+function RL.process( delta )
+ Gui:process()
+end
+
+function RL.draw()
+ RL.ClearBackground( RL.BLACK )
+ RL.BeginTextureMode( framebuffer )
+ RL.ClearBackground( { 50, 20, 75 } )
+ Gui:draw()
+ RL.EndTextureMode()
+
+ RL.DrawTexturePro(
+ RL.GetRenderTextureTexture( framebuffer ),
+ { 0, 0, resolution.x, -resolution.y },
+ { 0, 0, winSize.x, winSize.y },
+ { 0, 0 },
+ 0.0,
+ RL.WHITE
+ )
+end
diff --git a/examples/raygui_custom/spriteButton.lua b/examples/raygui_custom/spriteButton.lua
new file mode 100644
index 0000000..b37b208
--- /dev/null
+++ b/examples/raygui_custom/spriteButton.lua
@@ -0,0 +1,54 @@
+--- Button control
+local SpriteButton = {}
+SpriteButton.__index = SpriteButton
+
+function SpriteButton:new( bounds, text, texture, nPatchNormal, nPatchPressed, callback )
+ local object = setmetatable( {}, self )
+ object._parent = nil
+
+ object.bounds = bounds:clone()
+ object.text = text
+ object.buttonTexture = texture
+ object.nPatchNormal = nPatchNormal
+ object.nPatchPressed = nPatchPressed
+ object.callback = callback
+
+ object.visible = true
+ object.disabled = false
+
+ return object
+end
+
+function SpriteButton:process()
+ return RL.CheckCollisionPointRec( RL.GetMousePosition(), self.bounds )
+end
+
+function SpriteButton:draw()
+ if RL.IsMouseButtonDown( RL.MOUSE_BUTTON_LEFT ) and self:process() then
+ RL.DrawTextureNPatchRepeat( self.buttonTexture, self.nPatchPressed, self.bounds, { 0, 0 }, 0.0, RL.WHITE )
+ else
+ RL.DrawTextureNPatchRepeat( self.buttonTexture, self.nPatchNormal, self.bounds, { 0, 0 }, 0.0, RL.WHITE )
+ end
+
+ local result = RL.GuiLabelButton( self.bounds, self.text )
+
+ if result == 1 then
+ if self.callback ~= nil then
+ self.callback( self )
+ end
+ end
+
+end
+
+function SpriteButton:setPosition( pos )
+ self.bounds.x = pos.x
+ self.bounds.y = pos.y
+end
+
+function SpriteButton:register( gui )
+ function gui:SpriteButton( bounds, text, texture, nPatchNormal, nPatchPressed, callback )
+ return self:addElement( SpriteButton:new( bounds, text, texture, nPatchNormal, nPatchPressed, callback ) )
+ end
+end
+
+return SpriteButton
diff --git a/examples/resources/images/LICENCE b/examples/resources/images/LICENCE
index 8666043..9f8248a 100644
--- a/examples/resources/images/LICENCE
+++ b/examples/resources/images/LICENCE
@@ -9,6 +9,7 @@ ui_bgr.png Jussi Viitala CC0
gradient.png Jussi Viitala CC0
light.png Jussi Viitala CC0
nPatch.png Jussi Viitala CC0
+button.png Jussi Viitala CC0
check-mark.png Delapouite Creative Commons 3.0 https://game-icons.net Resized
circle.png Delapouite Creative Commons 3.0 https://game-icons.net Resized
plain-circle.png Delapouite Creative Commons 3.0 https://game-icons.net Resized
diff --git a/examples/resources/images/button.png b/examples/resources/images/button.png
new file mode 100644
index 0000000..372c4eb
--- /dev/null
+++ b/examples/resources/images/button.png
Binary files differ
diff --git a/examples/resources/lib/rectangle.lua b/examples/resources/lib/rectangle.lua
index 4a4fe66..ba1f9c6 100644
--- a/examples/resources/lib/rectangle.lua
+++ b/examples/resources/lib/rectangle.lua
@@ -32,9 +32,6 @@ Rectangle.meta = {
__unm = function( r )
return Rectangle:new( -r.x, -r.y, -r.width, -r.height )
end,
- __idiv = function( r, v )
- return Rectangle:new( r.x // v, r.y // v, r.width // v, r.height // v )
- end,
__len = function()
return 4
end,
diff --git a/examples/window/main.lua b/examples/window/main.lua
index 63c18d7..6111ffa 100644
--- a/examples/window/main.lua
+++ b/examples/window/main.lua
@@ -9,7 +9,7 @@ end
function RL.process( delta )
if RL.IsKeyPressed( RL.KEY_ENTER ) then
- local textSize = RL.MeasureText( 0, text, 20, 2 )
+ local textSize = RL.MeasureText( RL.GetFontDefault(), text, 20, 2 )
local winSize = RL.GetScreenSize()
textColor = RL.BLUE
diff --git a/include/lua_core.h b/include/lua_core.h
index ba56f27..59ebb8f 100644
--- a/include/lua_core.h
+++ b/include/lua_core.h
@@ -45,7 +45,6 @@ Matrix uluaGetMatrix( lua_State *L, int index );
BoundingBox uluaGetBoundingBox( lua_State *L, int index );
Ray uluaGetRay( lua_State *L, int index );
NPatchInfo uluaGetNPatchInfo( lua_State *L, int index );
-GlyphInfo uluaGetGlyphInfo( lua_State *L, int index );
BoneInfo uluaGetBoneInfo( lua_State *L, int index );
Transform uluaGetTransform( lua_State *L, int index );
Buffer* uluaGetBuffer( lua_State *L, int index );
@@ -57,6 +56,7 @@ Mesh* uluaGetMesh( lua_State *L, int index );
Camera2D* uluaGetCamera2D( lua_State *L, int index );
Camera3D* uluaGetCamera3D( lua_State *L, int index );
Font* uluaGetFont( lua_State *L, int index );
+GlyphInfo* uluaGetGlyphInfo( lua_State *L, int index );
Wave* uluaGetWave( lua_State *L, int index );
Sound* uluaGetSound( lua_State *L, int index );
Music* uluaGetMusic( lua_State *L, int index );
@@ -76,7 +76,6 @@ 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 uluaPushBoneInfo( lua_State *L, BoneInfo boneInfo );
void uluaPushTransform( lua_State *L, Transform transform );
void uluaPushBuffer( lua_State *L, Buffer buffer );
@@ -87,6 +86,7 @@ void uluaPushCamera2D( lua_State *L, Camera2D camera );
void uluaPushCamera3D( lua_State *L, Camera3D camera );
void uluaPushShader( lua_State *L, Shader shader );
void uluaPushFont( lua_State *L, Font font );
+void uluaPushGlyphInfo( lua_State *L, GlyphInfo glyph );
void uluaPushWave( lua_State *L, Wave wave );
void uluaPushSound( lua_State *L, Sound sound );
void uluaPushMusic( lua_State *L, Music music );
diff --git a/include/text.h b/include/text.h
index a38f979..96c9b82 100644
--- a/include/text.h
+++ b/include/text.h
@@ -1,12 +1,18 @@
#pragma once
+void unloadGlyphInfo( GlyphInfo *glyph );
/* Font loading/unloading functions. */
int ltextGetFontDefault( lua_State *L );
int ltextLoadFont( lua_State *L );
int ltextLoadFontEx( lua_State *L );
int ltextLoadFontFromImage( lua_State *L );
+int ltextLoadFontFromMemory( lua_State *L );
+int ltextLoadFontFromData( lua_State *L );
int ltextIsFontReady( lua_State *L );
+int ltextLoadFontData( lua_State *L );
+int ltextGenImageFontAtlas( lua_State *L );
int ltextUnloadFont( lua_State *L );
+int ltextExportFontAsCode( lua_State *L );
/* Text drawing functions. */
int ltextDrawFPS( lua_State *L );
int ltextDrawText( lua_State *L );
@@ -21,8 +27,21 @@ int ltextSetTextLineSpacing( lua_State *L );
int ltextMeasureText( lua_State *L );
int ltextGetGlyphIndex( lua_State *L );
int ltextGetGlyphInfo( lua_State *L );
+int ltextGetGlyphInfoByIndex( lua_State *L );
int ltextGetGlyphAtlasRec( lua_State *L );
+int ltextGetGlyphAtlasRecByIndex( lua_State *L );
int ltextGetFontBaseSize( lua_State *L );
int ltextGetFontGlyphCount( lua_State *L );
int ltextGetFontGlyphPadding( lua_State *L );
int ltextGetFontTexture( lua_State *L );
+/* GlyphInfo management functions. */
+int ltextLoadGlyphInfo( lua_State *L );
+int ltextUnloadGlyphInfo( lua_State *L );
+int ltextSetGlyphInfoValue( lua_State *L );
+int ltextSetGlyphInfoOffset( lua_State *L );
+int ltextSetGlyphInfoAdvanceX( lua_State *L );
+int ltextSetGlyphInfoImage( lua_State *L );
+int ltextGetGlyphInfoValue( lua_State *L );
+int ltextGetGlyphInfoOffset( lua_State *L );
+int ltextGetGlyphInfoAdvanceX( lua_State *L );
+int ltextGetGlyphInfoImage( lua_State *L );
diff --git a/src/lights.c b/src/lights.c
index 7131c99..bef40a5 100644
--- a/src/lights.c
+++ b/src/lights.c
@@ -179,7 +179,7 @@ int llightsGetLightColor( lua_State *L ) {
Get light enabled
-- Success return boolean
+- Success return bool
*/
int llightsIsLightEnabled( lua_State *L ) {
Light *light = uluaGetLight( L, 1 );
diff --git a/src/lua_core.c b/src/lua_core.c
index 45ea370..820cc20 100644
--- a/src/lua_core.c
+++ b/src/lua_core.c
@@ -156,6 +156,25 @@ static void defineFont() {
lua_setfield( L, -2, "__gc" );
}
+ /* GlyphInfo. */
+static int gcGlyphInfo( lua_State *L ) {
+ if ( state->gcUnload ) {
+ GlyphInfo *glyph = luaL_checkudata( L, 1, "GlyphInfo" );
+ unloadGlyphInfo( glyph );
+ }
+ return 0;
+}
+
+static void defineGlyphInfo() {
+ lua_State *L = state->luaState;
+
+ luaL_newmetatable( L, "GlyphInfo" );
+ lua_pushvalue( L, -1 );
+ lua_setfield( L, -2, "__index" );
+ lua_pushcfunction( L, gcGlyphInfo );
+ lua_setfield( L, -2, "__gc" );
+}
+
/* Wave. */
static int gcWave( lua_State *L ) {
if ( state->gcUnload ) {
@@ -357,7 +376,7 @@ static void defineGlobals() {
lua_setglobal( L, "RL" );
lua_getglobal( L, "RL" );
-/* Note! Docgen relyes on this line format. */
+/* Note! Docgen rely on this line format. */
/*DOC_DEFINES_START*/
/* System/Window config flags */
assignGlobalInt( FLAG_VSYNC_HINT, "FLAG_VSYNC_HINT" ); // Set to try enabling V-Sync on GPU
@@ -1004,6 +1023,7 @@ bool luaInit( int argn, const char **argc ) {
defineCamera3D();
defineShader();
defineFont();
+ defineGlyphInfo();
defineWave();
defineSound();
defineMusic();
@@ -1697,8 +1717,13 @@ void luaRegister() {
assingGlobalFunction( "LoadFont", ltextLoadFont );
assingGlobalFunction( "LoadFontEx", ltextLoadFontEx );
assingGlobalFunction( "LoadFontFromImage", ltextLoadFontFromImage );
+ assingGlobalFunction( "LoadFontFromMemory", ltextLoadFontFromMemory );
+ assingGlobalFunction( "LoadFontFromData", ltextLoadFontFromData );
assingGlobalFunction( "IsFontReady", ltextIsFontReady );
+ assingGlobalFunction( "LoadFontData", ltextLoadFontData );
+ assingGlobalFunction( "GenImageFontAtlas", ltextGenImageFontAtlas );
assingGlobalFunction( "UnloadFont", ltextUnloadFont );
+ assingGlobalFunction( "ExportFontAsCode", ltextExportFontAsCode );
/* Text drawing functions. */
assingGlobalFunction( "DrawFPS", ltextDrawFPS );
assingGlobalFunction( "DrawText", ltextDrawText );
@@ -1713,11 +1738,24 @@ void luaRegister() {
assingGlobalFunction( "MeasureText", ltextMeasureText );
assingGlobalFunction( "GetGlyphIndex", ltextGetGlyphIndex );
assingGlobalFunction( "GetGlyphInfo", ltextGetGlyphInfo );
+ assingGlobalFunction( "GetGlyphInfoByIndex", ltextGetGlyphInfoByIndex );
assingGlobalFunction( "GetGlyphAtlasRec", ltextGetGlyphAtlasRec );
+ assingGlobalFunction( "GetGlyphAtlasRecByIndex", ltextGetGlyphAtlasRecByIndex );
assingGlobalFunction( "GetFontBaseSize", ltextGetFontBaseSize );
assingGlobalFunction( "GetFontGlyphCount", ltextGetFontGlyphCount );
assingGlobalFunction( "GetFontGlyphPadding", ltextGetFontGlyphPadding );
assingGlobalFunction( "GetFontTexture", ltextGetFontTexture );
+ /* GlyphInfo management functions. */
+ assingGlobalFunction( "LoadGlyphInfo", ltextLoadGlyphInfo );
+ assingGlobalFunction( "UnloadGlyphInfo", ltextUnloadGlyphInfo );
+ assingGlobalFunction( "SetGlyphInfoValue", ltextSetGlyphInfoValue );
+ assingGlobalFunction( "SetGlyphInfoOffset", ltextSetGlyphInfoOffset );
+ assingGlobalFunction( "SetGlyphInfoAdvanceX", ltextSetGlyphInfoAdvanceX );
+ assingGlobalFunction( "SetGlyphInfoImage", ltextSetGlyphInfoImage );
+ assingGlobalFunction( "GetGlyphInfoValue", ltextGetGlyphInfoValue );
+ assingGlobalFunction( "GetGlyphInfoOffset", ltextGetGlyphInfoOffset );
+ assingGlobalFunction( "GetGlyphInfoAdvanceX", ltextGetGlyphInfoAdvanceX );
+ assingGlobalFunction( "GetGlyphInfoImage", ltextGetGlyphInfoImage );
/* Audio. */
/* Audio device management functions. */
@@ -2623,59 +2661,6 @@ NPatchInfo uluaGetNPatchInfo( lua_State *L, int index ) {
return npatch;
}
-GlyphInfo uluaGetGlyphInfo( lua_State *L, int index ) {
- luaL_checktype( L, index, LUA_TTABLE );
- GlyphInfo glyph = { 0 };
-
- int t = index, i = 0;
- lua_pushnil( L );
-
- while ( lua_next( L, t ) != 0 ) {
- /* Do not check type since there should be table and ints. */
- if ( lua_isnumber( L, -2 ) ) {
- switch ( i ) {
- case 0:
- glyph.value = lua_tointeger( L, -1 );
- break;
- case 1:
- glyph.offsetX = lua_tointeger( L, -1 );
- break;
- case 2:
- glyph.offsetY = lua_tointeger( L, -1 );
- break;
- case 3:
- glyph.advanceX = lua_tointeger( L, -1 );
- break;
- case 4:
- glyph.image = *uluaGetImage( L, lua_gettop( L ) );
- break;
- default:
- break;
- }
- }
- else if ( lua_isstring( L, -2 ) ) {
- if ( strcmp( "value", (char*)lua_tostring( L, -2 ) ) == 0 ) {
- glyph.value = lua_tointeger( L, -1 );
- }
- else if ( strcmp( "offsetX", (char*)lua_tostring( L, -2 ) ) == 0 ) {
- glyph.offsetX = lua_tointeger( L, -1 );
- }
- else if ( strcmp( "offsetY", (char*)lua_tostring( L, -2 ) ) == 0 ) {
- glyph.offsetY = lua_tointeger( L, -1 );
- }
- else if ( strcmp( "advanceX", (char*)lua_tostring( L, -2 ) ) == 0 ) {
- glyph.advanceX = lua_tointeger( L, -1 );
- }
- else if ( strcmp( "image", (char*)lua_tostring( L, -2 ) ) == 0 ) {
- glyph.image = *uluaGetImage( L, lua_gettop( L ) );
- }
- }
- i++;
- lua_pop( L, 1 );
- }
- return glyph;
-}
-
BoneInfo uluaGetBoneInfo( lua_State *L, int index ) {
luaL_checktype( L, index, LUA_TTABLE );
BoneInfo bone = { 0 };
@@ -2819,6 +2804,13 @@ Font* uluaGetFont( lua_State *L, int index ) {
return luaL_checkudata( L, index, "Font" );
}
+GlyphInfo* uluaGetGlyphInfo( lua_State *L, int index ) {
+ if ( lua_islightuserdata( L, index ) ) {
+ return (GlyphInfo*)lua_touserdata( L, index );
+ }
+ return luaL_checkudata( L, index, "GlyphInfo" );
+}
+
Wave* uluaGetWave( lua_State *L, int index ) {
if ( lua_islightuserdata( L, index ) ) {
return (Wave*)lua_touserdata( L, index );
@@ -3047,20 +3039,6 @@ void uluaPushBoundingBox( lua_State *L, BoundingBox box ) {
lua_rawseti( L, -2, 2 );
}
-void uluaPushGlyphInfo( lua_State *L, GlyphInfo glyphInfo, Image *image ) {
- lua_createtable( L, 5, 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 uluaPushBoneInfo( lua_State *L, BoneInfo boneInfo ) {
lua_createtable( L, 2, 0 );
lua_pushstring( L, boneInfo.name );
@@ -3130,6 +3108,12 @@ void uluaPushFont( lua_State *L, Font font ) {
luaL_setmetatable( L, "Font" );
}
+void uluaPushGlyphInfo( lua_State *L, GlyphInfo glyph ) {
+ GlyphInfo *glyphP = lua_newuserdata( L, sizeof( GlyphInfo ) );
+ *glyphP = glyph;
+ luaL_setmetatable( L, "GlyphInfo" );
+}
+
void uluaPushWave( lua_State *L, Wave wave ) {
Wave *waveP = lua_newuserdata( L, sizeof( Wave ) );
*waveP = wave;
diff --git a/src/models.c b/src/models.c
index b65fccf..84e0b1a 100644
--- a/src/models.c
+++ b/src/models.c
@@ -981,7 +981,7 @@ int lmodelsDrawBillboardPro( lua_State *L ) {
> RL.UpdateMesh( Mesh mesh, Mesh{} meshData )
Update mesh vertex data in GPU.
-Note! Mainly intented to be used with custom meshes.
+NOTE: Mainly intented to be used with custom meshes.
*/
int lmodelsUpdateMesh( lua_State *L ) {
Mesh *mesh = uluaGetMesh( L, 1 );
@@ -1820,7 +1820,7 @@ int lmodelsSetMaterialParams( lua_State *L ) {
/*
> texture = RL.GetMaterialTexture( Material material, int mapType )
-Get texture from material map type. Returns -1 if no texture
+Get texture from material map type. Return as lightuserdata
- Success return Texture
*/
@@ -1828,7 +1828,7 @@ int lmodelsGetMaterialTexture( lua_State *L ) {
Material *material = uluaGetMaterial( L, 1 );
int mapType = luaL_checkinteger( L, 2 );
- uluaPushTexture( L, material->maps[ mapType ].texture );
+ lua_pushlightuserdata( L, &material->maps[ mapType ].texture );
return 1;
}
@@ -1868,9 +1868,9 @@ int lmodelsGetMaterialValue( lua_State *L ) {
/*
> shader = RL.GetMaterialShader( Material material )
-Get material shader
+Get material shader. Return as lightuserdata
-- Success return Shader. Return as lightuserdata
+- Success return Shader
*/
int lmodelsGetMaterialShader( lua_State *L ) {
Material *material = uluaGetMaterial( L, 1 );
diff --git a/src/platforms/core_desktop.c b/src/platforms/core_desktop.c
index fa47d4a..a9c9527 100644
--- a/src/platforms/core_desktop.c
+++ b/src/platforms/core_desktop.c
@@ -517,7 +517,7 @@ static void joystickEvent( int jid, int event ) {
> GLFWpentabletdataEvent = { int type, float x, float y, float z, float pressure, float pitch, float yaw, float roll }
Called when the pen tablet data is updated. Type GLFW_PEN_TABLET_DATA_EVENT
-NOTE! Experimental. Needs glfw PR https://github.com/glfw/glfw/pull/1445
+NOTE: Experimental. Needs glfw PR https://github.com/glfw/glfw/pull/1445
*/
static void penTabletDataEvent( double x, double y, double z, double pressure, double pitch, double yaw, double roll ) {
lua_State *L = state->luaState;
@@ -559,7 +559,7 @@ static void penTabletDataEvent( double x, double y, double z, double pressure, d
> GLFWpentabletcursorEvent = { int type, int identifier }
Called when the pen tablet cursor has changed. Type GLFW_PEN_TABLET_CURSOR_EVENT
-NOTE! Experimental. Needs glfw PR https://github.com/glfw/glfw/pull/1445
+NOTE: Experimental. Needs glfw PR https://github.com/glfw/glfw/pull/1445
*/
static void penTabletCursorEvent( unsigned int identifier ) {
lua_State *L = state->luaState;
@@ -589,7 +589,7 @@ static void penTabletCursorEvent( unsigned int identifier ) {
> GLFWpentabletproximityEvent = { int type, int proxState }
Called when the pen tablet proximity has changed. Type GLFW_PEN_TABLET_PROXIMITY_EVENT
-NOTE! Experimental. Needs glfw PR https://github.com/glfw/glfw/pull/1445
+NOTE: Experimental. Needs glfw PR https://github.com/glfw/glfw/pull/1445
*/
static void penTabletProximityEvent( int proxState ) {
lua_State *L = state->luaState;
diff --git a/src/rlgl.c b/src/rlgl.c
index 02e2f75..4f45c19 100644
--- a/src/rlgl.c
+++ b/src/rlgl.c
@@ -1163,7 +1163,7 @@ int lrlglUnloadVertexBuffer( lua_State *L ) {
/*
> RL.rlSetVertexAttribute( int index, int compSize, int type, bool normalized, int stride, int pointer )
-Set vertex attribute. Note! Pointer should be given in size of bytes
+Set vertex attribute. NOTE: Pointer should be given in size of bytes
*/
int lrlglSetVertexAttribute( lua_State *L ) {
int index = luaL_checkinteger( L, 1 );
diff --git a/src/text.c b/src/text.c
index a670f3b..d44e8c1 100644
--- a/src/text.c
+++ b/src/text.c
@@ -4,6 +4,10 @@
#include "textures.h"
#include "lua_core.h"
+void unloadGlyphInfo( GlyphInfo *glyph ) {
+ UnloadImage( glyph->image );
+}
+
// DrawTextBoxed is modified DrawTextBoxedSelectable from raylib [text] example - Rectangle bounds
// Draw text using font inside rectangle limits
@@ -157,6 +161,18 @@ bool wordWrap, Color *tints, int tintCount, Color *backTints, int backTintCount
return mouseChar;
}
+static inline void getCodepoints( lua_State *L, int codepoints[], int index ) {
+ int t = index;
+ int i = 0;
+ lua_pushnil( L );
+
+ while ( lua_next( L, t ) != 0 ) {
+ codepoints[i] = lua_tointeger( L, -1 );
+ i++;
+ lua_pop( L, 1 );
+ }
+}
+
/*
## Text - Font loading/unloading functions
*/
@@ -210,16 +226,7 @@ int ltextLoadFontEx( lua_State *L ) {
int codepointCount = uluaGetTableLen( L, 3 );
int codepoints[ codepointCount ];
- int t = 3;
- int i = 0;
- lua_pushnil( L );
-
- while ( lua_next( L, t ) != 0 ) {
- codepoints[i] = lua_tointeger( L, -1 );
-
- i++;
- lua_pop( L, 1 );
- }
+ getCodepoints( L, codepoints, 3 );
uluaPushFont( L, LoadFontEx( lua_tostring( L, 1 ), fontSize, codepoints, codepointCount ) );
return 1;
@@ -252,6 +259,94 @@ int ltextLoadFontFromImage( lua_State *L ) {
}
/*
+> font = RL.LoadFontFromMemory( string fileType, Buffer fileData, int fontSize, int{} codepoints )
+
+Load font from memory buffer, fileType refers to extension: i.e. '.ttf'. NOTE: fileData type should be unsigned char
+
+- Success return Font
+*/
+int ltextLoadFontFromMemory( lua_State *L ) {
+ const char *fileType = luaL_checkstring( L, 1 );
+ Buffer *fileData = uluaGetBuffer( L, 2 );
+ int fontSize = luaL_checkinteger( L, 3 );
+
+ if ( lua_istable( L, 4 ) ) {
+ int codepointCount = uluaGetTableLen( L, 4 );
+ int codepoints[ codepointCount ];
+
+ getCodepoints( L, codepoints, 4 );
+ uluaPushFont( L, LoadFontFromMemory( fileType, fileData->data, fileData->size, fontSize, codepoints, codepointCount ) );
+
+ return 1;
+ }
+ /* If no codepoints provided. */
+ uluaPushFont( L, LoadFontFromMemory( fileType, fileData->data, fileData->size, fontSize, NULL, 0 ) );
+
+ return 1;
+}
+
+/*
+> font = RL.LoadFontFromData( Font{} fontData )
+
+Load Font from data
+
+- Success return Font
+*/
+int ltextLoadFontFromData( lua_State *L ) {
+ luaL_checktype( L, 1, LUA_TTABLE );
+
+ Font font = { 0 };
+
+ int t = 1;
+ lua_pushnil( L );
+
+ while ( lua_next( L, t ) != 0 ) {
+ if ( strcmp( "baseSize", (char*)lua_tostring( L, -2 ) ) == 0 ) {
+ font.baseSize = luaL_checkinteger( L, -1 );
+ }
+ else if ( strcmp( "glyphCount", (char*)lua_tostring( L, -2 ) ) == 0 ) {
+ font.glyphCount = luaL_checkinteger( L, -1 );
+ }
+ else if ( strcmp( "glyphPadding", (char*)lua_tostring( L, -2 ) ) == 0 ) {
+ font.glyphPadding = luaL_checkinteger( L, -1 );
+ }
+ else if ( strcmp( "texture", (char*)lua_tostring( L, -2 ) ) == 0 ) {
+ font.texture = *uluaGetTexture( L, lua_gettop( L ) );
+ }
+ else if ( strcmp( "recs", (char*)lua_tostring( L, -2 ) ) == 0 ) {
+ int recCount = uluaGetTableLen( L, lua_gettop( L ) );
+ font.recs = malloc( recCount * sizeof( Rectangle ) );
+ int t2 = lua_gettop( L );
+ int i = 0;
+ lua_pushnil( L );
+
+ while ( lua_next( L, t2 ) != 0 ) {
+ font.recs[i] = uluaGetRectangle( L, lua_gettop( L ) );
+ i++;
+ lua_pop( L, 1 );
+ }
+ }
+ else if ( strcmp( "glyphs", (char*)lua_tostring( L, -2 ) ) == 0 ) {
+ int glyphCount = uluaGetTableLen( L, lua_gettop( L ) );
+ font.glyphs = malloc( glyphCount * sizeof( GlyphInfo ) );
+ int t2 = lua_gettop( L );
+ int i = 0;
+ lua_pushnil( L );
+
+ while ( lua_next( L, t2 ) != 0 ) {
+ font.glyphs[i] = *uluaGetGlyphInfo( L, lua_gettop( L ) );
+ i++;
+ lua_pop( L, 1 );
+ }
+ }
+ lua_pop( L, 1 );
+ }
+ uluaPushFont( L, font );
+
+ return 1;
+}
+
+/*
> isReady = RL.IsFontReady( Font font )
Check if a font is ready
@@ -267,6 +362,84 @@ int ltextIsFontReady( lua_State *L ) {
}
/*
+> glyphs = RL.LoadFontData( Buffer fileData, int fontSize, int{} codepoints, int type )
+
+Load font data for further use. NOTE: fileData type should be unsigned char
+
+- Success return GlyphInfo{}
+*/
+int ltextLoadFontData( lua_State *L ) {
+ Buffer *fileData = uluaGetBuffer( L, 1 );
+ int fontSize = luaL_checkinteger( L, 2 );
+ int type = luaL_checkinteger( L, 4 );
+ int codepointCount = 95; // In case no chars count provided, default to 95.
+
+ if ( lua_istable( L, 3 ) ) {
+ codepointCount = uluaGetTableLen( L, 3 );
+ int codepoints[ codepointCount ];
+
+ getCodepoints( L, codepoints, 3 );
+ GlyphInfo *glyphs = LoadFontData( fileData->data, fileData->size, fontSize, codepoints, codepointCount, type );
+ lua_createtable( L, codepointCount, 0 );
+
+ for ( int i = 0; i < codepointCount; i++ ) {
+ uluaPushGlyphInfo( L, glyphs[i] );
+ lua_rawseti( L, -2, i + 1 );
+ }
+ UnloadFontData( glyphs, codepointCount );
+
+ return 1;
+ }
+ /* If no codepoints provided. */
+ GlyphInfo *glyphs = LoadFontData( fileData->data, fileData->size, fontSize, NULL, 0, type );
+ lua_createtable( L, codepointCount, 0 );
+
+ for ( int i = 0; i < codepointCount; i++ ) {
+ uluaPushGlyphInfo( L, glyphs[i] );
+ lua_rawseti( L, -2, i + 1 );
+ }
+ UnloadFontData( glyphs, codepointCount );
+
+ return 1;
+}
+
+/*
+> image, rectangles = RL.GenImageFontAtlas( GlyphInfo{} glyphs, int fontSize, int padding, int packMethod )
+
+Generate image font atlas using chars info. NOTE: Packing method: 0-Default, 1-Skyline
+
+- Success Image, Rectangle{}
+*/
+int ltextGenImageFontAtlas( lua_State *L ) {
+ int fontSize = luaL_checkinteger( L, 2 );
+ int padding = luaL_checkinteger( L, 3 );
+ int packMethod = luaL_checkinteger( L, 4 );
+
+ int glyphCount = uluaGetTableLen( L, 1 );
+ GlyphInfo glyphs[ glyphCount ];
+ Rectangle *glyphRecs;
+
+ int t = 1;
+ int i = 0;
+ lua_pushnil( L );
+
+ while ( lua_next( L, t ) != 0 ) {
+ glyphs[i] = *uluaGetGlyphInfo( L, lua_gettop( L ) );
+ i++;
+ lua_pop( L, 1 );
+ }
+ uluaPushImage( L, GenImageFontAtlas( glyphs, &glyphRecs, glyphCount, fontSize, padding, packMethod ) );
+ lua_createtable( L, glyphCount, 0 );
+
+ for ( i = 0; i < glyphCount; i++ ) {
+ uluaPushRectangle( L, glyphRecs[i] );
+ lua_rawseti( L, -2, i + 1 );
+ }
+
+ return 2;
+}
+
+/*
> RL.UnloadFont( Font font )
Unload font from GPU memory (VRAM)
@@ -280,6 +453,22 @@ int ltextUnloadFont( lua_State *L ) {
}
/*
+> RL.ExportFontAsCode( Font font, string fileName )
+
+Export font as code file, returns true on success
+
+- Success return bool
+*/
+int ltextExportFontAsCode( lua_State *L ) {
+ Font *font = uluaGetFont( L, 1 );
+ const char *fileName = luaL_checkstring( L, 2 );
+
+ lua_pushboolean( L, ExportFontAsCode( *font, fileName ) );
+
+ return 1;
+}
+
+/*
## Text - Text drawing functions
*/
@@ -509,8 +698,7 @@ int ltextGetGlyphIndex( lua_State *L ) {
/*
> 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
+Get glyph font info data for a codepoint (unicode character), fallback to '?' if not found
- Success return GlyphInfo
*/
@@ -519,7 +707,30 @@ int ltextGetGlyphInfo( lua_State *L ) {
int codepoint = luaL_checkinteger( L, 2 );
int id = GetGlyphIndex( *font, codepoint );
- uluaPushGlyphInfo( L, font->glyphs[id], &font->glyphs[id].image );
+ uluaPushGlyphInfo( L, font->glyphs[id] );
+
+ return 1;
+}
+
+/*
+> glyphInfo = RL.GetGlyphInfoByIndex( Font font, int index )
+
+Get glyph font info data by index
+
+- Failure return nil
+- Success return GlyphInfo
+*/
+int ltextGetGlyphInfoByIndex( lua_State *L ) {
+ Font *font = uluaGetFont( L, 1 );
+ int index = luaL_checkinteger( L, 2 );
+
+ if ( 0 <= index && index < font->glyphCount ) {
+ uluaPushGlyphInfo( L, font->glyphs[ index ] );
+ }
+ else {
+ TraceLog( state->logLevelInvalid, "Glyph index %d out of bounds", index );
+ lua_pushnil( L );
+ }
return 1;
}
@@ -541,6 +752,29 @@ int ltextGetGlyphAtlasRec( lua_State *L ) {
}
/*
+> rect = RL.GetGlyphAtlasRecByIndex( Font font, int index )
+
+Get glyph rectangle in font atlas by index
+
+- Failure return nil
+- Success return Rectangle
+*/
+int ltextGetGlyphAtlasRecByIndex( lua_State *L ) {
+ Font *font = uluaGetFont( L, 1 );
+ int index = luaL_checkinteger( L, 2 );
+
+ if ( 0 <= index && index < font->glyphCount ) {
+ uluaPushRectangle( L, font->recs[ index ] );
+ }
+ else {
+ TraceLog( state->logLevelInvalid, "Glyph index %d out of bounds", index );
+ lua_pushnil( L );
+ }
+
+ return 1;
+}
+
+/*
> baseSize = RL.GetFontBaseSize( Font font )
Get font base size (default chars height)
@@ -595,8 +829,179 @@ Get font texture atlas containing the glyphs. Return as lightuserdata
int ltextGetFontTexture( lua_State *L ) {
Font *font = uluaGetFont( L, 1 );
- // uluaPushTexture( L, font->texture );
lua_pushlightuserdata( L, &font->texture );
return 1;
}
+
+/*
+## Text - GlyphInfo management functions
+*/
+
+/*
+> glyphInfo = RL.LoadGlyphInfo( GlyphInfo{} glyphInfoData )
+
+Load GlyphInfo from data
+
+- Success return GlyphInfo
+*/
+int ltextLoadGlyphInfo( lua_State *L ) {
+ luaL_checktype( L, 1, LUA_TTABLE );
+
+ GlyphInfo glyph = { 0 };
+
+ int t = 1;
+ lua_pushnil( L );
+
+ while ( lua_next( L, t ) != 0 ) {
+ if ( strcmp( "value", (char*)lua_tostring( L, -2 ) ) == 0 ) {
+ glyph.value = (unsigned int)luaL_checkinteger( L, -1 );
+ }
+ else if ( strcmp( "offsetX", (char*)lua_tostring( L, -2 ) ) == 0 ) {
+ glyph.offsetX = luaL_checkinteger( L, -1 );
+ }
+ else if ( strcmp( "offsetY", (char*)lua_tostring( L, -2 ) ) == 0 ) {
+ glyph.offsetY = luaL_checkinteger( L, -1 );
+ }
+ else if ( strcmp( "advanceX", (char*)lua_tostring( L, -2 ) ) == 0 ) {
+ glyph.advanceX = luaL_checkinteger( L, -1 );
+ }
+ else if ( strcmp( "image", (char*)lua_tostring( L, -2 ) ) == 0 ) {
+ glyph.image = *uluaGetImage( L, lua_gettop( L ) );
+ }
+ lua_pop( L, 1 );
+ }
+ uluaPushGlyphInfo( L, glyph );
+
+ return 1;
+}
+
+/*
+> RL.UnloadGlyphInfo( GlyphInfo glyphInfo )
+
+Unload glyphInfo image from CPU memory (RAM)
+*/
+int ltextUnloadGlyphInfo( lua_State *L ) {
+ GlyphInfo *glyph = uluaGetGlyphInfo( L, 1 );
+
+ unloadGlyphInfo( glyph );
+
+ return 0;
+}
+
+/*
+> RL.SetGlyphInfoValue( GlyphInfo glyphInfo, int value )
+
+Set glyphInfo character value (Unicode)
+*/
+int ltextSetGlyphInfoValue( lua_State *L ) {
+ GlyphInfo *glyph = uluaGetGlyphInfo( L, 1 );
+ int value = luaL_checkinteger( L, 2 );
+
+ glyph->value = value;
+
+ return 0;
+}
+
+/*
+> RL.SetGlyphInfoOffset( GlyphInfo glyphInfo, Vector2 offset )
+
+Set glyphInfo character offset when drawing
+*/
+int ltextSetGlyphInfoOffset( lua_State *L ) {
+ GlyphInfo *glyph = uluaGetGlyphInfo( L, 1 );
+ Vector2 offset = uluaGetVector2( L, 2 );
+
+ glyph->offsetX = (int)offset.x;
+ glyph->offsetY = (int)offset.y;
+
+ return 0;
+}
+
+/*
+> RL.SetGlyphInfoAdvanceX( GlyphInfo glyphInfo, int advanceX )
+
+Set glyphInfo character advance position X
+*/
+int ltextSetGlyphInfoAdvanceX( lua_State *L ) {
+ GlyphInfo *glyph = uluaGetGlyphInfo( L, 1 );
+ int advanceX = luaL_checkinteger( L, 2 );
+
+ glyph->advanceX = advanceX;
+
+ return 0;
+}
+
+/*
+> RL.SetGlyphInfoImage( GlyphInfo glyphInfo, Image image )
+
+Set glyphInfo character image data
+*/
+int ltextSetGlyphInfoImage( lua_State *L ) {
+ GlyphInfo *glyph = uluaGetGlyphInfo( L, 1 );
+ Image image = *uluaGetImage( L, 2 );
+
+ glyph->image = image;
+
+ return 0;
+}
+
+/*
+> value = RL.GetGlyphInfoValue( GlyphInfo glyphInfo )
+
+Get glyphInfo character value (Unicode)
+
+- Success return int
+*/
+int ltextGetGlyphInfoValue( lua_State *L ) {
+ GlyphInfo *glyph = uluaGetGlyphInfo( L, 1 );
+
+ lua_pushinteger( L, glyph->value );
+
+ return 1;
+}
+
+/*
+> offset = RL.GetGlyphInfoOffset( GlyphInfo glyphInfo )
+
+Get glyphInfo character offset when drawing
+
+- Success return Vector2
+*/
+int ltextGetGlyphInfoOffset( lua_State *L ) {
+ GlyphInfo *glyph = uluaGetGlyphInfo( L, 1 );
+
+ uluaPushVector2( L, (Vector2){ glyph->offsetX, glyph->offsetY } );
+
+ return 1;
+}
+
+/*
+> advanceX = RL.GetGlyphInfoAdvanceX( GlyphInfo glyphInfo )
+
+Get glyphInfo character advance position X
+
+- Success return int
+*/
+int ltextGetGlyphInfoAdvanceX( lua_State *L ) {
+ GlyphInfo *glyph = uluaGetGlyphInfo( L, 1 );
+
+ lua_pushinteger( L, glyph->advanceX );
+
+ return 1;
+}
+
+/*
+> image = RL.GetGlyphInfoImage( GlyphInfo glyphInfo )
+
+Get glyphInfo character image data. Return as lightuserdata
+
+- Success return Image
+*/
+int ltextGetGlyphInfoImage( lua_State *L ) {
+ GlyphInfo *glyph = uluaGetGlyphInfo( L, 1 );
+
+ lua_pushlightuserdata( L, &glyph->image );
+
+ return 1;
+}
diff --git a/src/textures.c b/src/textures.c
index 24c8232..f88f9b3 100644
--- a/src/textures.c
+++ b/src/textures.c
@@ -1134,9 +1134,9 @@ int ltexturesLoadTextureFromData( lua_State *L ) {
Texture texture = { 0 };
int t = 1;
- lua_pushnil( L );
+ lua_pushnil( L );
- while ( lua_next( L, t ) != 0 ) {
+ while ( lua_next( L, t ) != 0 ) {
if ( strcmp( "id", (char*)lua_tostring( L, -2 ) ) == 0 ) {
texture.id = (unsigned int)luaL_checkinteger( L, -1 );
}
@@ -1152,8 +1152,8 @@ int ltexturesLoadTextureFromData( lua_State *L ) {
else if ( strcmp( "format", (char*)lua_tostring( L, -2 ) ) == 0 ) {
texture.format = luaL_checkinteger( L, -1 );
}
- lua_pop( L, 1 );
- }
+ lua_pop( L, 1 );
+ }
uluaPushTexture( L, texture );
return 1;