Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- button = {
- bkgColor = colors.blue,
- tColor = colors.white,
- text = "Text",
- w = 6,
- h = 3,
- textx = 1,
- texty = 1,
- x = 2,
- y = 2,
- visible = false,
- trigger = function()
- print("Default trigger function. :)")
- end,
- new = function(self)
- local new = {}
- setmetatable(new, {__index = self})
- return new
- end,
- detect = function(self, x, y, trig)
- if self.visible then
- if x >= self.x and x <= (self.x + self.w) and y >= self.y and y <= (self.y + self.h) then
- if trig then
- self.trigger()
- end
- return true
- end
- end
- end,
- draw = function(self)
- local x = self.x
- local y = self.y
- local bkgColor = self.bkgColor
- local tColor = self.tColor
- local text = self.text
- local w = self.w
- local h = self.h
- local textx = self.textx
- local texty = self.texty
- local tColor = self.tColor
- local oldBkgColor = term.getBackgroundColor()
- local oldTColor = term.getTextColor()
- term.setBackgroundColor(bkgColor)
- term.setTextColor(tColor)
- term.setCursorPos(x, y)
- for i=0, h do
- for i=0, w - 1 do
- term.write(" ")
- end
- term.setCursorPos(x, y + i)
- end
- term.setCursorPos(x + textx, y + texty)
- term.setTextColor(tColor)
- term.write(text)
- term.setBackgroundColor(oldBkgColor)
- term.setTextColor(oldTColor)
- self.visible = true
- return true
- end
- }
- label = {
- bkgColor = colors.black,
- tColor = colors.white,
- text = "Label",
- x = 2,
- y = 2,
- new = function(self)
- local new = {}
- setmetatable(new, {__index = self})
- return new
- end,
- draw = function(self)
- local bkgColor = self.bkgColor
- local tColor = self.tColor
- local text = self.text
- local x = self.x
- local y = self.y
- local oldBkgColor = term.getBackgroundColor()
- local oldTColor = term.getTextColor()
- term.setCursorPos(x, y)
- term.setBackgroundColor(bkgColor)
- term.setTextColor(tColor)
- term.write(text)
- term.setBackgroundColor(oldBkgColor)
- term.setTextColor(oldTColor)
- return true
- end,
- drawCentered = function(self, xoff)
- local bkgColor = self.bkgColor
- local tColor = self.tColor
- local text = self.text
- local termw, termh = term.getSize()
- local oldBkgColor = term.getBackgroundColor()
- local oldTColor = term.getTextColor()
- local x = termw / 2 - #text / 2
- if type(xoff) == "number" then
- x = x + xoff
- end
- term.setCursorPos(x, self.y)
- term.setBackgroundColor(bkgColor)
- term.setTextColor(tColor)
- term.write(text)
- term.setBackgroundColor(oldBkgColor)
- term.setTextColor(oldTColor)
- return true
- end,
- drawCornered = function(self, horcorner, vercorner)
- local bkgColor = self.bkgColor
- local tColor = self.tColor
- local text = self.text
- local x = self.x
- local y = self.y
- local oldBkgColor = term.getBackgroundColor()
- local oldTColor = term.getTextColor()
- local w, h = term.getSize()
- if vercorner == "top" then
- if horcorner == "left" then
- local termx, termy = 1, 1
- term.setCursorPos(termx, termy)
- term.setBackgroundColor(bkgColor)
- term.setTextColor(tColor)
- term.write(text)
- term.setBackgroundColor(oldBkgColor)
- term.setTextColor(oldTColor)
- return true
- elseif horcorner == "right" then
- local termx = w - #text + 1
- local termy = 1
- term.setCursorPos(termx, termy)
- term.setBackgroundColor(bkgColor)
- term.setTextColor(tColor)
- term.write(text)
- term.setBackgroundColor(oldBkgColor)
- term.setTextColor(oldTColor)
- return true
- end
- return false
- elseif vercorner == "bottom" then
- if horcorner == "left" then
- local termx = 1
- local termy = h
- term.setCursorPos(termx, termy)
- term.setBackgroundColor(bkgColor)
- term.setTextColor(tColor)
- term.write(text)
- term.setBackgroundColor(oldBkgColor)
- term.setTextColor(oldTColor)
- return true
- elseif horcorner == "right" then
- local termx = w - #text + 1
- local termy = h
- term.setCursorPos(termx, termy)
- term.setBackgroundColor(bkgColor)
- term.setTextColor(tColor)
- term.write(text)
- term.setBackgroundColor(oldBkgColor)
- term.setTextColor(oldTColor)
- return true
- end
- return false
- end
- return false
- end
- }
- checkbox = {
- text = "Check Box",
- x = 2,
- y = 2,
- checked = false,
- bkgColor = colors.black,
- w = 0,
- h = 0,
- new = function(self)
- local new = {}
- setmetatable(new, {__index = self})
- return new
- end,
- draw = function(self)
- local bkgColor = self.bkgColor
- local text = self.text
- local x = self.x
- local y = self.y
- term.setCursorPos(x, y)
- if self.checked == false then
- term.setBackgroundColor(colors.gray)
- term.write(" ")
- else
- term.setBackgroundColor(colors.blue)
- term.write(" ")
- end
- term.setBackgroundColor(bkgColor)
- term.write(" ")
- term.write(text)
- w = 2 + string.len(text)
- h = 1
- end,
- trigger = function()
- print("Default trigger function. :)")
- end,
- detect = function(self, x, y, trig)
- if x >= self.x and x <= (self.x + self.w) and y >= self.y and y <= (self.y + self.h) then
- if self.checked == false then
- self.checked = true
- self:draw()
- if trig then
- self.trigger()
- end
- else
- self.checked = false
- self:draw()
- if trig then
- self.trigger()
- end
- end
- end
- end,
- }
- backgroundimg = {
- path = "",
- new = function(self)
- local new = {}
- setmetatable(new, {__index = self})
- return new
- end,
- draw = function(self)
- local image = paintutils.loadImage(self.path)
- paintutils.drawImage(image, 1, 1)
- end
- }
- textinput = {
- bkgColor = colors.white,
- tColor = colors.black,
- phColor = colors.gray,
- x = 2,
- y = 2,
- text = "",
- placeholder = "",
- pwdchar = nil,
- w = 10,
- new = function(self)
- local new = {}
- setmetatable(new, {__index = self})
- return new
- end,
- draw = function(self)
- term.setCursorPos(self.x, self.y)
- term.setBackgroundColor(self.bkgColor)
- term.setTextColor(self.phColor)
- for i=1, self.w do
- term.write(" ")
- end
- term.setCursorPos(self.x, self.y)
- term.write(self.placeholder)
- return true
- end,
- detect = function(self, x, y)
- if x >= self.x and x <= (self.x + self.w) and y == self.y then
- term.setCursorPos(self.x, self.y)
- term.setBackgroundColor(self.bkgColor)
- term.setTextColor(self.tColor)
- for i=1, self.w do
- term.write(" ")
- end
- term.setCursorPos(self.x, self.y)
- self.text = self.pwdchar ~= nil and read(self.pwdchar) or read()
- end
- end
- }
- function fillScreen(color)
- term.clear()
- term.setCursorPos(1, 1)
- local w, h = term.getSize()
- paintutils.drawFilledBox(1, 1, w, h, color)
- end
Add Comment
Please, Sign In to add comment