Advertisement
NanoBob

WIP button API

Jun 26th, 2014
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.99 KB | None | 0 0
  1. --NanoButton api
  2.  
  3. Buttons={
  4.     --Format : [text]={x,y,width,readyColor,notReadyColor}
  5.     ["Spawner Door"]=   {['x']=1,['y']=3,['w']=15,['rc']=512,['nrc']=16384,['cc']=512},
  6.     ["Spawner Light"]=  {['x']=1,['y']=7,['w']=15,['rc']=512,['nrc']=16384,['cc']=512},
  7.     ["Spawner On"]=     {['x']=1,['y']=11,['w']=15,['rc']=512,['nrc']=16384,['cc']=512},
  8.     ["Spawner Off"]=    {['x']=1,['y']=15,['w']=15,['rc']=512,['nrc']=16384,['cc']=512},
  9. }
  10.  
  11. MonitorSide="top"
  12.  
  13. m=peripheral.wrap(MonitorSide)
  14. m.clear()
  15.  
  16. function drawButtons()
  17.     for text,data in pairs(Buttons) do
  18.         bx=data['x']
  19.         by=data['y']
  20.         bw=data['w']
  21.         bcc=data['cc']
  22.         bl=string.len(text)
  23.         if bw<bl then
  24.             bw=bl+4
  25.         end
  26.         textX=bx+2
  27.         m.setBackgroundColor(bcc)
  28.         for i=bx,bx+bw do
  29.             m.setBackgroundColor(bcc)
  30.             m.setCursorPos(i,by-1)
  31.             m.write(" ")
  32.             m.setCursorPos(i,by)
  33.             m.write(" ")
  34.             m.setCursorPos(i,by+1)
  35.             m.write(" ")
  36.         end
  37.         m.setCursorPos(textX,by)
  38.         m.write(text)
  39.         m.setBackgroundColor(32768)
  40.     end
  41. end
  42.  
  43.  
  44. drawButtons()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement