Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local side = "right"
- local m = peripheral.wrap(side)
- local w, h = m.getSize()
- -- moitor properties
- m.clear()
- m.setCursorPos(1, 1)
- m.setTextScale(1)
- m.setTextColor(colors.white)
- m.setBackgroundColor(colors.black)
- local btns = {}
- function addButton(name, xmin, ymin, xmax, ymax, text)
- btns[name] = {}
- btns[name]["xmin"] = xmin
- btns[name]["ymin"] = ymin
- btns[name]["xmax"] = xmax
- btns[name]["ymax"] = ymax
- btns[name]["active"] = false
- btns[name]["text"] = text
- end
- function toggleActive(btnName)
- if btns[btnName]["active"] == true then
- btns[btnName]["active"] = false
- else
- brns[brnName]["active"] = true
- end
- end
- function drawButtons()
- for key, value in pairs(btns) do
- btn = btns[key]
- btnColor = colors.red
- if btn["active"] == true then
- btnColor = colors.green
- end
- m.setBackgroundColor(btnColor)
- fill(btn["text"], btnColor, value)
- end
- m.setBackgroundColor(colors.black)
- end
- function fill(text, color, bData)
- m.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
- m.setCursorPos(bData["xmin"], j)
- if j == yspot then
- for k = 0, bData["xmax"] - bData["xmin"] - string.len(text) +1 do
- if k == xspot then
- m.write(text)
- else
- m.write(" ")
- end
- end
- else
- for i = bData["xmin"], bData["xmax"] do
- m.write(" ")
- end
- end
- end
- m.setBackgroundColor(colors.black)
- end
- addButton("test", 1, 3, 3, 5, "Hello!")
- addButton("test2", 3, 6, 5, 8, "HAI!")
- drawButtons()
- while true do
- event, p, x, y = os.pullEvent("mitor_touch")
- for key, value in pairs(btns) do
- btn = btns[key]
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement