2
0

Color.lua 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. class "Color"
  2. Color.BLEND_NORMAL = 0
  3. Color.BLEND_REPLACE_COLOR = 1
  4. Color.BLEND_ADDITIVE = 2
  5. function Color:__getvar(name)
  6. if name == "r" then
  7. return Polycode.Color_get_r(self.__ptr)
  8. elseif name == "g" then
  9. return Polycode.Color_get_g(self.__ptr)
  10. elseif name == "b" then
  11. return Polycode.Color_get_b(self.__ptr)
  12. elseif name == "a" then
  13. return Polycode.Color_get_a(self.__ptr)
  14. end
  15. end
  16. function Color:__setvar(name,value)
  17. if name == "r" then
  18. Polycode.Color_set_r(self.__ptr, value)
  19. return true
  20. elseif name == "g" then
  21. Polycode.Color_set_g(self.__ptr, value)
  22. return true
  23. elseif name == "b" then
  24. Polycode.Color_set_b(self.__ptr, value)
  25. return true
  26. elseif name == "a" then
  27. Polycode.Color_set_a(self.__ptr, value)
  28. return true
  29. end
  30. return false
  31. end
  32. function Color:Color(...)
  33. local arg = {...}
  34. for k,v in pairs(arg) do
  35. if type(v) == "table" then
  36. if v.__ptr ~= nil then
  37. arg[k] = v.__ptr
  38. end
  39. end
  40. end
  41. if self.__ptr == nil and arg[1] ~= "__skip_ptr__" then
  42. self.__ptr = Polycode.Color(unpack(arg))
  43. end
  44. end
  45. function Color:ColorWithInts(r, g, b, a)
  46. local retVal = Polycode.Color_ColorWithInts(self.__ptr, r, g, b, a)
  47. if retVal == nil then return nil end
  48. local __c = _G["Color"]("__skip_ptr__")
  49. __c.__ptr = retVal
  50. return __c
  51. end
  52. function Color:ColorWithHex(hex)
  53. local retVal = Polycode.Color_ColorWithHex(self.__ptr, hex)
  54. if retVal == nil then return nil end
  55. local __c = _G["Color"]("__skip_ptr__")
  56. __c.__ptr = retVal
  57. return __c
  58. end
  59. function Color:setColorHex(hex)
  60. local retVal = Polycode.Color_setColorHex(self.__ptr, hex)
  61. end
  62. function Color:setColorHexRGB(hex)
  63. local retVal = Polycode.Color_setColorHexRGB(self.__ptr, hex)
  64. end
  65. function Color:setColorHexFromString(hex)
  66. local retVal = Polycode.Color_setColorHexFromString(self.__ptr, hex)
  67. end
  68. function Color:setColorHexRGBFromString(hex)
  69. local retVal = Polycode.Color_setColorHexRGBFromString(self.__ptr, hex)
  70. end
  71. function Color:setColorHSV(h, s, v)
  72. local retVal = Polycode.Color_setColorHSV(self.__ptr, h, s, v)
  73. end
  74. function Color:setColorRGBA(r, g, b, a)
  75. local retVal = Polycode.Color_setColorRGBA(self.__ptr, r, g, b, a)
  76. end
  77. function Color:setColorRGB(r, g, b)
  78. local retVal = Polycode.Color_setColorRGB(self.__ptr, r, g, b)
  79. end
  80. function Color:setColor(r, g, b, a)
  81. local retVal = Polycode.Color_setColor(self.__ptr, r, g, b, a)
  82. end
  83. function Color:blendColor(c2, mode, amount, c3)
  84. local retVal = Polycode.Color_blendColor(self.__ptr, c2.__ptr, mode, amount, c3.__ptr)
  85. if retVal == nil then return nil end
  86. local __c = _G["Color"]("__skip_ptr__")
  87. __c.__ptr = retVal
  88. return __c
  89. end
  90. function Color:Random()
  91. local retVal = Polycode.Color_Random(self.__ptr)
  92. end
  93. function Color:getBrightness()
  94. local retVal = Polycode.Color_getBrightness(self.__ptr)
  95. return retVal
  96. end
  97. function Color:RGBtoHSV(r, g, b, h, s, v)
  98. local retVal = Polycode.Color_RGBtoHSV(self.__ptr, r, g, b, h, s, v)
  99. end
  100. function Color:getHue()
  101. local retVal = Polycode.Color_getHue(self.__ptr)
  102. return retVal
  103. end
  104. function Color:getSaturation()
  105. local retVal = Polycode.Color_getSaturation(self.__ptr)
  106. return retVal
  107. end
  108. function Color:getValue()
  109. local retVal = Polycode.Color_getValue(self.__ptr)
  110. return retVal
  111. end
  112. function Color:getUint()
  113. local retVal = Polycode.Color_getUint(self.__ptr)
  114. return retVal
  115. end
  116. function Color:__delete()
  117. if self then Polycode.delete_Color(self.__ptr) end
  118. end