Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function newButton(x,y,w,h,color1,color2,text,onClick)
- return {
- create = function(self)
- term.setCursorPos(self.x,self.y)
- self.window_ = window.create(term.current(),self.x,self.y,self.w,self.h)
- self.window_.setBackgroundColor(self.color1)
- self.window_.clear()
- -- add text
- local newX = math.floor((self.w - #self.text)/2) + 1
- local newY = math.floor(self.h / 2)
- self.window_.setCursorPos(newX, newY)
- self.window_.setTextColor(self.color2)
- self.window_.write(self.text)
- self.window_.redraw()
- self.window_.setTextColor(colors.white)
- term.setCursorPos(1,self.y + self.h + 1 )
- end,
- checkClick = function(self,x,y)
- if (x >= self.x) and (x < (self.w + self.x)) and (y >= self.y) and (y < (self.h + self.y)) then
- return true
- end
- return false
- end,
- x = x,
- y = y,
- w = w,
- h = h,
- color1 = color1,
- color2 = color2,
- text = text,
- onClick = onClick
- }
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement