Guest User

libgui

a guest
Oct 14th, 2023
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.68 KB | None | 0 0
  1. function setup(name)
  2.   sx,sy = nil
  3.   buttons = {}
  4.   if (name == "term") then
  5.     sx,sy = term.getSize()
  6.   else
  7.     m = peripheral.wrap(name)
  8.     term.redirect(m)
  9.     sx,sy = m.getSize()
  10.   end
  11. end
  12. function exit()
  13.   term.native()
  14. end
  15. function drawText(x,y,color,colorb,text)
  16.   term.setCursorPos(x,y)
  17.   term.setTextColor(color)
  18.   term.setBackgroundColor(colorb)
  19.   term.write(text)
  20. end
  21. function clearScreen()
  22.   term.clear()
  23. end
  24. function setBackgroundColor(color)
  25.   term.setBackgroundColor(color)
  26. end
  27. function setTextColor(color)
  28.   term.setTextColor(color)
  29. end
  30. function drawBT(name,x,xe,y,ye,color,colorb,text)
  31.   term.setBackgroundColor(colorb)
  32.   term.setTextColor(color)
  33.   for i=x,xe do
  34.     for g=y,ye do
  35.       term.setCursorPos(i,g)
  36.       term.write(" ")
  37.     end
  38.   end
  39.   textline = (y + ye) / 2
  40.   textline = string.format("%.1f", textline)
  41.   textline = tonumber(textline)
  42.   term.setCursorPos(x,textline)
  43.   term.write(text)
  44.   table.insert(buttons,name..";"..x..";"..xe..";"..y..";"..ye)  
  45. end
  46. function isButton(x,y)
  47.   for i=1,#buttons do
  48.     local parts = {}
  49.     for word in string.gmatch(buttons[i],"[^;]+") do
  50.       table.insert(parts,word)
  51.     end
  52.     name,bx,bxe,by,bye = parts[1],tonumber(parts[2]),tonumber(parts[3]),tonumber(parts[4]),tonumber(parts[5])
  53.     if (bx-1 < x and x < bxe + 1 ) then
  54.       if (by-1 < y and bye+1 > y) then
  55.         return name
  56.       end
  57.     end
  58.   end
  59.   return false
  60. end
  61. function fill(x,x2,y,y2,color)
  62.   term.setBackgroundColor(color)
  63.   for i=x,x2 do
  64.     for g=y,y2 do
  65.       term.setCursorPos(i,g)
  66.       term.write(" ")
  67.     end
  68.   end
  69. end
  70. function fillScreen(color)
  71.   term.setBackgroundColor(color)
  72.   term.clear()
  73. end
  74.      
Advertisement
Add Comment
Please, Sign In to add comment