Advertisement
CaptainSpaceCat

CC IOS

May 12th, 2015
352
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.82 KB | None | 0 0
  1. w, h = term.getSize()
  2. os.loadAPI("iosutils")
  3. os.loadAPI("iosvars")
  4.  
  5. function resetScreen()
  6.   term.setBackgroundColor(iosvars.backgroundColor)
  7.   term.clear()
  8.   term.setCursorPos(w, 1)
  9.   if iosvars.wifi then
  10.     term.setBackgroundColor(colors.red)
  11.     term.write(" ")
  12.   else
  13.     term.setBackgroundColor(colors.black)
  14.     term.write(" ")
  15.   end
  16. end
  17.  
  18. function initializeApps()
  19.   appPage = {}
  20.   pg = 1
  21.   cnt = 1
  22.   os.loadAPI("iostabs")
  23.   os.loadAPI("iostabsinit")
  24.   if iosvars.wifi then
  25.     rednet.open("back")
  26.   else
  27.     rednet.close("back")
  28.   end
  29.   for i, v in pairs(iostabs.appsinit) do
  30.     appPage[pg] = {}
  31.     if iostabs.appsinit[i] then
  32.       appPage[pg][cnt] = iostabs.appsinit[i][5]
  33.       cnt = cnt + 1
  34.     end
  35.     if cnt == 10 then
  36.       pg = pg + 1
  37.       cnt = 1
  38.     end
  39.   end
  40. end
  41.  
  42. function drawApps()
  43.   for i = page * 9 - 9, page * 9 do
  44.     if iostabs.appsinit[i] then
  45.       paintutils.drawImage(iostabs.appsinit[i][5], iostabs.appsinit[i][1] - (page - 1) * w, iostabs.appsinit[i][2])
  46.     end
  47.   end
  48. end
  49.  
  50. function appcheck(x, y, x2, y2, run)
  51.   if (clickTab[3] >= x and clickTab[3] <= x2) and
  52.   (clickTab[4] >= y and clickTab[4] <= y2) then
  53.     --print("recieved"..tostring(x).." "..tostring(y).." "..run)
  54.     shell.run(run)
  55.   end
  56. end
  57.  
  58. function click()
  59.   clickTab = {os.pullEvent("mouse_click")}
  60.   return clickTab
  61. end
  62.  
  63. function drag()
  64.   dragTab = {os.pullEvent("mouse_drag")}
  65.   return dragTab
  66. end
  67.  
  68. page = 1
  69. while true do
  70.   os.loadAPI("iosvars")
  71.   initializeApps()
  72.   resetScreen()
  73.   drawApps()
  74.   term.setCursorPos(1, h)
  75.   --term.write("Page: " .. page)
  76.   parallel.waitForAny(click, drag)
  77.   if clickTab then
  78.     for i = page * 9 - 8, #iostabs.appsinit do
  79.       appcheck(iostabs.appsinit[i][1] - (page - 1) * w, iostabs.appsinit[i][2], iostabs.appsinit[i][3] - (page - 1) * w, iostabs.appsinit[i][4], iostabs.appsinit[i][6])
  80.     end
  81.   end
  82.   if dragTab then
  83.     if math.abs(clickTab[3] - dragTab[3]) > 15 then
  84.       dir = math.abs(clickTab[3] - dragTab[3]) / (clickTab[3] - dragTab[3])
  85.       if not ((page == 1 and dir == -1) or (page == #appPage and dir == 1)) then
  86.         page = page + dir
  87.         for k = 1, w * dir, dir do
  88.           resetScreen()
  89.           for i = 1, #iostabs.appsinit do
  90.             if dir == 1 then
  91.               if i > (page - 1) * 9 - 9 and i <= (page - 1) * 9 + 9 then
  92.                 paintutils.drawImage(iostabs.appsinit[i][5], iostabs.appsinit[i][1] - k - w * (page - 2), iostabs.appsinit[i][2])
  93.               end
  94.             elseif dir == -1 then
  95.               if i > (page + 1) * 9 - 18 and i <= (page + 1) * 9 then
  96.                 paintutils.drawImage(iostabs.appsinit[i][5], iostabs.appsinit[i][1] - k - w * page, iostabs.appsinit[i][2])
  97.               end
  98.             end
  99.           end
  100.           sleep(.01)
  101.         end
  102.       end
  103.     end
  104.   end
  105. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement