Rest of font loading/unloading functions. GlyphInfo type to userdata. GlyphInfo management functions.

This commit is contained in:
jussi
2024-01-03 18:23:19 +02:00
parent 192d471fb3
commit 70a2bcba18
22 changed files with 957 additions and 139 deletions

165
API.md
View File

@@ -215,10 +215,20 @@ BoundingBox
--- ---
> GlyphInfo = { value = int, offsetX = int, offsetY = int, advanceX = int, image = Image } > GlyphInfo = Userdata
GlyphInfo, font characters glyphs info 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 } > 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 ) > isReady = RL.IsFontReady( Font font )
Check if a font is ready 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 ) > RL.UnloadFont( Font font )
Unload font from GPU memory (VRAM) 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 ## 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 ) > glyphInfo = RL.GetGlyphInfo( Font font, int codepoint )
Get glyph font info data for a codepoint (unicode character), fallback to '?' if not found. Get glyph font info data for a codepoint (unicode character), fallback to '?' if not found
Return Image as lightuserdata
- Success return GlyphInfo - 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 ) > rect = RL.GetGlyphAtlasRec( Font font, int codepoint )
Get glyph rectangle in font atlas for a codepoint (unicode character), fallback to '?' if not found 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 ) > baseSize = RL.GetFontBaseSize( Font font )
Get font base size (default chars height) 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 ## 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 ) > RL.UpdateMesh( Mesh mesh, Mesh{} meshData )
Update mesh vertex data in GPU. 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 ) > 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 - Success return Texture
@@ -7046,9 +7187,9 @@ Get color from material map type
> shader = RL.GetMaterialShader( Material material ) > 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 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 ) > 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 } > 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 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 } > GLFWpentabletcursorEvent = { int type, int identifier }
Called when the pen tablet cursor has changed. Type GLFW_PEN_TABLET_CURSOR_EVENT 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 } > GLFWpentabletproximityEvent = { int type, int proxState }
Called when the pen tablet proximity has changed. Type GLFW_PEN_TABLET_PROXIMITY_EVENT 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
--- ---

View File

@@ -3673,17 +3673,58 @@ function RL.LoadFontEx( fileName, fontSize, codepoints ) end
---@return any font ---@return any font
function RL.LoadFontFromImage( image, key, firstChar ) end 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 ---Check if a font is ready
---- Success return bool ---- Success return bool
---@param font any ---@param font any
---@return any isReady ---@return any isReady
function RL.IsFontReady( font ) end 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) ---Unload font from GPU memory (VRAM)
---@param font any ---@param font any
---@return any RL.UnloadFont ---@return any RL.UnloadFont
function RL.UnloadFont( font ) end 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 -- Text - Text drawing functions
---Draw current FPS ---Draw current FPS
@@ -3788,14 +3829,21 @@ function RL.MeasureText( font, text, fontSize, spacing ) end
---@return any index ---@return any index
function RL.GetGlyphIndex( font, codepoint ) end function RL.GetGlyphIndex( font, codepoint ) end
---Get glyph font info data for a codepoint (unicode character), fallback to '?' if not found. ---Get glyph font info data for a codepoint (unicode character), fallback to '?' if not found
---Return Image as lightuserdata
---- Success return GlyphInfo ---- Success return GlyphInfo
---@param font any ---@param font any
---@param codepoint integer ---@param codepoint integer
---@return any glyphInfo ---@return any glyphInfo
function RL.GetGlyphInfo( font, codepoint ) end 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 ---Get glyph rectangle in font atlas for a codepoint (unicode character), fallback to '?' if not found
---- Success return Rectangle ---- Success return Rectangle
---@param font any ---@param font any
@@ -3803,6 +3851,14 @@ function RL.GetGlyphInfo( font, codepoint ) end
---@return any rect ---@return any rect
function RL.GetGlyphAtlasRec( font, codepoint ) end 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) ---Get font base size (default chars height)
---- Success return int ---- Success return int
---@param font any ---@param font any
@@ -3827,6 +3883,67 @@ function RL.GetFontGlyphPadding( font ) end
---@return any texture ---@return any texture
function RL.GetFontTexture( font ) end 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 -- Models - Basic geometric 3D shapes drawing functions
---Draw a line in 3D world space ---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 -- Models - Mesh management functions
---Update mesh vertex data in GPU. ---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 mesh any
---@param meshData table ---@param meshData table
---@return any RL.UpdateMesh ---@return any RL.UpdateMesh
@@ -4409,7 +4526,7 @@ function RL.SetMaterialShader( material, shader ) end
---@return any RL.SetMaterialParams ---@return any RL.SetMaterialParams
function RL.SetMaterialParams( material, params ) end 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 ---- Success return Texture
---@param material any ---@param material any
---@param mapType integer ---@param mapType integer
@@ -4430,8 +4547,8 @@ function RL.GetMaterialColor( material, mapType ) end
---@return any value ---@return any value
function RL.GetMaterialValue( material, mapType ) end function RL.GetMaterialValue( material, mapType ) end
---Get material shader ---Get material shader. Return as lightuserdata
---- Success return Shader. Return as lightuserdata ---- Success return Shader
---@param material any ---@param material any
---@return any shader ---@return any shader
function RL.GetMaterialShader( material ) end function RL.GetMaterialShader( material ) end
@@ -6191,7 +6308,7 @@ function RL.GetLightTarget( light ) end
function RL.GetLightColor( light ) end function RL.GetLightColor( light ) end
---Get light enabled ---Get light enabled
---- Success return boolean ---- Success return bool
---@param light any ---@param light any
---@return any enabled ---@return any enabled
function RL.IsLightEnabled( light ) end function RL.IsLightEnabled( light ) end
@@ -6668,7 +6785,7 @@ function RL.rlUnloadVertexArray( vaoId ) end
---@return any RL.rlUnloadVertexBuffer ---@return any RL.rlUnloadVertexBuffer
function RL.rlUnloadVertexBuffer( vboId ) end 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 index integer
---@param compSize integer ---@param compSize integer
---@param type integer ---@param type integer

View File

@@ -27,6 +27,9 @@ KEY CHANGES:
- ADDED: Rest of rlRenderBatch functions. - ADDED: Rest of rlRenderBatch functions.
- ADDED: DrawTextureNPatchRepeat. - ADDED: DrawTextureNPatchRepeat.
- ADDED: GuiScrollBar and made it puplic in raygui.h. - 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: DETAILED CHANGES:
- REMOVED: DrawLineBezierQuad, DrawLineBezierCubic. - REMOVED: DrawLineBezierQuad, DrawLineBezierCubic.
@@ -52,6 +55,7 @@ DETAILED CHANGES:
- FIXED: rlSetVertexAttribute pointer offset. - FIXED: rlSetVertexAttribute pointer offset.
- ADDED: GetImageData. - ADDED: GetImageData.
- FIXED: CameraLib. Slow lateral movement. - FIXED: CameraLib. Slow lateral movement.
- ADDED: GetGlyphInfoByIndex and GetGlyphAtlasRecByIndex.
------------------------------------------------------------------------ ------------------------------------------------------------------------
Release: ReiLua version 0.6.0 Using Raylib 4.5 Release: ReiLua version 0.6.0 Using Raylib 4.5

View File

@@ -11,9 +11,6 @@ Backlog {
* Text * Text
* Text codepoints management functions (unicode characters)? Could be usefull for luajit. * 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. * Some of the Text strings management functions could be easier to use than the Lua ones.
* LoadFontFromMemory.
* LoadFontData.
* GenImageFontAtlas.
* Audio * Audio
* AudioStream. * AudioStream.
* Core * Core

View File

@@ -221,8 +221,17 @@ apiFile:write( "\n> RayCollision = { hit = true, distance = 1.0, point = { 0.0,
RayCollision, ray hit information\n\n---\n" ) 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\ 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" ) BoundingBox\n\n---\n" )
apiFile:write( "\n> GlyphInfo = { value = int, offsetX = int, offsetY = int, advanceX = int, image = Image }\n\ apiFile:write( "\n> GlyphInfo = Userdata\n\
GlyphInfo, font characters glyphs info\n\n---\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\ apiFile:write( "\n> BoneInfo = { name = string[32], parent = int }\n\
Bone, skeletal animation bone\n\n---\n" ) Bone, skeletal animation bone\n\n---\n" )
apiFile:write( "\n> Transform = { translation = Vector3, rotation = Quaternion, scale = Vector3 }\n\ apiFile:write( "\n> Transform = { translation = Vector3, rotation = Quaternion, scale = Vector3 }\n\

View File

@@ -103,21 +103,21 @@ function RL.init()
createShadowMesh() createShadowMesh()
addLight( Vector2:new( 230, 480 ), Color:new( RL.ORANGE ), 512 ) -- addLight( Vector2:new( 230, 480 ), Color:new( RL.ORANGE ), 512 )
addLight( Vector2:new( 600, 200 ), Color:new( RL.RED ), 512 ) -- addLight( Vector2:new( 600, 200 ), Color:new( RL.RED ), 512 )
addLight( Vector2:new( 384, 520 ), Color:new( RL.GREEN ), 400 ) -- addLight( Vector2:new( 384, 520 ), Color:new( RL.GREEN ), 400 )
addLight( Vector2:new( 880, 750 ), Color:new( RL.BLUE ), 300 ) -- addLight( Vector2:new( 880, 750 ), Color:new( RL.BLUE ), 300 )
addLight( Vector2:new( 800, 500 ), Color:new( RL.PURPLE ), 512 ) -- addLight( Vector2:new( 800, 500 ), Color:new( RL.PURPLE ), 512 )
addLight( Vector2:new( 200, 760 ), Color:new( RL.WHITE ), 400 ) -- addLight( Vector2:new( 200, 760 ), Color:new( RL.WHITE ), 400 )
-- Stress test -- Stress test
-- for i = 1, 300 do for i = 1, 300 do
-- addLight( Vector2:new( math.random( 20, RESOLUTION.x - 20 ), math.random( 20, RESOLUTION.y - 20 ) ), 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 } ), Color:new( { math.random( 40, 255 ), math.random( 40, 255 ), math.random( 40, 255 ), 255 } ),
-- 128 128
-- ) )
-- end end
-- Camera for shadow rendering. -- Camera for shadow rendering.
camera = RL.CreateCamera3D() camera = RL.CreateCamera3D()

View File

@@ -19,6 +19,7 @@ function RL.init()
RL.SetWindowState( RL.FLAG_VSYNC_HINT ) RL.SetWindowState( RL.FLAG_VSYNC_HINT )
RL.SetWindowSize( winSize ) RL.SetWindowSize( winSize )
RL.SetWindowPosition( { mPos.x + mSize.x / 2 - winSize.x / 2, mPos.y + mSize.y / 2 - winSize.y / 2 } ) RL.SetWindowPosition( { mPos.x + mSize.x / 2 - winSize.x / 2, mPos.y + mSize.y / 2 - winSize.y / 2 } )
RL.SetTextLineSpacing( 26 )
camera = Cam3D:new() camera = Cam3D:new()

View File

@@ -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

View File

@@ -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

View File

@@ -9,6 +9,7 @@ ui_bgr.png Jussi Viitala CC0
gradient.png Jussi Viitala CC0 gradient.png Jussi Viitala CC0
light.png Jussi Viitala CC0 light.png Jussi Viitala CC0
nPatch.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 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 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 plain-circle.png Delapouite Creative Commons 3.0 https://game-icons.net Resized

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

@@ -32,9 +32,6 @@ Rectangle.meta = {
__unm = function( r ) __unm = function( r )
return Rectangle:new( -r.x, -r.y, -r.width, -r.height ) return Rectangle:new( -r.x, -r.y, -r.width, -r.height )
end, end,
__idiv = function( r, v )
return Rectangle:new( r.x // v, r.y // v, r.width // v, r.height // v )
end,
__len = function() __len = function()
return 4 return 4
end, end,

View File

@@ -9,7 +9,7 @@ end
function RL.process( delta ) function RL.process( delta )
if RL.IsKeyPressed( RL.KEY_ENTER ) then 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() local winSize = RL.GetScreenSize()
textColor = RL.BLUE textColor = RL.BLUE

View File

@@ -45,7 +45,6 @@ Matrix uluaGetMatrix( lua_State *L, int index );
BoundingBox uluaGetBoundingBox( lua_State *L, int index ); BoundingBox uluaGetBoundingBox( lua_State *L, int index );
Ray uluaGetRay( lua_State *L, int index ); Ray uluaGetRay( lua_State *L, int index );
NPatchInfo uluaGetNPatchInfo( 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 ); BoneInfo uluaGetBoneInfo( lua_State *L, int index );
Transform uluaGetTransform( lua_State *L, int index ); Transform uluaGetTransform( lua_State *L, int index );
Buffer* uluaGetBuffer( 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 ); Camera2D* uluaGetCamera2D( lua_State *L, int index );
Camera3D* uluaGetCamera3D( lua_State *L, int index ); Camera3D* uluaGetCamera3D( lua_State *L, int index );
Font* uluaGetFont( 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 ); Wave* uluaGetWave( lua_State *L, int index );
Sound* uluaGetSound( lua_State *L, int index ); Sound* uluaGetSound( lua_State *L, int index );
Music* uluaGetMusic( 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 uluaPushRay( lua_State *L, Ray ray );
void uluaPushRayCollision( lua_State *L, RayCollision rayCol ); void uluaPushRayCollision( lua_State *L, RayCollision rayCol );
void uluaPushBoundingBox( lua_State *L, BoundingBox box ); void uluaPushBoundingBox( lua_State *L, BoundingBox box );
void uluaPushGlyphInfo( lua_State *L, GlyphInfo glyphInfo, Image *image );
void uluaPushBoneInfo( lua_State *L, BoneInfo boneInfo ); void uluaPushBoneInfo( lua_State *L, BoneInfo boneInfo );
void uluaPushTransform( lua_State *L, Transform transform ); void uluaPushTransform( lua_State *L, Transform transform );
void uluaPushBuffer( lua_State *L, Buffer buffer ); 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 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 ); void uluaPushFont( lua_State *L, Font font );
void uluaPushGlyphInfo( lua_State *L, GlyphInfo glyph );
void uluaPushWave( lua_State *L, Wave wave ); void uluaPushWave( lua_State *L, Wave wave );
void uluaPushSound( lua_State *L, Sound sound ); void uluaPushSound( lua_State *L, Sound sound );
void uluaPushMusic( lua_State *L, Music music ); void uluaPushMusic( lua_State *L, Music music );

View File

@@ -1,12 +1,18 @@
#pragma once #pragma once
void unloadGlyphInfo( GlyphInfo *glyph );
/* Font loading/unloading functions. */ /* Font loading/unloading functions. */
int ltextGetFontDefault( lua_State *L ); 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 ltextLoadFontFromMemory( lua_State *L );
int ltextLoadFontFromData( lua_State *L );
int ltextIsFontReady( lua_State *L ); int ltextIsFontReady( lua_State *L );
int ltextLoadFontData( lua_State *L );
int ltextGenImageFontAtlas( lua_State *L );
int ltextUnloadFont( lua_State *L ); int ltextUnloadFont( lua_State *L );
int ltextExportFontAsCode( lua_State *L );
/* Text drawing functions. */ /* Text drawing functions. */
int ltextDrawFPS( lua_State *L ); int ltextDrawFPS( lua_State *L );
int ltextDrawText( lua_State *L ); int ltextDrawText( lua_State *L );
@@ -21,8 +27,21 @@ int ltextSetTextLineSpacing( lua_State *L );
int ltextMeasureText( lua_State *L ); int ltextMeasureText( lua_State *L );
int ltextGetGlyphIndex( lua_State *L ); int ltextGetGlyphIndex( lua_State *L );
int ltextGetGlyphInfo( lua_State *L ); int ltextGetGlyphInfo( lua_State *L );
int ltextGetGlyphInfoByIndex( lua_State *L );
int ltextGetGlyphAtlasRec( lua_State *L ); int ltextGetGlyphAtlasRec( lua_State *L );
int ltextGetGlyphAtlasRecByIndex( lua_State *L );
int ltextGetFontBaseSize( lua_State *L ); int ltextGetFontBaseSize( lua_State *L );
int ltextGetFontGlyphCount( lua_State *L ); int ltextGetFontGlyphCount( lua_State *L );
int ltextGetFontGlyphPadding( lua_State *L ); int ltextGetFontGlyphPadding( lua_State *L );
int ltextGetFontTexture( 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 );

View File

@@ -179,7 +179,7 @@ int llightsGetLightColor( lua_State *L ) {
Get light enabled Get light enabled
- Success return boolean - Success return bool
*/ */
int llightsIsLightEnabled( lua_State *L ) { int llightsIsLightEnabled( lua_State *L ) {
Light *light = uluaGetLight( L, 1 ); Light *light = uluaGetLight( L, 1 );

View File

@@ -156,6 +156,25 @@ static void defineFont() {
lua_setfield( L, -2, "__gc" ); 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. */ /* Wave. */
static int gcWave( lua_State *L ) { static int gcWave( lua_State *L ) {
if ( state->gcUnload ) { if ( state->gcUnload ) {
@@ -357,7 +376,7 @@ static void defineGlobals() {
lua_setglobal( L, "RL" ); lua_setglobal( L, "RL" );
lua_getglobal( L, "RL" ); lua_getglobal( L, "RL" );
/* Note! Docgen relyes on this line format. */ /* Note! Docgen rely on this line format. */
/*DOC_DEFINES_START*/ /*DOC_DEFINES_START*/
/* System/Window config flags */ /* System/Window config flags */
assignGlobalInt( FLAG_VSYNC_HINT, "FLAG_VSYNC_HINT" ); // Set to try enabling V-Sync on GPU 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(); defineCamera3D();
defineShader(); defineShader();
defineFont(); defineFont();
defineGlyphInfo();
defineWave(); defineWave();
defineSound(); defineSound();
defineMusic(); defineMusic();
@@ -1697,8 +1717,13 @@ void luaRegister() {
assingGlobalFunction( "LoadFont", ltextLoadFont ); assingGlobalFunction( "LoadFont", ltextLoadFont );
assingGlobalFunction( "LoadFontEx", ltextLoadFontEx ); assingGlobalFunction( "LoadFontEx", ltextLoadFontEx );
assingGlobalFunction( "LoadFontFromImage", ltextLoadFontFromImage ); assingGlobalFunction( "LoadFontFromImage", ltextLoadFontFromImage );
assingGlobalFunction( "LoadFontFromMemory", ltextLoadFontFromMemory );
assingGlobalFunction( "LoadFontFromData", ltextLoadFontFromData );
assingGlobalFunction( "IsFontReady", ltextIsFontReady ); assingGlobalFunction( "IsFontReady", ltextIsFontReady );
assingGlobalFunction( "LoadFontData", ltextLoadFontData );
assingGlobalFunction( "GenImageFontAtlas", ltextGenImageFontAtlas );
assingGlobalFunction( "UnloadFont", ltextUnloadFont ); assingGlobalFunction( "UnloadFont", ltextUnloadFont );
assingGlobalFunction( "ExportFontAsCode", ltextExportFontAsCode );
/* Text drawing functions. */ /* Text drawing functions. */
assingGlobalFunction( "DrawFPS", ltextDrawFPS ); assingGlobalFunction( "DrawFPS", ltextDrawFPS );
assingGlobalFunction( "DrawText", ltextDrawText ); assingGlobalFunction( "DrawText", ltextDrawText );
@@ -1713,11 +1738,24 @@ void luaRegister() {
assingGlobalFunction( "MeasureText", ltextMeasureText ); assingGlobalFunction( "MeasureText", ltextMeasureText );
assingGlobalFunction( "GetGlyphIndex", ltextGetGlyphIndex ); assingGlobalFunction( "GetGlyphIndex", ltextGetGlyphIndex );
assingGlobalFunction( "GetGlyphInfo", ltextGetGlyphInfo ); assingGlobalFunction( "GetGlyphInfo", ltextGetGlyphInfo );
assingGlobalFunction( "GetGlyphInfoByIndex", ltextGetGlyphInfoByIndex );
assingGlobalFunction( "GetGlyphAtlasRec", ltextGetGlyphAtlasRec ); assingGlobalFunction( "GetGlyphAtlasRec", ltextGetGlyphAtlasRec );
assingGlobalFunction( "GetGlyphAtlasRecByIndex", ltextGetGlyphAtlasRecByIndex );
assingGlobalFunction( "GetFontBaseSize", ltextGetFontBaseSize ); assingGlobalFunction( "GetFontBaseSize", ltextGetFontBaseSize );
assingGlobalFunction( "GetFontGlyphCount", ltextGetFontGlyphCount ); assingGlobalFunction( "GetFontGlyphCount", ltextGetFontGlyphCount );
assingGlobalFunction( "GetFontGlyphPadding", ltextGetFontGlyphPadding ); assingGlobalFunction( "GetFontGlyphPadding", ltextGetFontGlyphPadding );
assingGlobalFunction( "GetFontTexture", ltextGetFontTexture ); 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. */
/* Audio device management functions. */ /* Audio device management functions. */
@@ -2623,59 +2661,6 @@ NPatchInfo uluaGetNPatchInfo( lua_State *L, int index ) {
return npatch; 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 ) { BoneInfo uluaGetBoneInfo( lua_State *L, int index ) {
luaL_checktype( L, index, LUA_TTABLE ); luaL_checktype( L, index, LUA_TTABLE );
BoneInfo bone = { 0 }; BoneInfo bone = { 0 };
@@ -2819,6 +2804,13 @@ Font* uluaGetFont( lua_State *L, int index ) {
return luaL_checkudata( L, index, "Font" ); 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 ) { Wave* uluaGetWave( lua_State *L, int index ) {
if ( lua_islightuserdata( L, index ) ) { if ( lua_islightuserdata( L, index ) ) {
return (Wave*)lua_touserdata( L, index ); return (Wave*)lua_touserdata( L, index );
@@ -3047,20 +3039,6 @@ void uluaPushBoundingBox( lua_State *L, BoundingBox box ) {
lua_rawseti( L, -2, 2 ); 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 ) { void uluaPushBoneInfo( lua_State *L, BoneInfo boneInfo ) {
lua_createtable( L, 2, 0 ); lua_createtable( L, 2, 0 );
lua_pushstring( L, boneInfo.name ); lua_pushstring( L, boneInfo.name );
@@ -3130,6 +3108,12 @@ void uluaPushFont( lua_State *L, Font font ) {
luaL_setmetatable( L, "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 ) { void uluaPushWave( lua_State *L, Wave wave ) {
Wave *waveP = lua_newuserdata( L, sizeof( Wave ) ); Wave *waveP = lua_newuserdata( L, sizeof( Wave ) );
*waveP = wave; *waveP = wave;

View File

@@ -981,7 +981,7 @@ int lmodelsDrawBillboardPro( lua_State *L ) {
> RL.UpdateMesh( Mesh mesh, Mesh{} meshData ) > RL.UpdateMesh( Mesh mesh, Mesh{} meshData )
Update mesh vertex data in GPU. 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 ) { int lmodelsUpdateMesh( lua_State *L ) {
Mesh *mesh = uluaGetMesh( L, 1 ); Mesh *mesh = uluaGetMesh( L, 1 );
@@ -1820,7 +1820,7 @@ int lmodelsSetMaterialParams( lua_State *L ) {
/* /*
> texture = RL.GetMaterialTexture( Material material, int mapType ) > 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 - Success return Texture
*/ */
@@ -1828,7 +1828,7 @@ int lmodelsGetMaterialTexture( lua_State *L ) {
Material *material = uluaGetMaterial( L, 1 ); Material *material = uluaGetMaterial( L, 1 );
int mapType = luaL_checkinteger( L, 2 ); int mapType = luaL_checkinteger( L, 2 );
uluaPushTexture( L, material->maps[ mapType ].texture ); lua_pushlightuserdata( L, &material->maps[ mapType ].texture );
return 1; return 1;
} }
@@ -1868,9 +1868,9 @@ int lmodelsGetMaterialValue( lua_State *L ) {
/* /*
> shader = RL.GetMaterialShader( Material material ) > 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 ) { int lmodelsGetMaterialShader( lua_State *L ) {
Material *material = uluaGetMaterial( L, 1 ); Material *material = uluaGetMaterial( L, 1 );

View File

@@ -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 } > 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 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 ) { static void penTabletDataEvent( double x, double y, double z, double pressure, double pitch, double yaw, double roll ) {
lua_State *L = state->luaState; 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 } > GLFWpentabletcursorEvent = { int type, int identifier }
Called when the pen tablet cursor has changed. Type GLFW_PEN_TABLET_CURSOR_EVENT 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 ) { static void penTabletCursorEvent( unsigned int identifier ) {
lua_State *L = state->luaState; lua_State *L = state->luaState;
@@ -589,7 +589,7 @@ static void penTabletCursorEvent( unsigned int identifier ) {
> GLFWpentabletproximityEvent = { int type, int proxState } > GLFWpentabletproximityEvent = { int type, int proxState }
Called when the pen tablet proximity has changed. Type GLFW_PEN_TABLET_PROXIMITY_EVENT 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 ) { static void penTabletProximityEvent( int proxState ) {
lua_State *L = state->luaState; lua_State *L = state->luaState;

View File

@@ -1163,7 +1163,7 @@ int lrlglUnloadVertexBuffer( lua_State *L ) {
/* /*
> RL.rlSetVertexAttribute( int index, int compSize, int type, bool normalized, int stride, int pointer ) > 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 lrlglSetVertexAttribute( lua_State *L ) {
int index = luaL_checkinteger( L, 1 ); int index = luaL_checkinteger( L, 1 );

View File

@@ -4,6 +4,10 @@
#include "textures.h" #include "textures.h"
#include "lua_core.h" #include "lua_core.h"
void unloadGlyphInfo( GlyphInfo *glyph ) {
UnloadImage( glyph->image );
}
// DrawTextBoxed is modified DrawTextBoxedSelectable from raylib [text] example - Rectangle bounds // DrawTextBoxed is modified DrawTextBoxedSelectable from raylib [text] example - Rectangle bounds
// Draw text using font inside rectangle limits // Draw text using font inside rectangle limits
@@ -157,6 +161,18 @@ bool wordWrap, Color *tints, int tintCount, Color *backTints, int backTintCount
return mouseChar; 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 ## Text - Font loading/unloading functions
*/ */
@@ -210,16 +226,7 @@ int ltextLoadFontEx( lua_State *L ) {
int codepointCount = uluaGetTableLen( L, 3 ); int codepointCount = uluaGetTableLen( L, 3 );
int codepoints[ codepointCount ]; int codepoints[ codepointCount ];
int t = 3; getCodepoints( L, codepoints, 3 );
int i = 0;
lua_pushnil( L );
while ( lua_next( L, t ) != 0 ) {
codepoints[i] = lua_tointeger( L, -1 );
i++;
lua_pop( L, 1 );
}
uluaPushFont( L, LoadFontEx( lua_tostring( L, 1 ), fontSize, codepoints, codepointCount ) ); uluaPushFont( L, LoadFontEx( lua_tostring( L, 1 ), fontSize, codepoints, codepointCount ) );
return 1; return 1;
@@ -251,6 +258,94 @@ int ltextLoadFontFromImage( lua_State *L ) {
return 1; return 1;
} }
/*
> 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 ) > isReady = RL.IsFontReady( Font font )
@@ -266,6 +361,84 @@ int ltextIsFontReady( lua_State *L ) {
return 1; return 1;
} }
/*
> 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 ) > RL.UnloadFont( Font font )
@@ -279,6 +452,22 @@ int ltextUnloadFont( lua_State *L ) {
return 0; return 0;
} }
/*
> 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 ## Text - Text drawing functions
*/ */
@@ -509,8 +698,7 @@ int ltextGetGlyphIndex( lua_State *L ) {
/* /*
> glyphInfo = RL.GetGlyphInfo( Font font, int codepoint ) > glyphInfo = RL.GetGlyphInfo( Font font, int codepoint )
Get glyph font info data for a codepoint (unicode character), fallback to '?' if not found. Get glyph font info data for a codepoint (unicode character), fallback to '?' if not found
Return Image as lightuserdata
- Success return GlyphInfo - Success return GlyphInfo
*/ */
@@ -519,7 +707,30 @@ int ltextGetGlyphInfo( lua_State *L ) {
int codepoint = luaL_checkinteger( L, 2 ); int codepoint = luaL_checkinteger( L, 2 );
int id = GetGlyphIndex( *font, codepoint ); 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; return 1;
} }
@@ -540,6 +751,29 @@ int ltextGetGlyphAtlasRec( lua_State *L ) {
return 1; return 1;
} }
/*
> 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 ) > baseSize = RL.GetFontBaseSize( Font font )
@@ -595,8 +829,179 @@ Get font texture atlas containing the glyphs. Return as lightuserdata
int ltextGetFontTexture( lua_State *L ) { int ltextGetFontTexture( lua_State *L ) {
Font *font = uluaGetFont( L, 1 ); Font *font = uluaGetFont( L, 1 );
// uluaPushTexture( L, font->texture );
lua_pushlightuserdata( L, &font->texture ); lua_pushlightuserdata( L, &font->texture );
return 1; 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;
}

View File

@@ -1134,9 +1134,9 @@ int ltexturesLoadTextureFromData( lua_State *L ) {
Texture texture = { 0 }; Texture texture = { 0 };
int t = 1; 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 ) { if ( strcmp( "id", (char*)lua_tostring( L, -2 ) ) == 0 ) {
texture.id = (unsigned int)luaL_checkinteger( L, -1 ); 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 ) { else if ( strcmp( "format", (char*)lua_tostring( L, -2 ) ) == 0 ) {
texture.format = luaL_checkinteger( L, -1 ); texture.format = luaL_checkinteger( L, -1 );
} }
lua_pop( L, 1 ); lua_pop( L, 1 );
} }
uluaPushTexture( L, texture ); uluaPushTexture( L, texture );
return 1; return 1;