Advertisement
Guest User

guiapi

a guest
Aug 23rd, 2014
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.68 KB | None | 0 0
  1. term.setTextColor(colors.white)
  2. local button={}
  3. term.setBackgroundColor(colors.black)
  4.  
  5. function clearTable()
  6.    button = {}
  7. end
  8.                
  9. function setButton(name, func, param, xmin, xmax, ymin, ymax)
  10.    button[name] = {}
  11.    button[name]["func"] = func
  12.    button[name]["active"] = false
  13.    button[name]["param"] = param
  14.    button[name]["xmin"] = xmin
  15.    button[name]["ymin"] = ymin
  16.    button[name]["xmax"] = xmax
  17.    button[name]["ymax"] = ymax
  18. end
  19.  
  20. function fill(text, color, bData)
  21.    term.setBackgroundColor(color)
  22.    local yspot = math.floor((bData["ymin"] + bData["ymax"]) /2)
  23.    local xspot = math.floor((bData["xmax"] - bData["xmin"] - string.len(text)) /2) +1
  24.    for j = bData["ymin"], bData["ymax"] do
  25.       term.setCursorPos(bData["xmin"], j)
  26.       if j == yspot then
  27.          for k = 0, bData["xmax"] - bData["xmin"] - string.len(text) +1 do
  28.             if k == xspot then
  29.                term.write(text)
  30.             else
  31.                term.write(" ")
  32.             end
  33.          end
  34.       else
  35.          for i = bData["xmin"], bData["xmax"] do
  36.             term.write(" ")
  37.          end
  38.       end
  39.    end
  40.    term.setBackgroundColor(colors.black)
  41. end
  42.      
  43. function screen()
  44.    local currColor
  45.    for name,data in pairs(button) do
  46.       local on = data["active"]
  47.       if on == true then currColor = colors.lime else currColor = colors.red end
  48.       fill(name, currColor, data)
  49.    end
  50. end
  51.  
  52. function setActive(name,status)
  53.    button[name]["active"] = status
  54. end  
  55.  
  56. function setButtonName(name,toName)
  57.     setTable(toName,button[name]["func"],button[name]["param"],button[name]["xmin"],button[name]["ymin"],button[name]["xmax"],button[name]["ymax"])
  58.     setActive(toName,button[name]["active"])
  59.     screen()
  60. end
  61.  
  62. function toggleButton(name)
  63.    button[name]["active"] = not button[name]["active"]
  64.    screen()
  65. end    
  66.  
  67. function flash(name)
  68.    toggleButton(name)
  69.    screen()
  70.    sleep(0.1)
  71.    toggleButton(name)
  72.    screen()
  73. end
  74.                                              
  75. function checkxy(x, y)
  76.    for name, data in pairs(button) do
  77.       if y>=data["ymin"] and  y <= data["ymax"] then
  78.          if x>=data["xmin"] and x<= data["xmax"] then
  79.             if data["param"] == "" then
  80.               data["func"]()
  81.             else
  82.               data["func"](data["param"])
  83.             end
  84.             return true
  85.             --data["active"] = not data["active"]
  86.             --print(name)
  87.          end
  88.       end
  89.    end
  90.    return false
  91. end
  92.      
  93. function heading(text)
  94.    w, h = term.getSize()
  95.    term.setCursorPos((w-string.len(text))/2+1, 1)
  96.    term.write(text)
  97. end
  98.      
  99. function label(w, h, text)
  100.    term.setCursorPos(w, h)
  101.    term.write(text)
  102. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement