Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local App = app.new()
- local missingIcon = "/missing.nfp"
- local buttons = {}
- local textButtons = {}
- local function addButton(x, y, w, h, s, b)
- table.insert(buttons, {x,y,w,h,s,b})
- return #buttons
- end
- local function addTextButton(x, y, i, s, b, c)
- textButtons[addButton(x, y, string.len(i), 1, s, b)] = {i,c}
- end
- local function checkBB(x1,y1,x2,y2,x,y)
- return x >= x1 and x < x2 and y >= y1 and y < y2
- end
- local c,b = "00000877", "ffffffff"
- if term.isColor() then c, b = "00000bde", "77777777" end
- local w,h = term.getSize()
- local apps = data.load("/.apps")
- function resize()
- w,h = term.getSize()
- buttons = {}
- textButtons = {}
- addTextButton(w,1,"X",function() App:stop() end, colors.red, colors.black)
- end
- resize()
- App.EventHandler:connect("term_resize", resize)
- App.EventHandler:connect("update_apps", function()
- apps = data.load("/.apps")
- end)
- App.EventHandler:connect("app_closed", function(app)
- apps = data.load("/.apps")
- local id = apps[app][3]
- for code,data in pairs(apps) do
- if data[3] and (not id or data[3] > id) then
- apps[code][3] = data[3] - 1
- end
- end
- if id then apps[app][3] = -1 end
- data.save("/.apps", apps)
- end)
- local selection = nil
- local dragging = false
- App.EventHandler:connect("mouse_click", function(btn,mx,my)
- selection = nil
- for code,pos in pairs(apps) do
- local x,y = math.min(math.max(pos[1], 1), w - 2), math.min(math.max(pos[2], 1), h - 2)
- if checkBB(x,y,x+3,y+3,mx,my) then
- selection = code
- break
- end
- end
- end)
- App.EventHandler:connect("mouse_up", function(btn,mx,my)
- if dragging then
- dragging = false
- data.save("/.apps", apps)
- return
- end
- for i,btn in ipairs(buttons) do
- if checkBB(btn[1],btn[2],btn[1]+btn[3],btn[2]+btn[4],mx,my) then
- btn[5]()
- return
- end
- end
- for code,pos in pairs(apps) do
- local x,y = math.min(math.max(pos[1], 1), w - 2), math.min(math.max(pos[2], 1), h - 2)
- if checkBB(x,y,x+3,y+3,mx,my) then
- shell.run(".app execute "..code)
- return
- end
- end
- end)
- App.EventHandler:connect("mouse_drag", function(btn,mx,my)
- dragging = true
- if not selection then return end
- apps[selection] = {mx,my}
- end)
- function App:draw()
- term.setTextColor(_G.TextColor)
- term.setBackgroundColor(_G.BackgroundColor)
- term.clear()
- term.setCursorPos(1,1)
- local cx,cy = term.getCursorPos()
- local tc = term.getTextColor()
- local tb = term.getBackgroundColor()
- for code,pos in pairs(apps) do
- local icon = "/appdata/"..code.."/.nfp"
- local image = paintutils.loadImage(fs.exists(icon) and icon or missingIcon)
- local x,y = math.min(math.max(pos[1], 1), w - 2), math.min(math.max(pos[2], 1), h - 2)
- paintutils.drawImage(image, x, y)
- end
- for i,btn in ipairs(buttons) do
- paintutils.drawFilledBox(btn[1],btn[2],btn[1]+btn[3]-1,btn[2]+btn[4]-1,btn[6])
- local textBtn = textButtons[i]
- if textBtn then
- term.setCursorPos(btn[1],btn[2])
- term.setTextColor(textBtn[2])
- term.setBackgroundColor(btn[6])
- term.write(textBtn[1])
- end
- end
- term.setCursorPos(cx,cy)
- term.setTextColor(tc)
- term.setBackgroundColor(tb)
- term.blit("nekOS///",c,b)
- term.write(" ".._G.User.Username)
- term.setCursorPos(1,2)
- end
- function App:stopped()
- shell.run(".login")
- end
- App:start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement