Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local mon = peripheral.wrap("top")
- local disp = peripheral.wrap("left")
- local button = {}
- --forward declarations
- setTable = function() end
- fill = function() end
- fillTable = function() end
- checkxy = function() end
- screen = function() end
- function main()
- mon.setTextColor(colors.white)
- mon.setBackgroundColor(colors.black)
- fillTable()
- while true do
- mon.clear()
- screen()
- local e,side,x,y = os.pullEvent("monitor_touch")
- print(x..":"..y)
- disp.clear()
- disp.setCursorPos(1,1)
- disp.write(x..":"..y)
- checkxy(x,y)
- sleep(.1)
- end
- end
- fillTable = function()
- setTable("1",1,1,1,1)
- setTable("2",3,3,1,1)
- setTable("3",5,5,1,1)
- setTable("4",7,7,1,1)
- setTable("5",2,2,2,2)
- setTable("6",4,4,2,2)
- setTable("7",6,6,2,2)
- end
- setTable = function(name, xmin, xmax, ymin, ymax)
- button[name] = {}
- button[name]["active"] = false
- button[name]["xmin"] = xmin
- button[name]["xmax"] = xmax
- button[name]["ymin"] = ymin
- button[name]["ymax"] = ymax
- end
- fill = function(text,color,bData)
- mon.setBackgroundColor(color)
- local yspot = math.floor((bData["ymin"] + bData["ymax"]) / 2)
- local xspot = math.floor((bData["xmax"] - bData["xmin"] - string.len(text)) / 2) + 1
- for j = bData["ymin"],bData["ymax"] do
- mon.setCursorPos(bData["xmin"],j)
- if j == yspot then
- for k = 0, bData["xmax"] - bData["xmin"] - string.len(text) + 1 do
- if k == xspot then
- mon.write(text)
- else
- mon.write(" ")
- end
- end
- else
- for i = bData["xmin"], bData["xmax"] do
- mon.write(" ")
- end
- end
- end
- mon.setBackgroundColor(colors.black)
- end
- screen = function()
- local currColor
- for name, data in pairs(button) do
- local on = data["active"]
- if on == true then currColor = colors.lime else currColor = colors.red end
- fill(name, currColor, data)
- end
- end
- checkxy = function(x,y)
- for name, data in pairs(button) do
- if y >= data["ymin"] and y <= data["ymax"] then
- if x >= data["xmin"] and x <= data["xmax"] then
- data["active"] = not data["active"]
- end
- end
- end
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment