Advertisement
CaptainSpaceCat

Draggable Window

Jun 11th, 2015
306
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.76 KB | None | 0 0
  1. term.setBackgroundColor(colors.black)
  2. term.clear()
  3. local boxlocation = {2, 2}
  4. local clickX, clickY = nil, nil
  5. while true do
  6.     term.setCursorPos(1, 1)
  7.     term.write("click & drag")
  8.     paintutils.drawFilledBox(boxlocation[1], boxlocation[2], boxlocation[1] + 4, boxlocation[2] + 2, colors.gray)
  9.     local events = {os.pullEvent()}
  10.     term.setBackgroundColor(colors.black)
  11.     term.clear()
  12.     if events[1] == "mouse_click" and events[2] == 1 then
  13.         clickX, clickY = events[3], events[4]
  14.     end
  15.     if events[1] == "mouse_drag" and events[2] == 1 and clickX and clickY and clickX >= boxlocation[1] - 1 and clickX <= boxlocation[1] + 5 and clickY >= boxlocation[2] - 1 and clickY <= boxlocation[2] + 2 then
  16.         clickX, clickY = events[3], events[4]
  17.         boxlocation = {clickX, clickY}
  18.     end
  19. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement