Rectangle.lua 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. class "Rectangle"
  2. function Rectangle:__index__(name)
  3. if name == "x" then
  4. return Polycore.Rectangle_get_x(self.__ptr)
  5. elseif name == "y" then
  6. return Polycore.Rectangle_get_y(self.__ptr)
  7. elseif name == "w" then
  8. return Polycore.Rectangle_get_w(self.__ptr)
  9. elseif name == "h" then
  10. return Polycore.Rectangle_get_h(self.__ptr)
  11. end
  12. end
  13. function Rectangle:__set_callback(name,value)
  14. if name == "x" then
  15. Polycore.Rectangle_set_x(self.__ptr, value)
  16. return true
  17. elseif name == "y" then
  18. Polycore.Rectangle_set_y(self.__ptr, value)
  19. return true
  20. elseif name == "w" then
  21. Polycore.Rectangle_set_w(self.__ptr, value)
  22. return true
  23. elseif name == "h" then
  24. Polycore.Rectangle_set_h(self.__ptr, value)
  25. return true
  26. end
  27. return false
  28. end
  29. function Rectangle:Rectangle(...)
  30. for k,v in pairs(arg) do
  31. if type(v) == "table" then
  32. if v.__ptr ~= nil then
  33. arg[k] = v.__ptr
  34. end
  35. end
  36. end
  37. if self.__ptr == nil and arg[1] ~= "__skip_ptr__" then
  38. self.__ptr = Polycore.Rectangle(unpack(arg))
  39. end
  40. end
  41. function Rectangle:setRect(x, y, w, h)
  42. local retVal = Polycore.Rectangle_setRect(self.__ptr, x, y, w, h)
  43. end