jay5476

button api

Sep 2nd, 2013
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. mainButton = {}
  2.  
  3. mt = {
  4. __index = mainButton
  5. }
  6. function create(name)
  7. return setmetatable(name,mt)
  8. end
  9.  
  10. function mainButton:new(x1,x2,y1,y2)
  11. self.map = {} -- create map of button
  12. self.pos = {x1,x2,y1,y2}
  13. for w = x1, x2 do
  14. --write("\n"..w.."-")
  15. self.map[w] = {} -- enter the current width
  16. for h = y1, y2 do
  17. self.map[w][h] = h -- enter then current height of the current width
  18. --write(" "..h)
  19. --sleep(0.1)
  20. end
  21. end
  22.  
  23. end
  24. --mainButton:new(4,8,4,8)
  25. function mainButton:draw(color)
  26. for key1, value1 in pairs(self["map"]) do
  27. for key2, value2 in pairs(self["map"][key1]) do
  28. paintutils.drawPixel(key1,value2,color)
  29. end
  30. end
  31.  
  32. end
  33.  
  34. function mainButton:cText(txt)
  35. w = math.ceil((self["pos"][1] + self['pos'][2])/2 - #txt/2)
  36. h = math.ceil((self['pos'][3] + self['pos'][4])/2 - #txt/2)
  37. term.setCursorPos(w,h)
  38. write(txt)
  39. end
  40.  
  41. function mainButton:click()
  42. _,_,x,y = os.pullEvent("mouse_click")
  43. for key1, value1 in pairs(self["map"]) do
  44. for key2, value2 in pairs(self["map"][key1]) do
  45. if x == key1 and y == value2 then
  46. return true
  47. end
  48. end
  49. end
  50. return false
  51. end
Advertisement
Add Comment
Please, Sign In to add comment