Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Coded by ResaloliPT--
- function center(str,width)
- while string.len(str) < width do
- str = " "..str.." "
- end
- return str
- end
- function round(num,dec)
- local mult = 10^(dec or 0)
- return math.floor(num + mult + 0.5)/mult
- end
- function Percentage(toCalculate,maxToCalculate)
- return round((toCalculate*100)/maxToCalculate,2)
- end
- function drawBoxes(xmin,ymin,width,height)
- mon.setBackgroundColor(colors.white)
- mon.setCursorPos(xmin,ymin)
- mon.write(string.rep(" ",width))
- mon.setCursorPos(xmin,ymin+height)
- mon.write(string.rep(" ",width))
- for i = 0, height do
- mon.setCursorPos(xmin,ymin+i)
- mon.write(string.rep(" ",2))
- end
- for i = 0, height do
- mon.setCursorPos(xmin+width,ymin+i)
- mon.write(string.rep(" ",2))
- end
- mon.setBackgroundColor(colors.black)
- end
- function drawRod(x,y,per)
- for i = 0,10 do
- mon.setCursorPos(x,y+i)
- mon.setBackgroundColor(colors.yellow)
- mon.write(string.rep(" ",3))
- end
- if per ~= nil then
- for i = 0, per/10 do
- mon.setCursorPos(x+1,y+i)
- mon.setBackgroundColor(colors.blue)
- mon.write(" ")
- end
- end
- mon.setBackgroundColor(colors.black)
- end
- function drawButtons(buttonT)
- for name,data in pairs(buttonT) do
- if data["state"] == 1 then
- mon.setBackgroundColor(data["onColor"])
- else
- mon.setBackgroundColor(data["offColor"])
- end
- mon.setCursorPos(data["xmin"],data["ymin"])
- for i = 0, data["height"] do
- mon.setCursorPos(data["xmin"],data["ymin"]+i)
- mon.write(string.rep(" ",data["width"]))
- end
- mon.setCursorPos(data["xmin"],data["ymin"]+(data["height"]/2))
- mon.write(center(data["display"],data["width"]))
- end
- mon.setBackgroundColor(colors.black)
- end
- function drawText(x,y,str,color)
- color = color or color.white
- mon.setBackgroundColor(colors.black)
- mon.setCursorPos(x,y)
- mon.setTextColor(color)
- mon.write(str)
- end
- function addButton(buttonT,name,func,display,xmin,ymin,width,height,offColor,onColor,state)
- buttonT[name] = {}
- buttonT[name]["name"] = name
- buttonT[name]["func"] = func
- buttonT[name]["display"] = display
- buttonT[name]["xmin"] = xmin
- buttonT[name]["ymin"] = ymin
- buttonT[name]["width"] = width
- buttonT[name]["height"] = height
- buttonT[name]["offColor"] = offColor
- buttonT[name]["onColor"] = onColor
- buttonT[name]["state"] = state
- end
- function checkxy(x, y, buttonT)
- for id,data in pairs(buttonT) do
- if x < data["xmin"]+data["width"] and x > data["xmin"] then
- if y < data["ymin"]+data["height"] and y > data["ymin"] then
- data["func"]()
- end
- end
- end
- return false
- end
- function getClick()
- event,side,x,y = os.pullEvent("monitor_touch")
- checkxy(x, y)
- end
Add Comment
Please, Sign In to add comment