resaloli

guiAPI

Oct 19th, 2016
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.63 KB | None | 0 0
  1. --Coded by ResaloliPT--
  2.  
  3. function center(str,width)
  4.     while string.len(str) < width do
  5.         str = " "..str.." "
  6.     end
  7.     return str
  8. end
  9.  
  10. function round(num,dec)
  11.     local mult = 10^(dec or 0)
  12.     return math.floor(num + mult + 0.5)/mult
  13. end
  14.  
  15. function Percentage(toCalculate,maxToCalculate)
  16.     return round((toCalculate*100)/maxToCalculate,2)
  17. end
  18.  
  19. function drawBoxes(xmin,ymin,width,height)
  20.     mon.setBackgroundColor(colors.white)
  21.     mon.setCursorPos(xmin,ymin)
  22.     mon.write(string.rep(" ",width))
  23.     mon.setCursorPos(xmin,ymin+height)
  24.     mon.write(string.rep(" ",width))
  25.    
  26.     for i = 0, height do
  27.         mon.setCursorPos(xmin,ymin+i)
  28.         mon.write(string.rep(" ",2))
  29.     end
  30.    
  31.     for i = 0, height do
  32.         mon.setCursorPos(xmin+width,ymin+i)
  33.         mon.write(string.rep(" ",2))
  34.     end
  35.     mon.setBackgroundColor(colors.black)
  36. end
  37.  
  38. function drawRod(x,y,per)
  39.     for i = 0,10 do
  40.         mon.setCursorPos(x,y+i)
  41.         mon.setBackgroundColor(colors.yellow)
  42.         mon.write(string.rep(" ",3))
  43.     end
  44.     if per ~= nil then
  45.         for i = 0, per/10 do
  46.             mon.setCursorPos(x+1,y+i)
  47.             mon.setBackgroundColor(colors.blue)
  48.             mon.write(" ")
  49.         end
  50.     end
  51.     mon.setBackgroundColor(colors.black)
  52. end
  53.  
  54. function drawButtons(buttonT)
  55.     for name,data in pairs(buttonT) do
  56.         if data["state"] == 1 then
  57.         mon.setBackgroundColor(data["onColor"])
  58.         else
  59.         mon.setBackgroundColor(data["offColor"])
  60.         end
  61.         mon.setCursorPos(data["xmin"],data["ymin"])
  62.         for i = 0, data["height"] do
  63.             mon.setCursorPos(data["xmin"],data["ymin"]+i)
  64.             mon.write(string.rep(" ",data["width"]))
  65.         end
  66.         mon.setCursorPos(data["xmin"],data["ymin"]+(data["height"]/2))
  67.         mon.write(center(data["display"],data["width"]))
  68.     end
  69.     mon.setBackgroundColor(colors.black)
  70. end
  71.  
  72. function drawText(x,y,str,color)
  73.     color = color or color.white
  74.     mon.setBackgroundColor(colors.black)
  75.     mon.setCursorPos(x,y)
  76.     mon.setTextColor(color)
  77.     mon.write(str)
  78. end
  79.  
  80. function addButton(buttonT,name,func,display,xmin,ymin,width,height,offColor,onColor,state)
  81.     buttonT[name] = {}
  82.     buttonT[name]["name"] = name
  83.     buttonT[name]["func"] = func
  84.     buttonT[name]["display"] = display
  85.     buttonT[name]["xmin"] = xmin
  86.     buttonT[name]["ymin"] = ymin
  87.     buttonT[name]["width"] = width
  88.     buttonT[name]["height"] = height
  89.     buttonT[name]["offColor"] = offColor
  90.     buttonT[name]["onColor"] = onColor
  91.     buttonT[name]["state"] = state
  92. end
  93.  
  94. function checkxy(x, y, buttonT)
  95.     for id,data in pairs(buttonT) do
  96.         if x < data["xmin"]+data["width"] and x > data["xmin"] then
  97.             if y < data["ymin"]+data["height"] and y > data["ymin"] then
  98.             data["func"]()
  99.             end
  100.         end
  101.     end
  102.    return false
  103. end
  104.  
  105. function getClick()
  106.     event,side,x,y = os.pullEvent("monitor_touch")
  107.     checkxy(x, y)
  108. end
Add Comment
Please, Sign In to add comment