summaryrefslogtreecommitdiff
path: root/examples/raygui_custom
diff options
context:
space:
mode:
authorjussi2024-01-03 18:23:19 +0200
committerjussi2024-01-03 18:23:19 +0200
commit70a2bcba18aa9855380c132f89e26b61bfd2cb40 (patch)
tree7f5d18d0d82afc352b5c75c68b136f4e2f6850d0 /examples/raygui_custom
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/raygui_custom')
-rw-r--r--examples/raygui_custom/main.lua89
-rw-r--r--examples/raygui_custom/spriteButton.lua54
2 files changed, 143 insertions, 0 deletions
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