Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --experiment, not tested, not working
- --pastebin get 1QUnMKbz startup
- function getClick(window0,list)
- window0.clear()
- window0.setCursorPos(1,1)
- local w,h=window0.getSize()
- for k,v in ipairs(list) do
- local window1=window.create(window0, 1, k, w, 1, true)
- window1.setBackgroundColor(colors.orange)
- window1.write(tostring(k)..": "..v)
- --window0.write(tostring(k)..": "..v)
- --nextLine(window0)
- end
- while(true) do
- local event={pullEvents({["key"]=true,["mouse_click"]=true,["mouse_scroll"]=true})}
- --window0.write(event[1])
- if event[1]=="mouse_click" then
- local b=event[2]
- local x=event[3]
- local y=event[4]
- if isInsideWindow(window0,x,y) then
- return x,y
- end
- elseif event[1]=="mouse_scroll" then
- local scrollDirection=event[2]
- local x=event[3]
- local y=event[4]
- if isInsideWindow(window0,x,y) then
- --window0.write(" "..tostring(scrollDirection).." ")
- window0.scroll(scrollDirection)
- window0.redraw()
- end
- elseif event[1]=="key" then
- local keycode=event[2]
- end
- --nextLine(window0)
- sleep(0.15)
- end
- end
- function nextLine(window0)
- local x,y=window0.getCursorPos()
- window0.setCursorPos(1,y+1)
- end
- function isInsideWindow(window0,x,y)
- local wx, wy=window0.getPosition()
- local w,h=window0.getSize()
- return x>=wx and y>=wy and x<=wx+w and y<=wy+h
- end
- function toWindowCoordinate(window0,x,y)
- local wx, wy=window0.getPosition()
- return x-wx+1, y-wy+1
- end
- --example usage: pullEvents({["key"]=true,["mouse_click"]=true})
- function pullEvents(eventDict)
- while(true) do
- local event = { os.pullEvent() }
- if eventDict[event[1]]~=nil then
- return unpack(event)
- end
- end
- end
- --window.create(table parentTerm, number x, number y, number width, number height [, boolean visible])
- function screenCoveringWindow()
- local w, h = term.getSize()
- return window.create(term.current(),1,1,w,h,true)
- end
- function test()
- local list={"one","two","three"}
- local window0=screenCoveringWindow()
- getClick(window0,list)
- end
- test()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement