Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Toggle = {
- name = "",
- x = 0,
- y = 0,
- x2 = 0,
- y2 = 0,
- txtcol = 0,
- bakcol = 0,
- txtcol2 = 0,
- bakcol2 = 0,
- state = false
- }
- iColor = {}
- for i = 0, 15 do
- iColor[i + 1] = 2 ^ i
- end
- 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 getClick()
- events = {os.pullEventRaw()}
- 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
- --otional display program--
- --[[term.setBackgroundColor(colors.black)
- term.clear()
- Start = Toggle:new("Start", 10, 5, 17, 7, 8, 10, 2, 1, true)
- Quit = Toggle:new("Quit", 19, 10, 24, 11, 15, 2, 12, 5, false)
- Banana = Toggle:new("Banana", 30, 2, 39, 5, 13, 5, 2, 11, false)
- while true do
- Start:display()
- Quit:display()
- Banana:display()
- events = {os.pullEventRaw()}
- if Start:check() == true then
- term.setCursorPos(1, 1)
- term.write("Started")
- end
- if Quit:check() == true then
- break
- end
- if Banana:check() == true then
- term.setCursorPos(1, 1)
- term.write("yum")
- term.setBackgroundColor(colors.black)
- term.write(" ")
- end
- end]]--
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement