Advertisement
Corona

[Computercraft] Monitor API

Dec 14th, 2013
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.93 KB | None | 0 0
  1. --(C) Corona 2013
  2. --DO NOT STEAL THIS CODE!!!
  3. function drawButton(button,side)
  4.   xStart=button["x1"]
  5.   xEnd=button["x2"]
  6.   yStart=button["y1"]
  7.   yEnd=button["y2"]
  8.   fillColor=button["color"]
  9.   x=xEnd-xStart
  10.   y=yEnd-yStart
  11.   textCentery=(yStart+y/2)
  12.   textCenterx=(xStart+(x/2))-(string.len(button["text"])/2)
  13.   monitor=peripheral.wrap(side)
  14.   monitor.setCursorPos(xStart,yStart)
  15.   if button["color"] ~= nil and term.isColor() then
  16.     monitor.setBackgroundColor(button["color"])
  17.   else
  18.     monitor.setBackgroundColor(colors.white)
  19.   end
  20.   for j=1,y do
  21.     for i=1,x do
  22.         monitor.write(" ")
  23.     end  
  24.   monitor.setCursorPos(xStart,yStart+j)
  25.   end  
  26.   if button["text"] ~= nil and monitor.isColor() then
  27.     monitor.setCursorPos(textCenterx,textCentery)
  28.     monitor.write(button["text"])
  29.   end
  30.   monitor.setBackgroundColor(colors.black)
  31. end
  32.  
  33. function drawBox(area,side)
  34.   m = peripheral.wrap(side)
  35.   x1 = area["x1"]
  36.   x2 = area["x2"]
  37.   y1 = area["y1"]
  38.   y2 = area["y2"]
  39.   color = area["color"]
  40.   xSpan = x2-x1
  41.   ySpan = y2-y1
  42.   cornerCount = 1
  43.   m.setCursorPos(x1,y1)
  44.   for j=1,ySpan do
  45.     for i=1,xSpan do
  46.       if (cornerCount == 1) or (cornerCount == ySpan) or (i == 1) or (i == xSpan) then
  47.         m.setBackgroundColor(color)
  48.         m.write(" ")
  49.       else
  50.         local tx,ty = m.getCursorPos()
  51.         m.setCursorPos(tx+1,ty)
  52.       end
  53.     end
  54.     cornerCount = cornerCount+1
  55.     m.setCursorPos(x1,y1+j)
  56.   end
  57. end
  58.  
  59. function pressed(object,x,y)
  60.   if (object["x1"]<=x) and (object["x2"]>=x) and (object["y1"]<=y) and (object["y2"]>=y) then
  61.     return true
  62.   else
  63.     return false
  64.   end
  65. end
  66.  
  67. function changeColor(button,color)
  68.   button["color"] = color
  69.   draw(button)
  70.   return button
  71. end
  72.  
  73. function cls(side)
  74.   local monitor=peripheral.wrap(side)
  75.   monitor.setBackgroundColor(colors.black)
  76.   monitor.clear()
  77. end
  78.  
  79. function getFocus(area)
  80.   term.setCursorPos(area["x1"]+1,area["y1"]+1)
  81. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement