Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- this is all completely untested so it might not work xd
- local BUTTONS = {}
- local CLICKED = {}
- function createButton(id, x, y, w, h, callback)
- local x2 = x + w - 1
- local y2 = y + h - 1
- local button = {
- x1 = x, y1 = y,
- x2 = x2, y2 = y2,
- id = id, callback = callback
- }
- table.insert(BUTTONS, id, button)
- return button
- end
- function getHitScan(x, y)
- for key, value in pairs(BUTTONS) do
- if (x >= value.x1 and x <= value.x2) then
- if (y >= value.y1 and y <= value.y2) then
- return value
- end
- end
- end
- return nil
- end
- function onScreenHit(x, y)
- local hit = getHitScan(x, y)
- if (hit == nil) then
- return
- end
- table.insert(CLICKED, hit.id, hit)
- hit.callback(x, y, hit.id)
- end
- function pullClickEvent()
- local mouse,x,y = os.pullEvent("mouse_click")
- onScreenHit(x, y)
- end
- function getButtons()
- return BUTTONS
- end
- function getClickedButtons()
- return CLICKED
- end
Add Comment
Please, Sign In to add comment