Advertisement
Guest User

button

a guest
May 30th, 2016
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.27 KB | None | 0 0
  1.  
  2. function AddButton(name,text,x,y,width,height,mainColor)
  3. buttons[name] = {name,text,x,y,width,height,mainColor}
  4. end
  5.  
  6. function RemoveButton(name)
  7. buttons[name] = nil
  8. end
  9.  
  10. function IsButtonPressed(name)
  11.     value = buttons[name]
  12.     uX = value[3]
  13.     uY = value[4]
  14.     bX = value[3] + value[5]
  15.     bY = value[4] + value[6]
  16.     if(uX <= xPos and xPos <= bX and uY <= yPos and yPos <= bY) then
  17.       return true
  18.     else
  19.       return false
  20.     end
  21. end
  22.  
  23. function IsAnyButtonPressed()
  24.   for key, value in pairs(buttons) do
  25.     uX = value[3]
  26.     uY = value[4]
  27.     bX = value[3] + value[5]
  28.     bY = value[4] + value[6]
  29.     if(uX <= xPos and xPos <= bX and uY <= yPos and yPos <= bY) then
  30.     return true
  31.     else
  32.     return false
  33.     end
  34.   end
  35. end
  36.  
  37. function SetCurrentCursorPos(x,y)
  38. xPos = x
  39. yPos = y
  40. end
  41.  
  42. function DrawButtons(d)
  43. term.redirect(d)
  44.   for key, value in pairs(buttons) do
  45.     --Draw Button box
  46.     paintutils.drawFilledBox(value[3],value[4],value[3] + value[5], value[4] + value[6],value[7])
  47.     --Set Cursor for text
  48.     d.setCursorPos(value[3] + math.floor((value[5] - #value[2])/2),value[4] + math.floor(value[6]))
  49.     d.write(value[2])
  50.   end
  51.   d.setCursorPos(0,0)
  52. term.redirect(term.native())
  53. end
  54.  
  55.  
  56. buttons = {}
  57. xPos = 0
  58. yPos = 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement