CoreInput.lua 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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 == "keyRepeat" then
  14. return Polycode.CoreInput_get_keyRepeat(self.__ptr)
  15. elseif name == "mousePosition" then
  16. local retVal = Polycode.CoreInput_get_mousePosition(self.__ptr)
  17. if retVal == nil then return nil end
  18. local __c = _G["Vector2"]("__skip_ptr__")
  19. __c.__ptr = retVal
  20. return __c
  21. elseif name == "deltaMousePosition" then
  22. local retVal = Polycode.CoreInput_get_deltaMousePosition(self.__ptr)
  23. if retVal == nil then return nil end
  24. local __c = _G["Vector2"]("__skip_ptr__")
  25. __c.__ptr = retVal
  26. return __c
  27. end
  28. if EventDispatcher["__getvar"] ~= nil then
  29. return EventDispatcher.__getvar(self, name)
  30. end
  31. end
  32. function CoreInput:__setvar(name,value)
  33. if name == "simulateTouchWithMouse" then
  34. Polycode.CoreInput_set_simulateTouchWithMouse(self.__ptr, value)
  35. return true
  36. elseif name == "simulateTouchAsPen" then
  37. Polycode.CoreInput_set_simulateTouchAsPen(self.__ptr, value)
  38. return true
  39. elseif name == "simulateMouseWithTouch" then
  40. Polycode.CoreInput_set_simulateMouseWithTouch(self.__ptr, value)
  41. return true
  42. elseif name == "keyRepeat" then
  43. Polycode.CoreInput_set_keyRepeat(self.__ptr, value)
  44. return true
  45. elseif name == "mousePosition" then
  46. Polycode.CoreInput_set_mousePosition(self.__ptr, value.__ptr)
  47. return true
  48. elseif name == "deltaMousePosition" then
  49. Polycode.CoreInput_set_deltaMousePosition(self.__ptr, value.__ptr)
  50. return true
  51. end
  52. if EventDispatcher["__setvar"] ~= nil then
  53. return EventDispatcher.__setvar(self, name, value)
  54. else
  55. return false
  56. end
  57. end
  58. function CoreInput:CoreInput(...)
  59. local arg = {...}
  60. if type(arg[1]) == "table" and count(arg) == 1 then
  61. if ""..arg[1].__classname == "EventDispatcher" then
  62. self.__ptr = arg[1].__ptr
  63. return
  64. end
  65. end
  66. for k,v in pairs(arg) do
  67. if type(v) == "table" then
  68. if v.__ptr ~= nil then
  69. arg[k] = v.__ptr
  70. end
  71. end
  72. end
  73. if self.__ptr == nil and arg[1] ~= "__skip_ptr__" then
  74. self.__ptr = Polycode.CoreInput(unpack(arg))
  75. end
  76. end
  77. function CoreInput:getMousePosition()
  78. local retVal = Polycode.CoreInput_getMousePosition(self.__ptr)
  79. if retVal == nil then return nil end
  80. local __c = _G["Vector2"]("__skip_ptr__")
  81. __c.__ptr = retVal
  82. return __c
  83. end
  84. function CoreInput:getKeyState(keyCode)
  85. local retVal = Polycode.CoreInput_getKeyState(self.__ptr, keyCode)
  86. return retVal
  87. end
  88. function CoreInput:getJoystickButtonState(joystickIndex, button)
  89. local retVal = Polycode.CoreInput_getJoystickButtonState(self.__ptr, joystickIndex, button)
  90. return retVal
  91. end
  92. function CoreInput:getJoystickAxisValue(joystickIndex, axis)
  93. local retVal = Polycode.CoreInput_getJoystickAxisValue(self.__ptr, joystickIndex, axis)
  94. return retVal
  95. end
  96. function CoreInput:getMouseDelta()
  97. local retVal = Polycode.CoreInput_getMouseDelta(self.__ptr)
  98. if retVal == nil then return nil end
  99. local __c = _G["Vector2"]("__skip_ptr__")
  100. __c.__ptr = retVal
  101. return __c
  102. end
  103. function CoreInput:getMouseButtonState(mouseButton)
  104. local retVal = Polycode.CoreInput_getMouseButtonState(self.__ptr, mouseButton)
  105. return retVal
  106. end
  107. function CoreInput:getNumJoysticks()
  108. local retVal = Polycode.CoreInput_getNumJoysticks(self.__ptr)
  109. return retVal
  110. end
  111. function CoreInput:addJoystick(deviceID)
  112. local retVal = Polycode.CoreInput_addJoystick(self.__ptr, deviceID)
  113. end
  114. function CoreInput:removeJoystick(deviceID)
  115. local retVal = Polycode.CoreInput_removeJoystick(self.__ptr, deviceID)
  116. end
  117. function CoreInput:joystickAxisMoved(axisID, value, deviceID)
  118. local retVal = Polycode.CoreInput_joystickAxisMoved(self.__ptr, axisID, value, deviceID)
  119. end
  120. function CoreInput:joystickButtonDown(buttonID, deviceID)
  121. local retVal = Polycode.CoreInput_joystickButtonDown(self.__ptr, buttonID, deviceID)
  122. end
  123. function CoreInput:joystickButtonUp(buttonID, deviceID)
  124. local retVal = Polycode.CoreInput_joystickButtonUp(self.__ptr, buttonID, deviceID)
  125. end
  126. function CoreInput:mouseWheelUp(ticks)
  127. local retVal = Polycode.CoreInput_mouseWheelUp(self.__ptr, ticks)
  128. end
  129. function CoreInput:mouseWheelDown(ticks)
  130. local retVal = Polycode.CoreInput_mouseWheelDown(self.__ptr, ticks)
  131. end
  132. function CoreInput:setMouseButtonState(mouseButton, state, ticks)
  133. local retVal = Polycode.CoreInput_setMouseButtonState(self.__ptr, mouseButton, state, ticks)
  134. end
  135. function CoreInput:setMousePosition(x, y, ticks)
  136. local retVal = Polycode.CoreInput_setMousePosition(self.__ptr, x, y, ticks)
  137. end
  138. function CoreInput:setKeyState(keyCode, newState, ticks)
  139. local retVal = Polycode.CoreInput_setKeyState(self.__ptr, keyCode, newState, ticks)
  140. end
  141. function CoreInput:setDeltaPosition(x, y)
  142. local retVal = Polycode.CoreInput_setDeltaPosition(self.__ptr, x, y)
  143. end
  144. function CoreInput:touchesBegan(touch, touches, ticks)
  145. local retVal = Polycode.CoreInput_touchesBegan(self.__ptr, touch.__ptr, touches.__ptr, ticks)
  146. end
  147. function CoreInput:touchesMoved(touch, touches, ticks)
  148. local retVal = Polycode.CoreInput_touchesMoved(self.__ptr, touch.__ptr, touches.__ptr, ticks)
  149. end
  150. function CoreInput:touchesEnded(touch, touches, ticks)
  151. local retVal = Polycode.CoreInput_touchesEnded(self.__ptr, touch.__ptr, touches.__ptr, ticks)
  152. end
  153. function CoreInput:textInput(text)
  154. local retVal = Polycode.CoreInput_textInput(self.__ptr, text)
  155. end
  156. function CoreInput:clearInput()
  157. local retVal = Polycode.CoreInput_clearInput(self.__ptr)
  158. end
  159. function CoreInput:__delete()
  160. if self then Polycode.delete_CoreInput(self.__ptr) end
  161. end