Add SetColor and GetColor methods to the imagebutton object

This commit is contained in:
Kenny Shields 2015-01-06 10:54:37 -05:00
parent 81074e44b7
commit cb6d7ca321
2 changed files with 26 additions and 3 deletions

View File

@ -24,6 +24,7 @@ function newobject:initialize()
self.clickable = true
self.enabled = true
self.image = nil
self.imagecolor = nil
self.OnClick = nil
end
@ -338,3 +339,24 @@ function newobject:GetImageHeight()
end
end
--[[---------------------------------------------------------
- func: SetColor(r, g, b, a)
- desc: sets the object's color
--]]---------------------------------------------------------
function newobject:SetColor(r, g, b, a)
self.imagecolor = {r, g, b, a}
return self
end
--[[---------------------------------------------------------
- func: GetColor()
- desc: gets the object's color
--]]---------------------------------------------------------
function newobject:GetColor()
return unpack(self.imagecolor)
end

View File

@ -508,6 +508,7 @@ function skin.DrawImageButton(object)
local text = object:GetText()
local hover = object:GetHover()
local image = object:GetImage()
local imagecolor = object.imagecolor or {255, 255, 255, 255}
local down = object.down
local font = skin.controls.imagebutton_text_font
local twidth = font:getWidth(object.text)
@ -518,7 +519,7 @@ function skin.DrawImageButton(object)
if down then
if image then
love.graphics.setColor(255, 255, 255, 255)
love.graphics.setColor(imagecolor)
love.graphics.draw(image, x + 1, y + 1)
end
love.graphics.setFont(font)
@ -528,7 +529,7 @@ function skin.DrawImageButton(object)
love.graphics.print(text, x + width/2 - twidth/2 + 1, y + height - theight - 6 + 1)
elseif hover then
if image then
love.graphics.setColor(255, 255, 255, 255)
love.graphics.setColor(imagecolor)
love.graphics.draw(image, x, y)
end
love.graphics.setFont(font)
@ -538,7 +539,7 @@ function skin.DrawImageButton(object)
love.graphics.print(text, x + width/2 - twidth/2, y + height - theight - 6)
else
if image then
love.graphics.setColor(255, 255, 255, 255)
love.graphics.setColor(imagecolor)
love.graphics.draw(image, x, y)
end
love.graphics.setFont(font)