From 70a2bcba18aa9855380c132f89e26b61bfd2cb40 Mon Sep 17 00:00:00 2001 From: jussi Date: Wed, 3 Jan 2024 18:23:19 +0200 Subject: Rest of font loading/unloading functions. GlyphInfo type to userdata. GlyphInfo management functions. --- examples/raygui_custom/spriteButton.lua | 54 +++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 examples/raygui_custom/spriteButton.lua (limited to 'examples/raygui_custom/spriteButton.lua') 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 -- cgit v1.2.3