Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Touchscreen Module--
- buttons = {}
- function checkForMonitor()
- local monitor = peripheral.find("monitor")
- if monitor then
- return monitor
- else
- error("No monitor found!")
- end
- end
- function createButton(x1,y1,x2,y2,text,color,func)
- local monitor = checkForMonitor()
- local oldTerm = term.redirect(monitor)
- paintutils.drawFilledBox(x1,y1,x2,y2,color)
- term.setTextColor(colors.black)
- term.setCursorPos(1,y1)
- term.write(text)
- term.redirect(oldTerm)
- table.insert(buttons,{x1,y1,x2,y2,text,color,func})
- end
- function render()
- while true do
- local monitor = checkForMonitor()
- local x,y = monitor.getSize()
- local oldTerm = term.redirect(monitor)
- term.setBackgroundColor(colors.black)
- term.clear()
- paintutils.drawFilledBox(1,1,x/monitor.getTextScale(),1,colors.orange)
- term.setTextColor(colors.black)
- term.setCursorPos(1,1)
- term.write("Lift")
- for i=1, #buttons do
- local x1 = buttons[i][1]
- local y1 = buttons[i][2]
- local x2 = buttons[i][3]
- local y2 = buttons[i][4]
- local text = buttons[i][5]
- local color = buttons[i][6]
- paintutils.drawFilledBox(x1,y1,x2,y2,color)
- term.setTextColor(colors.black)
- term.setCursorPos(x1,y1)
- term.write(text)
- end
- term.redirect(oldTerm)
- sleep()
- end
- end
- function mainShell()
- while true do
- event, side, xPos, yPos = os.pullEvent("monitor_touch")
- for i=1, #buttons do
- local x1 = buttons[i][1]
- local y1 = buttons[i][2]
- local x2 = buttons[i][3]
- local y2 = buttons[i][4]
- local text = buttons[i][5]
- local color = buttons[i][6]
- if x1 <= xPos and y1 <= yPos and x2 >= xPos and y2 >= yPos then
- buttons[i][6] = colors.gray
- else
- buttons[i][6] = colors.white
- end
- end
- end
- end
- function boot()
- parallel.waitForAll(mainShell,render)
- end
- -- boot()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement