Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.loadAPI("settings.lua")
- os.loadAPI("graphics.lua")
- os.loadAPI("notifications.lua")
- buttons = {}
- hasMonitor = false
- if peripheral.find("monitor") then
- hasMonitor = true
- end
- function createBtn(text,bkgColor,height,width,x,y)
- btn = graphics.button:new()
- btn.text = text
- btn.bkgColor = bkgColor
- btn.h = height
- btn.w = width
- btn.x = x
- btn.y = y
- return btn
- end
- function createCheckbox(text,x,y,checked,bkgColor)
- checkbox = graphics.checkbox:new()
- checkbox.text = text
- checkbox.x = x
- checkbox.y = y
- checkbox.checked = checked
- checkbox.bkgColor = bkgColor
- return checkbox
- end
- function addButton(btn)
- table.insert(buttons, btn )
- end
- function closeProgram()
- notifications.addNotification("close", 10, "Program Closing", colors.red, colors.black)
- graphics.fillScreen(colors.black)
- os.shutdown()
- end
- function setupButtons()
- local w, h = term.getSize()
- -- shutdown button
- shutdownBtn = createBtn("X",colors.red,3,3,w-2,2)
- shutdownBtn.trigger = function()
- closeProgram()
- end
- addButton(shutdownBtn)
- end
- function drawButtons()
- for k,v in pairs(buttons) do
- v.draw(v)
- end
- end
- function buttonClickEvent()
- eventType = ""
- if hasMonitor == true then
- eventType = "monitor_touch"
- else
- eventType = "mouse_click"
- end
- event, button, x, y = os.pullEvent(eventType)
- for k,v in pairs(buttons) do
- v.detect(v,x,y,true)
- end
- end
- function initButtons()
- setupButtons()
- drawButtons()
- end
- function update()
- drawButtons()
- end
Add Comment
Please, Sign In to add comment