CoreInput.lua 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. require "Polycode/EventDispatcher"
  2. class "CoreInput" (EventDispatcher)
  3. MOUSE_BUTTON1 = 0
  4. MOUSE_BUTTON2 = 1
  5. MOUSE_BUTTON3 = 2
  6. function CoreInput:__index__(name)
  7. if name == "PolyCore" then
  8. retVal = Polycore.CoreInput_get_PolyCore(self.__ptr)
  9. if Polycore.__ptr_lookup[retVal] ~= nil then
  10. return Polycore.__ptr_lookup[retVal]
  11. else
  12. Polycore.__ptr_lookup[retVal] = friend class("__skip_ptr__")
  13. Polycore.__ptr_lookup[retVal].__ptr = retVal
  14. return Polycore.__ptr_lookup[retVal]
  15. end
  16. end
  17. end
  18. function CoreInput:__set_callback(name,value)
  19. return false
  20. end
  21. function CoreInput:CoreInput(...)
  22. if type(arg[1]) == "table" and count(arg) == 1 then
  23. if ""..arg[1]:class() == "EventDispatcher" then
  24. self.__ptr = arg[1].__ptr
  25. return
  26. end
  27. end
  28. for k,v in pairs(arg) do
  29. if type(v) == "table" then
  30. if v.__ptr ~= nil then
  31. arg[k] = v.__ptr
  32. end
  33. end
  34. end
  35. if self.__ptr == nil and arg[1] ~= "__skip_ptr__" then
  36. self.__ptr = Polycore.CoreInput(unpack(arg))
  37. Polycore.__ptr_lookup[self.__ptr] = self
  38. end
  39. end
  40. function CoreInput:getMousePosition()
  41. local retVal = Polycore.CoreInput_getMousePosition(self.__ptr)
  42. if retVal == nil then return nil end
  43. if Polycore.__ptr_lookup[retVal] ~= nil then
  44. return Polycore.__ptr_lookup[retVal]
  45. else
  46. Polycore.__ptr_lookup[retVal] = Vector2("__skip_ptr__")
  47. Polycore.__ptr_lookup[retVal].__ptr = retVal
  48. return Polycore.__ptr_lookup[retVal]
  49. end
  50. end
  51. function CoreInput:getKeyState(keyCode)
  52. local retVal = Polycore.CoreInput_getKeyState(self.__ptr, keyCode.__ptr)
  53. return retVal
  54. end
  55. function CoreInput:getMouseDelta()
  56. local retVal = Polycore.CoreInput_getMouseDelta(self.__ptr)
  57. if retVal == nil then return nil end
  58. if Polycore.__ptr_lookup[retVal] ~= nil then
  59. return Polycore.__ptr_lookup[retVal]
  60. else
  61. Polycore.__ptr_lookup[retVal] = Vector2("__skip_ptr__")
  62. Polycore.__ptr_lookup[retVal].__ptr = retVal
  63. return Polycore.__ptr_lookup[retVal]
  64. end
  65. end
  66. function CoreInput:getMouseButtonState(mouseButton)
  67. local retVal = Polycore.CoreInput_getMouseButtonState(self.__ptr, mouseButton)
  68. return retVal
  69. end
  70. function CoreInput:getNumJoysticks()
  71. local retVal = Polycore.CoreInput_getNumJoysticks(self.__ptr)
  72. return retVal
  73. end
  74. function CoreInput:getJoystickInfoByIndex(index)
  75. local retVal = Polycore.CoreInput_getJoystickInfoByIndex(self.__ptr, index)
  76. if retVal == nil then return nil end
  77. if Polycore.__ptr_lookup[retVal] ~= nil then
  78. return Polycore.__ptr_lookup[retVal]
  79. else
  80. Polycore.__ptr_lookup[retVal] = JoystickInfo("__skip_ptr__")
  81. Polycore.__ptr_lookup[retVal].__ptr = retVal
  82. return Polycore.__ptr_lookup[retVal]
  83. end
  84. end
  85. function CoreInput:getJoystickInfoByID(deviceID)
  86. local retVal = Polycore.CoreInput_getJoystickInfoByID(self.__ptr, deviceID)
  87. if retVal == nil then return nil end
  88. if Polycore.__ptr_lookup[retVal] ~= nil then
  89. return Polycore.__ptr_lookup[retVal]
  90. else
  91. Polycore.__ptr_lookup[retVal] = JoystickInfo("__skip_ptr__")
  92. Polycore.__ptr_lookup[retVal].__ptr = retVal
  93. return Polycore.__ptr_lookup[retVal]
  94. end
  95. end
  96. function CoreInput:addJoystick(deviceID)
  97. local retVal = Polycore.CoreInput_addJoystick(self.__ptr, deviceID)
  98. end
  99. function CoreInput:removeJoystick(deviceID)
  100. local retVal = Polycore.CoreInput_removeJoystick(self.__ptr, deviceID)
  101. end
  102. function CoreInput:joystickAxisMoved(axisID, value, deviceID)
  103. local retVal = Polycore.CoreInput_joystickAxisMoved(self.__ptr, axisID, value, deviceID)
  104. end
  105. function CoreInput:joystickButtonDown(buttonID, deviceID)
  106. local retVal = Polycore.CoreInput_joystickButtonDown(self.__ptr, buttonID, deviceID)
  107. end
  108. function CoreInput:joystickButtonUp(buttonID, deviceID)
  109. local retVal = Polycore.CoreInput_joystickButtonUp(self.__ptr, buttonID, deviceID)
  110. end
  111. function CoreInput:mouseWheelUp(ticks)
  112. local retVal = Polycore.CoreInput_mouseWheelUp(self.__ptr, ticks)
  113. end
  114. function CoreInput:mouseWheelDown(ticks)
  115. local retVal = Polycore.CoreInput_mouseWheelDown(self.__ptr, ticks)
  116. end
  117. function CoreInput:setMouseButtonState(mouseButton, state, ticks)
  118. local retVal = Polycore.CoreInput_setMouseButtonState(self.__ptr, mouseButton, state, ticks)
  119. end
  120. function CoreInput:setMousePosition(x, y, ticks)
  121. local retVal = Polycore.CoreInput_setMousePosition(self.__ptr, x, y, ticks)
  122. end
  123. function CoreInput:setKeyState(keyCode, code, newState, ticks)
  124. local retVal = Polycore.CoreInput_setKeyState(self.__ptr, keyCode.__ptr, code.__ptr, newState, ticks)
  125. end
  126. function CoreInput:setDeltaPosition(x, y)
  127. local retVal = Polycore.CoreInput_setDeltaPosition(self.__ptr, x, y)
  128. end
  129. function CoreInput:createEvent(event)
  130. local retVal = Polycore.CoreInput_createEvent(event.__ptr)
  131. if retVal == nil then return nil end
  132. if Polycore.__ptr_lookup[retVal] ~= nil then
  133. return Polycore.__ptr_lookup[retVal]
  134. else
  135. Polycore.__ptr_lookup[retVal] = InputEvent("__skip_ptr__")
  136. Polycore.__ptr_lookup[retVal].__ptr = retVal
  137. return Polycore.__ptr_lookup[retVal]
  138. end
  139. end
  140. function CoreInput:__delete()
  141. Polycore.__ptr_lookup[self.__ptr] = nil
  142. Polycore.delete_CoreInput(self.__ptr)
  143. end