Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local bg = colors.orange
- local doubleclicktimeout = 0.4
- local apps = files.loadTableFromFile("/.bacon/appdata")
- local icon = paintutils.loadImage("/.bacon/theme")
- local lstc = os.clock()
- local selected = ""
- local tx,ty = term.getSize()
- function drawIcon(x,y,name)
- for i=1,3 do
- for j=1,4 do
- term.setCursorPos(j+x-1,i+y-1)
- term.setBackgroundColor(icon[i][j])
- buffer.write(" ")
- end
- end
- if name==selected then
- term.setBackgroundColor(colors.cyan)
- else
- term.setBackgroundColor(bg)
- end
- term.setCursorPos(x,y+3)
- buffer.write(name:sub(1,4))
- term.setBackgroundColor(bg)
- end
- function draw()
- term.setBackgroundColor(bg)
- term.setTextColor(colors.black)
- buffer.clear()
- for i=1,#apps do
- drawIcon((apps[i].x-1)*5+2,(apps[i].y-1)*5+2,apps[i].name)
- end
- term.setCursorPos(1,ty)
- term.setBackgroundColor(colors.pink)
- buffer.write(string.rep(" ",tx))
- term.setCursorPos(1,ty)
- buffer.write("Menu|")
- buffer.flush()
- end
- function inapp(x,y,app)
- if x>=((app.x-1)*5+2) then
- if x<=((app.x-1)*5+5) then
- if y>=((app.y-1)*5+2) then
- if y<=((app.y-1)*5+6) then
- return true
- end
- end
- end
- end
- return false
- end
- function sleep()
- term.setBackgroundColor(colors.black)
- -- term.setTextColor(colors.gray)
- for i=1,ty do
- term.setCursorPos(1,i)
- --write(string.rep(" ",tx))
- sleep(0.01)
- end
- term.setCursorPos(2,ty-1)
- write("Touch To Wake")
- os.pullEvent("mouse_click")
- end
- clkt = doubleclicktimeout --To shorten the name for code usage
- while true do
- draw()
- local e, p1, p2, p3 = os.pullEvent()
- if e=="mouse_click" then
- local b,x,y = p1,p2,p3
- if b==1 then
- if x<6 and y==ty then
- local cm = menu.new(1,ty-1)
- cm:addMenuButton("Shutdown",function() os.shutdown() end)
- cm:addMenuButton("Reboot",function() os.reboot() end)
- cm:addMenuButton("Sleep",sleep)
- cm:captureButton()
- else
- local found = false
- for i=1,#apps do
- if inapp(x,y,apps[i]) then
- found = true
- if os.clock()<=lstc+clkt and selected == apps[i].name then
- --Run app
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- term.clear()
- term.setCursorPos(1,1)
- shell.run(apps[i].exec)
- else
- selected = apps[i].name
- end
- lstc = os.clock()
- end
- end
- if not found then
- selected = ""
- end
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment