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

View File

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

View File

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

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

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

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

View File

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