Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- mainButton = {}
- mt = {
- __index = mainButton
- }
- function create(name)
- return setmetatable(name,mt)
- end
- function mainButton:new(x1,x2,y1,y2)
- self.map = {} -- create map of button
- self.pos = {x1,x2,y1,y2}
- for w = x1, x2 do
- --write("\n"..w.."-")
- self.map[w] = {} -- enter the current width
- for h = y1, y2 do
- self.map[w][h] = h -- enter then current height of the current width
- --write(" "..h)
- --sleep(0.1)
- end
- end
- end
- --mainButton:new(4,8,4,8)
- function mainButton:draw(color)
- for key1, value1 in pairs(self["map"]) do
- for key2, value2 in pairs(self["map"][key1]) do
- paintutils.drawPixel(key1,value2,color)
- end
- end
- end
- function mainButton:cText(txt)
- w = math.ceil((self["pos"][1] + self['pos'][2])/2 - #txt/2)
- h = math.ceil((self['pos'][3] + self['pos'][4])/2 - #txt/2)
- term.setCursorPos(w,h)
- write(txt)
- end
- function mainButton:click()
- _,_,x,y = os.pullEvent("mouse_click")
- for key1, value1 in pairs(self["map"]) do
- for key2, value2 in pairs(self["map"][key1]) do
- if x == key1 and y == value2 then
- return true
- end
- end
- end
- return false
- end
Advertisement
Add Comment
Please, Sign In to add comment