Advertisement
GladdeSnaak

Buttontest

Jan 30th, 2020
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.46 KB | None | 0 0
  1. local mon = peripheral.find("monitor")
  2. local button = {}
  3.  
  4. function setButton(name, title, func, xstart, ystart, xend, yend, color)
  5.     button[name] = {}
  6.     button[name][title] = title
  7.     button[name]["func"] = func
  8.     button[name]["active"] = false
  9.     button[name]["xstart"] = xstart
  10.     button[name]["ystart"] = ystart
  11.     button[name]["xend"] = xend
  12.     button[name]["yend"] = yend
  13.     button[name]["color"] = color
  14. end
  15.  
  16. data = button[name]
  17.  
  18. function checkxy()
  19. event, side, xpos, ypos = os.pullEvent("monitor_touch")
  20.  
  21. if xpos >= data["xstart"] and xpos =< data["xend"] then
  22.     if ypos >= data["ystart"] and ypos =< data["yend"] then
  23.     return true
  24.     end
  25. else
  26.     return false
  27. end
  28.  
  29. local bData = button[name]
  30.  
  31. function fill(text, color, bData)
  32.    mon.setBackgroundColor(color)
  33.    mon.setTextColor(colors.white)
  34.    local yspot = math.floor((bData["ymin"] + bData["ymax"]) /2)
  35.    local xspot = math.floor((bData["xmax"] - bData["xmin"] - string.len(bData["title"])) /2) +1
  36.    for j = bData["ymin"], bData["ymax"] do
  37.       mon.setCursorPos(bData["xmin"], j)
  38.       if j == yspot then
  39.          for k = 0, bData["xmax"] - bData["xmin"] - string.len(bData["title"]) +1 do
  40.             if k == xspot then
  41.                mon.write(bData["title"])
  42.             else
  43.                mon.write(" ")
  44.             end
  45.          end
  46.       else
  47.          for i = bData["xmin"], bData["xmax"] do
  48.             mon.write(" ")
  49.          end
  50.       end
  51.    end
  52.    mon.setBackgroundColor(colors.black)
  53. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement