Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function initialize(side)
- m = peripheral.wrap(side)
- m.setBackgroundColor(colors.black)
- m.clear()
- m.setCursorPos(1,1)
- items = {}
- m_x,m_y = m.getSize()
- end
- function clear()
- m.clear()
- for i = 1, #items do
- items[i]["loc"] = {}
- end
- end
- function mkItem(...)
- local id = #items + 1
- items[id] = {}
- items[id]["type"] = arg[1]
- items[id]["name"] = arg[2]
- if arg[1] == "btn" then
- items[id]["text"] = arg[3]
- items[id]["w"] = arg[4]
- items[id]["h"] = arg[5]
- items[id]["txtColor"] = arg[6]
- items[id]["bgColor"] = arg[7]
- items[id]["fn"] = arg[8]
- items[id]["args"] = arg[9]
- items[id]["loc"] = {}
- elseif arg[1] == "scn" then
- items[id]["items"] = arg[3]
- items[id]["bgColor"] = arg[4]
- end
- end
- function dispItem(...)
- for i = 1, #items do
- if items[i]["name"] == arg[1] then
- item = items[i]
- if item["type"] ~= "scn" then
- items[i]["loc"][#items[i]["loc"] + 1] = {arg[2],arg[3]}
- end
- break
- end
- end
- if item["type"] == "btn" then
- m.setBackgroundColor(item["bgColor"])
- m.setTextColor(item["txtColor"])
- for i = 1, item["h"] do
- m.setCursorPos(arg[2], arg[3]+i-1)
- if i ~= math.ceil(item["h"]/2) then
- for j = 1, item["w"] do
- m.write(" ")
- end
- else
- for j = 1, math.floor((item["w"] - string.len(item["text"])) / 2) do
- m.write(" ")
- end
- m.write(item["text"])
- for j = 1, math.ceil( (item["w"] - string.len(item["text"])) / 2) do
- m.write(" ")
- end
- end
- end
- elseif item["type"] == "scn" then
- clear()
- m.setBackgroundColor(item["bgColor"])
- for i = 1, m_y do
- m.setCursorPos(1,i)
- for j = 1, m_x do
- m.write(" ")
- end
- end
- for i = 1, #item["items"] do
- dispItem(item["items"][i][1],item["items"][i][2],item["items"][i][3])
- end
- end
- end
- function waitEvent()
- _,_,x,y = os.pullEvent("monitor_touch")
- for i = 1, #items do
- if items[i]["type"] == "btn" then
- for j = 1, #items[i]["loc"] do
- if x >= items[i]["loc"][j][1] and x < items[i]["loc"][j][1] + items[i]["w"] and y >= items[i]["loc"][j][2] and y < items[i]["loc"][j][2] + items[i]["h"] then
- items[i]["fn"](items[i]["args"])
- end
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment