Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --------------------------------------------------------------------------------------------------------------------------------------------
- --Base Classes
- --------------------------------------------------------------------------------------------------------------------------------------------
- local visual = {}
- function visual:new(o)
- o = o or {}
- setmetatable(o, self)
- self.__index = self
- return o
- end
- function visual:print(amask, acomp)
- printError("visual: \""..self.name.."\":print() is not defined")
- return false
- end
- local component = {x = 1, y = 1, width = 0, height = 0, visuals = {}}
- function component:new(o)
- o = o or {}
- setmetatable(o, self)
- self.__index = self
- local newv = {}
- for I = 1, #self.visuals do
- newv[I] = self.visuals[I]
- end
- o.visuals = newv
- return o
- end
- function component:print(amask)
- for I = 1, #self.visuals do
- self.visuals[I]:print(amask, self)
- end
- end
- function component:isTouched(x, y)
- if x >= self.x and x < (self.x + self.width) then
- if y >= self.y and y < (self.y + self.height) then
- return true
- else
- return false
- end
- else
- return false
- end
- end
- function component:touch()
- return false
- end
- local mask = {comps = {}, backgroundColor = 32768}
- function mask:new(o)
- o = o or {}
- setmetatable(o, self)
- self.__index = self
- local newc = {}
- for I = 1, #self.comps do
- newc[I] = self.comps[I]
- end
- o.comps = newc
- return o
- end
- function mask:print()
- --if self.terminal[1] == nil then printError("No terminal assigend") return false end
- term.setBackgroundColor(self.backgroundColor)
- term.clear()
- for I = 1, #self.comps do
- self.comps[I]:print(self)
- end
- end
- function mask:touch(x, y)
- for I = 1, #self.comps do
- if self.comps[I]:isTouched(x, y) then
- self.comps[I]:touch()
- end
- end
- end
- --------------------------------------------------------------------------------------------------------------------------------------------
- -- implemented components
- --------------------------------------------------------------------------------------------------------------------------------------------
- local background = visual:new()
- background.color = 1
- function background:print(amask, acomp)
- local fillString = ""
- for I = 1, acomp.width do
- fillString = fillString.." "
- end
- local beforeColor = term.getBackgroundColor()
- term.setBackgroundColor(self.color)
- for I = 1, acomp.height do
- term.setCursorPos(acomp.x, acomp.y + (I - 1))
- term.write(fillString)
- end
- term.setBackgroundColor(beforeColor)
- end
- local contour = visual:new()
- contour.color = 128
- function contour:print(amask, acomp)
- local fillString = ""
- for I = 1, acomp.width do
- fillString = fillString.." "
- end
- local beforeColor = term.getBackgroundColor()
- term.setBackgroundColor(self.color)
- term.setCursorPos(acomp.x, acomp.y)
- term.write(fillString)
- for I = 2, (acomp.height - 1) do
- term.setCursorPos(acomp.x, acomp.y + (I - 1))
- term.write(" ")
- term.setCursorPos((acomp.x + acomp.width) - 1, acomp.y + (I - 1))
- term.write(" ")
- end
- term.setCursorPos(acomp.x, (acomp.y + acomp.height) - 1)
- term.write(fillString)
- term.setBackgroundColor(beforeColor)
- end
- local label = {x = 1, y = 1, text = "", textColor = 0, backgroundColor = 0}
- label = visual:new(label)
- function label:print(amask, acomp)
- local tcolor = ""
- local bcolor = ""
- if self.textColor == 0 then
- tcolor = term.getTextColor()
- else
- tcolor = self.textColor
- end
- if self.backgroundColor == 0 then
- bcolor = term.getBackgroundColor()
- else
- bcolor = self.backgroundColor
- end
- term.setCursorPos(acomp.x + (self.x - 1), acomp.y + (self.y - 1))
- term.setTextColor(tcolor)
- term.setBackgroundColor(bcolor)
- term.write(self.text)
- end
- local button = component:new()
- local bbackground = background:new()
- button.background = bbackground
- local blabel = label:new()
- button.label = blabel
- button.label.text = "button"
- table.insert(button.visuals, bbackground)
- table.insert(button.visuals, blabel)
- terminal =
- {
- masks = { base = mask },
- components = { base = component, button = button },
- visuals = { base = visual, background = background , label = label, contour = contour }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement