Advertisement
Arthur57980

Untitled

Jul 29th, 2014
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.97 KB | None | 0 0
  1. -- By Sp1rit
  2.  
  3. local windows = {
  4. getTitle = function(self)
  5. return self.title
  6. end,
  7. setTitle = function(self, text)
  8. if text ~= nil and string.len(text) > 0 then
  9. self.title = text
  10. else
  11. self.title = ""
  12. end
  13. end,
  14. setLine = function(self, line, text, color)
  15. if text ~= nil and string.len(text) > 0 then
  16. self.content[line] = {}
  17. self.content[line]["text"] = text
  18. self.content[line]["color"] = color or colors.white
  19. end
  20. end,
  21. getLine = function(self, line)
  22. return self.content[line]
  23. end,
  24. clearLine = function(self, line)
  25. table.remove(self.content, line)
  26. end,
  27. setBackgroundColor = function(self, color)
  28. if color ~= nil and tonumber(color) > 0 then
  29. self.backgroundColor = color
  30. else
  31. self.backgroundColor = colors.black
  32. end
  33. end,
  34. setBorderColor = function(self, color)
  35. if color ~= nil and tonumber(color) > 0 then
  36. self.borderColor = color
  37. else
  38. self.borderColor = colors.white
  39. end
  40. end,
  41. setTitleColor = function(self, color)
  42. if color ~= nil and tonumber(color) > 0 then
  43. self.titleColor = color
  44. else
  45. self.titleColor = colors.white
  46. end
  47. end,
  48. draw = function(self)
  49. local drawTitle = (string.len(self.title) > 0)
  50. local startPos = vector.new(self.x, self.y)
  51. local endPos = startPos:add(vector.new(self.width - 1, self.height - 1))
  52.  
  53. term.setBackgroundColor(self.backgroundColor)
  54.  
  55. for y = startPos.y, endPos.y do
  56. for x = startPos.x, endPos.x do
  57. term.setCursorPos(x, y)
  58.  
  59. if x == startPos.x or x == endPos.x then
  60. term.setTextColor(self.borderColor)
  61.  
  62. if y == startPos.y then
  63. term.write(",")
  64. elseif y == endPos.y or y == startPos.y + 2 and drawTitle then
  65. term.write("+")
  66. else
  67. term.write("|")
  68. end
  69. else
  70. if y == startPos.y or y == endPos.y or y == startPos.y + 2 and drawTitle then
  71. term.setTextColor(self.borderColor)
  72. term.write("-")
  73. else
  74. term.write(" ")
  75. end
  76. end
  77. end
  78. end
  79.  
  80. local textPos = startPos:add(vector.new(2, (drawTitle and 3 or 1)))
  81. local lineCount = self.height - (drawTitle and 4 or 2)
  82.  
  83. if drawTitle then
  84. term.setCursorPos(textPos.x, textPos.y - 2)
  85. term.setTextColor(self.titleColor)
  86. term.write(self.title)
  87. end
  88.  
  89. term.setTextColor(colors.white)
  90. for i = 1, lineCount do
  91. if self.content[i] ~= nil then
  92. term.setCursorPos(textPos.x, textPos.y + i - 1)
  93. term.setTextColor(self.content[i].color)
  94. term.write(self.content[i].text)
  95. end
  96. end
  97.  
  98. term.setCursorPos(endPos.x, endPos.y)
  99. term.setBackgroundColor(colors.black)
  100. term.setTextColor(colors.white)
  101. end
  102. }
  103.  
  104. local wmetatable = {
  105. __index = windows
  106. }
  107.  
  108. function new(x, y, width, height)
  109. local w = {
  110. x = x or 0,
  111. y = y or 0,
  112. width = width or 0,
  113. height = height or 0,
  114. title = "",
  115. content = {},
  116. backgroundColor = colors.black,
  117. borderColor = colors.white,
  118. titleColor = colors.white
  119. }
  120. setmetatable( w, wmetatable )
  121. return w
  122. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement