CoreInput.lua 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. require "Polycode/EventDispatcher"
  2. class "CoreInput" (EventDispatcher)
  3. CoreInput.MOUSE_BUTTON1 = 0
  4. CoreInput.MOUSE_BUTTON2 = 1
  5. CoreInput.MOUSE_BUTTON3 = 2
  6. function CoreInput:__getvar(name)
  7. if name == "simulateTouchWithMouse" then
  8. return Polycode.CoreInput_get_simulateTouchWithMouse(self.__ptr)
  9. elseif name == "simulateTouchAsPen" then
  10. return Polycode.CoreInput_get_simulateTouchAsPen(self.__ptr)
  11. elseif name == "simulateMouseWithTouch" then
  12. return Polycode.CoreInput_get_simulateMouseWithTouch(self.__ptr)
  13. elseif name == "ignoreOffScreenTouch" then
  14. return Polycode.CoreInput_get_ignoreOffScreenTouch(self.__ptr)
  15. elseif name == "keyRepeat" then
  16. return Polycode.CoreInput_get_keyRepeat(self.__ptr)
  17. elseif name == "mousePosition" then
  18. local retVal = Polycode.CoreInput_get_mousePosition(self.__ptr)
  19. if retVal == nil then return nil end
  20. local __c = _G["Vector2"]("__skip_ptr__")
  21. __c.__ptr = retVal
  22. return __c
  23. elseif name == "deltaMousePosition" then
  24. local retVal = Polycode.CoreInput_get_deltaMousePosition(self.__ptr)
  25. if retVal == nil then return nil end
  26. local __c = _G["Vector2"]("__skip_ptr__")
  27. __c.__ptr = retVal
  28. return __c
  29. end
  30. if EventDispatcher["__getvar"] ~= nil then
  31. return EventDispatcher.__getvar(self, name)
  32. end
  33. end
  34. function CoreInput:__setvar(name,value)
  35. if name == "simulateTouchWithMouse" then
  36. Polycode.CoreInput_set_simulateTouchWithMouse(self.__ptr, value)
  37. return true
  38. elseif name == "simulateTouchAsPen" then
  39. Polycode.CoreInput_set_simulateTouchAsPen(self.__ptr, value)
  40. return true
  41. elseif name == "simulateMouseWithTouch" then
  42. Polycode.CoreInput_set_simulateMouseWithTouch(self.__ptr, value)
  43. return true
  44. elseif name == "ignoreOffScreenTouch" then
  45. Polycode.CoreInput_set_ignoreOffScreenTouch(self.__ptr, value)
  46. return true
  47. elseif name == "keyRepeat" then
  48. Polycode.CoreInput_set_keyRepeat(self.__ptr, value)
  49. return true
  50. elseif name == "mousePosition" then
  51. Polycode.CoreInput_set_mousePosition(self.__ptr, value.__ptr)
  52. return true
  53. elseif name == "deltaMousePosition" then
  54. Polycode.CoreInput_set_deltaMousePosition(self.__ptr, value.__ptr)
  55. return true
  56. end
  57. if EventDispatcher["__setvar"] ~= nil then
  58. return EventDispatcher.__setvar(self, name, value)
  59. else
  60. return false
  61. end
  62. end
  63. function CoreInput:CoreInput(...)
  64. local arg = {...}
  65. if type(arg[1]) == "table" and count(arg) == 1 then
  66. if ""..arg[1].__classname == "EventDispatcher" then
  67. self.__ptr = arg[1].__ptr
  68. return
  69. end
  70. end
  71. for k,v in pairs(arg) do
  72. if type(v) == "table" then
  73. if v.__ptr ~= nil then
  74. arg[k] = v.__ptr
  75. end
  76. end
  77. end
  78. if self.__ptr == nil and arg[1] ~= "__skip_ptr__" then
  79. self.__ptr = Polycode.CoreInput(unpack(arg))
  80. end
  81. end
  82. function CoreInput:getMousePosition()
  83. local retVal = Polycode.CoreInput_getMousePosition(self.__ptr)
  84. if retVal == nil then return nil end
  85. local __c = _G["Vector2"]("__skip_ptr__")
  86. __c.__ptr = retVal
  87. return __c
  88. end
  89. function CoreInput:getKeyState(keyCode)
  90. local retVal = Polycode.CoreInput_getKeyState(self.__ptr, keyCode)
  91. return retVal
  92. end
  93. function CoreInput:getJoystickButtonState(joystickIndex, button)
  94. local retVal = Polycode.CoreInput_getJoystickButtonState(self.__ptr, joystickIndex, button)
  95. return retVal
  96. end
  97. function CoreInput:getJoystickAxisValue(joystickIndex, axis)
  98. local retVal = Polycode.CoreInput_getJoystickAxisValue(self.__ptr, joystickIndex, axis)
  99. return retVal
  100. end
  101. function CoreInput:getMouseDelta()
  102. local retVal = Polycode.CoreInput_getMouseDelta(self.__ptr)
  103. if retVal == nil then return nil end
  104. local __c = _G["Vector2"]("__skip_ptr__")
  105. __c.__ptr = retVal
  106. return __c
  107. end
  108. function CoreInput:getMouseButtonState(mouseButton)
  109. local retVal = Polycode.CoreInput_getMouseButtonState(self.__ptr, mouseButton)
  110. return retVal
  111. end
  112. function CoreInput:getNumJoysticks()
  113. local retVal = Polycode.CoreInput_getNumJoysticks(self.__ptr)
  114. return retVal
  115. end
  116. function CoreInput:getJoystickInfoByIndex(index)
  117. local retVal = Polycode.CoreInput_getJoystickInfoByIndex(self.__ptr, index)
  118. if retVal == nil then return nil end
  119. local __c = _G["JoystickInfo"]("__skip_ptr__")
  120. __c.__ptr = retVal
  121. return __c
  122. end
  123. function CoreInput:getJoystickInfoByID(deviceID)
  124. local retVal = Polycode.CoreInput_getJoystickInfoByID(self.__ptr, deviceID)
  125. if retVal == nil then return nil end
  126. local __c = _G["JoystickInfo"]("__skip_ptr__")
  127. __c.__ptr = retVal
  128. return __c
  129. end
  130. function CoreInput:addJoystick(deviceID)
  131. local retVal = Polycode.CoreInput_addJoystick(self.__ptr, deviceID)
  132. end
  133. function CoreInput:removeJoystick(deviceID)
  134. local retVal = Polycode.CoreInput_removeJoystick(self.__ptr, deviceID)
  135. end
  136. function CoreInput:joystickAxisMoved(axisID, value, deviceID)
  137. local retVal = Polycode.CoreInput_joystickAxisMoved(self.__ptr, axisID, value, deviceID)
  138. end
  139. function CoreInput:joystickButtonDown(buttonID, deviceID)
  140. local retVal = Polycode.CoreInput_joystickButtonDown(self.__ptr, buttonID, deviceID)
  141. end
  142. function CoreInput:joystickButtonUp(buttonID, deviceID)
  143. local retVal = Polycode.CoreInput_joystickButtonUp(self.__ptr, buttonID, deviceID)
  144. end
  145. function CoreInput:mouseWheelUp(ticks)
  146. local retVal = Polycode.CoreInput_mouseWheelUp(self.__ptr, ticks)
  147. end
  148. function CoreInput:mouseWheelDown(ticks)
  149. local retVal = Polycode.CoreInput_mouseWheelDown(self.__ptr, ticks)
  150. end
  151. function CoreInput:setMouseButtonState(mouseButton, state, ticks)
  152. local retVal = Polycode.CoreInput_setMouseButtonState(self.__ptr, mouseButton, state, ticks)
  153. end
  154. function CoreInput:setMousePosition(x, y, ticks)
  155. local retVal = Polycode.CoreInput_setMousePosition(self.__ptr, x, y, ticks)
  156. end
  157. function CoreInput:setKeyState(keyCode, code, newState, ticks)
  158. local retVal = Polycode.CoreInput_setKeyState(self.__ptr, keyCode, code.__ptr, newState, ticks)
  159. end
  160. function CoreInput:setDeltaPosition(x, y)
  161. local retVal = Polycode.CoreInput_setDeltaPosition(self.__ptr, x, y)
  162. end
  163. function CoreInput:touchesBegan(touch, touches, ticks)
  164. local retVal = Polycode.CoreInput_touchesBegan(self.__ptr, touch.__ptr, touches.__ptr, ticks)
  165. end
  166. function CoreInput:touchesMoved(touch, touches, ticks)
  167. local retVal = Polycode.CoreInput_touchesMoved(self.__ptr, touch.__ptr, touches.__ptr, ticks)
  168. end
  169. function CoreInput:touchesEnded(touch, touches, ticks)
  170. local retVal = Polycode.CoreInput_touchesEnded(self.__ptr, touch.__ptr, touches.__ptr, ticks)
  171. end
  172. function CoreInput:createEvent(event)
  173. local retVal = Polycode.CoreInput_createEvent(self.__ptr, event.__ptr)
  174. if retVal == nil then return nil end
  175. local __c = _G["InputEvent"]("__skip_ptr__")
  176. __c.__ptr = retVal
  177. return __c
  178. end
  179. function CoreInput:clearInput()
  180. local retVal = Polycode.CoreInput_clearInput(self.__ptr)
  181. end
  182. function CoreInput:__delete()
  183. if self then Polycode.delete_CoreInput(self.__ptr) end
  184. end