ScreenEntity.lua 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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. for k,v in pairs(arg) do
  34. if type(v) == "table" then
  35. if v.__ptr ~= nil then
  36. arg[k] = v.__ptr
  37. end
  38. end
  39. end
  40. if self.__ptr == nil and arg[1] ~= "__skip_ptr__" then
  41. self.__ptr = Polycore.ScreenEntity(unpack(arg))
  42. end
  43. end
  44. function ScreenEntity:setPosition(x, y)
  45. local retVal = Polycore.ScreenEntity_setPosition(self.__ptr, x, y)
  46. end
  47. function ScreenEntity:setScale(x, y)
  48. local retVal = Polycore.ScreenEntity_setScale(self.__ptr, x, y)
  49. end
  50. function ScreenEntity:setRotation(roatation)
  51. local retVal = Polycore.ScreenEntity_setRotation(self.__ptr, roatation)
  52. end
  53. function ScreenEntity:getRotation()
  54. local retVal = Polycore.ScreenEntity_getRotation(self.__ptr)
  55. return retVal
  56. end
  57. function ScreenEntity:_onMouseDown(x, y, mouseButton, timestamp)
  58. local retVal = Polycore.ScreenEntity__onMouseDown(self.__ptr, x, y, mouseButton, timestamp)
  59. return retVal
  60. end
  61. function ScreenEntity:_onMouseUp(x, y, mouseButton, timestamp)
  62. local retVal = Polycore.ScreenEntity__onMouseUp(self.__ptr, x, y, mouseButton, timestamp)
  63. return retVal
  64. end
  65. function ScreenEntity:_onMouseMove(x, y, timestamp)
  66. local retVal = Polycore.ScreenEntity__onMouseMove(self.__ptr, x, y, timestamp)
  67. end
  68. function ScreenEntity:_onMouseWheelUp(x, y, timestamp)
  69. local retVal = Polycore.ScreenEntity__onMouseWheelUp(self.__ptr, x, y, timestamp)
  70. end
  71. function ScreenEntity:_onMouseWheelDown(x, y, timestamp)
  72. local retVal = Polycore.ScreenEntity__onMouseWheelDown(self.__ptr, x, y, timestamp)
  73. end
  74. function ScreenEntity:onMouseDown(x, y)
  75. local retVal = Polycore.ScreenEntity_onMouseDown(self.__ptr, x, y)
  76. end
  77. function ScreenEntity:onMouseUp(x, y)
  78. local retVal = Polycore.ScreenEntity_onMouseUp(self.__ptr, x, y)
  79. end
  80. function ScreenEntity:onMouseMove(x, y)
  81. local retVal = Polycore.ScreenEntity_onMouseMove(self.__ptr, x, y)
  82. end
  83. function ScreenEntity:onMouseWheelUp(x, y)
  84. local retVal = Polycore.ScreenEntity_onMouseWheelUp(self.__ptr, x, y)
  85. end
  86. function ScreenEntity:onMouseWheelDown(x, y)
  87. local retVal = Polycore.ScreenEntity_onMouseWheelDown(self.__ptr, x, y)
  88. end
  89. function ScreenEntity:_onKeyDown(key, charCode)
  90. local retVal = Polycore.ScreenEntity__onKeyDown(self.__ptr, key.__ptr, charCode.__ptr)
  91. end
  92. function ScreenEntity:_onKeyUp(key, charCode)
  93. local retVal = Polycore.ScreenEntity__onKeyUp(self.__ptr, key.__ptr, charCode.__ptr)
  94. end
  95. function ScreenEntity:onKeyDown(key, charCode)
  96. local retVal = Polycore.ScreenEntity_onKeyDown(self.__ptr, key.__ptr, charCode.__ptr)
  97. end
  98. function ScreenEntity:onKeyUp(key, charCode)
  99. local retVal = Polycore.ScreenEntity_onKeyUp(self.__ptr, key.__ptr, charCode.__ptr)
  100. end
  101. function ScreenEntity:hitTest(x, y)
  102. local retVal = Polycore.ScreenEntity_hitTest(self.__ptr, x, y)
  103. return retVal
  104. end
  105. function ScreenEntity:buildPositionMatrix()
  106. local retVal = Polycore.ScreenEntity_buildPositionMatrix(self.__ptr)
  107. if Polycore.__ptr_lookup[retVal] ~= nil then
  108. return Polycore.__ptr_lookup[retVal]
  109. else
  110. Polycore.__ptr_lookup[retVal] = Matrix4("__skip_ptr__")
  111. Polycore.__ptr_lookup[retVal].__ptr = retVal
  112. return Polycore.__ptr_lookup[retVal]
  113. end
  114. end
  115. function ScreenEntity:adjustMatrixForChildren()
  116. local retVal = Polycore.ScreenEntity_adjustMatrixForChildren(self.__ptr)
  117. end
  118. function ScreenEntity:getWidth()
  119. local retVal = Polycore.ScreenEntity_getWidth(self.__ptr)
  120. return retVal
  121. end
  122. function ScreenEntity:getHeight()
  123. local retVal = Polycore.ScreenEntity_getHeight(self.__ptr)
  124. return retVal
  125. end
  126. function ScreenEntity:setWidth(w)
  127. local retVal = Polycore.ScreenEntity_setWidth(self.__ptr, w)
  128. end
  129. function ScreenEntity:setHeight(h)
  130. local retVal = Polycore.ScreenEntity_setHeight(self.__ptr, h)
  131. end
  132. function ScreenEntity:onGainFocus()
  133. local retVal = Polycore.ScreenEntity_onGainFocus(self.__ptr)
  134. end
  135. function ScreenEntity:onLoseFocus()
  136. local retVal = Polycore.ScreenEntity_onLoseFocus(self.__ptr)
  137. end
  138. function ScreenEntity:startDrag(xOffset, yOffset)
  139. local retVal = Polycore.ScreenEntity_startDrag(self.__ptr, xOffset, yOffset)
  140. end
  141. function ScreenEntity:stopDrag()
  142. local retVal = Polycore.ScreenEntity_stopDrag(self.__ptr)
  143. end
  144. function ScreenEntity:setBlendingMode(newBl_endingMode)
  145. local retVal = Polycore.ScreenEntity_setBlendingMode(self.__ptr, newBl_endingMode)
  146. end
  147. function ScreenEntity:setPositionMode(newPositionMode)
  148. local retVal = Polycore.ScreenEntity_setPositionMode(self.__ptr, newPositionMode)
  149. end
  150. function ScreenEntity:setDragLimits(rect)
  151. local retVal = Polycore.ScreenEntity_setDragLimits(self.__ptr, rect.__ptr)
  152. end
  153. function ScreenEntity:clearDragLimits()
  154. local retVal = Polycore.ScreenEntity_clearDragLimits(self.__ptr)
  155. end
  156. function ScreenEntity:focusChild(child)
  157. local retVal = Polycore.ScreenEntity_focusChild(self.__ptr, child.__ptr)
  158. end
  159. function ScreenEntity:focusNextChild()
  160. local retVal = Polycore.ScreenEntity_focusNextChild(self.__ptr)
  161. end
  162. function ScreenEntity:getPosition2D()
  163. local retVal = Polycore.ScreenEntity_getPosition2D(self.__ptr)
  164. if Polycore.__ptr_lookup[retVal] ~= nil then
  165. return Polycore.__ptr_lookup[retVal]
  166. else
  167. Polycore.__ptr_lookup[retVal] = Vector2("__skip_ptr__")
  168. Polycore.__ptr_lookup[retVal].__ptr = retVal
  169. return Polycore.__ptr_lookup[retVal]
  170. end
  171. end
  172. function ScreenEntity:isFocusable()
  173. local retVal = Polycore.ScreenEntity_isFocusable(self.__ptr)
  174. return retVal
  175. end