Advertisement
Redxone

Example UGAPI, GRID

Feb 18th, 2016
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.50 KB | None | 0 0
  1. os.loadAPI("grid")
  2. os.loadAPI("ugapi")
  3. local w, h = term.getSize()
  4. local surface = grid.create(w,h-1)
  5. local menu = ugapi.newMenu(1,h-2,5,2,colors.gray)
  6. local menubtn = ugapi.newButton("Menu",2,h,4,1,colors.white,colors.black,colors.gray)
  7. menu:setPreset("basic",colors.white,colors.gray,colors.gray,colors.black)
  8. ugapi.clrlnycolor(colors.gray,h)
  9. local args = { ... }
  10. if(#args &lt; 1)then error("Ussage: XPaint <file>") end
  11. local file = args[1]
  12. if(fs.exists(file))then
  13. f=fs.open(file,"r")
  14. ns = textutils.unserialize(f.readAll())
  15. f.close()
  16. surface:replace(ns)
  17. else
  18. surface:fill("\127")
  19. end
  20. local inMenu = false
  21. local running = true
  22. 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)
  23. menu:addOption('Exit ',"basic",function() ugapu.pos(1,1) ugapi.bcolor(colors.black) ugapi.clr() running = false end)
  24. menubtn:onPress(function() if(inMenu)then inMenu = false menubtn:draw() surface:draw() else inMenu = true menu:draw() end end)
  25. menubtn:draw()
  26. surface:draw()
  27. while running do
  28. ev = {os.pullEvent()}
  29. menubtn:update(ev)
  30. if(inMenu ~= true)then
  31.   if(ev[1] == "mouse_click" or ev[1] == "mouse_drag")then
  32.    if(ev[2] == 1 and ev[4] ~= h)then surface:set(ev[3],ev[4],"X") end
  33.    if(ev[2] == 2 and ev[4] ~= h)then surface:set(ev[3],ev[4],"\127") end
  34.    if(ev[4] ~= h)then surface:drawRegion(ev[3],ev[4],ev[3],ev[4]) end
  35.   end
  36. else
  37.   menu:update(ev)
  38. end
  39. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement