SHARE
TWEET

dt

AquaJD Feb 22nd, 2017 (edited) 320 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. local tMenus = {
  3.   ["Notifications"] = { x = 20, y = 3, w = 29, h = 13, label = "Notifications", type = "menu", active = false },
  4.   ["Control Panel"] = { x = 20, y = 3, w = 29, h = 11, label = "Control Panel", type = "menu", active = false, slc = 0 },
  5.   ["Window Creator"] = { x = 20, y = 3, w = 30, h = 14, label = "Window Creator", type = "menu", active = false }
  6. }
  7.  
  8. local tButtons = {
  9.   ["CP_Appearance"] = { x = 22, y = 5, w = 25, h = 3, label = "Appearance", type = "button" },
  10.   ["CP_Users"] = { x = 22, y = 9, w = 25, h = 3, label = "Users", type = "button" },
  11.   ["WC_Path"] = { x = 22, y = 5, w = 26, h = 1, label = "Path:", type = "button_input", data = nil },
  12.   ["WC_Width"] = { x = 22, y = 7, w = 26, h = 1, label = "Width:", type = "button_input", data = nil },
  13.   ["WC_Height"] = { x = 22, y = 9, w = 26, h = 1, label = "Height:", type = "button_input", data = nil },
  14.   ["WC_Create"] = { x = 22, y = 12, w = 26, h = 3, label = "Create", type = "button" },
  15.   ["MSG_Input"] = { x = 5, y = 13, w = 31, h = 4, label = "Input Box", type = "message_input", prompt = "", data = "", active = false }
  16. }
  17.  
  18. local tNotifications = {
  19.   [1] = { label = "", func = function() end, time = "", type = "notification", id = 1 },
  20.   [2] = { label = "", func = function() end, time = "", type = "notification", id = 2 },
  21.   [3] = { label = "", func = function() end, time = "", type = "notification", id = 3 },
  22.   [4] = { label = "", func = function() end, time = "", type = "notification", id = 4 },
  23.   [5] = { label = "", func = function() end, time = "", type = "notification", id = 5 },
  24.   [6] = { label = "", func = function() end, time = "", type = "notification", id = 6 },
  25.   [7] = { label = "", func = function() end, time = "", type = "notification", id = 7 },
  26.   [8] = { label = "", func = function() end, time = "", type = "notification", id = 8 },
  27.   [9] = { label = "", func = function() end, time = "", type = "notification", id = 9 },
  28.   [10] = { label = "", func = function() end, time = "", type = "notification", id = 10 }
  29. }
  30.  
  31. local tColourPalette = {
  32.   ["white"] = 1,
  33.   ["orange"] = 2,
  34.   ["magenta"] = 4,
  35.   ["light blue"] = 8,
  36.   ["lightblue"] = 8,
  37.   ["yellow"] = 16,
  38.   ["lime"] = 32,
  39.   ["pink"] = 64,
  40.   ["gray"] = 128,
  41.   ["light gray"] = 256,
  42.   ["lightgray"] = 256,
  43.   ["cyan"] = 512,
  44.   ["purple"] = 1024,
  45.   ["blue"] = 2048,
  46.   ["brown"] = 4096,
  47.   ["green"] = 8192,
  48.   ["red"] = 16384,
  49.   ["black"] = 32768
  50. }
  51.  
  52. local tWindows = {}
  53. local tIcons = {}
  54. local tFolders = {}
  55. local tColors = {
  56.   ["main"] = {},
  57.   ["menu"] = {},
  58.   ["button"] = {},
  59.   ["taskbar"] = {},
  60.   ["icon"] = {},
  61.   ["folder"] = {},
  62.   ["bar"] = {}
  63. }
  64. local tBackgroundEvents = {
  65.   "alarm",
  66.   "timer",
  67.   "redstone",
  68.   "rednet_message",
  69.   "disk",
  70.   "disk_eject",
  71.   "peripheral",
  72.   "peripheral_detach",
  73.   "modem_message"
  74. }
  75. local tPrograms = fs.list("/rom/programs/")
  76.  
  77. local fs_config = "/djos/dj.cfg"
  78. local fs_activeDir = "/desktop/"
  79.  
  80. local bRunning = true
  81.  
  82. local rUpdate = os.startTimer(30)
  83. local rTime = os.startTimer(1)
  84.  
  85. local term_width, term_height = term.getSize()
  86. local original_term = term.current()
  87.  
  88. local bMenu_Start = false
  89. local bMenu_File = false
  90. local bMenu_Logout = false
  91.  
  92. local activeWindow = nil
  93.  
  94. local rDragTime = 0
  95. local bDragging = false
  96.  
  97. if not fs.exists("/desktop") then
  98.   fs.makeDir("/desktop")
  99. end
  100. if not fs.exists("/djos") then
  101.   fs.makeDir("/djos")
  102. end
  103.  
  104. -- Load complete settings of computer
  105. local function loadConfig()
  106.   if fs.exists(fs_config) then
  107.     settings.load(fs_config)
  108.     tColors["main"].bg = settings.get("dj_main.bg")
  109.     tColors["main"].fg = settings.get("dj_main.fg")
  110.     tColors["menu"].bg = settings.get("dj_menu.bg")
  111.     tColors["menu"].fg = settings.get("dj_menu.fg")
  112.     tColors["taskbar"].bg = settings.get("dj_taskbar.bg")
  113.     tColors["taskbar"].fg = settings.get("dj_taskbar.fg")
  114.     tColors["taskbar"].start = settings.get("dj_taskbar.start")
  115.     tColors["taskbar"].other = settings.get("dj_taskbar.other")
  116.     tColors["button"].bg = settings.get("dj_button.bg")
  117.     tColors["button"].fg = settings.get("dj_button.fg")
  118.     tColors["bar"].bg = settings.get("dj_bar.bg")
  119.     tColors["bar"].fg = settings.get("dj_bar.fg")
  120.     tColors["bar"].drag = settings.get("dj_bar.drag")
  121.     tColors["bar"].close = settings.get("dj_bar.close")
  122.     tColors["bar"].edit = settings.get("dj_bar.edit")
  123.     tColors["folder"].bg = settings.get("dj_folder.bg")
  124.     tColors["folder"].fg = settings.get("dj_folder.fg")
  125.     tColors["icon"].bg = settings.get("dj_icon.bg")
  126.     tColors["icon"].fg = settings.get("dj_icon.fg")
  127.   else
  128.     settings.set("dj_main.bg",colors.white)
  129.     settings.set("dj_main.fg",colors.black)
  130.     settings.set("dj_menu.bg",colors.blue)
  131.     settings.set("dj_menu.fg",colors.white)
  132.     settings.set("dj_taskbar.bg",colors.blue)
  133.     settings.set("dj_taskbar.fg",colors.white)
  134.     settings.set("dj_taskbar.start",colors.green)
  135.     settings.set("dj_taskbar.other",colors.lightBlue)
  136.     settings.set("dj_button.bg",colors.lightBlue)
  137.     settings.set("dj_button.fg",colors.white)
  138.     settings.set("dj_bar.bg",colors.gray)
  139.     settings.set("dj_bar.fg",colors.white)
  140.     settings.set("dj_bar.drag",colors.yellow)
  141.     settings.set("dj_bar.close",colors.red)
  142.     settings.set("dj_bar.edit",colors.green)
  143.     settings.set("dj_folder.bg",colors.yellow)
  144.     settings.set("dj_folder.fg",colors.lightGray)
  145.     settings.set("dj_icon.bg",colors.orange)
  146.     settings.set("dj_icon.fg",colors.lightGray)
  147.     settings.save(fs_config)
  148.     loadConfig()
  149.   end
  150. end
  151.  
  152. -- Load current directory config
  153. local function loadDirConfig()
  154.   tIcons = {}
  155.   tFolders = {}
  156.   local dir_list = fs.list(fs_activeDir)
  157.   local n = 0
  158.   for i=1,#dir_list do
  159.     local type = "icon"
  160.     local tChoice = tIcons
  161.     if fs.isDir(fs_activeDir..dir_list[i]) then
  162.       tChoice = tFolders
  163.       type = "folder"
  164.     end
  165.     if settings.get(fs_activeDir..dir_list[i]..".x") then
  166.       table.insert(tChoice,fs_activeDir..dir_list[i])
  167.       tChoice[fs_activeDir..dir_list[i]] = {}
  168.       tChoice[fs_activeDir..dir_list[i]].x = settings.get(fs_activeDir..dir_list[i]..".x")
  169.       tChoice[fs_activeDir..dir_list[i]].y = settings.get(fs_activeDir..dir_list[i]..".y")
  170.       tChoice[fs_activeDir..dir_list[i]].w = settings.get(fs_activeDir..dir_list[i]..".w")
  171.       tChoice[fs_activeDir..dir_list[i]].h = settings.get(fs_activeDir..dir_list[i]..".h")
  172.       tChoice[fs_activeDir..dir_list[i]].type = settings.get(fs_activeDir..dir_list[i]..".type")
  173.       tChoice[fs_activeDir..dir_list[i]].label = settings.get(fs_activeDir..dir_list[i]..".label")
  174.     else
  175.       settings.set(fs_activeDir..dir_list[i]..".x",4+(5*n))
  176.       settings.set(fs_activeDir..dir_list[i]..".y",3)
  177.       settings.set(fs_activeDir..dir_list[i]..".w",4)
  178.       settings.set(fs_activeDir..dir_list[i]..".h",3)
  179.       settings.set(fs_activeDir..dir_list[i]..".type",type)
  180.       settings.set(fs_activeDir..dir_list[i]..".label",dir_list[i])
  181.       settings.save(fs_config)
  182.       loadDirConfig()
  183.     end
  184.     n = n + 1
  185.   end
  186. end
  187.  
  188. -- Save file/folder configs in current directory
  189. local function saveDirConfig()
  190.   local dir_list = fs.list(fs_activeDir)
  191.   for i=1,#dir_list do
  192.     if fs.exists(fs_activeDir..dir_list[i]) and fs.isDir(fs_activeDir..dir_list[i]) then
  193.       settings.set(fs_activeDir..dir_list[i]..".x",tFolders[fs_activeDir..dir_list[i]].x)
  194.       settings.set(fs_activeDir..dir_list[i]..".y",tFolders[fs_activeDir..dir_list[i]].y)
  195.       settings.set(fs_activeDir..dir_list[i]..".w",tFolders[fs_activeDir..dir_list[i]].w)
  196.       settings.set(fs_activeDir..dir_list[i]..".h",tFolders[fs_activeDir..dir_list[i]].h)
  197.       settings.set(fs_activeDir..dir_list[i]..".type",tFolders[fs_activeDir..dir_list[i]].type)
  198.       settings.set(fs_activeDir..dir_list[i]..".label",tFolders[fs_activeDir..dir_list[i]].label)
  199.     elseif fs.exists(fs_activeDir..dir_list[i]) then
  200.       settings.set(fs_activeDir..dir_list[i]..".x",tIcons[fs_activeDir..dir_list[i]].x)
  201.       settings.set(fs_activeDir..dir_list[i]..".y",tIcons[fs_activeDir..dir_list[i]].y)
  202.       settings.set(fs_activeDir..dir_list[i]..".w",tIcons[fs_activeDir..dir_list[i]].w)
  203.       settings.set(fs_activeDir..dir_list[i]..".h",tIcons[fs_activeDir..dir_list[i]].h)
  204.       settings.set(fs_activeDir..dir_list[i]..".type",tIcons[fs_activeDir..dir_list[i]].type)
  205.       settings.set(fs_activeDir..dir_list[i]..".label",tIcons[fs_activeDir..dir_list[i]].label)
  206.     end
  207.   end
  208.   settings.save(fs_config)
  209. end
  210.  
  211. -- Create a new window
  212. local function window_new(path,w,h)
  213.   if not tWindows[path] then
  214.     tWindows[path] = {}
  215.     local startIndex = 0
  216.     local bPossible = false
  217.     for i=1,#path do
  218.       if string.sub(path,i,i) == "/" then
  219.         if bPossible == false then
  220.           bPossible = true
  221.           startIndex = i + 1
  222.         else
  223.           startIndex = i + 1
  224.         end
  225.       end
  226.     end
  227.     tWindows[path].x = 4
  228.     tWindows[path].y = 8
  229.     tWindows[path].w = w
  230.     tWindows[path].h = h-1
  231.     tWindows[path].func = function() shell.run(path) end
  232.     tWindows[path].label = string.sub(path,startIndex,#path)
  233.     tWindows[path].type = "window"
  234.     tWindows[path].cor = coroutine.create(tWindows[path].func)
  235.     tWindows[path].active = true
  236.     tWindows[path].obj = window.create(original_term,tWindows[path].x,tWindows[path].y,tWindows[path].w,tWindows[path].h,true)
  237.     return tWindows[path]
  238.   end
  239.   return false
  240. end
  241.  
  242. function notification_new(label,func,time)
  243.   local bChosen = 0
  244.   for i=1,#tNotifications do
  245.     if tNotifications[i].label == "" and bChosen == 0 then
  246.       bChosen = i
  247.     end
  248.   end
  249.   if bChosen == 0 then
  250.     bChosen = 10
  251.     for i=1,9 do
  252.       tNotifications[i].label = tNotifications[i+1].label
  253.       tNotifications[i].func = tNotifications[i+1].func
  254.       tNotifications[i].time = tNotifications[i+1].time
  255.     end
  256.   end
  257.   tNotifications[bChosen].label = label
  258.   tNotifications[bChosen].func = func
  259.   tNotifications[bChosen].time = time
  260. end
  261.  
  262. -- Update Control Panel buttons to be on the right coords
  263. local function updateControlPanel()
  264.   tButtons["CP_Appearance"].x = tMenus["Control Panel"].x + 2
  265.   tButtons["CP_Appearance"].y = tMenus["Control Panel"].y + 2
  266.   tButtons["CP_Users"].x = tMenus["Control Panel"].x + 2
  267.   tButtons["CP_Users"].y = tMenus["Control Panel"].y + 6
  268. end
  269.  
  270. -- Update Window Creator buttons to be on the right coords
  271. local function updateWindowCreator()
  272.   tButtons["WC_Path"].x = tMenus["Window Creator"].x + 2
  273.   tButtons["WC_Path"].y = tMenus["Window Creator"].y + 2
  274.   tButtons["WC_Width"].x = tMenus["Window Creator"].x + 2
  275.   tButtons["WC_Width"].y = tMenus["Window Creator"].y + 4
  276.   tButtons["WC_Height"].x = tMenus["Window Creator"].x + 2
  277.   tButtons["WC_Height"].y = tMenus["Window Creator"].y + 6
  278.   tButtons["WC_Create"].x = tMenus["Window Creator"].x + 2
  279.   tButtons["WC_Create"].y = tMenus["Window Creator"].y + 9
  280. end
  281.  
  282. -- Update notifications, making sure they are in order
  283. local function updateNotifications()
  284.   for i=1,#tNotifications do
  285.     if i >= 2 then
  286.       if tNotifications[i-1].label == "" then
  287.         tNotifications[i-1].label = tNotifications[i].label
  288.         tNotifications[i-1].func = tNotifications[i].func
  289.         tNotifications[i-1].time = tNotifications[i].time
  290.         if tNotifications[i+1] then
  291.           tNotifications[i].label = tNotifications[i+1].label
  292.           tNotifications[i].func = tNotifications[i+1].func
  293.           tNotifications[i].time = tNotifications[i+1].time
  294.           if tNotifications[i+2] then
  295.             tNotifications[i+1].label = tNotifications[i+2].label
  296.             tNotifications[i+1].func = tNotifications[i+2].func
  297.             tNotifications[i+1].time = tNotifications[i+2].time
  298.             if tNotifications[i+3] then
  299.               tNotifications[i+2].label = tNotifications[i+3].label
  300.               tNotifications[i+2].func = tNotifications[i+3].func
  301.               tNotifications[i+2].time = tNotifications[i+3].time
  302.               if tNotifications[i+4] then
  303.                 tNotifications[i+3].label = tNotifications[i+4].label
  304.                 tNotifications[i+3].func = tNotifications[i+4].func
  305.                 tNotifications[i+3].time = tNotifications[i+4].time
  306.                 if tNotifications[i+5] then
  307.                   tNotifications[i+4].label = tNotifications[i+5].label
  308.                   tNotifications[i+4].func = tNotifications[i+5].func
  309.                   tNotifications[i+4].time = tNotifications[i+5].time
  310.                   if tNotifications[i+6] then
  311.                     tNotifications[i+5].label = tNotifications[i+6].label
  312.                     tNotifications[i+5].func = tNotifications[i+6].func
  313.                     tNotifications[i+5].time = tNotifications[i+6].time
  314.                     if tNotifications[i+7] then
  315.                       tNotifications[i+6].label = tNotifications[i+7].label
  316.                       tNotifications[i+6].func = tNotifications[i+7].func
  317.                       tNotifications[i+6].time = tNotifications[i+7].time
  318.                       if tNotifications[i+8] then
  319.                         tNotifications[i+7].label = tNotifications[i+8].label
  320.                         tNotifications[i+7].func = tNotifications[i+8].func
  321.                         tNotifications[i+7].time = tNotifications[i+8].time
  322.                         if tNotifications[i+9] then
  323.                           tNotifications[i+8].label = tNotifications[i+9].label
  324.                           tNotifications[i+8].func = tNotifications[i+9].func
  325.                           tNotifications[i+8].time = tNotifications[i+9].time
  326.                         else
  327.                           tNotifications[i+8].label = ""
  328.                           tNotifications[i+8].func = function() end
  329.                           tNotifications[i+8].time = ""
  330.                         end
  331.                       else
  332.                         tNotifications[i+7].label = ""
  333.                         tNotifications[i+7].func = function() end
  334.                         tNotifications[i+7].time = ""
  335.                       end
  336.                     else
  337.                       tNotifications[i+6].label = ""
  338.                       tNotifications[i+6].func = function() end
  339.                       tNotifications[i+6].time = ""
  340.                     end
  341.                   else
  342.                     tNotifications[i+5].label = ""
  343.                     tNotifications[i+5].func = function() end
  344.                     tNotifications[i+5].time = ""
  345.                   end
  346.                 else
  347.                   tNotifications[i+4].label = ""
  348.                   tNotifications[i+4].func = function() end
  349.                   tNotifications[i+4].time = ""
  350.                 end
  351.               else
  352.                 tNotifications[i+3].label = ""
  353.                 tNotifications[i+3].func = function() end
  354.                 tNotifications[i+3].time = ""
  355.               end
  356.             else
  357.               tNotifications[i+2].label = ""
  358.               tNotifications[i+2].func = function() end
  359.               tNotifications[i+2].time = ""
  360.             end
  361.           else
  362.             tNotifications[i+1].label = ""
  363.             tNotifications[i+1].func = function() end
  364.             tNotifications[i+1].time = ""
  365.           end
  366.         else
  367.           tNotifications[i].label = ""
  368.           tNotifications[i].func = function() end
  369.           tNotifications[i].time = ""
  370.         end
  371.       end
  372.     end
  373.   end
  374. end
  375.  
  376. -- Convert a colour's number to it's name
  377. local function convertNumToCol(num)
  378.   for k,v in pairs(tColourPalette) do
  379.     if v == num then
  380.       return k
  381.     end
  382.   end
  383. end
  384.  
  385. -- Draw a box with specific data
  386. local function drawBox(x,y,w,h,colour,bar)
  387.   term.setBackgroundColor(colour)
  388.   term.setCursorPos(x,y)
  389.   for i=1,h do
  390.     for i=1,w do
  391.       write(" ")
  392.     end
  393.     term.setCursorPos(x,y+i)
  394.   end
  395.   term.setTextColor(tColors["bar"].bg)
  396.   term.setCursorPos(x,y)
  397.   if bar then
  398.     for i=1,h do
  399.       write(string.char(133))
  400.       term.setCursorPos(x,y+i)
  401.     end
  402.     term.setCursorPos(x+w-1,y)
  403.     for i=1,h do
  404.       write(string.char(138))
  405.       term.setCursorPos(x+w-1,y+i)
  406.     end
  407.     term.setCursorPos(x,y+h-1)
  408.     for i=1,w do
  409.       write(string.char(140))
  410.       term.setCursorPos(x+i,y+h-1)
  411.     end
  412.     term.setCursorPos(x,y+h-1)
  413.     write(string.char(141))
  414.     term.setCursorPos(x+w-1,y+h-1)
  415.     write(string.char(142))
  416.   end
  417. end
  418.  
  419. -- Draw status bar
  420. local function drawBar(x,y,w,bC,bD,bE,text)
  421.   term.setBackgroundColor(tColors["bar"].bg)
  422.   term.setCursorPos(x,y)
  423.   for i=1,w do
  424.     write(" ")
  425.   end
  426.   if bC then
  427.     term.setCursorPos(x+w-1,y)
  428.     term.setTextColor(tColors["bar"].close)
  429.     print(string.char(7))
  430.   end
  431.   if bE then
  432.     term.setCursorPos(x+w-2,y)
  433.     term.setTextColor(tColors["bar"].edit)
  434.     print(string.char(7))
  435.   end
  436.   if bD then
  437.     term.setCursorPos(x,y)
  438.     term.setTextColor(tColors["bar"].drag)
  439.     print(string.char(7))
  440.   end
  441.   if text then
  442.     term.setCursorPos(x+(w/2)-(#text/2),y)
  443.     term.setTextColor(tColors["bar"].fg)
  444.     print(text)
  445.   end
  446. end
  447.  
  448. -- Draw an object (object being a table of data)
  449. local function drawObject(obj)
  450.   if obj.type == "notification" then
  451.     if obj.label ~= "" then
  452.       term.setBackgroundColor(tColors["menu"].bg)
  453.       term.setTextColor(colors.white)
  454.       if obj.id == 2 or obj.id == 4 or obj.id == 6 or obj.id == 8 or obj.id == 10 then
  455.         term.setTextColor(colors.black)
  456.       end
  457.       term.setCursorPos(tMenus["Notifications"].x+1,tMenus["Notifications"].y+obj.id+1)
  458.       print(obj.label)
  459.       term.setCursorPos(tMenus["Notifications"].x+tMenus["Notifications"].w-2,tMenus["Notifications"].y+obj.id+1)
  460.       term.setTextColor(tColors["bar"].close)
  461.       print(string.char(7))
  462.       term.setCursorPos(tMenus["Notifications"].x+tMenus["Notifications"].w-3,tMenus["Notifications"].y+obj.id+1)
  463.       term.setTextColor(tColors["bar"].edit)
  464.       print(string.char(7))
  465.     end
  466.   elseif obj.type == "folder" then
  467.     drawBox(obj.x,obj.y,obj.w,obj.h,tColors["folder"].bg)
  468.     drawBar(obj.x,obj.y,obj.w,true,true,true,"")
  469.     term.setCursorPos(obj.x,obj.y+obj.h-1)
  470.     term.setBackgroundColor(tColors["folder"].bg)
  471.     term.setTextColor(tColors["folder"].fg)
  472.     if #obj.label >= obj.w then
  473.       print(string.sub(obj.label,1,obj.w-1)..".")
  474.     else
  475.       print(obj.label)
  476.     end
  477.   elseif obj.type == "icon" then
  478.     drawBox(obj.x,obj.y,obj.w,obj.h,tColors["icon"].bg)
  479.     drawBar(obj.x,obj.y,obj.w,true,true,true,"")
  480.     term.setCursorPos(obj.x,obj.y+obj.h-1)
  481.     term.setBackgroundColor(tColors["icon"].bg)
  482.     term.setTextColor(tColors["icon"].fg)
  483.     if #obj.label >= obj.w then
  484.       print(string.sub(obj.label,1,obj.w-1)..".")
  485.     else
  486.       print(obj.label)
  487.     end
  488.   elseif obj.type == "button" then
  489.     drawBox(obj.x,obj.y,obj.w,obj.h,tColors["button"].bg)
  490.     term.setBackgroundColor(tColors["button"].bg)
  491.     term.setTextColor(tColors["button"].fg)
  492.     if obj.h == 3 then
  493.       term.setCursorPos(obj.x+(obj.w/2)-(#obj.label/2),obj.y+1)
  494.     else
  495.       term.setCursorPos(obj.x+(obj.w/2)-(#obj.label/2),obj.y)
  496.     end
  497.     print(obj.label)
  498.   elseif obj.type == "menu" then
  499.     drawBox(obj.x,obj.y,obj.w,obj.h,tColors["menu"].bg,true)
  500.     drawBar(obj.x,obj.y,obj.w,true,true,false,obj.label)
  501.   elseif obj.type == "message_input" then
  502.     drawBox(obj.x,obj.y,obj.w,obj.h,tColors["menu"].bg,true)
  503.     drawBar(obj.x,obj.y,obj.w,true,true,false,obj.label)
  504.     term.setBackgroundColor(colors.lightGray)
  505.     term.setCursorPos(obj.x+#obj.prompt+2,obj.y+2)
  506.     for i=1,obj.w-(#obj.prompt+3) do
  507.       write(" ")
  508.     end
  509.     term.setCursorPos(obj.x+#obj.prompt+2,obj.y+2)
  510.     term.setTextColor(colors.black)
  511.     write(obj.data)
  512.     term.setBackgroundColor(tColors["menu"].bg)
  513.     term.setTextColor(tColors["menu"].fg)
  514.     term.setCursorPos(obj.x+1,obj.y+2)
  515.     write(obj.prompt..":")
  516.   elseif obj.type == "button_input" then
  517.     term.setBackgroundColor(colors.lightGray)
  518.     term.setCursorPos(obj.x+#obj.label,obj.y)
  519.     for i=1,obj.w-(#obj.label) do
  520.       write(" ")
  521.     end
  522.     if obj.data then
  523.       term.setTextColor(colors.black)
  524.       term.setCursorPos(obj.x+#obj.label,obj.y)
  525.       write(obj.data)
  526.     end
  527.     term.setCursorPos(obj.x,obj.y)
  528.     term.setTextColor(tColors["menu"].fg)
  529.     term.setBackgroundColor(tColors["menu"].bg)
  530.     write(obj.label)
  531.   elseif obj.type == "window" then
  532.     drawBar(obj.x,obj.y-1,obj.w,true,true,true,obj.label)
  533.   end
  534. end
  535.  
  536. -- Draw folders/icons on desktop
  537. local function drawObjects()
  538.   for k,v in pairs(tFolders) do
  539.     drawObject(v)
  540.   end
  541.   for k,v in pairs(tIcons) do
  542.     drawObject(v)
  543.   end
  544. end
  545.  
  546. -- Draw the time
  547. local function drawTime()
  548.   term.setCursorPos((term_width - #textutils.formatTime(os.time(),false)) + 1,term_height)
  549.   term.setBackgroundColor(tColors["taskbar"].bg)
  550.   term.setTextColor(tColors["taskbar"].fg)
  551.   write(textutils.formatTime(os.time(),false))
  552. end
  553.  
  554. -- Draw the Control Panel
  555. local function drawMenu_ControlPanel()
  556.   drawObject(tMenus["Control Panel"])
  557.   if tMenus["Control Panel"].slc == 0 then
  558.     drawObject(tButtons["CP_Appearance"])
  559.     drawObject(tButtons["CP_Users"])
  560.   elseif tMenus["Control Panel"].slc == 1 then
  561.     term.setCursorPos((tMenus["Control Panel"].x+tMenus["Control Panel"].w-2),tMenus["Control Panel"].y)
  562.     term.setBackgroundColor(tColors["bar"].bg)
  563.     term.setTextColor(tColors["bar"].edit)
  564.     print(string.char(17))
  565.   elseif tMenus["Control Panel"].slc == 2 then
  566.     term.setCursorPos((tMenus["Control Panel"].x+tMenus["Control Panel"].w-2),tMenus["Control Panel"].y)
  567.     term.setBackgroundColor(tColors["bar"].bg)
  568.     term.setTextColor(tColors["bar"].edit)
  569.     print(string.char(17))
  570.   end
  571. end
  572.  
  573. -- Draw the Notifications Menu
  574. local function drawMenu_Notifications()
  575.   drawObject(tMenus["Notifications"])
  576.   for i=1,#tNotifications do
  577.     drawObject(tNotifications[i])
  578.   end
  579. end
  580.  
  581. -- Draw the Window Creator menu
  582. local function drawMenu_WindowCreator()
  583.   drawObject(tMenus["Window Creator"])
  584.   drawObject(tButtons["WC_Path"])
  585.   drawObject(tButtons["WC_Width"])
  586.   drawObject(tButtons["WC_Height"])
  587.   drawObject(tButtons["WC_Create"])
  588. end
  589.  
  590. -- Draw the Start menu
  591. local function drawMenu_Start()
  592.   term.setTextColor(tColors["taskbar"].fg)
  593.   term.setBackgroundColor(tColors["taskbar"].start)
  594.   term.setCursorPos(1,term_height-5)
  595.   print("               ")
  596.   term.setCursorPos(1,term_height-4)
  597.   print(" CraftOS       ")
  598.   term.setCursorPos(1,term_height-3)
  599.   print(" Control Panel ")
  600.   term.setCursorPos(1,term_height-2)
  601.   print(" Notifications ")
  602.   term.setCursorPos(1,term_height-1)
  603.   print("               ")
  604. end
  605.  
  606. -- Draw the File menu
  607. local function drawMenu_File()
  608.   term.setTextColor(tColors["taskbar"].fg)
  609.   term.setBackgroundColor(tColors["taskbar"].other)
  610.   term.setCursorPos(9,term_height-4)
  611.   print("               ")
  612.   term.setCursorPos(9,term_height-3)
  613.   print(" New Window    ")
  614.   term.setCursorPos(9,term_height-2)
  615.   print(" Set Directory ")
  616.   term.setCursorPos(9,term_height-1)
  617.   print("               ")
  618. end
  619.  
  620. -- Draw the Logout menu
  621. local function drawMenu_Logout()
  622.   term.setTextColor(tColors["taskbar"].fg)
  623.   term.setBackgroundColor(tColors["taskbar"].other)
  624.   term.setCursorPos(16,term_height-4)
  625.   print("          ")
  626.   term.setCursorPos(16,term_height-3)
  627.   print(" Reboot   ")
  628.   term.setCursorPos(16,term_height-2)
  629.   print(" Shutdown ")
  630.   term.setCursorPos(16,term_height-1)
  631.   print("          ")
  632. end
  633.  
  634. -- Draw the desktop
  635. local function drawBackground()
  636.   term.redirect(original_term)
  637.   term.setBackgroundColor(tColors["main"].bg)
  638.   term.clear()
  639.   term.setCursorPos(1,term_height)
  640.   term.setBackgroundColor(tColors["taskbar"].bg)
  641.   term.clearLine()
  642.   term.setBackgroundColor(tColors["taskbar"].start)
  643.   term.setTextColor(tColors["taskbar"].fg)
  644.   write(" Start ")
  645.   term.setCursorPos(9,term_height)
  646.   term.setBackgroundColor(tColors["taskbar"].other)
  647.   write(" File ")
  648.   term.setCursorPos(16,term_height)
  649.   write(" Logout ")
  650.   if activeWindow then
  651.     term.setBackgroundColor(tColors["taskbar"].bg)
  652.     term.setTextColor(tColors["taskbar"].fg)
  653.     term.setCursorPos(25,term_height)
  654.     write(activeWindow.label)
  655.   end
  656.   drawObjects()
  657.   for k,v in pairs(tMenus) do
  658.     if v.active then
  659.       if v.label == "Control Panel" then
  660.         drawMenu_ControlPanel()
  661.       elseif v.label == "Notifications" then
  662.         drawMenu_Notifications()
  663.       elseif v.label == "Window Creator" then
  664.         drawMenu_WindowCreator()
  665.       else
  666.         drawObject(v)
  667.       end
  668.     end
  669.   end
  670.   for k,v in pairs(tButtons) do
  671.     if v.active then
  672.       drawObject(v)
  673.     end
  674.   end
  675.   for k,v in pairs(tWindows) do
  676.     if v.active then
  677.       v.obj.setVisible(true)
  678.       v.obj.redraw()
  679.       drawObject(v)
  680.     end
  681.   end
  682.   if activeWindow then
  683.     if activeWindow == tMenus["Control Panel"] then
  684.       drawMenu_ControlPanel()
  685.     elseif activeWindow == tMenus["Notifications"] then
  686.       drawMenu_Notifications()
  687.     elseif activeWindow == tMenus["Window Creator"] then
  688.       drawMenu_WindowCreator()
  689.     else
  690.       if activeWindow.active then
  691.         drawObject(activeWindow)
  692.       end
  693.     end
  694.   end
  695.   if bMenu_Start then
  696.     drawMenu_Start()
  697.   elseif bMenu_File then
  698.     drawMenu_File()
  699.   elseif bMenu_Logout then
  700.     drawMenu_Logout()
  701.   end
  702.   drawTime()
  703. end
  704.  
  705. -- Trigger Function for: Close
  706. local function trigger_Close(x,y,v)
  707.   local n = 0
  708.   if v.type == "window" then
  709.     n = 1
  710.   end
  711.   if x == v.x + v.w - 1 and y == v.y-n then
  712.     return true
  713.   end
  714.   return false
  715. end
  716.  
  717. -- Trigger Function for: Edit
  718. local function trigger_Edit(x,y,v)
  719.   local n = 0
  720.   if v.type == "window" then
  721.     n = 1
  722.   end
  723.   if x == v.x + v.w - 2 and y == v.y-n then
  724.     return true
  725.   end
  726.   return false
  727. end
  728.  
  729. -- Trigger Function for: Drag
  730. local function trigger_Drag(x,y,v)
  731.   local n = 0
  732.   if v.type == "window" then
  733.     n = 1
  734.   end
  735.   if x == v.x and y == v.y-n then
  736.     return true
  737.   end
  738.   return false
  739. end
  740.  
  741. -- Trigger Function for: Start Menu
  742. local function trigger_Start(x,y)
  743.   if x >= 1 and x <= 7 and y == term_height then
  744.     return true
  745.   end
  746.   return false
  747. end
  748.  
  749. -- Trigger Function for: File Menu
  750. local function trigger_File(x,y)
  751.   if x >= 9 and x <= 14 and y == term_height then
  752.     return true
  753.   end
  754.   return false
  755. end
  756.  
  757. -- Trigger Function for: Logout Menu
  758. local function trigger_Logout(x,y)
  759.   if x >= 16 and x <= 23 and y == term_height then
  760.     return true
  761.   end
  762.   return false
  763. end
  764.  
  765. -- Trigger Function: For Buttons
  766. local function trigger_Button(x,y,button)
  767.   if x >= button.x and x <= button.x + button.w - 1 and y >= button.y and y <= button.y + button.h - 1 then
  768.     return true
  769.   end
  770.   return false
  771. end
  772.  
  773. -- Trigger Function: For all pop-up menus
  774. local function trigger_Menu(x,y,menuX,menuXW)
  775.   if x >= menuX and x <= menuXW and y == term_height - 2 then
  776.     return 1
  777.   elseif x >= menuX and x <= menuXW and y == term_height - 3 then
  778.     return 2
  779.   elseif x >= menuX and x <= menuXW and y == term_height - 4 then
  780.     return 3
  781.   end
  782. end
  783.  
  784. local function trigger_Notification(x,y,type)
  785.   local n = 0
  786.   if type == "run" then
  787.     n = 1
  788.   end
  789.   if x <= tMenus["Notifications"].x + tMenus["Notifications"].w - (2 + n) then
  790.     if y == tMenus["Notifications"].y + 2 then
  791.       return 1
  792.     elseif y == tMenus["Notifications"].y + 3 then
  793.       return 2
  794.     elseif y == tMenus["Notifications"].y + 4 then
  795.       return 3
  796.     elseif y == tMenus["Notifications"].y + 5 then
  797.       return 4
  798.     elseif y == tMenus["Notifications"].y + 6 then
  799.       return 5
  800.     elseif y == tMenus["Notifications"].y + 7 then
  801.       return 6
  802.     elseif y == tMenus["Notifications"].y + 8 then
  803.       return 7
  804.     elseif y == tMenus["Notifications"].y + 9 then
  805.       return 8
  806.     elseif y == tMenus["Notifications"].y + 10 then
  807.       return 9
  808.     elseif y == tMenus["Notifications"].y + 11 then
  809.       return 10
  810.     end
  811.   end
  812.   return false
  813. end
  814.  
  815. -- Trigger Function: MSG Input
  816. local function trigger_Input(x,y)
  817.   if x >= tButtons["MSG_Input"].x+#tButtons["MSG_Input"].prompt+2 and x <= (tButtons["MSG_Input"].x+#tButtons["MSG_Input"].prompt+2) + tButtons["MSG_Input"].w-(#tButtons["MSG_Input"].prompt+4) and y == tButtons["MSG_Input"].y + tButtons["MSG_Input"].h-2 then
  818.     return true
  819.   end
  820.   return false
  821. end
  822.  
  823. -- Trigger Function: Button Input
  824. local function trigger_InputB(x,y,obj)
  825.   if x >= obj.x+#obj.label and x <= obj.x+#obj.label+(obj.w-#obj.label-1) and y == obj.y then
  826.     return true
  827.   end
  828.   return false
  829. end
  830.  
  831. -- Check if clicked inside the specified window
  832. local function clickedWithin(x,y,obj)
  833.   if obj ~= nil then
  834.     if obj.active then
  835.       if x >= obj.x and x <= obj.x + obj.w - 1 and y >= obj.y and y <= obj.y + obj.h - 1 then
  836.         return true
  837.       end
  838.     end
  839.   end
  840.   return false
  841. end
  842.  
  843. -- Reassign the active window
  844. local function reassignActiveWindow(pref)
  845.   if pref.active then
  846.     activeWindow = pref
  847.   else
  848.     activeWindow = nil
  849.     for k,v in pairs(tMenus) do
  850.       if v.active then
  851.         activeWindow = v
  852.       end
  853.     end
  854.     if activeWindow == nil then
  855.       for k,v in pairs(tWindows) do
  856.         if v.active then
  857.           activeWindow = v
  858.         end
  859.       end
  860.     end
  861.   end
  862. end
  863.  
  864. -- Do the thing with the input message box
  865. local function activateMSGInput(i)
  866.   if tButtons["MSG_Input"].label == "Set Directory" then
  867.     if fs.exists(i) and string.sub(i,1,1) == "/" and string.sub(i,#i,#i) == "/" then
  868.       saveDirConfig()
  869.       fs_activeDir = i
  870.       tButtons["MSG_Input"].data = i
  871.       loadDirConfig()
  872.     end
  873.   end
  874. end
  875.  
  876. notification_new("Test1",function() term.clear() print("Test1") sleep(1) end, textutils.formatTime(os.time(),false))
  877. notification_new("Test2",function() term.clear() print("Test2") sleep(1) end, textutils.formatTime(os.time(),false))
  878. notification_new("Test3",function() term.clear() print("Test3") sleep(1) end, textutils.formatTime(os.time(),false))
  879. loadConfig()
  880. loadDirConfig()
  881. drawBackground()
  882. while bRunning do
  883.   local e = { os.pullEvent() }
  884.   for k,v in pairs(tWindows) do
  885.     if v.active and v == activeWindow then
  886.       term.redirect(activeWindow.obj)
  887.       if not bMenu_File and not bMenu_Start and not bMenu_Logout then
  888.         activeWindow.obj.restoreCursor()
  889.         activeWindow.obj.redraw()
  890.       end
  891.       coroutine.resume(activeWindow.cor,unpack(e))
  892.     else
  893.       local stat = coroutine.status(v.cor)
  894.       if stat == "dead" then
  895.         v.obj.setVisible(false)
  896.         v.active = false
  897.         v = nil
  898.       else
  899.         term.redirect(v.obj)
  900.         local b = false
  901.         for i=1,#tBackgroundEvents do
  902.           if e[1] == tBackgroundEvents[i] then
  903.             b = true
  904.           end
  905.         end
  906.         if b == false then
  907.           coroutine.resume(v.cor)
  908.         else
  909.           coroutine.resume(v.cor,unpack(e))
  910.         end
  911.       end
  912.     end
  913.   end
  914.   term.redirect(original_term)
  915.   for i=1,#tBackgroundEvents do
  916.     if e[1] == tBackgroundEvents[i] and not e[1] == "timer" then
  917.       notification_new(e[1], function() tButtons["MSG_Notification"].active = true end, textutils.formatTime(os.time(),false))
  918.       break
  919.     end
  920.   end
  921.   local button = e[2] or nil
  922.   local X = e[3] or nil
  923.   local Y = e[4] or nil
  924.   if e[1] == "mouse_click" then
  925.     _X = X
  926.     _Y = Y
  927.     if button == 1 then
  928.       if trigger_Start(X,Y) then
  929.         bMenu_Start = not bMenu_Start
  930.         bMenu_File = false
  931.         bMenu_Logout = false
  932.         drawBackground()
  933.       elseif trigger_File(X,Y) then
  934.         bMenu_File = not bMenu_File
  935.         bMenu_Start = false
  936.         bMenu_Logout = false
  937.         drawBackground()
  938.       elseif trigger_Logout(X,Y) then
  939.         bMenu_Logout = not bMenu_Logout
  940.         bMenu_Start = false
  941.         bMenu_File = false
  942.         drawBackground()
  943.       end
  944.  
  945.       if clickedWithin(X,Y,tMenus["Notifications"]) then
  946.         if activeWindow == tMenus["Notifications"] then
  947.           if trigger_Close(X,Y,tMenus["Notifications"]) then
  948.             tMenus["Notifications"].active = false
  949.             reassignActiveWindow(tMenus["Control Panel"])
  950.             drawBackground()
  951.           else
  952.             local _nE = trigger_Notification(X,Y,"run")
  953.             local _nC = trigger_Notification(X,Y,"close")
  954.             if not _nE == false then
  955.               tNotifications[_nE].func()
  956.               drawBackground()
  957.             elseif not _nC == false then
  958.               tNotifications[_nC].label = ""
  959.               tNotifications[_nC].func = function() end
  960.               tNotifications[_nC].time = ""
  961.               updateNotifications()
  962.               drawBackground()
  963.             end
  964.           end
  965.         else
  966.           if not clickedWithin(X,Y,activeWindow) then
  967.             reassignActiveWindow(tMenus["Notifications"])
  968.             drawBackground()
  969.           end
  970.         end
  971.       end
  972.  
  973.       if clickedWithin(X,Y,tMenus["Control Panel"]) then
  974.         if activeWindow == tMenus["Control Panel"] then
  975.           if trigger_Close(X,Y,tMenus["Control Panel"]) then
  976.             tMenus["Control Panel"].active = false
  977.             reassignActiveWindow(tMenus["Notifications"])
  978.             drawBackground()
  979.           else
  980.             if tMenus["Control Panel"].slc == 0 then
  981.               if trigger_Button(X,Y,tButtons["CP_Appearance"]) then
  982.                 tMenus["Control Panel"].slc = 1
  983.                 drawBackground()
  984.               elseif trigger_Button(X,Y,tButtons["CP_Users"]) then
  985.                 tMenus["Control Panel"].slc = 2
  986.                 drawBackground()
  987.               end
  988.             else
  989.               if trigger_Edit(X,Y,tMenus["Control Panel"]) then
  990.                 tMenus["Control Panel"].slc = 0
  991.                 drawBackground()
  992.               end
  993.             end
  994.             if tMenus["Control Panel"].slc == 1 then
  995.  
  996.             elseif tMenus["Control Panel"].slc == 2 then
  997.  
  998.             end
  999.           end
  1000.         else
  1001.           if not clickedWithin(X,Y,activeWindow) then
  1002.             reassignActiveWindow(tMenus["Control Panel"])
  1003.             drawBackground()
  1004.           end
  1005.         end
  1006.       end
  1007.  
  1008.       if clickedWithin(X,Y,tMenus["Window Creator"]) then
  1009.         if activeWindow == tMenus["Window Creator"] then
  1010.           if trigger_Close(X,Y,tMenus["Window Creator"]) then
  1011.             tMenus["Window Creator"].active = false
  1012.             reassignActiveWindow(tMenus["Control Panel"])
  1013.             drawBackground()
  1014.           else
  1015.             if trigger_InputB(X,Y,tButtons["WC_Path"]) then
  1016.               term.setBackgroundColor(colors.lightGray)
  1017.               term.setCursorPos(tButtons["WC_Path"].x+#tButtons["WC_Path"].label,tButtons["WC_Path"].y)
  1018.               for i=1,tButtons["WC_Path"].w-(#tButtons["WC_Path"].label) do
  1019.                 write(" ")
  1020.               end
  1021.               term.setTextColor(colors.black)
  1022.               term.setCursorPos(tButtons["WC_Path"].x+#tButtons["WC_Path"].label,tButtons["WC_Path"].y)
  1023.               local i = read()
  1024.               if fs.exists(i) and not fs.isDir(i) then
  1025.                 tButtons["WC_Path"].data = i
  1026.               else
  1027.                 local nEnd = 0
  1028.                 for x=1,#i do
  1029.                   if string.sub(i,x,x) == " " then
  1030.                     nEnd = x
  1031.                     break
  1032.                   end
  1033.                 end
  1034.                 for x=1,#tPrograms do
  1035.                   if string.sub(i,1,nEnd-1) == tPrograms[x] and not fs.isDir("/rom/programs/"..tPrograms[x]) then
  1036.                     tButtons["WC_Path"].data = i
  1037.                   end
  1038.                 end
  1039.               end
  1040.               drawBackground()
  1041.             elseif trigger_InputB(X,Y,tButtons["WC_Width"]) then
  1042.               term.setBackgroundColor(colors.lightGray)
  1043.               term.setCursorPos(tButtons["WC_Width"].x+#tButtons["WC_Width"].label,tButtons["WC_Width"].y)
  1044.               for i=1,tButtons["WC_Width"].w-(#tButtons["WC_Width"].label) do
  1045.                 write(" ")
  1046.               end
  1047.               term.setTextColor(colors.black)
  1048.               term.setCursorPos(tButtons["WC_Width"].x+#tButtons["WC_Width"].label,tButtons["WC_Width"].y)
  1049.               local i = tonumber(read())
  1050.               if i then
  1051.                 tButtons["WC_Width"].data = i
  1052.               end
  1053.               drawBackground()
  1054.             elseif trigger_InputB(X,Y,tButtons["WC_Height"]) then
  1055.               term.setBackgroundColor(colors.lightGray)
  1056.               term.setCursorPos(tButtons["WC_Height"].x+#tButtons["WC_Height"].label,tButtons["WC_Height"].y)
  1057.               for i=1,tButtons["WC_Height"].w-(#tButtons["WC_Height"].label) do
  1058.                 write(" ")
  1059.               end
  1060.               term.setTextColor(colors.black)
  1061.               term.setCursorPos(tButtons["WC_Height"].x+#tButtons["WC_Height"].label,tButtons["WC_Height"].y)
  1062.               local i = tonumber(read())
  1063.               if i then
  1064.                 tButtons["WC_Height"].data = i
  1065.               end
  1066.               drawBackground()
  1067.             elseif trigger_Button(X,Y,tButtons["WC_Create"]) then
  1068.               if tButtons["WC_Height"] and tButtons["WC_Width"] and tButtons["WC_Path"] then
  1069.                 local newWindow = window_new(tButtons["WC_Path"].data,tButtons["WC_Width"].data,tButtons["WC_Height"].data)
  1070.                 reassignActiveWindow(newWindow)
  1071.                 tMenus["Window Creator"].active = false
  1072.                 drawBackground()
  1073.               end
  1074.             end
  1075.           end
  1076.         else
  1077.           if not clickedWithin(X,Y,activeWindow) then
  1078.             reassignActiveWindow(tMenus["Window Creator"])
  1079.             drawBackground()
  1080.           end
  1081.         end
  1082.       end
  1083.  
  1084.       if clickedWithin(X,Y,tButtons["MSG_Input"]) then
  1085.         if activeWindow == tButtons["MSG_Input"] then
  1086.           if trigger_Close(X,Y,tButtons["MSG_Input"]) then
  1087.             tButtons["MSG_Input"].active = false
  1088.             reassignActiveWindow(tMenus["Control Panel"])
  1089.             drawBackground()
  1090.           elseif trigger_Input(X,Y,tButtons["MSG_Input"]) then
  1091.             term.setBackgroundColor(colors.lightGray)
  1092.             term.setCursorPos(tButtons["MSG_Input"].x+#tButtons["MSG_Input"].prompt+2,tButtons["MSG_Input"].y+2)
  1093.             for i=1,tButtons["MSG_Input"].w-(#tButtons["MSG_Input"].prompt+3) do
  1094.               write(" ")
  1095.             end
  1096.             term.setCursorPos(tButtons["MSG_Input"].x+#tButtons["MSG_Input"].prompt+2,tButtons["MSG_Input"].y+2)
  1097.             term.setTextColor(colors.black)
  1098.             local inputData = read()
  1099.             activateMSGInput(inputData)
  1100.             drawBackground()
  1101.           end
  1102.         else
  1103.           if not clickedWithin(X,Y,activeWindow) then
  1104.             reassignActiveWindow(tButtons["MSG_Input"])
  1105.             drawBackground()
  1106.           end
  1107.         end
  1108.       end
  1109.  
  1110.       if bMenu_Start then
  1111.         -- 1 = Notifications, 2 = Control Panel, 3 = CraftOS
  1112.         local t = trigger_Menu(X,Y,1,15)
  1113.         if t == 1 then
  1114.           tMenus["Notifications"].active = true
  1115.           bMenu_Start = false
  1116.           reassignActiveWindow(tMenus["Notifications"])
  1117.           drawBackground()
  1118.         elseif t == 2 then
  1119.           tMenus["Control Panel"].active = true
  1120.           bMenu_Start = false
  1121.           reassignActiveWindow(tMenus["Control Panel"])
  1122.           drawBackground()
  1123.         elseif t == 3 then
  1124.           saveDirConfig()
  1125.           bRunning = false
  1126.           term.setBackgroundColor(colors.black)
  1127.           term.clear()
  1128.           term.setTextColor(colors.yellow)
  1129.           term.setCursorPos(1,1)
  1130.           print(os.version())
  1131.           term.setCursorPos(1,2)
  1132.           term.setTextColor(colors.white)
  1133.         end
  1134.       end
  1135.       if bMenu_File then
  1136.         -- 1 = Set Directory, 2 = New Window
  1137.         local t = trigger_Menu(X,Y,9,23)
  1138.         if t == 1 then
  1139.           bMenu_File = false
  1140.           tButtons["MSG_Input"].active = true
  1141.           tButtons["MSG_Input"].label = "Set Directory"
  1142.           tButtons["MSG_Input"].prompt = "Path"
  1143.           reassignActiveWindow(tButtons["MSG_Input"])
  1144.           drawBackground()
  1145.         elseif t == 2 then
  1146.           bMenu_File = false
  1147.           tMenus["Window Creator"].active = true
  1148.           reassignActiveWindow(tMenus["Window Creator"])
  1149.           drawBackground()
  1150.         end
  1151.       end
  1152.       if bMenu_Logout then
  1153.         -- 1 = Shutdown, 2 = Reboot
  1154.         local t = trigger_Menu(X,Y,16,25)
  1155.         if t == 1 then
  1156.           os.shutdown()
  1157.         elseif t == 2 then
  1158.           os.reboot()
  1159.         end
  1160.       end
  1161.  
  1162.       for k,v in pairs(tWindows) do
  1163.         if activeWindow ~= v then
  1164.           if clickedWithin(X,Y,v) and not clickedWithin(X,Y,activeWindow) then
  1165.             reassignActiveWindow(v)
  1166.             drawBackground()
  1167.             break
  1168.           end
  1169.         else
  1170.           if trigger_Close(X,Y,v) then
  1171.             v.obj.setVisible(false)
  1172.             v.active = false
  1173.             v = nil
  1174.             reassignActiveWindow(tMenus["Control Panel"])
  1175.             drawBackground()
  1176.           end
  1177.         end
  1178.       end
  1179.     end
  1180.   elseif e[1] == "timer" then
  1181.     if button == rTime then
  1182.       drawTime()
  1183.       rTime = os.startTimer(3)
  1184.     elseif button == rUpdate then
  1185.       drawBackground()
  1186.       rUpdate = os.startTimer(30)
  1187.     elseif button == rDragTime then
  1188.       bDragging = false
  1189.     end
  1190.   elseif e[1] == "mouse_drag" then
  1191.     if button == 1 then
  1192.       if tMenus["Control Panel"].active and trigger_Drag(_X,_Y,tMenus["Control Panel"]) then
  1193.         bDragging = true
  1194.         rDragTime = os.startTimer(1)
  1195.         if X >= 1 and X <= (term_width - tMenus["Control Panel"].w + 1) and Y >= 1 and Y <= (term_height - tMenus["Control Panel"].h) then
  1196.           tMenus["Control Panel"].x = X
  1197.           tMenus["Control Panel"].y = Y
  1198.           _X = X
  1199.           _Y = Y
  1200.           updateControlPanel()
  1201.           drawBackground()
  1202.         end
  1203.       elseif tMenus["Notifications"].active and trigger_Drag(_X,_Y,tMenus["Notifications"]) then
  1204.         bDragging = true
  1205.         rDragTime = os.startTimer(1)
  1206.         if X >= 1 and X <= (term_width - tMenus["Notifications"].w + 1) and Y >= 1 and Y <= (term_height - tMenus["Notifications"].h) then
  1207.           tMenus["Notifications"].x = X
  1208.           tMenus["Notifications"].y = Y
  1209.           _X = X
  1210.           _Y = Y
  1211.           updateNotifications()
  1212.           drawBackground()
  1213.         end
  1214.       elseif tMenus["Window Creator"].active and trigger_Drag(_X,_Y,tMenus["Window Creator"]) then
  1215.         bDragging = true
  1216.         rDragTime = os.startTimer(1)
  1217.         if X >= 1 and X <= (term_width - tMenus["Window Creator"].w + 1) and Y >= 1 and Y <= (term_height - tMenus["Window Creator"].h) then
  1218.           tMenus["Window Creator"].x = X
  1219.           tMenus["Window Creator"].y = Y
  1220.           _X = X
  1221.           _Y = Y
  1222.           updateWindowCreator()
  1223.           drawBackground()
  1224.         end
  1225.       elseif tButtons["MSG_Input"].active and trigger_Drag(_X,_Y,tButtons["MSG_Input"]) then
  1226.         bDragging = true
  1227.         rDragTime = os.startTimer(1)
  1228.         if X >= 1 and X <= (term_width - tButtons["MSG_Input"].w + 1) and Y >= 1 and Y <= (term_height - tButtons["MSG_Input"].h) then
  1229.           tButtons["MSG_Input"].x = X
  1230.           tButtons["MSG_Input"].y = Y
  1231.           _X = X
  1232.           _Y = Y
  1233.           drawBackground()
  1234.         end
  1235.       else
  1236.         for k,v in pairs(tWindows) do
  1237.           if v.active and trigger_Drag(_X,_Y,v) then
  1238.             bDragging = true
  1239.             rDragTime = os.startTimer(1)
  1240.             if X >= 1 and X <= (term_width - v.w + 1) and Y >= 1 and Y <= (term_height - v.h) then
  1241.               v.x = X
  1242.               v.y = Y + 1
  1243.               _X = X
  1244.               _Y = Y
  1245.               v.obj.reposition(v.x,v.y,v.w,v.h)
  1246.               v.obj.redraw()
  1247.               drawBackground()
  1248.             end
  1249.           end
  1250.         end
  1251.       end
  1252.     end
  1253.   end
  1254. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top