ScreenEntity.lua 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. require "Polycode/Entity"
  2. class "ScreenEntity" (Entity)
  3. POSITION_TOPLEFT = 0
  4. POSITION_CENTER = 1
  5. function ScreenEntity:__index__(name)
  6. if name == "hasFocus" then
  7. return Polycore.ScreenEntity_get_hasFocus(self.__ptr)
  8. elseif name == "blockMouseInput" then
  9. return Polycore.ScreenEntity_get_blockMouseInput(self.__ptr)
  10. elseif name == "zindex" then
  11. return Polycore.ScreenEntity_get_zindex(self.__ptr)
  12. elseif name == "snapToPixels" then
  13. return Polycore.ScreenEntity_get_snapToPixels(self.__ptr)
  14. end
  15. end
  16. function ScreenEntity:__set_callback(name,value)
  17. if name == "hasFocus" then
  18. Polycore.ScreenEntity_set_hasFocus(self.__ptr, value)
  19. return true
  20. elseif name == "blockMouseInput" then
  21. Polycore.ScreenEntity_set_blockMouseInput(self.__ptr, value)
  22. return true
  23. elseif name == "zindex" then
  24. Polycore.ScreenEntity_set_zindex(self.__ptr, value)
  25. return true
  26. elseif name == "snapToPixels" then
  27. Polycore.ScreenEntity_set_snapToPixels(self.__ptr, value)
  28. return true
  29. end
  30. return false
  31. end
  32. function ScreenEntity:ScreenEntity(...)
  33. if type(arg[1]) == "table" and count(arg) == 1 then
  34. if ""..arg[1]:class() == "Entity" then
  35. self.__ptr = arg[1].__ptr
  36. return
  37. end
  38. end
  39. for k,v in pairs(arg) do
  40. if type(v) == "table" then
  41. if v.__ptr ~= nil then
  42. arg[k] = v.__ptr
  43. end
  44. end
  45. end
  46. if self.__ptr == nil and arg[1] ~= "__skip_ptr__" then
  47. self.__ptr = Polycore.ScreenEntity(unpack(arg))
  48. Polycore.__ptr_lookup[self.__ptr] = self
  49. end
  50. end
  51. function ScreenEntity:setPosition(x, y)
  52. local retVal = Polycore.ScreenEntity_setPosition(self.__ptr, x, y)
  53. end
  54. function ScreenEntity:setScale(x, y)
  55. local retVal = Polycore.ScreenEntity_setScale(self.__ptr, x, y)
  56. end
  57. function ScreenEntity:setRotation(roatation)
  58. local retVal = Polycore.ScreenEntity_setRotation(self.__ptr, roatation)
  59. end
  60. function ScreenEntity:getRotation()
  61. local retVal = Polycore.ScreenEntity_getRotation(self.__ptr)
  62. return retVal
  63. end
  64. function ScreenEntity:_onMouseDown(x, y, mouseButton, timestamp)
  65. local retVal = Polycore.ScreenEntity__onMouseDown(self.__ptr, x, y, mouseButton, timestamp)
  66. return retVal
  67. end
  68. function ScreenEntity:_onMouseUp(x, y, mouseButton, timestamp)
  69. local retVal = Polycore.ScreenEntity__onMouseUp(self.__ptr, x, y, mouseButton, timestamp)
  70. return retVal
  71. end
  72. function ScreenEntity:_onMouseMove(x, y, timestamp)
  73. local retVal = Polycore.ScreenEntity__onMouseMove(self.__ptr, x, y, timestamp)
  74. end
  75. function ScreenEntity:_onMouseWheelUp(x, y, timestamp)
  76. local retVal = Polycore.ScreenEntity__onMouseWheelUp(self.__ptr, x, y, timestamp)
  77. end
  78. function ScreenEntity:_onMouseWheelDown(x, y, timestamp)
  79. local retVal = Polycore.ScreenEntity__onMouseWheelDown(self.__ptr, x, y, timestamp)
  80. end
  81. function ScreenEntity:onMouseDown(x, y)
  82. local retVal = Polycore.ScreenEntity_onMouseDown(self.__ptr, x, y)
  83. end
  84. function ScreenEntity:onMouseUp(x, y)
  85. local retVal = Polycore.ScreenEntity_onMouseUp(self.__ptr, x, y)
  86. end
  87. function ScreenEntity:onMouseMove(x, y)
  88. local retVal = Polycore.ScreenEntity_onMouseMove(self.__ptr, x, y)
  89. end
  90. function ScreenEntity:onMouseWheelUp(x, y)
  91. local retVal = Polycore.ScreenEntity_onMouseWheelUp(self.__ptr, x, y)
  92. end
  93. function ScreenEntity:onMouseWheelDown(x, y)
  94. local retVal = Polycore.ScreenEntity_onMouseWheelDown(self.__ptr, x, y)
  95. end
  96. function ScreenEntity:_onKeyDown(key, charCode)
  97. local retVal = Polycore.ScreenEntity__onKeyDown(self.__ptr, key.__ptr, charCode.__ptr)
  98. end
  99. function ScreenEntity:_onKeyUp(key, charCode)
  100. local retVal = Polycore.ScreenEntity__onKeyUp(self.__ptr, key.__ptr, charCode.__ptr)
  101. end
  102. function ScreenEntity:onKeyDown(key, charCode)
  103. local retVal = Polycore.ScreenEntity_onKeyDown(self.__ptr, key.__ptr, charCode.__ptr)
  104. end
  105. function ScreenEntity:onKeyUp(key, charCode)
  106. local retVal = Polycore.ScreenEntity_onKeyUp(self.__ptr, key.__ptr, charCode.__ptr)
  107. end
  108. function ScreenEntity:hitTest(x, y)
  109. local retVal = Polycore.ScreenEntity_hitTest(self.__ptr, x, y)
  110. return retVal
  111. end
  112. function ScreenEntity:buildPositionMatrix()
  113. local retVal = Polycore.ScreenEntity_buildPositionMatrix(self.__ptr)
  114. if retVal == nil then return nil end
  115. if Polycore.__ptr_lookup[retVal] ~= nil then
  116. return Polycore.__ptr_lookup[retVal]
  117. else
  118. Polycore.__ptr_lookup[retVal] = Matrix4("__skip_ptr__")
  119. Polycore.__ptr_lookup[retVal].__ptr = retVal
  120. return Polycore.__ptr_lookup[retVal]
  121. end
  122. end
  123. function ScreenEntity:adjustMatrixForChildren()
  124. local retVal = Polycore.ScreenEntity_adjustMatrixForChildren(self.__ptr)
  125. end
  126. function ScreenEntity:getWidth()
  127. local retVal = Polycore.ScreenEntity_getWidth(self.__ptr)
  128. return retVal
  129. end
  130. function ScreenEntity:getHeight()
  131. local retVal = Polycore.ScreenEntity_getHeight(self.__ptr)
  132. return retVal
  133. end
  134. function ScreenEntity:setWidth(w)
  135. local retVal = Polycore.ScreenEntity_setWidth(self.__ptr, w)
  136. end
  137. function ScreenEntity:setHeight(h)
  138. local retVal = Polycore.ScreenEntity_setHeight(self.__ptr, h)
  139. end
  140. function ScreenEntity:onGainFocus()
  141. local retVal = Polycore.ScreenEntity_onGainFocus(self.__ptr)
  142. end
  143. function ScreenEntity:onLoseFocus()
  144. local retVal = Polycore.ScreenEntity_onLoseFocus(self.__ptr)
  145. end
  146. function ScreenEntity:startDrag(xOffset, yOffset)
  147. local retVal = Polycore.ScreenEntity_startDrag(self.__ptr, xOffset, yOffset)
  148. end
  149. function ScreenEntity:stopDrag()
  150. local retVal = Polycore.ScreenEntity_stopDrag(self.__ptr)
  151. end
  152. function ScreenEntity:setBlendingMode(newBl_endingMode)
  153. local retVal = Polycore.ScreenEntity_setBlendingMode(self.__ptr, newBl_endingMode)
  154. end
  155. function ScreenEntity:setPositionMode(newPositionMode)
  156. local retVal = Polycore.ScreenEntity_setPositionMode(self.__ptr, newPositionMode)
  157. end
  158. function ScreenEntity:setDragLimits(rect)
  159. local retVal = Polycore.ScreenEntity_setDragLimits(self.__ptr, rect.__ptr)
  160. end
  161. function ScreenEntity:clearDragLimits()
  162. local retVal = Polycore.ScreenEntity_clearDragLimits(self.__ptr)
  163. end
  164. function ScreenEntity:focusChild(child)
  165. local retVal = Polycore.ScreenEntity_focusChild(self.__ptr, child.__ptr)
  166. end
  167. function ScreenEntity:focusNextChild()
  168. local retVal = Polycore.ScreenEntity_focusNextChild(self.__ptr)
  169. end
  170. function ScreenEntity:getPosition2D()
  171. local retVal = Polycore.ScreenEntity_getPosition2D(self.__ptr)
  172. if retVal == nil then return nil end
  173. if Polycore.__ptr_lookup[retVal] ~= nil then
  174. return Polycore.__ptr_lookup[retVal]
  175. else
  176. Polycore.__ptr_lookup[retVal] = Vector2("__skip_ptr__")
  177. Polycore.__ptr_lookup[retVal].__ptr = retVal
  178. return Polycore.__ptr_lookup[retVal]
  179. end
  180. end
  181. function ScreenEntity:isFocusable()
  182. local retVal = Polycore.ScreenEntity_isFocusable(self.__ptr)
  183. return retVal
  184. end
  185. function ScreenEntity:__delete()
  186. Polycore.__ptr_lookup[self.__ptr] = nil
  187. Polycore.delete_ScreenEntity(self.__ptr)
  188. end