progressbar.lua 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. -------------------------------------------------------------
  2. ------ PROGRESS BAR.
  3. -------------------------------------------------------------
  4. goo.progressbar = class('goo progressbar', goo.object)
  5. function goo.progressbar:initialize( parent )
  6. super.initialize(self,parent)
  7. self.current_progress = 0
  8. self.max_progress = 100
  9. self.max_width = 100
  10. self.scale = 100
  11. self:setRange()
  12. end
  13. function goo.progressbar:draw( x, y )
  14. love.graphics.setColor( unpack(self.style.backgroundColor) )
  15. love.graphics.rectangle( self.style.fillMode, x, y, self.w, self.h )
  16. end
  17. function goo.progressbar:setProgress( progress )
  18. self.current_progress = progress
  19. local w = self.current_progress/self.range
  20. end
  21. function goo.progressbar:setPercentage( percentage )
  22. local percentage = percentage or 0
  23. self.w = self.max_width * (percentage/100)
  24. end
  25. function goo.progressbar:setRange( min, max )
  26. local min = min or 0
  27. local max = max or 100
  28. self.range = (max-min)
  29. return self.range
  30. end
  31. function goo.progressbar:setSize( w, h )
  32. super.setSize( self, w, h )
  33. self.max_width = w
  34. self.scale = self.range / w
  35. end
  36. function goo.progressbar:updateSize( w, h )
  37. local w = w or self.w or 0
  38. local h = h or self.h or 20
  39. self.w = w
  40. self.h = h
  41. end
  42. function goo.progressbar:incrementProgress()
  43. self.current_progress = self.current_progress + 1
  44. self:updateSize( (self.current_progress / self.range) * self.max_width )
  45. end
  46. function goo.progressbar:getProgress()
  47. return self.current_progress
  48. end
  49. function goo.progressbar:getPercentage()
  50. return (self.w/self.max_width)*100
  51. end
  52. return goo.progressbar