summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorjussi2024-01-03 18:23:19 +0200
committerjussi2024-01-03 18:23:19 +0200
commit70a2bcba18aa9855380c132f89e26b61bfd2cb40 (patch)
tree7f5d18d0d82afc352b5c75c68b136f4e2f6850d0 /examples
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.
Diffstat (limited to 'examples')
-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
8 files changed, 158 insertions, 16 deletions
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