Advertisement
Guest User

Untitled

a guest
May 27th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.74 KB | None | 0 0
  1. local EVENT -- List of all os.pullEvent() variables
  2. local GUI_DATA -- List of all components data: ["Component_1"] = [{x, y}, {x, y}, func()]
  3.  
  4. function init(GUI) -- New eventhandler for new GUI
  5.     GUI_DATA = GUI.getComponents()
  6. end
  7.  
  8. function timed_mouseclick_Event(t)
  9.     os.startTimer(t)
  10.     EVENT = {os.pullEvent()}
  11.     if EVENT[1] == "timer" then
  12.         return
  13.     else
  14.         mouse_clickListener(EVENT)
  15.     end;
  16. end;
  17.  
  18. function mouse_clickListener(mouseEvent) -- "Listens" to an eventobject fired by a mouse_click and executes the function given by componentdata
  19.    
  20.     _,x,y = unpack(mouseEvent)
  21.    
  22.     for j, k in pairs(GUI_DATA) do
  23.         if x >= k[1].x and x <= k[2].x then
  24.             if y >= k[1].y and y <= k[2].y then
  25.                 k.action()
  26.             end
  27.         end
  28.     end
  29. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement