Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local ButtonAPI = {}
- ButtonAPI.Buttons = {}
- ButtonAPI.createButton = function(Name,Connection,Type,Color1,Color2,PosX,PosY,SizeX,SizeY)
- local newButton = {}
- -- big O'l vars
- newButton.Name = Name
- newButton.Connection = Connection
- newButton.ButtonType = Type or "Click"
- newButton.State = false
- newButton.Color1 = Color1
- newButton.Color2 = Color2
- newButton.PosX = PosX
- newButton.PosY = PosY
- newButton.SizeX = SizeX
- newButton.SizeY = SizeY
- newButton.Thread = nil
- -- state shit
- newButton.SetState = function(newState)
- newButton.State = newState
- end
- newButton.GetState = function()
- return newButton.State
- end
- -- drawing
- newButton.Draw = function()
- term.setCursorPos(newButton.PosX,newButton.PosY)
- if newButton.State == false then
- paintutils.drawFilledBox(
- newButton.PosX,
- newButton.PosY,
- newButton.PosX + newButton.SizeX,
- newButton.PosY + newButton.SizeY,
- newButton.Color1
- )
- else
- paintutils.drawFilledBox(
- newButton.PosX,
- newButton.PosY,
- newButton.PosX + newButton.SizeX,
- newButton.PosY + newButton.SizeY,
- newButton.Color2
- )
- end
- term.setBackgroundColor(colors.black)
- end
- -- dtecet clickty
- newButton.Detection = function()
- local event,side,x,y = os.pullEvent("monitor_touch")
- --print("Pressed")
- -- annoying if'y shit
- if x >= newButton.PosX
- and x <= newButton.PosX + newButton.SizeX
- and y >= newButton.PosY
- and y <= newButton.PosY + newButton.SizeY then
- newButton.State = not newButton.State
- if newButton.ButtonType == "Click" then
- sleep(1)
- newButton.State = not newButton.State
- print("Pressed")
- end
- end
- end
- -- add to list of buttons
- table.insert(ButtonAPI.Buttons, newButton)
- -- start
- newButton.Detection()
- end
- ButtonAPI.ClearButtons = function()
- ButtonAPI.Buttons = {}
- end
- ButtonAPI.DrawAllButtons = function()
- for i,q in pairs(ButtonAPI.Buttons) do
- q.Draw()
- end
- end
- return ButtonAPI
Advertisement
Add Comment
Please, Sign In to add comment