diff options
| author | jussi | 2024-01-03 18:23:19 +0200 |
|---|---|---|
| committer | jussi | 2024-01-03 18:23:19 +0200 |
| commit | 70a2bcba18aa9855380c132f89e26b61bfd2cb40 (patch) | |
| tree | 7f5d18d0d82afc352b5c75c68b136f4e2f6850d0 /examples/raygui_custom/spriteButton.lua | |
| parent | 192d471fb3caaa6d73796185e5cadc62075743f7 (diff) | |
| download | reilua-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.lua | 54 |
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 |
