Kryzeth

makeButton

Oct 18th, 2017
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.88 KB | None | 0 0
  1. --label, row, column, background, text color
  2. local args = { ... }
  3.  
  4. --Set variables
  5. local length = 10
  6. local height = 3
  7. local label = args[1] or "EMPTY"
  8. local tx  = args[2] or 1
  9. local ty  = args[3] or 1
  10. local color = args[4] or colors.blue
  11. local text = args[5] or colors.white
  12.  
  13. --Set monitor properties
  14. mon = peripheral.wrap("monitor_1")
  15. mon.setTextScale(0.5)
  16.  
  17. --Calculate offset and position
  18. offsetX = (tx-1) * length + 1
  19. posX = offsetX + math.floor((length - #label)/2)
  20. posY = (ty-1) * height + 1
  21.  
  22. --Draw button first
  23. mon.setBackgroundColor(tonumber(color))
  24. mon.setTextColor(tonumber(text))
  25. mon.setCursorPos(offsetX,posY)
  26. mon.write(string.rep(" ", length))
  27. mon.setCursorPos(offsetX,posY+1)
  28. mon.write(string.rep(" ", length))
  29. mon.setCursorPos(offsetX,posY+2)
  30. mon.write(string.rep(" ", length))
  31.  
  32. --Draw label afterwards
  33. mon.setCursorPos(posX,posY+1)
  34. mon.write(label)
Advertisement
Add Comment
Please, Sign In to add comment