Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- monitor = peripheral.find("monitor")
- width, height = monitor.getSize()
- title = "Ore Processing"
- buttons = {}
- function createButton(name, func, x, y, w, h)
- nameLen = string.len(name)
- buttons[name] = { name = name, func = func, x = x, y = y, w = w, h = h, len = nameLen }
- monitor.setBackgroundColor(colors.red)
- for i = y, y + h do
- monitor.setCursorPos(x, i)
- for j = 1, w do
- monitor.write(" ")
- end
- end
- monitor.setCursorPos((x + x + w) / 2 - nameLen / 2, (y + y + h) / 2)
- monitor.write(name)
- --monitor.setCursorPos(5, 3)
- --monitor.write()
- end
- function checkEvent()
- event, side, xPos, yPos = os.pullEvent("monitor_touch")
- print(event .. " => Side: " .. tostring(side) .. ", " ..
- "X: " .. tostring(xPos) .. ", " ..
- "Y: " .. tostring(yPos))
- for _, btn in pairs(buttons) do
- print(tostring(xPos > btn.x))
- print(tostring(xPos < (btn.x + btn.h)))
- print(tostring(yPos > btn.y))
- print(tostring(yPos < (btn.y + btn.h)))
- if (xPos > btn.x) and (xPos < (btn.x + btn.h)) and (yPos > btn.y) and (yPos < (btn.y + btn.h)) then
- print("clicked " .. btn.name)
- end
- end
- end
- function draw()
- monitor.setBackgroundColor(colors.black)
- monitor.clear()
- monitor.setCursorPos(width / 2 - 7, 1)
- monitor.write(title)
- createButton("Test Button", test1, 5, 3, 13, 2)
- end
- while true do
- draw()
- checkEvent()
- os.sleep(0.5)
- end
- -- while true do
- -- event, side, xPos, yPos = os.pullEvent("monitor_touch")
- -- print(event .. " => Side: " .. tostring(side) .. ", " ..
- -- "X: " .. tostring(xPos) .. ", " ..
- -- "Y: " .. tostring(yPos))
- -- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement