Advertisement
DeBrates

Double Click Demo

Jul 2nd, 2018
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.10 KB | None | 0 0
  1. local component = require("component")
  2. local event = require("event")
  3. local gray = 0x47494C
  4. local black = 0x000000
  5. local mon = component.gpu
  6. mon.setResolution(58,18)
  7.  
  8. --Page Variable
  9. local page
  10.  
  11. --Irrelevant variables
  12. local a = {}
  13. local w, h = mon.getResolution()
  14. --
  15.  
  16.  
  17. --Irrelevant Functions
  18. function centerText(mon, text, height)
  19.     local x2, y2 = mon.getResolution()
  20.     mon.set( x2/2 - (#text / 2) + 1, height, text)
  21. end
  22.  
  23. function clear()
  24.     mon.fill(1,1,w,h, " ")
  25. end
  26.  
  27. function tableLength(T)
  28.     local count = 0
  29.     for _ in pairs(T) do count = count + 1 end
  30.     return count
  31. end    
  32. --
  33.  
  34. --Draw Page 1 ***
  35. function pageOne()
  36.     centerText(mon, "Page 1", 1)
  37.     mon.setBackground(gray)
  38.     mon.fill(w/2 - 5, h/2 - 1, 12, 3, " ")
  39.     centerText(mon, "Button 1", h/2)
  40.     mon.setBackground(black)
  41.  
  42.     local aLength = tableLength(a)
  43.     lh = h/2 + 3
  44.     while aLength > 0 and lh < 19 do
  45.         centerText(mon, tostring(a[aLength]), lh)
  46.         lh = lh + 1
  47.         aLength = aLength - 1
  48.     end
  49. end
  50.  
  51. --Drag Page Two ***
  52. function pageTwo()
  53.     centerText(mon, "Page 2", 1)
  54.     mon.setBackground(gray)
  55.     mon.fill(w/2 - 5, h/2 - 1, 12, 3, " ")
  56.     centerText(mon, "Button 2", h/2)
  57.     mon.setBackground(black)
  58. end    
  59.  
  60. --Draw Page One and set Page = "page1" ***
  61. clear()
  62. pageOne()
  63. page = "page1"
  64.  
  65. while true do
  66.  
  67.     --if page then draw corresponding Page ***
  68.     if page == "page1" then
  69.         pageOne()
  70.     elseif page == "page2" then
  71.         pageTwo()
  72.     end    
  73.  
  74.     --Irrelevant os.exit when table reaches end of screen
  75.     if lh == 19 then
  76.         os.exit()
  77.     end    
  78.  
  79.     local touch, _, x, y = event.pull("touch")
  80.  
  81.     --Page 1 Handle ***
  82.     if page == "page1" and (x >= w/2 - 5 and x <= (w/2 - 5) + 11) and (y >= h/2 - 1 and y <= h/2 + 1) then
  83.         mon.set(4, 10, "Event 1")
  84.         table.insert(a, "X")
  85.         page = "page2"
  86.     end
  87.  
  88.     --Page 2 Handle ***
  89.     if page == "page2" and (x >= w/2 - 5 and x <= (w/2 - 5) + 11) and (y >= h/2 - 1 and y <= h/2 + 1) then
  90.         mon.set(4, 45, "Event 2")
  91.         page = "page1"
  92.     end
  93. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement