Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- rednet.open("left")
- if viewportAPI then os.unloadAPI("viewportAPI") end
- os.loadAPI("viewportAPI")
- if buttonAPI then os.unloadAPI("buttonAPI") end
- os.loadAPI("buttonAPI")
- if eventDispatcherAPI then os.unloadAPI("eventDispatcherAPI") end
- os.loadAPI("eventDispatcherAPI")
- viewportLeft = viewportAPI.new({term = peripheral.wrap("up")})
- buttonUp = buttonAPI.new({
- text = "up",
- x = buttonAPI.anchorLeft,
- y = buttonAPI.anchorTop,
- isSticky = true,
- width = buttonAPI.maxWidth,
- height = 1
- })
- viewportLeft:addElement(buttonUp)
- buttonDown = buttonAPI.new({
- text = "down",
- x = buttonAPI.anchorLeft,
- y = buttonAPI.anchorBottom,
- isSticky = true,
- width = buttonAPI.maxWidth,
- height = 1
- })
- viewportLeft:addElement(buttonDown)
- buttonLeft = buttonAPI.new({
- text = "left",
- x = buttonAPI.anchorLeft,
- y = buttonAPI.anchorTop,
- isSticky = true,
- width = 1,
- height = buttonAPI.maxHeight,
- isVertical = true
- })
- viewportLeft:addElement(testbtn)
- viewportLeft:redraw()
- handler = function(element, x, y)
- dx = 0
- dy = 0
- if element == buttonUp then
- dy = -1
- elseif element == buttonDown then
- dy = 1
- elseif element == buttonLeft then
- dx = -1
- elseif element == buttonRight then
- dx = 1
- elseif element == testbtn then
- testbtn.backgroundColor = testbtn.backgroundColor == colors.green and colors.red or colors.green
- else
- error("Unknown Button")
- end
- viewportLeft:move(dx, dy)
- return true -- requests redraw of current viewport
- end
- buttonUp.callback = handler
- buttonDown.callback = handler
- buttonLeft.callback = handler
- buttonRight.callback = handler
- testbtn.callback = handler
- eventDispatcherAPI.addFilteredHandler("monitor_touch", "monitor_0", function(event, side, xPos, yPos)
- redraw = viewportLeft:handleClick(xPos, yPos)
- if redraw then
- viewportRight:redraw()
- end
- end)
- eventDispatcherAPI.addFilteredHandler("monitor_resize", "monitor_0", function()
- viewportLeft:redraw()
- end)
- eventDispatcherAPI.runDispatchLoop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement