Advertisement
Guest User

buttonapi

a guest
Aug 27th, 2014
249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.10 KB | None | 0 0
  1. mon = peripheral.wrap("top")
  2. backgroundC = colors.black -- change me
  3. mon.setBackgroundColor(backgroundC)
  4. mon.clear()
  5.  
  6. local button = {}
  7.  
  8.  
  9.  
  10. function box(xmin,xmax,ymin,ymax,color)
  11.    mon.setBackgroundColor(color)
  12.    for i = xmin,xmax do
  13.      for j = ymin,ymax do
  14.        mon.setCursorPos(i,j)
  15.        mon.write(" ")
  16.      end
  17.      i = i + 1
  18.    end
  19. end
  20.  
  21. function setTable(name,color,func,xmin,xmax,ymin,ymax)
  22.   button[name] = {}
  23.   button[name].color = color
  24.   button[name].func = func
  25.   button[name].active = false
  26.   button[name].xmin = xmin
  27.   button[name].xmax = xmax
  28.   button[name].ymin = ymin
  29.   button[name].ymax = ymax
  30. end
  31.  
  32. function fill(text,color,bData)
  33.   mon.setBackgroundColor(color)
  34.   local yspot = math.floor((bData.ymin + bData.ymax)/2)
  35.   local xspot = math.floor((bData.xmax - bData.xmin - #text)/2)+1
  36.   for j = bData.ymin, bData.ymax do
  37.     mon.setCursorPos(bData.xmin,j)
  38.     if j == yspot then
  39.       for k = 0, bData.xmax - bData.xmin - #text + 1 do
  40.         if k == xspot then
  41.           mon.setTextColor(bData.color)
  42.           mon.write(text)
  43.         else
  44.           mon.write (" ")
  45.         end
  46.       end
  47.     else
  48.       for i = bData.xmin, bData.xmax do
  49.         mon.write(" ")
  50.       end
  51.     end
  52.   end
  53.   mon.setBackgroundColor(backgroundC)
  54. end
  55.  
  56. function screen()
  57.   local currColor
  58.   for name,data in pairs(button) do
  59.     local on = data.active
  60.     if on == true then
  61.       currColor = colors.lime
  62.     else
  63.       currColor = colors.red
  64.     end
  65.     fill(name,currColor,data)
  66.   end
  67. end
  68.      
  69.  
  70. function checkxy(x,y)
  71.   for name,data in pairs(button) do
  72.     if y >= data.ymin and y <= data.ymax then
  73.       if x >= data.xmin and x <= data.xmax then
  74.         data.func()
  75.         return true
  76.       end
  77.     end
  78.   end
  79. end
  80.  
  81. function heading(text,color)
  82.   local w,h = mon.getSize()
  83.   print (w/2)
  84.   mon.setCursorPos(w/2 - (#text/2),1)
  85.   mon.setTextColor(color)
  86.   mon.write(text)
  87. end
  88.      
  89.      
  90. box(1,50,1,1.5,colors.white) -- heading box
  91. heading("Crazypkr1099 Button API",colors.black)
  92. setTable("test",colors.white,Test,5,10,4,8)
  93. screen()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement