Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- core = {}
- core.temp = {}
- core.temp.term = term.current()
- user = {} -- Temporary
- user.apps = {} -- Temporary
- -- Test Code
- user.apps[1] = {path="rom/programs/fun/advanced/paint",image = ".Glass/UI/img/default_ico.nfp",x = 39,y = 7,name = "Hello"}
- user.apps[2] = {path="sketch",image = ".Glass/UI/img/default_ico.nfp",x = 25,y = 1,name = "Chicken"}
- user.apps[3] = {path="sketch",image = ".Glass/UI/img/default_ico.nfp",x = 5,y = 5,name = "Nong"}
- user.apps[4] = {path="sketch",image = ".Glass/UI/img/default_ico.nfp",x = 23,y = 10,name = "Ning"}
- -- End of Test Code
- -- To-do: Get .JSON from Glass Cloud
- core.test = function()
- shell.run("sketch")
- end
- core.runApp = function( path, name )
- term.setBackgroundColor( colors.cyan )
- term.setTextColor( colors.white )
- term.clear()
- term.setCursorPos(50,1)
- print( "x" )
- local func = function() os.run( {} , path ) end
- local process = coroutine.create( func )
- local win = window.create( core.temp.term , 1 , 2 , 51 , 19 , true )
- term.redirect( win )
- while true do
- local eventData = { os.pullEvent() }
- local event = eventData[1]
- if event == "mouse_click" then
- local button, x, y = eventData[2], eventData[3], eventData[4]
- if x == 50 and y == 1 then
- term.redirect( core.temp.term )
- win.setVisible( false )
- core.main()
- break
- elseif y > 1 then
- coroutine.resume( process, event, button, x, y - 1 )
- end
- elseif event == "mouse_drag" or event == "mouse_up" or event == "mouse_scroll" then
- local button, x, y = eventData[2], eventData[3], eventData[4]
- coroutine.resume( process, event, button, x, y - 1 )
- elseif coroutine.status( process ) == "dead" then
- win.setVisible( false )
- term.redirect( core.temp.term )
- core.main()
- break
- else coroutine.resume( process , table.unpack(eventData) )
- end
- end
- end
- core.main = function()
- while true do
- core.drawIcons()
- if core.temp.appRemove then
- table.remove(user.apps,core.temp.appRemove)
- core.temp.appRemove = nil
- core.drawIcons()
- end
- local e, button , x , y = os.pullEvent()
- for k , v in pairs(user.apps) do
- term.setTextColor(colors.black)
- term.setCursorPos(1,1)
- local appName = user.apps[k]["name"]
- local appX = user.apps[k]["x"]
- local appY = user.apps[k]["y"]
- local path = user.apps[k]["path"]
- if e == "mouse_click" and x == appX+12 and y == appY and button == 1 then
- core.temp.appRemove = k
- core.main()
- end
- if e == "mouse_click" and x >= appX and x <= appX+12 and y >= appY and y <= appY+6 and x ~= appX + 12 and button == 1 then
- core.runApp( user.apps[k]["path"] , user.apps[k]["name"] )
- end
- if e == "mouse_drag" and x >= appX and x <= appX+12 and y >= appY and y <= appY+6 and x ~= appX + 12 and button == 2 then
- user.apps[k]["x"] = x - 1
- user.apps[k]["y"] = y - 1
- end
- end
- end
- end
- core.drawIcons = function()
- local icons = surface.create(51, 19, " ", colors.orange, colors.white)
- local bg = surface.load(".Glass/UI/img/hills.nfp")
- icons:drawSurface(1,1,bg)
- icons:drawText(2, 2, "=")
- icons:drawText(4, 2, "Glass UI Prototype")
- for k , v in pairs(user.apps) do
- local image = user.apps[k]["image"]
- local x = user.apps[k]["x"]
- local y = user.apps[k]["y"]
- local name = user.apps[k]["name"]
- local image2 = surface.load(image)
- icons:drawSurface(x,y,image2)
- icons:drawText(x+12,y,"x",nil,colors.white)
- icons:drawText(x+1,y,name,nil,colors.white)
- --local surf = surface.create(51, 19, " ", colors.orange, colors.blue)
- --surf.drawSurface(1, 1, image2)
- --surf.drawSurface(x, y, image2)
- --surf.drawText(x + 12, y + 1, name)
- --surf.drawText(3, 3, "Hello, world!")
- --local term = term.current()
- --surf.render(term)
- --paintutils.drawImage(image2,x,y)
- --term.setCursorPos(x + 12,y+1)
- --print("x")
- end
- icons:render(term)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement