Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- mon = peripheral.wrap("top")
- backgroundC = colors.black -- change me
- mon.setBackgroundColor(backgroundC)
- mon.clear()
- local button = {}
- function box(xmin,xmax,ymin,ymax,color)
- mon.setBackgroundColor(color)
- for i = xmin,xmax do
- for j = ymin,ymax do
- mon.setCursorPos(i,j)
- mon.write(" ")
- end
- i = i + 1
- end
- end
- function setTable(name,color,func,xmin,xmax,ymin,ymax)
- button[name] = {}
- button[name].color = color
- button[name].func = func
- button[name].active = false
- button[name].xmin = xmin
- button[name].xmax = xmax
- button[name].ymin = ymin
- button[name].ymax = ymax
- end
- function fill(text,color,bData)
- mon.setBackgroundColor(color)
- local yspot = math.floor((bData.ymin + bData.ymax)/2)
- local xspot = math.floor((bData.xmax - bData.xmin - #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 - #text + 1 do
- if k == xspot then
- mon.setTextColor(bData.color)
- mon.write(text)
- else
- mon.write (" ")
- end
- end
- else
- for i = bData.xmin, bData.xmax do
- mon.write(" ")
- end
- end
- end
- mon.setBackgroundColor(backgroundC)
- end
- function screen()
- 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
- 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
- end
- function heading(text,color)
- local w,h = mon.getSize()
- print (w/2)
- mon.setCursorPos(w/2 - (#text/2),1)
- mon.setTextColor(color)
- mon.write(text)
- end
- box(1,50,1,1.5,colors.white) -- heading box
- heading("Crazypkr1099 Button API",colors.black)
- setTable("test",colors.white,Test,5,10,4,8)
- screen()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement