Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ------------============COMMON FUNCS============------------
- events = {}
- function getEvents(table)
- if table then
- events = table
- else
- events = {os.pullEvent()}
- end
- end
- iColor = {}
- for i = 0, 15 do
- iColor[i + 1] = 2 ^ i
- end
- ------------============BUTTON API============------------
- Button = {
- name = "",
- x = 0,
- y = 0,
- x2 = 0,
- y2 = 0,
- txtcol = 0,
- bakcol = 0,
- txtcol2 = 0,
- bakcol2 = 0
- }
- function Button:new(name, x, y, x2, y2, txtcol, bakcol, txtcol2, bakcol2)
- class = {name = name, x = x, y = y, x2 = x2, y2 = y2, txtcol = txtcol, bakcol = bakcol, txtcol2 = txtcol2, bakcol2 = bakcol2}
- setmetatable(class, self)
- self.__index = self
- return class
- end
- function Button:display()
- term.setTextColor(iColor[self.txtcol])
- paintutils.drawFilledBox(self.x, self.y, self.x2, self.y2, iColor[self.bakcol])
- term.setCursorPos(((self.x2 - self.x) / 2) - (#self.name / 2) + self.x + 1, ((self.y2 - self.y) / 2) + self.y)
- term.write(self.name)
- end
- function Button:activate()
- term.setTextColor(iColor[self.txtcol2])
- paintutils.drawFilledBox(self.x, self.y, self.x2, self.y2, iColor[self.bakcol2])
- term.setCursorPos(((self.x2 - self.x) / 2) - (#self.name / 2) + self.x + 1, ((self.y2 - self.y) / 2) + self.y)
- term.write(self.name)
- end
- function Button:check()
- if events[1] == "mouse_click" and events[2] == 1 and events[3] >= self.x and events[3] <= self.x2 and events[4] >= self.y and events[4] <= self.y2 then
- self:activate()
- sleep(.2)
- return true
- else
- return false
- end
- end
- ------------============TOGGLE API============------------
- Toggle = {
- name = "",
- x = 0,
- y = 0,
- x2 = 0,
- y2 = 0,
- txtcol = 0,
- bakcol = 0,
- txtcol2 = 0,
- bakcol2 = 0,
- state = false
- }
- function Toggle:new(name, x, y, x2, y2, txtcol, bakcol, txtcol2, bakcol2, state)
- class = {name = name, x = x, y = y, x2 = x2, y2 = y2, txtcol = txtcol, bakcol = bakcol, txtcol2 = txtcol2, bakcol2 = bakcol2, state = state}
- setmetatable(class, self)
- self.__index = self
- return class
- end
- function Toggle:display()
- if self.state == true then
- term.setTextColor(iColor[self.txtcol2])
- paintutils.drawFilledBox(self.x, self.y, self.x2, self.y2, iColor[self.bakcol2])
- else
- term.setTextColor(iColor[self.txtcol])
- paintutils.drawFilledBox(self.x, self.y, self.x2, self.y2, iColor[self.bakcol])
- end
- term.setCursorPos(((self.x2 - self.x) / 2) - (#self.name / 2) + self.x + 1, ((self.y2 - self.y) / 2) + self.y)
- term.write(self.name)
- end
- function Toggle:activate()
- if self.state == true then
- self.state = false
- else
- self.state = true
- end
- end
- function Toggle:check()
- if events[1] == "mouse_click" and events[2] == 1 and events[3] >= self.x and events[3] <= self.x2 and events[4] >= self.y and events[4] <= self.y2 then
- self:activate()
- return self.state
- else
- return self.state
- end
- end
- ------------============SWITCH API============------------
- Switch = {
- name = "",
- x = 0,
- y = 0,
- dir = "",
- state = false
- }
- function Switch:new(name, x, y, dir)
- local class = {name = name, x = x, y = y, dir = dir, state = false}
- setmetatable(class, self)
- self.__index = self
- return class
- end
- function Switch:clear()
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- if self.dir == "horizontal" then
- term.setCursorPos(self.x - 4, self.y)
- term.write("X O")
- elseif self.dir == "vertical" then
- term.setCursorPos(self.x, self.y + 4)
- term.write("X")
- term.setCursorPos(self.x, self.y - 4)
- term.write("O")
- for i = -3, 3 do
- term.setCursorPos(self.x, self.y - i)
- term.write(" ")
- end
- end
- term.setBackgroundColor(colors.gray)
- term.setCursorPos(self.x, self.y)
- term.write(" ")
- end
- function Switch:display()
- self:clear()
- term.setBackgroundColor(colors.lightGray)
- if self.dir == "horizontal" then
- if self.state then
- term.setCursorPos(self.x + 1, self.y)
- term.write(" ")
- else
- term.setCursorPos(self.x - 3, self.y)
- term.write(" ")
- end
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- term.setCursorPos(self.x - #self.name / 2 + 1, self.y + 1)
- term.write(self.name)
- elseif self.dir == "vertical" then
- if self.state then
- for i = 3, 1, -1 do
- term.setCursorPos(self.x, self.y - i)
- term.write(" ")
- end
- else
- for i = 1, 3 do
- term.setCursorPos(self.x, self.y + i)
- term.write(" ")
- end
- end
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- term.setCursorPos(self.x - #self.name / 2 + 1, self.y + 5)
- term.write(self.name)
- end
- end
- local switchClickX = nil
- local switchClickY = nil
- function Switch:check()
- if events[1] == "mouse_click" and events[2] == 1 then
- switchClickX = events[3]
- switchClickY = events[4]
- end
- if events[1] == "mouse_drag" and events[2] == 1 then
- if self.dir == "horizontal" then
- if self.state then
- if switchClickX > self.x and switchClickX <= self.x + 3 and switchClickY == self.y then
- self.state = false
- self:display()
- return false
- end
- else
- if switchClickX >= self.x - 3 and switchClickX < self.x and switchClickY == self.y then
- self.state = true
- self:display()
- return true
- end
- end
- elseif self.dir == "vertical" then
- if self.state then
- if switchClickX == self.x and switchClickY >= self.y - 3 and switchClickY < self.y then
- self.state = false
- self:display()
- return false
- end
- else
- if switchClickX == self.x and switchClickY > self.y and switchClickY <= self.y + 3 then
- self.state = true
- self:display()
- return true
- end
- end
- end
- end
- end
- ------------============SLIDER API============------------
- Slider = {
- name = "",
- x = 0,
- y = 0,
- dir = "",
- state = 0,
- length = 0
- }
- function Slider:new(name, x, y, dir, length)
- local class = {name = name, x = x, y = y, dir = dir, state = 0, length = length}
- setmetatable(class, self)
- self.__index = self
- return class
- end
- function Slider:clear()
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- term.setCursorPos(self.x, self.y)
- if self.dir == "horizontal" then
- for i = 1, self.length * 2 + 1 do
- term.write("-")
- end
- term.setCursorPos(self.x, self.y - 1)
- for i = 0, self.length do
- term.write(tostring(i) .. " ")
- end
- term.setCursorPos(self.x - 1, self.y)
- term.write(" ")
- term.setCursorPos(self.x + self.length * 2 + 1, self.y)
- term.write(" ")
- term.setCursorPos(self.x + self.length - #self.name / 2 + 1, self.y + 1)
- term.write(self.name)
- elseif self.dir == "vertical" then
- term.setCursorPos(self.x, self.y - 1)
- term.write(" ")
- term.setCursorPos(self.x, self.y + self.length * 2 + 1)
- term.write(" ")
- for i = 0, self.length * 2 do
- term.setCursorPos(self.x, self.y + i)
- term.write("|")
- end
- for i = 0, self.length do
- term.setCursorPos(self.x - 1, self.length * 2 + self.y - i * 2)
- term.write(tostring(i))
- end
- term.setCursorPos(self.x - #self.name / 2 + 1, self.y + self.length * 2 + 2)
- term.write(self.name)
- end
- end
- function Slider:display()
- self:clear()
- if self.dir == "horizontal" then
- term.setBackgroundColor(colors.lightGray)
- term.setCursorPos(self.x + self.state - 1, self.y)
- term.write(" ")
- term.setBackgroundColor(colors.gray)
- term.setCursorPos(self.x + self.state, self.y)
- term.write(" ")
- elseif self.dir == "vertical" then
- term.setBackgroundColor(colors.lightGray)
- for i = -1, 1 do
- term.setCursorPos(self.x, self.y + self.length * 2 - self.state + i)
- term.write(" ")
- end
- term.setBackgroundColor(colors.gray)
- term.setCursorPos(self.x, self.y + self.length * 2 - self.state)
- term.write(" ")
- end
- end
- local sliderClickX = nil
- local sliderClickY = nil
- function Slider:check()
- if events[1] == "mouse_click" and events[2] == 1 then
- sliderClickX = tonumber(events[3])
- sliderClickY = tonumber(events[4])
- end
- if self.dir == "horizontal" and sliderClickX and sliderClickY then
- if sliderClickX >= self.x + self.state - 1 and sliderClickX <= self.x + self.state + 1 and sliderClickY == self.y then
- if events[1] == "mouse_drag" and events[2] == 1 then
- sliderClickX = events[3]
- sliderClickY = events[4]
- if sliderClickX >= self.x and sliderClickX <= self.x + self.length * 2 then
- self.state = sliderClickX - self.x
- end
- end
- self:display()
- return self.state / 2
- end
- elseif self.dir == "vertical" and sliderClickX and sliderClickY then
- if sliderClickY >= self.y + self.length * 2 - self.state - 1 and sliderClickY <= self.y + self.length * 2 - self.state + 1 and sliderClickX == self.x then
- if events[1] == "mouse_drag" and events[2] == 1 then
- sliderClickX = events[3]
- sliderClickY = events[4]
- if sliderClickY >= self.y and sliderClickY <= self.y + self.length * 2 then
- self.state = self.y + self.length * 2 - sliderClickY
- end
- end
- self:display()
- return self.state / 2
- end
- end
- end
- ------------============DIAL API============------------
- local dialimg = {}
- for i = 1, 4 do
- dialimg[i] = {}
- end
- dialimg[1][1] = 0
- dialimg[4][1] = 0
- for i = 1, 4, 3 do
- for n = 2, 4 do
- dialimg[i][n] = 128
- end
- end
- dialimg[1][1] = 0
- dialimg[1][2] = 128
- dialimg[1][3] = 128
- dialimg[1][4] = 128
- dialimg[1][5] = 0
- for i = 2, 3 do
- for n = 1, 5 do
- dialimg[i][n] = 128
- end
- end
- Dial = {
- name = "",
- xImg = 0,
- yImg = 0,
- x = 0,
- y = 0,
- state = 1,
- mark = ""
- }
- function Dial:new(name, xImg, yImg)
- local class = {name = name, xImg = xImg, yImg = yImg, x = xImg, y = yImg + 3, state = 1, mark = "/"}
- setmetatable(class, self)
- self.__index = self
- return class
- end
- function Dial:clear()
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- term.setCursorPos(self.xImg - 1, self.yImg + 4)
- term.write("1")
- term.setCursorPos(self.xImg - 2, self.yImg + 1)
- term.write("2")
- term.setCursorPos(self.xImg - 1, self.yImg - 1)
- term.write("3")
- term.setCursorPos(self.xImg + 2, self.yImg - 2)
- term.write("4")
- term.setCursorPos(self.xImg + 5, self.yImg - 1)
- term.write("5")
- term.setCursorPos(self.xImg + 6, self.yImg + 1)
- term.write("6")
- term.setCursorPos(self.xImg + 5, self.yImg + 4)
- term.write("7")
- term.setCursorPos(self.xImg, self.yImg + 3)
- term.write(" ")
- term.setCursorPos(self.xImg - 1, self.yImg + 2)
- term.write(" ")
- term.setCursorPos(self.xImg - 1, self.yImg + 1)
- term.write(" ")
- term.setCursorPos(self.xImg, self.yImg)
- term.write(" ")
- term.setCursorPos(self.xImg + 1, self.yImg - 1)
- term.write(" ")
- term.setCursorPos(self.xImg + 2, self.yImg - 1)
- term.write(" ")
- term.setCursorPos(self.xImg + 3, self.yImg - 1)
- term.write(" ")
- term.setCursorPos(self.xImg + 4, self.yImg)
- term.write(" ")
- term.setCursorPos(self.xImg + 5, self.yImg + 1)
- term.write(" ")
- term.setCursorPos(self.xImg + 5, self.yImg + 2)
- term.write(" ")
- term.setCursorPos(self.xImg + 4, self.yImg + 3)
- term.write(" ")
- end
- function Dial:display()
- paintutils.drawImage(dialimg, self.xImg, self.yImg)
- self:clear()
- term.setBackgroundColor(colors.lightGray)
- term.setCursorPos(self.x, self.y)
- term.write(self.mark)
- term.setCursorPos(self.xImg + 2.5 - (#self.name / 2), self.yImg + 5)
- term.setBackgroundColor(colors.black)
- term.write(self.name)
- end
- local clickDialX = nil
- local clickDialY = nil
- local begin = false
- function Dial:check()
- if events[1] == "mouse_click" and events[2] == 1 then
- clickDialX = tonumber(events[3])
- clickDialY = tonumber(events[4])
- end
- if clickDialX and clickDialY and clickDialX >= self.x - 1 and clickDialX <= self.x + 1 and clickDialY >= self.y - 1 and clickDialY <= self.y + 1 then
- begin = true
- if events[1] == "mouse_drag" and events[2] == 1 then
- clickDialX = events[3]
- clickDialY = events[4]
- end
- else
- begin = false
- end
- if begin and clickDialX and clickDialY then
- if clickDialX <= self.xImg and clickDialY >= self.yImg + 3 then --1
- self.x, self.y = self.xImg, self.yImg + 3
- self.state = 1
- self.mark = "/"
- self:display()
- return 1
- elseif clickDialX <= self.xImg - 1 and clickDialY == self.yImg + 2 then --2
- self.x, self.y = self.xImg - 1, self.yImg + 2
- self.state = 2
- self.mark = "-"
- elseif clickDialX <= self.xImg - 1 and clickDialY >= self.yImg + 1 then --3
- self.x, self.y = self.xImg - 1, self.yImg + 1
- self.state = 3
- self.mark = "-"
- self:display()
- return 2
- elseif clickDialX <= self.xImg and clickDialY <= self.yImg then --4
- self.x, self.y = self.xImg, self.yImg
- self.state = 4
- self.mark = "\\"
- self:display()
- return 3
- elseif clickDialX == self.xImg + 1 and clickDialY <= self.yImg - 1 then --5
- self.x, self.y = self.xImg + 1, self.yImg - 1
- self.state = 5
- self.mark = "|"
- elseif clickDialX == self.xImg + 2 and clickDialY <= self.yImg - 1 then --6
- self.x, self.y = self.xImg + 2, self.yImg - 1
- self.state = 6
- self.mark = "|"
- self:display()
- return 4
- elseif clickDialX == self.xImg + 3 and clickDialY <= self.yImg - 1 then --7
- self.x, self.y = self.xImg + 3, self.yImg - 1
- self.state = 7
- self.mark = "|"
- elseif clickDialX >= self.xImg + 4 and clickDialY <= self.yImg then --8
- self.x, self.y = self.xImg + 4, self.yImg
- self.state = 8
- self.mark = "/"
- self:display()
- return 5
- elseif clickDialX >= self.xImg + 5 and clickDialY == self.yImg + 1 then --9
- self.x, self.y = self.xImg + 5, self.yImg + 1
- self.state = 9
- self.mark = "-"
- self:display()
- return 6
- elseif clickDialX >= self.xImg + 5 and clickDialY == self.yImg + 2 then --10
- self.x, self.y = self.xImg + 5, self.yImg + 2
- self.state = 10
- self.mark = "-"
- elseif clickDialX >= self.xImg + 4 and clickDialY >= self.yImg + 3 then --11
- self.x, self.y = self.xImg + 4, self.yImg + 3
- self.state = 11
- self.mark = "\\"
- self:display()
- return 7
- end
- end
- self:display()
- end
- ------------optional display program------------
- --[[term.setBackgroundColor(colors.black)
- term.clear()
- Spin = Dial:new("Spin", 3, 3)
- SlideX = Slider:new("SlideX", 2, 11, "horizontal", 4)
- SlideY = Slider:new("SlideY", 16, 2, "vertical", 6)
- Flip = Switch:new("Flip", 6, 16, "horizontal")
- Flap = Switch:new("Flap", 22, 7, "vertical")
- OnOff = Toggle:new("Onoff", 30, 2, 34, 5, 2, 15, 5, 4, false)
- Push = Button:new("Push", 27, 12, 33, 14, 1, 6, 16, 15)
- while true do
- Spin:display()
- SlideX:display()
- SlideY:display()
- Flip:display()
- Flap:display()
- OnOff:display()
- Push:display()
- getEvents()
- Spin:check()
- SlideX:check()
- SlideY:check()
- Flip:check()
- Flap:check()
- OnOff:check()
- Push:check()
- end]]--
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement