mirror of
https://github.com/linux-man/LoveFrames.git
synced 2024-11-18 16:04:22 +00:00
Add toggle functionality to the button object
This commit is contained in:
parent
324c686445
commit
0db6ac9dda
@ -20,6 +20,8 @@ function newobject:initialize()
|
||||
self.down = false
|
||||
self.clickable = true
|
||||
self.enabled = true
|
||||
self.toggleable = false
|
||||
self.toggle = false
|
||||
self.OnClick = nil
|
||||
|
||||
end
|
||||
@ -179,6 +181,13 @@ function newobject:mousereleased(x, y, button)
|
||||
if onclick then
|
||||
onclick(self, x, y)
|
||||
end
|
||||
if self.toggleable then
|
||||
local ontoggle = self.OnToggle
|
||||
self.toggle = not self.toggle
|
||||
if ontoggle then
|
||||
ontoggle(self, self.toggle)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -259,3 +268,24 @@ function newobject:GetDown()
|
||||
return self.down
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: SetToggleable(bool)
|
||||
- desc: sets whether or not the object is toggleable
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:SetToggleable(bool)
|
||||
|
||||
self.toggleable = bool
|
||||
return self
|
||||
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
- func: GetToggleable()
|
||||
- desc: gets whether or not the object is toggleable
|
||||
--]]---------------------------------------------------------
|
||||
function newobject:GetToggleable()
|
||||
|
||||
return self.toggleable
|
||||
|
||||
end
|
@ -276,14 +276,13 @@ function skin.DrawButton(object)
|
||||
local texthovercolor = skin.controls.button_text_hover_color
|
||||
local textnohovercolor = skin.controls.button_text_nohover_color
|
||||
local textnonclickablecolor = skin.controls.button_text_nonclickable_color
|
||||
local image_hover = skin.images["button-hover.png"]
|
||||
local scaley = height/image_hover:getHeight()
|
||||
|
||||
if not enabled or not clickable then
|
||||
local image = skin.images["button-unclickable.png"]
|
||||
local imageheight = image:getHeight()
|
||||
local scaley = height/imageheight
|
||||
-- button body
|
||||
love.graphics.setColor(255, 255, 255, 255)
|
||||
love.graphics.draw(image, x, y, 0, width, scaley)
|
||||
love.graphics.draw(skin.images["button-unclickable.png"], x, y, 0, width, scaley)
|
||||
-- button text
|
||||
love.graphics.setFont(font)
|
||||
love.graphics.setColor(textnonclickablecolor)
|
||||
@ -294,48 +293,91 @@ function skin.DrawButton(object)
|
||||
return
|
||||
end
|
||||
|
||||
if down then
|
||||
local image = skin.images["button-down.png"]
|
||||
local imageheight = image:getHeight()
|
||||
local scaley = height/imageheight
|
||||
-- button body
|
||||
love.graphics.setColor(255, 255, 255, 255)
|
||||
love.graphics.draw(image, x, y, 0, width, scaley)
|
||||
-- button text
|
||||
love.graphics.setFont(font)
|
||||
love.graphics.setColor(textdowncolor)
|
||||
love.graphics.print(text, x + width/2 - twidth/2, y + height/2 - theight/2)
|
||||
-- button border
|
||||
love.graphics.setColor(bordercolor)
|
||||
skin.OutlinedRectangle(x, y, width, height)
|
||||
elseif hover then
|
||||
local image = skin.images["button-hover.png"]
|
||||
local imageheight = image:getHeight()
|
||||
local scaley = height/imageheight
|
||||
-- button body
|
||||
love.graphics.setColor(255, 255, 255, 255)
|
||||
love.graphics.draw(image, x, y, 0, width, scaley)
|
||||
-- button text
|
||||
love.graphics.setFont(font)
|
||||
love.graphics.setColor(texthovercolor)
|
||||
love.graphics.print(text, x + width/2 - twidth/2, y + height/2 - theight/2)
|
||||
-- button border
|
||||
love.graphics.setColor(bordercolor)
|
||||
skin.OutlinedRectangle(x, y, width, height)
|
||||
if object.toggleable then
|
||||
if hover then
|
||||
if down then
|
||||
-- button body
|
||||
love.graphics.setColor(255, 255, 255, 255)
|
||||
love.graphics.draw(skin.images["button-down.png"], x, y, 0, width, scaley)
|
||||
-- button text
|
||||
love.graphics.setFont(font)
|
||||
love.graphics.setColor(textdowncolor)
|
||||
love.graphics.print(text, x + width/2 - twidth/2, y + height/2 - theight/2)
|
||||
-- button border
|
||||
love.graphics.setColor(bordercolor)
|
||||
skin.OutlinedRectangle(x, y, width, height)
|
||||
else
|
||||
-- button body
|
||||
love.graphics.setColor(255, 255, 255, 255)
|
||||
love.graphics.draw(image_hover, x, y, 0, width, scaley)
|
||||
-- button text
|
||||
love.graphics.setFont(font)
|
||||
love.graphics.setColor(texthovercolor)
|
||||
love.graphics.print(text, x + width/2 - twidth/2, y + height/2 - theight/2)
|
||||
-- button border
|
||||
love.graphics.setColor(bordercolor)
|
||||
skin.OutlinedRectangle(x, y, width, height)
|
||||
end
|
||||
else
|
||||
if object.toggle then
|
||||
-- button body
|
||||
love.graphics.setColor(255, 255, 255, 255)
|
||||
love.graphics.draw(skin.images["button-down.png"], x, y, 0, width, scaley)
|
||||
-- button text
|
||||
love.graphics.setFont(font)
|
||||
love.graphics.setColor(textdowncolor)
|
||||
love.graphics.print(text, x + width/2 - twidth/2, y + height/2 - theight/2)
|
||||
-- button border
|
||||
love.graphics.setColor(bordercolor)
|
||||
skin.OutlinedRectangle(x, y, width, height)
|
||||
else
|
||||
-- button body
|
||||
love.graphics.setColor(255, 255, 255, 255)
|
||||
love.graphics.draw(skin.images["button-nohover.png"], x, y, 0, width, scaley)
|
||||
-- button text
|
||||
love.graphics.setFont(font)
|
||||
love.graphics.setColor(textnohovercolor)
|
||||
love.graphics.print(text, x + width/2 - twidth/2, y + height/2 - theight/2)
|
||||
-- button border
|
||||
love.graphics.setColor(bordercolor)
|
||||
skin.OutlinedRectangle(x, y, width, height)
|
||||
end
|
||||
end
|
||||
else
|
||||
local image = skin.images["button-nohover.png"]
|
||||
local imageheight = image:getHeight()
|
||||
local scaley = height/imageheight
|
||||
-- button body
|
||||
love.graphics.setColor(255, 255, 255, 255)
|
||||
love.graphics.draw(image, x, y, 0, width, scaley)
|
||||
-- button text
|
||||
love.graphics.setFont(font)
|
||||
love.graphics.setColor(textnohovercolor)
|
||||
love.graphics.print(text, x + width/2 - twidth/2, y + height/2 - theight/2)
|
||||
-- button border
|
||||
love.graphics.setColor(bordercolor)
|
||||
skin.OutlinedRectangle(x, y, width, height)
|
||||
if down then
|
||||
-- button body
|
||||
love.graphics.setColor(255, 255, 255, 255)
|
||||
love.graphics.draw(skin.images["button-down.png"], x, y, 0, width, scaley)
|
||||
-- button text
|
||||
love.graphics.setFont(font)
|
||||
love.graphics.setColor(textdowncolor)
|
||||
love.graphics.print(text, x + width/2 - twidth/2, y + height/2 - theight/2)
|
||||
-- button border
|
||||
love.graphics.setColor(bordercolor)
|
||||
skin.OutlinedRectangle(x, y, width, height)
|
||||
elseif hover then
|
||||
-- button body
|
||||
love.graphics.setColor(255, 255, 255, 255)
|
||||
love.graphics.draw(image_hover, x, y, 0, width, scaley)
|
||||
-- button text
|
||||
love.graphics.setFont(font)
|
||||
love.graphics.setColor(texthovercolor)
|
||||
love.graphics.print(text, x + width/2 - twidth/2, y + height/2 - theight/2)
|
||||
-- button border
|
||||
love.graphics.setColor(bordercolor)
|
||||
skin.OutlinedRectangle(x, y, width, height)
|
||||
else
|
||||
-- button body
|
||||
love.graphics.setColor(255, 255, 255, 255)
|
||||
love.graphics.draw(skin.images["button-nohover.png"], x, y, 0, width, scaley)
|
||||
-- button text
|
||||
love.graphics.setFont(font)
|
||||
love.graphics.setColor(textnohovercolor)
|
||||
love.graphics.print(text, x + width/2 - twidth/2, y + height/2 - theight/2)
|
||||
-- button border
|
||||
love.graphics.setColor(bordercolor)
|
||||
skin.OutlinedRectangle(x, y, width, height)
|
||||
end
|
||||
end
|
||||
|
||||
love.graphics.setColor(255, 255, 255, 150)
|
||||
|
Loading…
Reference in New Issue
Block a user