babylon.brushes2d.js 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. var __extends = (this && this.__extends) || function (d, b) {
  2. for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  3. function __() { this.constructor = d; }
  4. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  5. };
  6. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  7. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  8. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  9. else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  10. return c > 3 && r && Object.defineProperty(target, key, r), r;
  11. };
  12. var BABYLON;
  13. (function (BABYLON) {
  14. /**
  15. * Base class implementing the ILocable interface.
  16. * The particularity of this class is to call the protected onLock() method when the instance is about to be locked for good.
  17. */
  18. var LockableBase = (function () {
  19. function LockableBase() {
  20. }
  21. LockableBase.prototype.isLocked = function () {
  22. return this._isLocked;
  23. };
  24. LockableBase.prototype.lock = function () {
  25. if (this._isLocked) {
  26. return true;
  27. }
  28. this.onLock();
  29. this._isLocked = true;
  30. return false;
  31. };
  32. /**
  33. * Protected handler that will be called when the instance is about to be locked.
  34. */
  35. LockableBase.prototype.onLock = function () {
  36. };
  37. return LockableBase;
  38. }());
  39. BABYLON.LockableBase = LockableBase;
  40. var SolidColorBrush2D = (function (_super) {
  41. __extends(SolidColorBrush2D, _super);
  42. function SolidColorBrush2D(color, lock) {
  43. if (lock === void 0) { lock = false; }
  44. _super.call(this);
  45. this._color = color;
  46. if (lock) {
  47. {
  48. this.lock();
  49. }
  50. }
  51. }
  52. /**
  53. * Return true if the brush is transparent, false if it's totally opaque
  54. */
  55. SolidColorBrush2D.prototype.isTransparent = function () {
  56. return this._color && this._color.a < 1.0;
  57. };
  58. Object.defineProperty(SolidColorBrush2D.prototype, "color", {
  59. /**
  60. * The color used by this instance to render
  61. * @returns the color object. Note that it's not a clone of the actual object stored in the instance so you MUST NOT modify it, otherwise unexpected behavior might occurs.
  62. */
  63. get: function () {
  64. return this._color;
  65. },
  66. set: function (value) {
  67. if (this.isLocked()) {
  68. return;
  69. }
  70. this._color = value;
  71. },
  72. enumerable: true,
  73. configurable: true
  74. });
  75. /**
  76. * Return a unique identifier of the instance, which is simply the hexadecimal representation (CSS Style) of the solid color.
  77. */
  78. SolidColorBrush2D.prototype.toString = function () {
  79. return this._color.toHexString();
  80. };
  81. SolidColorBrush2D = __decorate([
  82. BABYLON.className("SolidColorBrush2D", "BABYLON")
  83. ], SolidColorBrush2D);
  84. return SolidColorBrush2D;
  85. }(LockableBase));
  86. BABYLON.SolidColorBrush2D = SolidColorBrush2D;
  87. var GradientColorBrush2D = (function (_super) {
  88. __extends(GradientColorBrush2D, _super);
  89. function GradientColorBrush2D(color1, color2, translation, rotation, scale, lock) {
  90. if (translation === void 0) { translation = BABYLON.Vector2.Zero(); }
  91. if (rotation === void 0) { rotation = 0; }
  92. if (scale === void 0) { scale = 1; }
  93. if (lock === void 0) { lock = false; }
  94. _super.call(this);
  95. this._color1 = color1;
  96. this._color2 = color2;
  97. this._translation = translation;
  98. this._rotation = rotation;
  99. this._scale = scale;
  100. if (lock) {
  101. this.lock();
  102. }
  103. }
  104. /**
  105. * Return true if the brush is transparent, false if it's totally opaque
  106. */
  107. GradientColorBrush2D.prototype.isTransparent = function () {
  108. return (this._color1 && this._color1.a < 1.0) || (this._color2 && this._color2.a < 1.0);
  109. };
  110. Object.defineProperty(GradientColorBrush2D.prototype, "color1", {
  111. /**
  112. * First color, the blend will start from this color
  113. */
  114. get: function () {
  115. return this._color1;
  116. },
  117. set: function (value) {
  118. if (this.isLocked()) {
  119. return;
  120. }
  121. this._color1 = value;
  122. },
  123. enumerable: true,
  124. configurable: true
  125. });
  126. Object.defineProperty(GradientColorBrush2D.prototype, "color2", {
  127. /**
  128. * Second color, the blend will end to this color
  129. */
  130. get: function () {
  131. return this._color2;
  132. },
  133. set: function (value) {
  134. if (this.isLocked()) {
  135. return;
  136. }
  137. this._color2 = value;
  138. },
  139. enumerable: true,
  140. configurable: true
  141. });
  142. Object.defineProperty(GradientColorBrush2D.prototype, "translation", {
  143. /**
  144. * Translation vector to apply on the blend
  145. * Default is [0;0]
  146. */
  147. get: function () {
  148. return this._translation;
  149. },
  150. set: function (value) {
  151. if (this.isLocked()) {
  152. return;
  153. }
  154. this._translation = value;
  155. },
  156. enumerable: true,
  157. configurable: true
  158. });
  159. Object.defineProperty(GradientColorBrush2D.prototype, "rotation", {
  160. /**
  161. * Rotation in radian to apply to the brush
  162. * Default direction of the brush is vertical, you can change this using this property.
  163. * Default is 0.
  164. */
  165. get: function () {
  166. return this._rotation;
  167. },
  168. set: function (value) {
  169. if (this.isLocked()) {
  170. return;
  171. }
  172. this._rotation = value;
  173. },
  174. enumerable: true,
  175. configurable: true
  176. });
  177. Object.defineProperty(GradientColorBrush2D.prototype, "scale", {
  178. /**
  179. * Scale factor to apply to the gradient.
  180. * Default is 1: no scale.
  181. */
  182. get: function () {
  183. return this._scale;
  184. },
  185. set: function (value) {
  186. if (this.isLocked()) {
  187. return;
  188. }
  189. this._scale = value;
  190. },
  191. enumerable: true,
  192. configurable: true
  193. });
  194. /**
  195. * Return a string describing the brush
  196. */
  197. GradientColorBrush2D.prototype.toString = function () {
  198. return "C1:" + this._color1 + ";C2:" + this._color2 + ";T:" + this._translation.toString() + ";R:" + this._rotation + ";S:" + this._scale + ";";
  199. };
  200. /**
  201. * Build a unique key string for the given parameters
  202. */
  203. GradientColorBrush2D.BuildKey = function (color1, color2, translation, rotation, scale) {
  204. return "C1:" + color1 + ";C2:" + color2 + ";T:" + translation.toString() + ";R:" + rotation + ";S:" + scale + ";";
  205. };
  206. GradientColorBrush2D = __decorate([
  207. BABYLON.className("GradientColorBrush2D", "BABYLON")
  208. ], GradientColorBrush2D);
  209. return GradientColorBrush2D;
  210. }(LockableBase));
  211. BABYLON.GradientColorBrush2D = GradientColorBrush2D;
  212. })(BABYLON || (BABYLON = {}));