Rectangle.lua 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. class "Rectangle"
  2. function Rectangle:__getvar(name)
  3. if name == "x" then
  4. return Polycode.Rectangle_get_x(self.__ptr)
  5. elseif name == "y" then
  6. return Polycode.Rectangle_get_y(self.__ptr)
  7. elseif name == "w" then
  8. return Polycode.Rectangle_get_w(self.__ptr)
  9. elseif name == "h" then
  10. return Polycode.Rectangle_get_h(self.__ptr)
  11. end
  12. end
  13. function Rectangle:__setvar(name,value)
  14. if name == "x" then
  15. Polycode.Rectangle_set_x(self.__ptr, value)
  16. return true
  17. elseif name == "y" then
  18. Polycode.Rectangle_set_y(self.__ptr, value)
  19. return true
  20. elseif name == "w" then
  21. Polycode.Rectangle_set_w(self.__ptr, value)
  22. return true
  23. elseif name == "h" then
  24. Polycode.Rectangle_set_h(self.__ptr, value)
  25. return true
  26. end
  27. return false
  28. end
  29. function Rectangle:Rectangle(...)
  30. local arg = {...}
  31. for k,v in pairs(arg) do
  32. if type(v) == "table" then
  33. if v.__ptr ~= nil then
  34. arg[k] = v.__ptr
  35. end
  36. end
  37. end
  38. if self.__ptr == nil and arg[1] ~= "__skip_ptr__" then
  39. self.__ptr = Polycode.Rectangle(unpack(arg))
  40. end
  41. end
  42. function Rectangle:setRect(x, y, w, h)
  43. local retVal = Polycode.Rectangle_setRect(self.__ptr, x, y, w, h)
  44. end
  45. function Rectangle:Clipped(rect)
  46. local retVal = Polycode.Rectangle_Clipped(self.__ptr, rect.__ptr)
  47. if retVal == nil then return nil end
  48. local __c = _G["Rectangle"]("__skip_ptr__")
  49. __c.__ptr = retVal
  50. return __c
  51. end
  52. function Rectangle:minX()
  53. local retVal = Polycode.Rectangle_minX(self.__ptr)
  54. return retVal
  55. end
  56. function Rectangle:maxX()
  57. local retVal = Polycode.Rectangle_maxX(self.__ptr)
  58. return retVal
  59. end
  60. function Rectangle:minY()
  61. local retVal = Polycode.Rectangle_minY(self.__ptr)
  62. return retVal
  63. end
  64. function Rectangle:maxY()
  65. local retVal = Polycode.Rectangle_maxY(self.__ptr)
  66. return retVal
  67. end
  68. function Rectangle:__delete()
  69. if self then Polycode.delete_Rectangle(self.__ptr) end
  70. end