/
checkbox.lua
42 lines (40 loc) · 1.24 KB
/
checkbox.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
-- CHECKBOX
goo.checkbox = class('goo checkbox', goo.object)
goo.checkbox.image = {}
function goo.checkbox:initialize(parent)
super.initialize(self,parent)
self:setSkin()
self.checkState = 'unchecked'
self.w = 16
self.h = 16
end
function goo.checkbox:setSkin()
goo.checkbox.image.unchecked = love.graphics.newImage( goo.skin..'checkbox_unchecked.png' )
goo.checkbox.image.checked = love.graphics.newImage( goo.skin..'checkbox_checked.png' )
end
function goo.checkbox:draw(x,y)
self:setColor( 255,255,255 )
love.graphics.draw(self.image[self.checkState], x, y)
end
function goo.checkbox:mousepressed(x,y,button)
super.mousepressed(self,x,y,button)
if self.checkState == 'checked' then
self.checkState = 'unchecked'
else
self.checkState = 'checked'
end
end
function goo.checkbox:isChecked()
if self.checkState == 'checked' then return true else return false end
end
function goo.checkbox:setChecked(bool)
if bool then self.checkState = 'checked' else self.checkState = 'unchecked' end
end
function goo.checkbox:updateBounds()
local x,y = self:getAbsolutePos()
self.bounds.x1 = x
self.bounds.y1 = y
self.bounds.x2 = self.image[self.checkState]:getWidth() + x
self.bounds.y2 = self.image[self.checkState]:getHeight() + y
end
return goo.checkbox