Advertisement
pedrosgali

Window Manager

Sep 7th, 2014
612
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.44 KB | None | 0 0
  1. local scr = require("screen")
  2. local fs = require("filesystem")
  3. local event = require("event")
  4. local shell = require("shell")
  5. local term = require("term")
  6. local comp = require("component")
  7. local gpu = comp.gpu
  8.  
  9. --LOCAL CONSTANTS--
  10.  
  11. local maxPanes = 10
  12.  
  13. --LOCAL VARIABLES--
  14.  
  15. local mx, my = gpu.getResolution()
  16. local running = true
  17. local needRender = false
  18. local localPath = shell.getWorkingDirectory()
  19.  
  20. --GLOBAL VARIABLES--
  21.  
  22. st = {}
  23. sCount = 1
  24.  
  25. --TASKBAR SETUP--
  26.  
  27. local tb = scr:newPane(tb, mx, 1)
  28. tb:move(1, my)
  29. tb:box(1, 1, mx, 1, 0x999999)
  30. tb.priority = 10
  31. tb.isMoveable = false
  32.  
  33. function tb:run(ev, p1, p2, p3, p4, p5)
  34.     if ev == "touch" then
  35.         if self:clicked(p2, p3) then
  36.             ret = self:buttonClicked(p2, p3)
  37.             if ret == "time" then
  38.                
  39.             elseif type(ret) == "number" then
  40.                 st[ret].renderBool = true
  41.                 st[ret].needRender = true
  42.                 sortStack(ret)
  43.                 return true
  44.             end
  45.         else
  46.             return false
  47.         end
  48.     end
  49. end
  50.  
  51. st[1] = tb
  52.  
  53. --SCREEN MANAGER START--
  54.  
  55. function drawScreen()
  56.     st[1].buttonTab = nil
  57.     st[1].needRender = true
  58.     st[1].priority = 10
  59.     if needRender then
  60.         term.clear()
  61.         for i = 2, #st do
  62.             st[i].needRender = true
  63.         end
  64.     end
  65.     local xPos = 1
  66.     for p = 1, maxPanes do
  67.         for i = 1, #st do
  68.             if st[i].priority == p then
  69.                 if i ~= 1 then
  70.                     if st[i].selected then
  71.                         st[1]:button(st[i].label, xPos, 1, math.floor(160/(#st - 1)), 1, 0x666666, i)
  72.                     else
  73.                         st[1]:button(st[i].label, xPos, 1, math.floor(160/(#st - 1)), 1, 0x999999, i)
  74.                     end
  75.                     xPos = xPos + math.floor(160/(#st - 1))
  76.                 end
  77.                 if st[i].needRender then
  78.                     st[i]:render()
  79.                     st[i].needRender = false
  80.                 end
  81.             end
  82.         end
  83.     end
  84.     needRender = false
  85. end
  86.  
  87. function adjustStack()
  88.     if #st < sCount then
  89.         needRender = true
  90.         for i = 1, #st do
  91.             if st[i] == nil then
  92.                 for j = i + 1, #st do
  93.                     st[j - 1] = st[j]
  94.                     st[j] = nil
  95.                 end
  96.             end
  97.         end
  98.     end
  99.     sCount = #st
  100. end
  101.  
  102. function sortStack(num)
  103.     if num == 1 then return end
  104.     for i = 1, #st do
  105.         if i ~= num then
  106.             if st[i].priority > 1 then
  107.                 st[i].priority = st[i].priority - 1
  108.                 st[i].selected = false
  109.                 st[i].grabbed = false
  110.             end
  111.         else
  112.             st[i].priority = 9
  113.             st[i].selected = true
  114.         end
  115.     end
  116. end
  117.  
  118. function run()
  119.     local ev, p1, p2, p3, p4, p5 = event.pull(10, _, ev, p1, p2, p3, p4, p5)
  120.     if ev == "drop" then
  121.         for i = 1, #st do
  122.             st[i].grabbed = false
  123.             st[i].needRender = true
  124.         end
  125.     end
  126.     for p = maxPanes, 1, -1 do
  127.         for i = 1, #st do
  128.             if st[i].priority == p then
  129.                 if st[i]:run(ev, p1, p2, p3, p4, p5) then
  130.                     sortStack(i)
  131.                     return
  132.                 end
  133.             end
  134.         end
  135.     end
  136.     --add right click code here...
  137. end
  138.  
  139. shell.execute("konSoul")
  140.  
  141. while running do
  142.     drawScreen()
  143.     run()
  144.     adjustStack()
  145. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement