Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.loadAPI("grid")
- os.loadAPI("ugapi")
- local w, h = term.getSize()
- local surface = grid.create(w,h-1)
- local menu = ugapi.newMenu(1,h-2,5,2,colors.gray)
- local menubtn = ugapi.newButton("Menu",2,h,4,1,colors.white,colors.black,colors.gray)
- menu:setPreset("basic",colors.white,colors.gray,colors.gray,colors.black)
- ugapi.clrlnycolor(colors.gray,h)
- local args = { ... }
- if(#args < 1)then error("Ussage: XPaint <file>") end
- local file = args[1]
- if(fs.exists(file))then
- f=fs.open(file,"r")
- ns = textutils.unserialize(f.readAll())
- f.close()
- surface:replace(ns)
- else
- surface:fill("\127")
- end
- local inMenu = false
- local running = true
- menu:addOption('Save ',"basic",function() f=fs.open(file,"w") f.write(surface:getSerial()) f.close() ugapi.clrlny(h) write("File saved as: " .. file) os.pullEvent("mouse_click") ugapi.clrln() menubtn:draw() end)
- menu:addOption('Exit ',"basic",function() ugapu.pos(1,1) ugapi.bcolor(colors.black) ugapi.clr() running = false end)
- menubtn:onPress(function() if(inMenu)then inMenu = false menubtn:draw() surface:draw() else inMenu = true menu:draw() end end)
- menubtn:draw()
- surface:draw()
- while running do
- ev = {os.pullEvent()}
- menubtn:update(ev)
- if(inMenu ~= true)then
- if(ev[1] == "mouse_click" or ev[1] == "mouse_drag")then
- if(ev[2] == 1 and ev[4] ~= h)then surface:set(ev[3],ev[4],"X") end
- if(ev[2] == 2 and ev[4] ~= h)then surface:set(ev[3],ev[4],"\127") end
- if(ev[4] ~= h)then surface:drawRegion(ev[3],ev[4],ev[3],ev[4]) end
- end
- else
- menu:update(ev)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement