Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- By Sp1rit
- local windows = {
- getTitle = function(self)
- return self.title
- end,
- setTitle = function(self, text)
- if text ~= nil and string.len(text) > 0 then
- self.title = text
- else
- self.title = ""
- end
- end,
- setLine = function(self, line, text, color)
- if text ~= nil and string.len(text) > 0 then
- self.content[line] = {}
- self.content[line]["text"] = text
- self.content[line]["color"] = color or colors.white
- end
- end,
- getLine = function(self, line)
- return self.content[line]
- end,
- clearLine = function(self, line)
- table.remove(self.content, line)
- end,
- setBackgroundColor = function(self, color)
- if color ~= nil and tonumber(color) > 0 then
- self.backgroundColor = color
- else
- self.backgroundColor = colors.black
- end
- end,
- setBorderColor = function(self, color)
- if color ~= nil and tonumber(color) > 0 then
- self.borderColor = color
- else
- self.borderColor = colors.white
- end
- end,
- setTitleColor = function(self, color)
- if color ~= nil and tonumber(color) > 0 then
- self.titleColor = color
- else
- self.titleColor = colors.white
- end
- end,
- draw = function(self)
- local drawTitle = (string.len(self.title) > 0)
- local startPos = vector.new(self.x, self.y)
- local endPos = startPos:add(vector.new(self.width - 1, self.height - 1))
- term.setBackgroundColor(self.backgroundColor)
- for y = startPos.y, endPos.y do
- for x = startPos.x, endPos.x do
- term.setCursorPos(x, y)
- if x == startPos.x or x == endPos.x then
- term.setTextColor(self.borderColor)
- if y == startPos.y then
- term.write(",")
- elseif y == endPos.y or y == startPos.y + 2 and drawTitle then
- term.write("+")
- else
- term.write("|")
- end
- else
- if y == startPos.y or y == endPos.y or y == startPos.y + 2 and drawTitle then
- term.setTextColor(self.borderColor)
- term.write("-")
- else
- term.write(" ")
- end
- end
- end
- end
- local textPos = startPos:add(vector.new(2, (drawTitle and 3 or 1)))
- local lineCount = self.height - (drawTitle and 4 or 2)
- if drawTitle then
- term.setCursorPos(textPos.x, textPos.y - 2)
- term.setTextColor(self.titleColor)
- term.write(self.title)
- end
- term.setTextColor(colors.white)
- for i = 1, lineCount do
- if self.content[i] ~= nil then
- term.setCursorPos(textPos.x, textPos.y + i - 1)
- term.setTextColor(self.content[i].color)
- term.write(self.content[i].text)
- end
- end
- term.setCursorPos(endPos.x, endPos.y)
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- end
- }
- local wmetatable = {
- __index = windows
- }
- function new(x, y, width, height)
- local w = {
- x = x or 0,
- y = y or 0,
- width = width or 0,
- height = height or 0,
- title = "",
- content = {},
- backgroundColor = colors.black,
- borderColor = colors.white,
- titleColor = colors.white
- }
- setmetatable( w, wmetatable )
- return w
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement