checkbox.lua 1.2 KB

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