Advertisement
LBPHacker

mouse_scroll test for SuicidalSTDz

Mar 13th, 2013
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.82 KB | None | 0 0
  1. local offset = 0
  2. local lines = {} -- load all lines you want to display here
  3. local termw, termh = term.getSize()
  4.  
  5. -- for testing
  6. for i = 64, 69 + termh do lines[#lines + 1] = string.char(i) end
  7.  
  8. local redraw = function()
  9.     term.clear()
  10.     for i = 1, termh do
  11.         term.setCursorPos(1, i)
  12.         term.write(lines[i + offset])
  13.     end
  14. end
  15. redraw()
  16.  
  17. local running = true
  18. while running do
  19.     local event, p1 = os.pullEvent()
  20.     if event == "mouse_scroll" then
  21.         if p1 == 1 and offset < math.max(#lines - termh, 0) then
  22.             offset = offset + 1
  23.             redraw()
  24.         end
  25.         if p1 == -1 and offset > 0 then
  26.             offset = offset - 1
  27.             redraw()
  28.         end
  29.     end
  30.     if event == "key" and p1 == 157 then running = false end -- rigth control stops the program
  31. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement