Advertisement
lewislovesgames

Box

Jul 13th, 2015
333
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.88 KB | None | 0 0
  1. --[[ Simple function to draw a square with desired colours, x and y co-ordinates,
  2. and text within the function.
  3.  
  4. borderCol = colour of the outside border
  5. boxCol = colour of the inside of the box
  6. textCol = colour of the text that appears within the box
  7. xStart = starting X position of the box (top left hand corner of the box)
  8. xEnd = ending X position of the box (top right hand corner of the box)
  9. yStart = starting Y positon of the box
  10. ... = arguments, accepts as many as you want. First one is the title.
  11. --]]
  12.  
  13. function drawSquare( borderCol, boxCol, textCol, xStart, xEnd, yStart, ... )
  14.  
  15. --[[ Defines the max amount of characters that can be printed within
  16. the box. If exceeded, it will error.
  17. --]]
  18. local maxLength = xEnd - xStart - 2
  19.  
  20. --[[ This part does the border of the box ]]--
  21. term.setBackgroundColour(borderCol)
  22. for x = xStart, xEnd do
  23. term.setCursorPos(x, yStart)
  24. write(" ")
  25. term.setCursorPos(x, yStart+#arg+2)
  26. write(" ")
  27. end
  28. for y = yStart + 1, yStart + #arg + 1 do
  29. term.setCursorPos(xStart, y)
  30. write(" ")
  31. term.setCursorPos(xEnd, y)
  32. write(" ")
  33. end
  34.  
  35. --[[ This writes the title, which is the first string within
  36. the '...'
  37. --]]
  38. term.setTextColour(textCol)
  39. term.setCursorPos((xEnd - xStart - #arg[1])/2 + xStart + 1, yStart)
  40. write(arg[1])
  41.  
  42. --[[ This part fills the insides of the box with the desired
  43. colour
  44. --]]
  45. term.setBackgroundColour(boxCol)
  46. for x = xStart + 1, xEnd - 1 do
  47. for y = yStart + 1, yStart + #arg + 1 do
  48. term.setCursorPos(x, y)
  49. write(" ")
  50. end
  51. end
  52.  
  53. --[[ arg is '...' and accepts as many as you want, but of course - having
  54. more than 16? would be silly.
  55. It centeres each text within the box
  56. --]]
  57. for i = 2, #arg do
  58. if #arg[i] > maxLength then error("Length of arg #" .. i .. " exceeds max limit of " .. maxLength .. " characters.") end
  59. term.setCursorPos((xEnd - xStart - #arg[i])/2 + xStart + 1, yStart + i)
  60. write(arg[i])
  61. end
  62.  
  63. --[[ Resets the variables and sets the cursorpos to be after the box. --]]
  64. term.setBackgroundColour(colours.black)
  65. term.setTextColour(colours.white)
  66. term.setCursorPos(1, yStart + #arg + 4)
  67. end
  68.  
  69. term.clear()
  70.  
  71. drawSquare(colours.lime, colours.lightBlue, colours.red, 10,30,2, "Warning", "It works!", "lssssssssssssstol", "Line 3", "Line 4")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement