Advertisement
Corona

[Computercraft] Screen API

Dec 14th, 2013
472
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.71 KB | None | 0 0
  1. --(C) Corona 2013
  2. --DO NOT STEAL THIS CODE!!!
  3. local ver = 0.36
  4.  
  5. function version()
  6.   return ver
  7. end
  8.  
  9. function about()
  10.   print("--------------------------------------------------")
  11.   print("Screen API Version "..version().." (C) Corona 2013")
  12.   print("--------------------------------------------------")
  13. end
  14.  
  15. function drawButton(button,boolCenter)
  16.   xStart=button["x1"]
  17.   xEnd=button["x2"]
  18.   yStart=button["y1"]
  19.   yEnd=button["y2"]
  20.   x=xEnd-xStart
  21.   y=yEnd-yStart
  22.   term.setCursorPos(xStart,yStart)
  23.   if (button["color"] ~= nil) and (term.isColor()) then
  24.     term.setBackgroundColor(button["color"])
  25.   else
  26.     term.setBackgroundColor(colors.white)
  27.   end
  28.   if (button["textcolor"] ~= nil) and (term.isColor()) then
  29.     term.setTextColor(button["textcolor"])
  30.   else
  31.     term.setTextColor(colors.white)
  32.   end
  33.   for j=0,y do
  34.     for i=0,x do
  35.         term.write(" ")
  36.     end  
  37.   term.setCursorPos(xStart,yStart+j)
  38.   end
  39.   if (button["text"] ~= nil) and (term.isColor()) then
  40.     if boolCenter then
  41.       textCentery=(yStart+math.floor(y/2))
  42.       textCenterx=(math.ceil((xStart+(x/2)))-math.ceil((string.len(button["text"])/2)))
  43.       term.setCursorPos(textCenterx,textCentery)
  44.     else
  45.       term.setCursorPos(xStart,yStart)
  46.     end
  47.     term.write(button["text"])
  48.   end
  49.   term.setBackgroundColor(colors.black)
  50.   term.setTextColor(colors.white)
  51. end
  52.  
  53. function drawBox(area)
  54.   x1 = area["x1"]
  55.   x2 = area["x2"]
  56.   y1 = area["y1"]
  57.   y2 = area["y2"]
  58.   xSpan = x2-x1
  59.   ySpan = y2-y1
  60.   cornerCount = 1
  61.   if area["color"] ~= nil and term.isColor() then
  62.     term.setBackgroundColor(area["color"])
  63.   else
  64.     term.setBackgroundColor(colors.white)
  65.   end
  66.   term.setCursorPos(x1,y1)
  67.   for j=1,ySpan do
  68.     for i=0,xSpan do
  69.       if (cornerCount == 1) or (cornerCount == ySpan) or (i == 0) or (i == xSpan) then
  70.         term.write(" ")
  71.       else
  72.         local tx,ty = term.getCursorPos()
  73.         term.setCursorPos(tx+1,ty)
  74.       end
  75.     end
  76.     cornerCount = cornerCount+1
  77.     term.setCursorPos(x1,y1+j)
  78.   end
  79. end
  80.  
  81. function pressed(object,x,y)
  82.   if (object["x2"]-object["x1"]<2) or (object["y2"]-object["y1"]<2) then
  83.     if (object["x1"]-1<=x) and (object["x2"]>=x) and (object["y1"]<=y) and (object["y2"]>=y) then
  84.       return true
  85.     else
  86.       return false
  87.     end
  88.   elseif (object["x2"]-object["x1"]>=2) or (object["y2"]-object["y1"]>=2) then
  89.     if (object["x1"]-1<x) and (object["x2"]>x) and (object["y1"]-1<y) and (object["y2"]-1>y) then
  90.       return true
  91.     else
  92.       return false
  93.     end
  94.   end
  95. end
  96.  
  97.  
  98. function cls()
  99.   term.setBackgroundColor(colors.black)
  100.   term.clear()
  101.   term.setCursorPos(1,1)
  102. end
  103.  
  104. function getFocus(area)
  105.   term.setCursorPos(area["x1"]+1,area["y1"]+1)
  106. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement