Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local button={}
- local component = require("component")
- local colors = require("colors")
- local term = require("term")
- local mon = component.gpu
- local w, h = mon.getResolution()
- local Green = 0x00AA00
- local Red = 0xAA0000
- local Black = 0x000000
- function clear()
- mon.setBackground(Black)
- mon.fill(1, 1, w, h, " ")
- end
- function clearTable()
- button = {}
- clear()
- end
- function setTable(name, func, xmin, xmax, ymin, ymax)
- button[name] = {}
- button[name]["func"] = func
- button[name]["active"] = false
- button[name]["xmin"] = xmin
- button[name]["ymin"] = ymin
- button[name]["xmax"] = xmax
- button[name]["ymax"] = ymax
- end
- function funcName()
- print("You clicked buttonText")
- end
- function fillTable() -- not needed(?)
- setTable("ButtonText", funcName, 5, 25, 4, 8)
- end
- function fill(text, color, bData)
- mon.setBackground(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
- term.setCursor(bData["xmin"], j)
- if j == yspot then
- for k = 0, bData["xmax"] - bData["xmin"] - string.len(text) +1 do
- if k == xspot then
- term.write(text)
- else
- term.write(" ")
- end
- end
- else
- for i = bData["xmin"], bData["xmax"] do
- term.write(" ")
- end
- end
- end
- mon.setBackground(Black)
- end
- function screen()
- local currColor
- for name,data in pairs(button) do
- local on = data["active"]
- if on == true then currColor = Green else currColor = Red end
- fill(name, currColor, data)
- end
- end
- function toggleButton(name)
- button[name]["active"] = not button[name]["active"]
- screen()
- end
- function flash(name,length)
- toggleButton(name)
- screen()
- os.sleep(length)
- toggleButton(name)
- screen()
- end
- function checkxy(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["func"]()
- return true
- end
- end
- end
- return false
- end
- function heading(text)
- w, h = mon.getResolution()
- term.setCursor((w-string.len(text))/2+1, 1)
- term.write(text)
- end
- function label(w, h, text)
- mon.setCursorPos(w, h)
- mon.write(text)
- end
- --eof
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement