No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

mouse.lua 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. -- @docclass
  2. g_mouse = {}
  3. local cursorChanged = false
  4. function g_mouse.setTargetCursor()
  5. g_window.setMouseCursor('/cursors/targetcursor.png', {x=9,y=9})
  6. cursorChanged = true
  7. end
  8. function g_mouse.setHorizontalCursor()
  9. g_window.setMouseCursor('/cursors/horizontal.png', {x=9,y=4})
  10. cursorChanged = true
  11. end
  12. function g_mouse.setVerticalCursor()
  13. g_window.setMouseCursor('/cursors/vertical.png', {x=4,y=9})
  14. cursorChanged = true
  15. end
  16. function g_mouse.restoreCursor()
  17. g_window.restoreMouseCursor()
  18. cursorChanged = false
  19. end
  20. function g_mouse.isCursorChanged()
  21. return cursorChanged
  22. end
  23. function g_mouse.isPressed(button)
  24. if not button then button = MouseLeftButton end
  25. return g_window.isMouseButtonPressed(button)
  26. end
  27. function g_mouse.bindAutoPress(widget, callback, delay)
  28. connect(widget, { onMousePress = function(widget, mousePos, mouseButton)
  29. local startTime = g_clock.millis()
  30. callback(widget, mousePos, mouseButton, 0)
  31. periodicalEvent(function()
  32. callback(widget, g_window.getMousePosition(), mouseButton, g_clock.millis() - startTime)
  33. end, function()
  34. return widget:isPressed()
  35. end, 30, delay)
  36. return true
  37. end })
  38. end
  39. function g_mouse.bindPressMove(widget, callback)
  40. connect(widget, { onMouseMove = function(widget, mousePos, mouseMoved)
  41. if widget:isPressed() then
  42. callback(mousePos, mouseMoved)
  43. end
  44. return true
  45. end })
  46. end