Advertisement
Guest User

buttonAPI

a guest
Feb 22nd, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.95 KB | None | 0 0
  1. function newButton(x,y,w,h,color1,color2,text,onClick)
  2.   return {
  3.   create = function(self)
  4.     term.setCursorPos(self.x,self.y)
  5.     self.window_ = window.create(term.current(),self.x,self.y,self.w,self.h)
  6.     self.window_.setBackgroundColor(self.color1)
  7.     self.window_.clear()
  8.    
  9.     -- add text
  10.     local newX = math.floor((self.w - #self.text)/2) + 1
  11.     local newY = math.floor(self.h / 2)
  12.     self.window_.setCursorPos(newX, newY)
  13.     self.window_.setTextColor(self.color2)
  14.     self.window_.write(self.text)
  15.     self.window_.redraw()
  16.     self.window_.setTextColor(colors.white)
  17.     term.setCursorPos(1,self.y + self.h + 1 )
  18.   end,
  19.   checkClick = function(self,x,y)
  20.     if (x >= self.x) and (x < (self.w + self.x)) and (y >= self.y) and (y < (self.h + self.y)) then
  21.         return true
  22.     end
  23.     return false
  24.   end,
  25.   x = x,
  26.   y = y,
  27.   w = w,
  28.   h = h,
  29.   color1 = color1,
  30.   color2 = color2,
  31.   text = text,
  32.   onClick = onClick
  33.   }
  34. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement