summaryrefslogtreecommitdiff
path: root/examples/raygui_custom/spriteButton.lua
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/spriteButton.lua
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/spriteButton.lua')
-rw-r--r--examples/raygui_custom/spriteButton.lua54
1 files changed, 54 insertions, 0 deletions
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