ScreenShape.lua 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. require "Polycode/ScreenMesh"
  2. class "ScreenShape" (ScreenMesh)
  3. SHAPE_RECT = 1
  4. SHAPE_CIRCLE = 2
  5. SHAPE_CUSTOM = 4
  6. function ScreenShape:__index__(name)
  7. if name == "strokeEnabled" then
  8. return Polycore.ScreenShape_get_strokeEnabled(self.__ptr)
  9. elseif name == "strokeColor" then
  10. retVal = Polycore.ScreenShape_get_strokeColor(self.__ptr)
  11. if Polycore.__ptr_lookup[retVal] ~= nil then
  12. return Polycore.__ptr_lookup[retVal]
  13. else
  14. Polycore.__ptr_lookup[retVal] = Color("__skip_ptr__")
  15. Polycore.__ptr_lookup[retVal].__ptr = retVal
  16. return Polycore.__ptr_lookup[retVal]
  17. end
  18. elseif name == "lineSmooth" then
  19. return Polycore.ScreenShape_get_lineSmooth(self.__ptr)
  20. end
  21. end
  22. function ScreenShape:__set_callback(name,value)
  23. if name == "strokeEnabled" then
  24. Polycore.ScreenShape_set_strokeEnabled(self.__ptr, value)
  25. return true
  26. elseif name == "lineSmooth" then
  27. Polycore.ScreenShape_set_lineSmooth(self.__ptr, value)
  28. return true
  29. end
  30. return false
  31. end
  32. function ScreenShape:ScreenShape(...)
  33. if type(arg[1]) == "table" and count(arg) == 1 then
  34. if ""..arg[1]:class() == "ScreenMesh" 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.ScreenShape(unpack(arg))
  48. Polycore.__ptr_lookup[self.__ptr] = self
  49. end
  50. end
  51. function ScreenShape:Render()
  52. local retVal = Polycore.ScreenShape_Render(self.__ptr)
  53. end
  54. function ScreenShape:setStrokeColor(r, g, b, a)
  55. local retVal = Polycore.ScreenShape_setStrokeColor(self.__ptr, r, g, b, a)
  56. end
  57. function ScreenShape:setStrokeWidth(width)
  58. local retVal = Polycore.ScreenShape_setStrokeWidth(self.__ptr, width)
  59. end
  60. function ScreenShape:setGradient(r1, g1, b1, a1, r2, g2, b2, a2)
  61. local retVal = Polycore.ScreenShape_setGradient(self.__ptr, r1, g1, b1, a1, r2, g2, b2, a2)
  62. end
  63. function ScreenShape:clearGradient()
  64. local retVal = Polycore.ScreenShape_clearGradient(self.__ptr)
  65. end
  66. function ScreenShape:setShapeSize(newWidth, newHeight)
  67. local retVal = Polycore.ScreenShape_setShapeSize(self.__ptr, newWidth, newHeight)
  68. end
  69. function ScreenShape:addShapePoint(x, y)
  70. local retVal = Polycore.ScreenShape_addShapePoint(self.__ptr, x, y)
  71. end
  72. function ScreenShape:__delete()
  73. Polycore.__ptr_lookup[self.__ptr] = nil
  74. Polycore.delete_ScreenShape(self.__ptr)
  75. end