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