Color.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. function Color(r,g,b,a) {
  2. if(arguments[0] != "__skip_ptr__") {
  3. this.__ptr = Polycode.Color(r,g,b,a)
  4. }
  5. Object.defineProperties(this, {
  6. 'r': { enumerable: true, configurable: true, get: Color.prototype.__get_r, set: Color.prototype.__set_r},
  7. 'g': { enumerable: true, configurable: true, get: Color.prototype.__get_g, set: Color.prototype.__set_g},
  8. 'b': { enumerable: true, configurable: true, get: Color.prototype.__get_b, set: Color.prototype.__set_b},
  9. 'a': { enumerable: true, configurable: true, get: Color.prototype.__get_a, set: Color.prototype.__set_a}
  10. })
  11. }
  12. Color.BLEND_NORMAL = 0
  13. Color.BLEND_REPLACE_COLOR = 1
  14. Color.BLEND_ADDITIVE = 2
  15. Color.prototype.__get_r = function() {
  16. return Polycode.Color__get_r(this.__ptr)
  17. }
  18. Color.prototype.__set_r = function(val) {
  19. Polycode.Color__set_r(this.__ptr, val)
  20. }
  21. Color.prototype.__get_g = function() {
  22. return Polycode.Color__get_g(this.__ptr)
  23. }
  24. Color.prototype.__set_g = function(val) {
  25. Polycode.Color__set_g(this.__ptr, val)
  26. }
  27. Color.prototype.__get_b = function() {
  28. return Polycode.Color__get_b(this.__ptr)
  29. }
  30. Color.prototype.__set_b = function(val) {
  31. Polycode.Color__set_b(this.__ptr, val)
  32. }
  33. Color.prototype.__get_a = function() {
  34. return Polycode.Color__get_a(this.__ptr)
  35. }
  36. Color.prototype.__set_a = function(val) {
  37. Polycode.Color__set_a(this.__ptr, val)
  38. }
  39. Duktape.fin(Color.prototype, function (x) {
  40. if (x === Color.prototype) {
  41. return;
  42. }
  43. Polycode.Color__delete(x.__ptr)
  44. })
  45. Color.prototype.ColorWithInts = function(r,g,b,a) {
  46. var retVal = new Color()
  47. retVal.__ptr = Polycode.Color_ColorWithInts(r, g, b, a)
  48. return retVal
  49. }
  50. Color.prototype.ColorWithHex = function(hex) {
  51. var retVal = new Color()
  52. retVal.__ptr = Polycode.Color_ColorWithHex(hex)
  53. return retVal
  54. }
  55. Color.prototype.setColorHex = function(hex) {
  56. Polycode.Color_setColorHex(this.__ptr, hex)
  57. }
  58. Color.prototype.setColorHexRGB = function(hex) {
  59. Polycode.Color_setColorHexRGB(this.__ptr, hex)
  60. }
  61. Color.prototype.setColorHexFromString = function(hex) {
  62. Polycode.Color_setColorHexFromString(this.__ptr, hex)
  63. }
  64. Color.prototype.setColorHexRGBFromString = function(hex) {
  65. Polycode.Color_setColorHexRGBFromString(this.__ptr, hex)
  66. }
  67. Color.prototype.setColorHSV = function(h,s,v) {
  68. Polycode.Color_setColorHSV(this.__ptr, h, s, v)
  69. }
  70. Color.prototype.setColorRGBA = function(r,g,b,a) {
  71. Polycode.Color_setColorRGBA(this.__ptr, r, g, b, a)
  72. }
  73. Color.prototype.setColorRGB = function(r,g,b) {
  74. Polycode.Color_setColorRGB(this.__ptr, r, g, b)
  75. }
  76. Color.prototype.setColor = function(r,g,b,a) {
  77. Polycode.Color_setColor(this.__ptr, r, g, b, a)
  78. }
  79. Color.prototype.blendColor = function(c2,mode,amount,c3) {
  80. var retVal = new Color()
  81. retVal.__ptr = Polycode.Color_blendColor(this.__ptr, c2, mode, amount, c3)
  82. return retVal
  83. }
  84. Color.prototype.Random = function() {
  85. Polycode.Color_Random(this.__ptr)
  86. }
  87. Color.prototype.getBrightness = function() {
  88. return Polycode.Color_getBrightness(this.__ptr)
  89. }
  90. Color.prototype.RGBtoHSV = function(r,g,b,h,s,v) {
  91. Polycode.Color_RGBtoHSV(r, g, b, h, s, v)
  92. }
  93. Color.prototype.getHue = function() {
  94. return Polycode.Color_getHue(this.__ptr)
  95. }
  96. Color.prototype.getSaturation = function() {
  97. return Polycode.Color_getSaturation(this.__ptr)
  98. }
  99. Color.prototype.getValue = function() {
  100. return Polycode.Color_getValue(this.__ptr)
  101. }
  102. Color.prototype.getUint = function() {
  103. return Polycode.Color_getUint(this.__ptr)
  104. }