display.js 88 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985
  1. /*!
  2. * @pixi/display - v6.5.10
  3. * Compiled Thu, 06 Jul 2023 15:25:11 UTC
  4. *
  5. * @pixi/display is licensed under the MIT License.
  6. * http://www.opensource.org/licenses/mit-license
  7. */
  8. this.PIXI = this.PIXI || {};
  9. var _pixi_display = (function (exports, settings, math, utils, constants) {
  10. 'use strict';
  11. /**
  12. * Sets the default value for the container property 'sortableChildren'.
  13. * If set to true, the container will sort its children by zIndex value
  14. * when updateTransform() is called, or manually if sortChildren() is called.
  15. *
  16. * This actually changes the order of elements in the array, so should be treated
  17. * as a basic solution that is not performant compared to other solutions,
  18. * such as @link https://github.com/pixijs/pixi-display
  19. *
  20. * Also be aware of that this may not work nicely with the addChildAt() function,
  21. * as the zIndex sorting may cause the child to automatically sorted to another position.
  22. * @static
  23. * @constant
  24. * @name SORTABLE_CHILDREN
  25. * @memberof PIXI.settings
  26. * @type {boolean}
  27. * @default false
  28. */
  29. settings.settings.SORTABLE_CHILDREN = false;
  30. /**
  31. * 'Builder' pattern for bounds rectangles.
  32. *
  33. * This could be called an Axis-Aligned Bounding Box.
  34. * It is not an actual shape. It is a mutable thing; no 'EMPTY' or those kind of problems.
  35. * @memberof PIXI
  36. */
  37. var Bounds = /** @class */ (function () {
  38. function Bounds() {
  39. this.minX = Infinity;
  40. this.minY = Infinity;
  41. this.maxX = -Infinity;
  42. this.maxY = -Infinity;
  43. this.rect = null;
  44. this.updateID = -1;
  45. }
  46. /**
  47. * Checks if bounds are empty.
  48. * @returns - True if empty.
  49. */
  50. Bounds.prototype.isEmpty = function () {
  51. return this.minX > this.maxX || this.minY > this.maxY;
  52. };
  53. /** Clears the bounds and resets. */
  54. Bounds.prototype.clear = function () {
  55. this.minX = Infinity;
  56. this.minY = Infinity;
  57. this.maxX = -Infinity;
  58. this.maxY = -Infinity;
  59. };
  60. /**
  61. * Can return Rectangle.EMPTY constant, either construct new rectangle, either use your rectangle
  62. * It is not guaranteed that it will return tempRect
  63. * @param rect - Temporary object will be used if AABB is not empty
  64. * @returns - A rectangle of the bounds
  65. */
  66. Bounds.prototype.getRectangle = function (rect) {
  67. if (this.minX > this.maxX || this.minY > this.maxY) {
  68. return math.Rectangle.EMPTY;
  69. }
  70. rect = rect || new math.Rectangle(0, 0, 1, 1);
  71. rect.x = this.minX;
  72. rect.y = this.minY;
  73. rect.width = this.maxX - this.minX;
  74. rect.height = this.maxY - this.minY;
  75. return rect;
  76. };
  77. /**
  78. * This function should be inlined when its possible.
  79. * @param point - The point to add.
  80. */
  81. Bounds.prototype.addPoint = function (point) {
  82. this.minX = Math.min(this.minX, point.x);
  83. this.maxX = Math.max(this.maxX, point.x);
  84. this.minY = Math.min(this.minY, point.y);
  85. this.maxY = Math.max(this.maxY, point.y);
  86. };
  87. /**
  88. * Adds a point, after transformed. This should be inlined when its possible.
  89. * @param matrix
  90. * @param point
  91. */
  92. Bounds.prototype.addPointMatrix = function (matrix, point) {
  93. var a = matrix.a, b = matrix.b, c = matrix.c, d = matrix.d, tx = matrix.tx, ty = matrix.ty;
  94. var x = (a * point.x) + (c * point.y) + tx;
  95. var y = (b * point.x) + (d * point.y) + ty;
  96. this.minX = Math.min(this.minX, x);
  97. this.maxX = Math.max(this.maxX, x);
  98. this.minY = Math.min(this.minY, y);
  99. this.maxY = Math.max(this.maxY, y);
  100. };
  101. /**
  102. * Adds a quad, not transformed
  103. * @param vertices - The verts to add.
  104. */
  105. Bounds.prototype.addQuad = function (vertices) {
  106. var minX = this.minX;
  107. var minY = this.minY;
  108. var maxX = this.maxX;
  109. var maxY = this.maxY;
  110. var x = vertices[0];
  111. var y = vertices[1];
  112. minX = x < minX ? x : minX;
  113. minY = y < minY ? y : minY;
  114. maxX = x > maxX ? x : maxX;
  115. maxY = y > maxY ? y : maxY;
  116. x = vertices[2];
  117. y = vertices[3];
  118. minX = x < minX ? x : minX;
  119. minY = y < minY ? y : minY;
  120. maxX = x > maxX ? x : maxX;
  121. maxY = y > maxY ? y : maxY;
  122. x = vertices[4];
  123. y = vertices[5];
  124. minX = x < minX ? x : minX;
  125. minY = y < minY ? y : minY;
  126. maxX = x > maxX ? x : maxX;
  127. maxY = y > maxY ? y : maxY;
  128. x = vertices[6];
  129. y = vertices[7];
  130. minX = x < minX ? x : minX;
  131. minY = y < minY ? y : minY;
  132. maxX = x > maxX ? x : maxX;
  133. maxY = y > maxY ? y : maxY;
  134. this.minX = minX;
  135. this.minY = minY;
  136. this.maxX = maxX;
  137. this.maxY = maxY;
  138. };
  139. /**
  140. * Adds sprite frame, transformed.
  141. * @param transform - transform to apply
  142. * @param x0 - left X of frame
  143. * @param y0 - top Y of frame
  144. * @param x1 - right X of frame
  145. * @param y1 - bottom Y of frame
  146. */
  147. Bounds.prototype.addFrame = function (transform, x0, y0, x1, y1) {
  148. this.addFrameMatrix(transform.worldTransform, x0, y0, x1, y1);
  149. };
  150. /**
  151. * Adds sprite frame, multiplied by matrix
  152. * @param matrix - matrix to apply
  153. * @param x0 - left X of frame
  154. * @param y0 - top Y of frame
  155. * @param x1 - right X of frame
  156. * @param y1 - bottom Y of frame
  157. */
  158. Bounds.prototype.addFrameMatrix = function (matrix, x0, y0, x1, y1) {
  159. var a = matrix.a;
  160. var b = matrix.b;
  161. var c = matrix.c;
  162. var d = matrix.d;
  163. var tx = matrix.tx;
  164. var ty = matrix.ty;
  165. var minX = this.minX;
  166. var minY = this.minY;
  167. var maxX = this.maxX;
  168. var maxY = this.maxY;
  169. var x = (a * x0) + (c * y0) + tx;
  170. var y = (b * x0) + (d * y0) + ty;
  171. minX = x < minX ? x : minX;
  172. minY = y < minY ? y : minY;
  173. maxX = x > maxX ? x : maxX;
  174. maxY = y > maxY ? y : maxY;
  175. x = (a * x1) + (c * y0) + tx;
  176. y = (b * x1) + (d * y0) + ty;
  177. minX = x < minX ? x : minX;
  178. minY = y < minY ? y : minY;
  179. maxX = x > maxX ? x : maxX;
  180. maxY = y > maxY ? y : maxY;
  181. x = (a * x0) + (c * y1) + tx;
  182. y = (b * x0) + (d * y1) + ty;
  183. minX = x < minX ? x : minX;
  184. minY = y < minY ? y : minY;
  185. maxX = x > maxX ? x : maxX;
  186. maxY = y > maxY ? y : maxY;
  187. x = (a * x1) + (c * y1) + tx;
  188. y = (b * x1) + (d * y1) + ty;
  189. minX = x < minX ? x : minX;
  190. minY = y < minY ? y : minY;
  191. maxX = x > maxX ? x : maxX;
  192. maxY = y > maxY ? y : maxY;
  193. this.minX = minX;
  194. this.minY = minY;
  195. this.maxX = maxX;
  196. this.maxY = maxY;
  197. };
  198. /**
  199. * Adds screen vertices from array
  200. * @param vertexData - calculated vertices
  201. * @param beginOffset - begin offset
  202. * @param endOffset - end offset, excluded
  203. */
  204. Bounds.prototype.addVertexData = function (vertexData, beginOffset, endOffset) {
  205. var minX = this.minX;
  206. var minY = this.minY;
  207. var maxX = this.maxX;
  208. var maxY = this.maxY;
  209. for (var i = beginOffset; i < endOffset; i += 2) {
  210. var x = vertexData[i];
  211. var y = vertexData[i + 1];
  212. minX = x < minX ? x : minX;
  213. minY = y < minY ? y : minY;
  214. maxX = x > maxX ? x : maxX;
  215. maxY = y > maxY ? y : maxY;
  216. }
  217. this.minX = minX;
  218. this.minY = minY;
  219. this.maxX = maxX;
  220. this.maxY = maxY;
  221. };
  222. /**
  223. * Add an array of mesh vertices
  224. * @param transform - mesh transform
  225. * @param vertices - mesh coordinates in array
  226. * @param beginOffset - begin offset
  227. * @param endOffset - end offset, excluded
  228. */
  229. Bounds.prototype.addVertices = function (transform, vertices, beginOffset, endOffset) {
  230. this.addVerticesMatrix(transform.worldTransform, vertices, beginOffset, endOffset);
  231. };
  232. /**
  233. * Add an array of mesh vertices.
  234. * @param matrix - mesh matrix
  235. * @param vertices - mesh coordinates in array
  236. * @param beginOffset - begin offset
  237. * @param endOffset - end offset, excluded
  238. * @param padX - x padding
  239. * @param padY - y padding
  240. */
  241. Bounds.prototype.addVerticesMatrix = function (matrix, vertices, beginOffset, endOffset, padX, padY) {
  242. if (padX === void 0) { padX = 0; }
  243. if (padY === void 0) { padY = padX; }
  244. var a = matrix.a;
  245. var b = matrix.b;
  246. var c = matrix.c;
  247. var d = matrix.d;
  248. var tx = matrix.tx;
  249. var ty = matrix.ty;
  250. var minX = this.minX;
  251. var minY = this.minY;
  252. var maxX = this.maxX;
  253. var maxY = this.maxY;
  254. for (var i = beginOffset; i < endOffset; i += 2) {
  255. var rawX = vertices[i];
  256. var rawY = vertices[i + 1];
  257. var x = (a * rawX) + (c * rawY) + tx;
  258. var y = (d * rawY) + (b * rawX) + ty;
  259. minX = Math.min(minX, x - padX);
  260. maxX = Math.max(maxX, x + padX);
  261. minY = Math.min(minY, y - padY);
  262. maxY = Math.max(maxY, y + padY);
  263. }
  264. this.minX = minX;
  265. this.minY = minY;
  266. this.maxX = maxX;
  267. this.maxY = maxY;
  268. };
  269. /**
  270. * Adds other {@link Bounds}.
  271. * @param bounds - The Bounds to be added
  272. */
  273. Bounds.prototype.addBounds = function (bounds) {
  274. var minX = this.minX;
  275. var minY = this.minY;
  276. var maxX = this.maxX;
  277. var maxY = this.maxY;
  278. this.minX = bounds.minX < minX ? bounds.minX : minX;
  279. this.minY = bounds.minY < minY ? bounds.minY : minY;
  280. this.maxX = bounds.maxX > maxX ? bounds.maxX : maxX;
  281. this.maxY = bounds.maxY > maxY ? bounds.maxY : maxY;
  282. };
  283. /**
  284. * Adds other Bounds, masked with Bounds.
  285. * @param bounds - The Bounds to be added.
  286. * @param mask - TODO
  287. */
  288. Bounds.prototype.addBoundsMask = function (bounds, mask) {
  289. var _minX = bounds.minX > mask.minX ? bounds.minX : mask.minX;
  290. var _minY = bounds.minY > mask.minY ? bounds.minY : mask.minY;
  291. var _maxX = bounds.maxX < mask.maxX ? bounds.maxX : mask.maxX;
  292. var _maxY = bounds.maxY < mask.maxY ? bounds.maxY : mask.maxY;
  293. if (_minX <= _maxX && _minY <= _maxY) {
  294. var minX = this.minX;
  295. var minY = this.minY;
  296. var maxX = this.maxX;
  297. var maxY = this.maxY;
  298. this.minX = _minX < minX ? _minX : minX;
  299. this.minY = _minY < minY ? _minY : minY;
  300. this.maxX = _maxX > maxX ? _maxX : maxX;
  301. this.maxY = _maxY > maxY ? _maxY : maxY;
  302. }
  303. };
  304. /**
  305. * Adds other Bounds, multiplied by matrix. Bounds shouldn't be empty.
  306. * @param bounds - other bounds
  307. * @param matrix - multiplicator
  308. */
  309. Bounds.prototype.addBoundsMatrix = function (bounds, matrix) {
  310. this.addFrameMatrix(matrix, bounds.minX, bounds.minY, bounds.maxX, bounds.maxY);
  311. };
  312. /**
  313. * Adds other Bounds, masked with Rectangle.
  314. * @param bounds - TODO
  315. * @param area - TODO
  316. */
  317. Bounds.prototype.addBoundsArea = function (bounds, area) {
  318. var _minX = bounds.minX > area.x ? bounds.minX : area.x;
  319. var _minY = bounds.minY > area.y ? bounds.minY : area.y;
  320. var _maxX = bounds.maxX < area.x + area.width ? bounds.maxX : (area.x + area.width);
  321. var _maxY = bounds.maxY < area.y + area.height ? bounds.maxY : (area.y + area.height);
  322. if (_minX <= _maxX && _minY <= _maxY) {
  323. var minX = this.minX;
  324. var minY = this.minY;
  325. var maxX = this.maxX;
  326. var maxY = this.maxY;
  327. this.minX = _minX < minX ? _minX : minX;
  328. this.minY = _minY < minY ? _minY : minY;
  329. this.maxX = _maxX > maxX ? _maxX : maxX;
  330. this.maxY = _maxY > maxY ? _maxY : maxY;
  331. }
  332. };
  333. /**
  334. * Pads bounds object, making it grow in all directions.
  335. * If paddingY is omitted, both paddingX and paddingY will be set to paddingX.
  336. * @param paddingX - The horizontal padding amount.
  337. * @param paddingY - The vertical padding amount.
  338. */
  339. Bounds.prototype.pad = function (paddingX, paddingY) {
  340. if (paddingX === void 0) { paddingX = 0; }
  341. if (paddingY === void 0) { paddingY = paddingX; }
  342. if (!this.isEmpty()) {
  343. this.minX -= paddingX;
  344. this.maxX += paddingX;
  345. this.minY -= paddingY;
  346. this.maxY += paddingY;
  347. }
  348. };
  349. /**
  350. * Adds padded frame. (x0, y0) should be strictly less than (x1, y1)
  351. * @param x0 - left X of frame
  352. * @param y0 - top Y of frame
  353. * @param x1 - right X of frame
  354. * @param y1 - bottom Y of frame
  355. * @param padX - padding X
  356. * @param padY - padding Y
  357. */
  358. Bounds.prototype.addFramePad = function (x0, y0, x1, y1, padX, padY) {
  359. x0 -= padX;
  360. y0 -= padY;
  361. x1 += padX;
  362. y1 += padY;
  363. this.minX = this.minX < x0 ? this.minX : x0;
  364. this.maxX = this.maxX > x1 ? this.maxX : x1;
  365. this.minY = this.minY < y0 ? this.minY : y0;
  366. this.maxY = this.maxY > y1 ? this.maxY : y1;
  367. };
  368. return Bounds;
  369. }());
  370. /*! *****************************************************************************
  371. Copyright (c) Microsoft Corporation.
  372. Permission to use, copy, modify, and/or distribute this software for any
  373. purpose with or without fee is hereby granted.
  374. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
  375. REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  376. AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
  377. INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  378. LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  379. OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  380. PERFORMANCE OF THIS SOFTWARE.
  381. ***************************************************************************** */
  382. /* global Reflect, Promise */
  383. var extendStatics = function(d, b) {
  384. extendStatics = Object.setPrototypeOf ||
  385. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  386. function (d, b) { for (var p in b) { if (b.hasOwnProperty(p)) { d[p] = b[p]; } } };
  387. return extendStatics(d, b);
  388. };
  389. function __extends(d, b) {
  390. extendStatics(d, b);
  391. function __() { this.constructor = d; }
  392. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  393. }
  394. var __assign = function() {
  395. __assign = Object.assign || function __assign(t) {
  396. var arguments$1 = arguments;
  397. for (var s, i = 1, n = arguments.length; i < n; i++) {
  398. s = arguments$1[i];
  399. for (var p in s) { if (Object.prototype.hasOwnProperty.call(s, p)) { t[p] = s[p]; } }
  400. }
  401. return t;
  402. };
  403. return __assign.apply(this, arguments);
  404. };
  405. function __rest(s, e) {
  406. var t = {};
  407. for (var p in s) { if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
  408. { t[p] = s[p]; } }
  409. if (s != null && typeof Object.getOwnPropertySymbols === "function")
  410. { for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
  411. if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
  412. { t[p[i]] = s[p[i]]; }
  413. } }
  414. return t;
  415. }
  416. function __decorate(decorators, target, key, desc) {
  417. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  418. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") { r = Reflect.decorate(decorators, target, key, desc); }
  419. 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; } } }
  420. return c > 3 && r && Object.defineProperty(target, key, r), r;
  421. }
  422. function __param(paramIndex, decorator) {
  423. return function (target, key) { decorator(target, key, paramIndex); }
  424. }
  425. function __metadata(metadataKey, metadataValue) {
  426. if (typeof Reflect === "object" && typeof Reflect.metadata === "function") { return Reflect.metadata(metadataKey, metadataValue); }
  427. }
  428. function __awaiter(thisArg, _arguments, P, generator) {
  429. function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
  430. return new (P || (P = Promise))(function (resolve, reject) {
  431. function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
  432. function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
  433. function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
  434. step((generator = generator.apply(thisArg, _arguments || [])).next());
  435. });
  436. }
  437. function __generator(thisArg, body) {
  438. var _ = { label: 0, sent: function() { if (t[0] & 1) { throw t[1]; } return t[1]; }, trys: [], ops: [] }, f, y, t, g;
  439. return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
  440. function verb(n) { return function (v) { return step([n, v]); }; }
  441. function step(op) {
  442. if (f) { throw new TypeError("Generator is already executing."); }
  443. while (_) { try {
  444. if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) { return t; }
  445. if (y = 0, t) { op = [op[0] & 2, t.value]; }
  446. switch (op[0]) {
  447. case 0: case 1: t = op; break;
  448. case 4: _.label++; return { value: op[1], done: false };
  449. case 5: _.label++; y = op[1]; op = [0]; continue;
  450. case 7: op = _.ops.pop(); _.trys.pop(); continue;
  451. default:
  452. if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
  453. if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
  454. if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
  455. if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
  456. if (t[2]) { _.ops.pop(); }
  457. _.trys.pop(); continue;
  458. }
  459. op = body.call(thisArg, _);
  460. } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } }
  461. if (op[0] & 5) { throw op[1]; } return { value: op[0] ? op[1] : void 0, done: true };
  462. }
  463. }
  464. function __createBinding(o, m, k, k2) {
  465. if (k2 === undefined) { k2 = k; }
  466. o[k2] = m[k];
  467. }
  468. function __exportStar(m, exports) {
  469. for (var p in m) { if (p !== "default" && !exports.hasOwnProperty(p)) { exports[p] = m[p]; } }
  470. }
  471. function __values(o) {
  472. var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
  473. if (m) { return m.call(o); }
  474. if (o && typeof o.length === "number") { return {
  475. next: function () {
  476. if (o && i >= o.length) { o = void 0; }
  477. return { value: o && o[i++], done: !o };
  478. }
  479. }; }
  480. throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
  481. }
  482. function __read(o, n) {
  483. var m = typeof Symbol === "function" && o[Symbol.iterator];
  484. if (!m) { return o; }
  485. var i = m.call(o), r, ar = [], e;
  486. try {
  487. while ((n === void 0 || n-- > 0) && !(r = i.next()).done) { ar.push(r.value); }
  488. }
  489. catch (error) { e = { error: error }; }
  490. finally {
  491. try {
  492. if (r && !r.done && (m = i["return"])) { m.call(i); }
  493. }
  494. finally { if (e) { throw e.error; } }
  495. }
  496. return ar;
  497. }
  498. function __spread() {
  499. var arguments$1 = arguments;
  500. for (var ar = [], i = 0; i < arguments.length; i++)
  501. { ar = ar.concat(__read(arguments$1[i])); }
  502. return ar;
  503. }
  504. function __spreadArrays() {
  505. var arguments$1 = arguments;
  506. for (var s = 0, i = 0, il = arguments.length; i < il; i++) { s += arguments$1[i].length; }
  507. for (var r = Array(s), k = 0, i = 0; i < il; i++)
  508. { for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
  509. { r[k] = a[j]; } }
  510. return r;
  511. };
  512. function __await(v) {
  513. return this instanceof __await ? (this.v = v, this) : new __await(v);
  514. }
  515. function __asyncGenerator(thisArg, _arguments, generator) {
  516. if (!Symbol.asyncIterator) { throw new TypeError("Symbol.asyncIterator is not defined."); }
  517. var g = generator.apply(thisArg, _arguments || []), i, q = [];
  518. return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
  519. function verb(n) { if (g[n]) { i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; } }
  520. function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
  521. function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
  522. function fulfill(value) { resume("next", value); }
  523. function reject(value) { resume("throw", value); }
  524. function settle(f, v) { if (f(v), q.shift(), q.length) { resume(q[0][0], q[0][1]); } }
  525. }
  526. function __asyncDelegator(o) {
  527. var i, p;
  528. return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
  529. function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; }
  530. }
  531. function __asyncValues(o) {
  532. if (!Symbol.asyncIterator) { throw new TypeError("Symbol.asyncIterator is not defined."); }
  533. var m = o[Symbol.asyncIterator], i;
  534. return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
  535. function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
  536. function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
  537. }
  538. function __makeTemplateObject(cooked, raw) {
  539. if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
  540. return cooked;
  541. };
  542. function __importStar(mod) {
  543. if (mod && mod.__esModule) { return mod; }
  544. var result = {};
  545. if (mod != null) { for (var k in mod) { if (Object.hasOwnProperty.call(mod, k)) { result[k] = mod[k]; } } }
  546. result.default = mod;
  547. return result;
  548. }
  549. function __importDefault(mod) {
  550. return (mod && mod.__esModule) ? mod : { default: mod };
  551. }
  552. function __classPrivateFieldGet(receiver, privateMap) {
  553. if (!privateMap.has(receiver)) {
  554. throw new TypeError("attempted to get private field on non-instance");
  555. }
  556. return privateMap.get(receiver);
  557. }
  558. function __classPrivateFieldSet(receiver, privateMap, value) {
  559. if (!privateMap.has(receiver)) {
  560. throw new TypeError("attempted to set private field on non-instance");
  561. }
  562. privateMap.set(receiver, value);
  563. return value;
  564. }
  565. /**
  566. * The base class for all objects that are rendered on the screen.
  567. *
  568. * This is an abstract class and can not be used on its own; rather it should be extended.
  569. *
  570. * ## Display objects implemented in PixiJS
  571. *
  572. * | Display Object | Description |
  573. * | ------------------------------- | --------------------------------------------------------------------- |
  574. * | {@link PIXI.Container} | Adds support for `children` to DisplayObject |
  575. * | {@link PIXI.Graphics} | Shape-drawing display object similar to the Canvas API |
  576. * | {@link PIXI.Sprite} | Draws textures (i.e. images) |
  577. * | {@link PIXI.Text} | Draws text using the Canvas API internally |
  578. * | {@link PIXI.BitmapText} | More scaleable solution for text rendering, reusing glyph textures |
  579. * | {@link PIXI.TilingSprite} | Draws textures/images in a tiled fashion |
  580. * | {@link PIXI.AnimatedSprite} | Draws an animation of multiple images |
  581. * | {@link PIXI.Mesh} | Provides a lower-level API for drawing meshes with custom data |
  582. * | {@link PIXI.NineSlicePlane} | Mesh-related |
  583. * | {@link PIXI.SimpleMesh} | v4-compatible mesh |
  584. * | {@link PIXI.SimplePlane} | Mesh-related |
  585. * | {@link PIXI.SimpleRope} | Mesh-related |
  586. *
  587. * ## Transforms
  588. *
  589. * The [transform]{@link DisplayObject#transform} of a display object describes the projection from its
  590. * local coordinate space to its parent's local coordinate space. The following properties are derived
  591. * from the transform:
  592. *
  593. * <table>
  594. * <thead>
  595. * <tr>
  596. * <th>Property</th>
  597. * <th>Description</th>
  598. * </tr>
  599. * </thead>
  600. * <tbody>
  601. * <tr>
  602. * <td>[pivot]{@link PIXI.DisplayObject#pivot}</td>
  603. * <td>
  604. * Invariant under rotation, scaling, and skewing. The projection of into the parent's space of the pivot
  605. * is equal to position, regardless of the other three transformations. In other words, It is the center of
  606. * rotation, scaling, and skewing.
  607. * </td>
  608. * </tr>
  609. * <tr>
  610. * <td>[position]{@link PIXI.DisplayObject#position}</td>
  611. * <td>
  612. * Translation. This is the position of the [pivot]{@link PIXI.DisplayObject#pivot} in the parent's local
  613. * space. The default value of the pivot is the origin (0,0). If the top-left corner of your display object
  614. * is (0,0) in its local space, then the position will be its top-left corner in the parent's local space.
  615. * </td>
  616. * </tr>
  617. * <tr>
  618. * <td>[scale]{@link PIXI.DisplayObject#scale}</td>
  619. * <td>
  620. * Scaling. This will stretch (or compress) the display object's projection. The scale factors are along the
  621. * local coordinate axes. In other words, the display object is scaled before rotated or skewed. The center
  622. * of scaling is the [pivot]{@link PIXI.DisplayObject#pivot}.
  623. * </td>
  624. * </tr>
  625. * <tr>
  626. * <td>[rotation]{@link PIXI.DisplayObject#rotation}</td>
  627. * <td>
  628. * Rotation. This will rotate the display object's projection by this angle (in radians).
  629. * </td>
  630. * </tr>
  631. * <tr>
  632. * <td>[skew]{@link PIXI.DisplayObject#skew}</td>
  633. * <td>
  634. * <p>Skewing. This can be used to deform a rectangular display object into a parallelogram.</p>
  635. * <p>
  636. * In PixiJS, skew has a slightly different behaviour than the conventional meaning. It can be
  637. * thought of the net rotation applied to the coordinate axes (separately). For example, if "skew.x" is
  638. * ⍺ and "skew.y" is β, then the line x = 0 will be rotated by ⍺ (y = -x*cot⍺) and the line y = 0 will be
  639. * rotated by β (y = x*tanβ). A line y = x*tanϴ (i.e. a line at angle ϴ to the x-axis in local-space) will
  640. * be rotated by an angle between ⍺ and β.
  641. * </p>
  642. * <p>
  643. * It can be observed that if skew is applied equally to both axes, then it will be equivalent to applying
  644. * a rotation. Indeed, if "skew.x" = -ϴ and "skew.y" = ϴ, it will produce an equivalent of "rotation" = ϴ.
  645. * </p>
  646. * <p>
  647. * Another quite interesting observation is that "skew.x", "skew.y", rotation are communtative operations. Indeed,
  648. * because rotation is essentially a careful combination of the two.
  649. * </p>
  650. * </td>
  651. * </tr>
  652. * <tr>
  653. * <td>angle</td>
  654. * <td>Rotation. This is an alias for [rotation]{@link PIXI.DisplayObject#rotation}, but in degrees.</td>
  655. * </tr>
  656. * <tr>
  657. * <td>x</td>
  658. * <td>Translation. This is an alias for position.x!</td>
  659. * </tr>
  660. * <tr>
  661. * <td>y</td>
  662. * <td>Translation. This is an alias for position.y!</td>
  663. * </tr>
  664. * <tr>
  665. * <td>width</td>
  666. * <td>
  667. * Implemented in [Container]{@link PIXI.Container}. Scaling. The width property calculates scale.x by dividing
  668. * the "requested" width by the local bounding box width. It is indirectly an abstraction over scale.x, and there
  669. * is no concept of user-defined width.
  670. * </td>
  671. * </tr>
  672. * <tr>
  673. * <td>height</td>
  674. * <td>
  675. * Implemented in [Container]{@link PIXI.Container}. Scaling. The height property calculates scale.y by dividing
  676. * the "requested" height by the local bounding box height. It is indirectly an abstraction over scale.y, and there
  677. * is no concept of user-defined height.
  678. * </td>
  679. * </tr>
  680. * </tbody>
  681. * </table>
  682. *
  683. * ## Bounds
  684. *
  685. * The bounds of a display object is defined by the minimum axis-aligned rectangle in world space that can fit
  686. * around it. The abstract `calculateBounds` method is responsible for providing it (and it should use the
  687. * `worldTransform` to calculate in world space).
  688. *
  689. * There are a few additional types of bounding boxes:
  690. *
  691. * | Bounds | Description |
  692. * | --------------------- | ---------------------------------------------------------------------------------------- |
  693. * | World Bounds | This is synonymous is the regular bounds described above. See `getBounds()`. |
  694. * | Local Bounds | This the axis-aligned bounding box in the parent's local space. See `getLocalBounds()`. |
  695. * | Render Bounds | The bounds, but including extra rendering effects like filter padding. |
  696. * | Projected Bounds | The bounds of the projected display object onto the screen. Usually equals world bounds. |
  697. * | Relative Bounds | The bounds of a display object when projected onto a ancestor's (or parent's) space. |
  698. * | Natural Bounds | The bounds of an object in its own local space (not parent's space, like in local bounds)|
  699. * | Content Bounds | The natural bounds when excluding all children of a `Container`. |
  700. *
  701. * ### calculateBounds
  702. *
  703. * [Container]{@link Container} already implements `calculateBounds` in a manner that includes children.
  704. *
  705. * But for a non-Container display object, the `calculateBounds` method must be overridden in order for `getBounds` and
  706. * `getLocalBounds` to work. This method must write the bounds into `this._bounds`.
  707. *
  708. * Generally, the following technique works for most simple cases: take the list of points
  709. * forming the "hull" of the object (i.e. outline of the object's shape), and then add them
  710. * using {@link PIXI.Bounds#addPointMatrix}.
  711. *
  712. * ```js
  713. * calculateBounds(): void
  714. * {
  715. * const points = [...];
  716. *
  717. * for (let i = 0, j = points.length; i < j; i++)
  718. * {
  719. * this._bounds.addPointMatrix(this.worldTransform, points[i]);
  720. * }
  721. * }
  722. * ```
  723. *
  724. * You can optimize this for a large number of points by using {@link PIXI.Bounds#addVerticesMatrix} to pass them
  725. * in one array together.
  726. *
  727. * ## Alpha
  728. *
  729. * This alpha sets a display object's **relative opacity** w.r.t its parent. For example, if the alpha of a display
  730. * object is 0.5 and its parent's alpha is 0.5, then it will be rendered with 25% opacity (assuming alpha is not
  731. * applied on any ancestor further up the chain).
  732. *
  733. * The alpha with which the display object will be rendered is called the [worldAlpha]{@link PIXI.DisplayObject#worldAlpha}.
  734. *
  735. * ## Renderable vs Visible
  736. *
  737. * The `renderable` and `visible` properties can be used to prevent a display object from being rendered to the
  738. * screen. However, there is a subtle difference between the two. When using `renderable`, the transforms of the display
  739. * object (and its children subtree) will continue to be calculated. When using `visible`, the transforms will not
  740. * be calculated.
  741. *
  742. * It is recommended that applications use the `renderable` property for culling. See
  743. * [@pixi-essentials/cull]{@link https://www.npmjs.com/package/@pixi-essentials/cull} or
  744. * [pixi-cull]{@link https://www.npmjs.com/package/pixi-cull} for more details.
  745. *
  746. * Otherwise, to prevent an object from rendering in the general-purpose sense - `visible` is the property to use. This
  747. * one is also better in terms of performance.
  748. * @memberof PIXI
  749. */
  750. var DisplayObject = /** @class */ (function (_super) {
  751. __extends(DisplayObject, _super);
  752. function DisplayObject() {
  753. var _this = _super.call(this) || this;
  754. _this.tempDisplayObjectParent = null;
  755. // TODO: need to create Transform from factory
  756. _this.transform = new math.Transform();
  757. _this.alpha = 1;
  758. _this.visible = true;
  759. _this.renderable = true;
  760. _this.cullable = false;
  761. _this.cullArea = null;
  762. _this.parent = null;
  763. _this.worldAlpha = 1;
  764. _this._lastSortedIndex = 0;
  765. _this._zIndex = 0;
  766. _this.filterArea = null;
  767. _this.filters = null;
  768. _this._enabledFilters = null;
  769. _this._bounds = new Bounds();
  770. _this._localBounds = null;
  771. _this._boundsID = 0;
  772. _this._boundsRect = null;
  773. _this._localBoundsRect = null;
  774. _this._mask = null;
  775. _this._maskRefCount = 0;
  776. _this._destroyed = false;
  777. _this.isSprite = false;
  778. _this.isMask = false;
  779. return _this;
  780. }
  781. /**
  782. * Mixes all enumerable properties and methods from a source object to DisplayObject.
  783. * @param source - The source of properties and methods to mix in.
  784. */
  785. DisplayObject.mixin = function (source) {
  786. // in ES8/ES2017, this would be really easy:
  787. // Object.defineProperties(DisplayObject.prototype, Object.getOwnPropertyDescriptors(source));
  788. // get all the enumerable property keys
  789. var keys = Object.keys(source);
  790. // loop through properties
  791. for (var i = 0; i < keys.length; ++i) {
  792. var propertyName = keys[i];
  793. // Set the property using the property descriptor - this works for accessors and normal value properties
  794. Object.defineProperty(DisplayObject.prototype, propertyName, Object.getOwnPropertyDescriptor(source, propertyName));
  795. }
  796. };
  797. Object.defineProperty(DisplayObject.prototype, "destroyed", {
  798. /**
  799. * Fired when this DisplayObject is added to a Container.
  800. * @instance
  801. * @event added
  802. * @param {PIXI.Container} container - The container added to.
  803. */
  804. /**
  805. * Fired when this DisplayObject is removed from a Container.
  806. * @instance
  807. * @event removed
  808. * @param {PIXI.Container} container - The container removed from.
  809. */
  810. /**
  811. * Fired when this DisplayObject is destroyed. This event is emitted once
  812. * destroy is finished.
  813. * @instance
  814. * @event destroyed
  815. */
  816. /** Readonly flag for destroyed display objects. */
  817. get: function () {
  818. return this._destroyed;
  819. },
  820. enumerable: false,
  821. configurable: true
  822. });
  823. /** Recursively updates transform of all objects from the root to this one internal function for toLocal() */
  824. DisplayObject.prototype._recursivePostUpdateTransform = function () {
  825. if (this.parent) {
  826. this.parent._recursivePostUpdateTransform();
  827. this.transform.updateTransform(this.parent.transform);
  828. }
  829. else {
  830. this.transform.updateTransform(this._tempDisplayObjectParent.transform);
  831. }
  832. };
  833. /** Updates the object transform for rendering. TODO - Optimization pass! */
  834. DisplayObject.prototype.updateTransform = function () {
  835. this._boundsID++;
  836. this.transform.updateTransform(this.parent.transform);
  837. // multiply the alphas..
  838. this.worldAlpha = this.alpha * this.parent.worldAlpha;
  839. };
  840. /**
  841. * Calculates and returns the (world) bounds of the display object as a [Rectangle]{@link PIXI.Rectangle}.
  842. *
  843. * This method is expensive on containers with a large subtree (like the stage). This is because the bounds
  844. * of a container depend on its children's bounds, which recursively causes all bounds in the subtree to
  845. * be recalculated. The upside, however, is that calling `getBounds` once on a container will indeed update
  846. * the bounds of all children (the whole subtree, in fact). This side effect should be exploited by using
  847. * `displayObject._bounds.getRectangle()` when traversing through all the bounds in a scene graph. Otherwise,
  848. * calling `getBounds` on each object in a subtree will cause the total cost to increase quadratically as
  849. * its height increases.
  850. *
  851. * The transforms of all objects in a container's **subtree** and of all **ancestors** are updated.
  852. * The world bounds of all display objects in a container's **subtree** will also be recalculated.
  853. *
  854. * The `_bounds` object stores the last calculation of the bounds. You can use to entirely skip bounds
  855. * calculation if needed.
  856. *
  857. * ```js
  858. * const lastCalculatedBounds = displayObject._bounds.getRectangle(optionalRect);
  859. * ```
  860. *
  861. * Do know that usage of `getLocalBounds` can corrupt the `_bounds` of children (the whole subtree, actually). This
  862. * is a known issue that has not been solved. See [getLocalBounds]{@link PIXI.DisplayObject#getLocalBounds} for more
  863. * details.
  864. *
  865. * `getBounds` should be called with `skipUpdate` equal to `true` in a render() call. This is because the transforms
  866. * are guaranteed to be update-to-date. In fact, recalculating inside a render() call may cause corruption in certain
  867. * cases.
  868. * @param skipUpdate - Setting to `true` will stop the transforms of the scene graph from
  869. * being updated. This means the calculation returned MAY be out of date BUT will give you a
  870. * nice performance boost.
  871. * @param rect - Optional rectangle to store the result of the bounds calculation.
  872. * @returns - The minimum axis-aligned rectangle in world space that fits around this object.
  873. */
  874. DisplayObject.prototype.getBounds = function (skipUpdate, rect) {
  875. if (!skipUpdate) {
  876. if (!this.parent) {
  877. this.parent = this._tempDisplayObjectParent;
  878. this.updateTransform();
  879. this.parent = null;
  880. }
  881. else {
  882. this._recursivePostUpdateTransform();
  883. this.updateTransform();
  884. }
  885. }
  886. if (this._bounds.updateID !== this._boundsID) {
  887. this.calculateBounds();
  888. this._bounds.updateID = this._boundsID;
  889. }
  890. if (!rect) {
  891. if (!this._boundsRect) {
  892. this._boundsRect = new math.Rectangle();
  893. }
  894. rect = this._boundsRect;
  895. }
  896. return this._bounds.getRectangle(rect);
  897. };
  898. /**
  899. * Retrieves the local bounds of the displayObject as a rectangle object.
  900. * @param rect - Optional rectangle to store the result of the bounds calculation.
  901. * @returns - The rectangular bounding area.
  902. */
  903. DisplayObject.prototype.getLocalBounds = function (rect) {
  904. if (!rect) {
  905. if (!this._localBoundsRect) {
  906. this._localBoundsRect = new math.Rectangle();
  907. }
  908. rect = this._localBoundsRect;
  909. }
  910. if (!this._localBounds) {
  911. this._localBounds = new Bounds();
  912. }
  913. var transformRef = this.transform;
  914. var parentRef = this.parent;
  915. this.parent = null;
  916. this.transform = this._tempDisplayObjectParent.transform;
  917. var worldBounds = this._bounds;
  918. var worldBoundsID = this._boundsID;
  919. this._bounds = this._localBounds;
  920. var bounds = this.getBounds(false, rect);
  921. this.parent = parentRef;
  922. this.transform = transformRef;
  923. this._bounds = worldBounds;
  924. this._bounds.updateID += this._boundsID - worldBoundsID; // reflect side-effects
  925. return bounds;
  926. };
  927. /**
  928. * Calculates the global position of the display object.
  929. * @param position - The world origin to calculate from.
  930. * @param point - A Point object in which to store the value, optional
  931. * (otherwise will create a new Point).
  932. * @param skipUpdate - Should we skip the update transform.
  933. * @returns - A point object representing the position of this object.
  934. */
  935. DisplayObject.prototype.toGlobal = function (position, point, skipUpdate) {
  936. if (skipUpdate === void 0) { skipUpdate = false; }
  937. if (!skipUpdate) {
  938. this._recursivePostUpdateTransform();
  939. // this parent check is for just in case the item is a root object.
  940. // If it is we need to give it a temporary parent so that displayObjectUpdateTransform works correctly
  941. // this is mainly to avoid a parent check in the main loop. Every little helps for performance :)
  942. if (!this.parent) {
  943. this.parent = this._tempDisplayObjectParent;
  944. this.displayObjectUpdateTransform();
  945. this.parent = null;
  946. }
  947. else {
  948. this.displayObjectUpdateTransform();
  949. }
  950. }
  951. // don't need to update the lot
  952. return this.worldTransform.apply(position, point);
  953. };
  954. /**
  955. * Calculates the local position of the display object relative to another point.
  956. * @param position - The world origin to calculate from.
  957. * @param from - The DisplayObject to calculate the global position from.
  958. * @param point - A Point object in which to store the value, optional
  959. * (otherwise will create a new Point).
  960. * @param skipUpdate - Should we skip the update transform
  961. * @returns - A point object representing the position of this object
  962. */
  963. DisplayObject.prototype.toLocal = function (position, from, point, skipUpdate) {
  964. if (from) {
  965. position = from.toGlobal(position, point, skipUpdate);
  966. }
  967. if (!skipUpdate) {
  968. this._recursivePostUpdateTransform();
  969. // this parent check is for just in case the item is a root object.
  970. // If it is we need to give it a temporary parent so that displayObjectUpdateTransform works correctly
  971. // this is mainly to avoid a parent check in the main loop. Every little helps for performance :)
  972. if (!this.parent) {
  973. this.parent = this._tempDisplayObjectParent;
  974. this.displayObjectUpdateTransform();
  975. this.parent = null;
  976. }
  977. else {
  978. this.displayObjectUpdateTransform();
  979. }
  980. }
  981. // simply apply the matrix..
  982. return this.worldTransform.applyInverse(position, point);
  983. };
  984. /**
  985. * Set the parent Container of this DisplayObject.
  986. * @param container - The Container to add this DisplayObject to.
  987. * @returns - The Container that this DisplayObject was added to.
  988. */
  989. DisplayObject.prototype.setParent = function (container) {
  990. if (!container || !container.addChild) {
  991. throw new Error('setParent: Argument must be a Container');
  992. }
  993. container.addChild(this);
  994. return container;
  995. };
  996. /**
  997. * Convenience function to set the position, scale, skew and pivot at once.
  998. * @param x - The X position
  999. * @param y - The Y position
  1000. * @param scaleX - The X scale value
  1001. * @param scaleY - The Y scale value
  1002. * @param rotation - The rotation
  1003. * @param skewX - The X skew value
  1004. * @param skewY - The Y skew value
  1005. * @param pivotX - The X pivot value
  1006. * @param pivotY - The Y pivot value
  1007. * @returns - The DisplayObject instance
  1008. */
  1009. DisplayObject.prototype.setTransform = function (x, y, scaleX, scaleY, rotation, skewX, skewY, pivotX, pivotY) {
  1010. if (x === void 0) { x = 0; }
  1011. if (y === void 0) { y = 0; }
  1012. if (scaleX === void 0) { scaleX = 1; }
  1013. if (scaleY === void 0) { scaleY = 1; }
  1014. if (rotation === void 0) { rotation = 0; }
  1015. if (skewX === void 0) { skewX = 0; }
  1016. if (skewY === void 0) { skewY = 0; }
  1017. if (pivotX === void 0) { pivotX = 0; }
  1018. if (pivotY === void 0) { pivotY = 0; }
  1019. this.position.x = x;
  1020. this.position.y = y;
  1021. this.scale.x = !scaleX ? 1 : scaleX;
  1022. this.scale.y = !scaleY ? 1 : scaleY;
  1023. this.rotation = rotation;
  1024. this.skew.x = skewX;
  1025. this.skew.y = skewY;
  1026. this.pivot.x = pivotX;
  1027. this.pivot.y = pivotY;
  1028. return this;
  1029. };
  1030. /**
  1031. * Base destroy method for generic display objects. This will automatically
  1032. * remove the display object from its parent Container as well as remove
  1033. * all current event listeners and internal references. Do not use a DisplayObject
  1034. * after calling `destroy()`.
  1035. * @param _options
  1036. */
  1037. DisplayObject.prototype.destroy = function (_options) {
  1038. if (this.parent) {
  1039. this.parent.removeChild(this);
  1040. }
  1041. this._destroyed = true;
  1042. this.transform = null;
  1043. this.parent = null;
  1044. this._bounds = null;
  1045. this.mask = null;
  1046. this.cullArea = null;
  1047. this.filters = null;
  1048. this.filterArea = null;
  1049. this.hitArea = null;
  1050. this.interactive = false;
  1051. this.interactiveChildren = false;
  1052. this.emit('destroyed');
  1053. this.removeAllListeners();
  1054. };
  1055. Object.defineProperty(DisplayObject.prototype, "_tempDisplayObjectParent", {
  1056. /**
  1057. * @protected
  1058. * @member {PIXI.Container}
  1059. */
  1060. get: function () {
  1061. if (this.tempDisplayObjectParent === null) {
  1062. // eslint-disable-next-line @typescript-eslint/no-use-before-define
  1063. this.tempDisplayObjectParent = new TemporaryDisplayObject();
  1064. }
  1065. return this.tempDisplayObjectParent;
  1066. },
  1067. enumerable: false,
  1068. configurable: true
  1069. });
  1070. /**
  1071. * Used in Renderer, cacheAsBitmap and other places where you call an `updateTransform` on root
  1072. *
  1073. * ```
  1074. * const cacheParent = elem.enableTempParent();
  1075. * elem.updateTransform();
  1076. * elem.disableTempParent(cacheParent);
  1077. * ```
  1078. * @returns - current parent
  1079. */
  1080. DisplayObject.prototype.enableTempParent = function () {
  1081. var myParent = this.parent;
  1082. this.parent = this._tempDisplayObjectParent;
  1083. return myParent;
  1084. };
  1085. /**
  1086. * Pair method for `enableTempParent`
  1087. * @param cacheParent - Actual parent of element
  1088. */
  1089. DisplayObject.prototype.disableTempParent = function (cacheParent) {
  1090. this.parent = cacheParent;
  1091. };
  1092. Object.defineProperty(DisplayObject.prototype, "x", {
  1093. /**
  1094. * The position of the displayObject on the x axis relative to the local coordinates of the parent.
  1095. * An alias to position.x
  1096. */
  1097. get: function () {
  1098. return this.position.x;
  1099. },
  1100. set: function (value) {
  1101. this.transform.position.x = value;
  1102. },
  1103. enumerable: false,
  1104. configurable: true
  1105. });
  1106. Object.defineProperty(DisplayObject.prototype, "y", {
  1107. /**
  1108. * The position of the displayObject on the y axis relative to the local coordinates of the parent.
  1109. * An alias to position.y
  1110. */
  1111. get: function () {
  1112. return this.position.y;
  1113. },
  1114. set: function (value) {
  1115. this.transform.position.y = value;
  1116. },
  1117. enumerable: false,
  1118. configurable: true
  1119. });
  1120. Object.defineProperty(DisplayObject.prototype, "worldTransform", {
  1121. /**
  1122. * Current transform of the object based on world (parent) factors.
  1123. * @readonly
  1124. */
  1125. get: function () {
  1126. return this.transform.worldTransform;
  1127. },
  1128. enumerable: false,
  1129. configurable: true
  1130. });
  1131. Object.defineProperty(DisplayObject.prototype, "localTransform", {
  1132. /**
  1133. * Current transform of the object based on local factors: position, scale, other stuff.
  1134. * @readonly
  1135. */
  1136. get: function () {
  1137. return this.transform.localTransform;
  1138. },
  1139. enumerable: false,
  1140. configurable: true
  1141. });
  1142. Object.defineProperty(DisplayObject.prototype, "position", {
  1143. /**
  1144. * The coordinate of the object relative to the local coordinates of the parent.
  1145. * @since 4.0.0
  1146. */
  1147. get: function () {
  1148. return this.transform.position;
  1149. },
  1150. set: function (value) {
  1151. this.transform.position.copyFrom(value);
  1152. },
  1153. enumerable: false,
  1154. configurable: true
  1155. });
  1156. Object.defineProperty(DisplayObject.prototype, "scale", {
  1157. /**
  1158. * The scale factors of this object along the local coordinate axes.
  1159. *
  1160. * The default scale is (1, 1).
  1161. * @since 4.0.0
  1162. */
  1163. get: function () {
  1164. return this.transform.scale;
  1165. },
  1166. set: function (value) {
  1167. this.transform.scale.copyFrom(value);
  1168. },
  1169. enumerable: false,
  1170. configurable: true
  1171. });
  1172. Object.defineProperty(DisplayObject.prototype, "pivot", {
  1173. /**
  1174. * The center of rotation, scaling, and skewing for this display object in its local space. The `position`
  1175. * is the projection of `pivot` in the parent's local space.
  1176. *
  1177. * By default, the pivot is the origin (0, 0).
  1178. * @since 4.0.0
  1179. */
  1180. get: function () {
  1181. return this.transform.pivot;
  1182. },
  1183. set: function (value) {
  1184. this.transform.pivot.copyFrom(value);
  1185. },
  1186. enumerable: false,
  1187. configurable: true
  1188. });
  1189. Object.defineProperty(DisplayObject.prototype, "skew", {
  1190. /**
  1191. * The skew factor for the object in radians.
  1192. * @since 4.0.0
  1193. */
  1194. get: function () {
  1195. return this.transform.skew;
  1196. },
  1197. set: function (value) {
  1198. this.transform.skew.copyFrom(value);
  1199. },
  1200. enumerable: false,
  1201. configurable: true
  1202. });
  1203. Object.defineProperty(DisplayObject.prototype, "rotation", {
  1204. /**
  1205. * The rotation of the object in radians.
  1206. * 'rotation' and 'angle' have the same effect on a display object; rotation is in radians, angle is in degrees.
  1207. */
  1208. get: function () {
  1209. return this.transform.rotation;
  1210. },
  1211. set: function (value) {
  1212. this.transform.rotation = value;
  1213. },
  1214. enumerable: false,
  1215. configurable: true
  1216. });
  1217. Object.defineProperty(DisplayObject.prototype, "angle", {
  1218. /**
  1219. * The angle of the object in degrees.
  1220. * 'rotation' and 'angle' have the same effect on a display object; rotation is in radians, angle is in degrees.
  1221. */
  1222. get: function () {
  1223. return this.transform.rotation * math.RAD_TO_DEG;
  1224. },
  1225. set: function (value) {
  1226. this.transform.rotation = value * math.DEG_TO_RAD;
  1227. },
  1228. enumerable: false,
  1229. configurable: true
  1230. });
  1231. Object.defineProperty(DisplayObject.prototype, "zIndex", {
  1232. /**
  1233. * The zIndex of the displayObject.
  1234. *
  1235. * If a container has the sortableChildren property set to true, children will be automatically
  1236. * sorted by zIndex value; a higher value will mean it will be moved towards the end of the array,
  1237. * and thus rendered on top of other display objects within the same container.
  1238. * @see PIXI.Container#sortableChildren
  1239. */
  1240. get: function () {
  1241. return this._zIndex;
  1242. },
  1243. set: function (value) {
  1244. this._zIndex = value;
  1245. if (this.parent) {
  1246. this.parent.sortDirty = true;
  1247. }
  1248. },
  1249. enumerable: false,
  1250. configurable: true
  1251. });
  1252. Object.defineProperty(DisplayObject.prototype, "worldVisible", {
  1253. /**
  1254. * Indicates if the object is globally visible.
  1255. * @readonly
  1256. */
  1257. get: function () {
  1258. var item = this;
  1259. do {
  1260. if (!item.visible) {
  1261. return false;
  1262. }
  1263. item = item.parent;
  1264. } while (item);
  1265. return true;
  1266. },
  1267. enumerable: false,
  1268. configurable: true
  1269. });
  1270. Object.defineProperty(DisplayObject.prototype, "mask", {
  1271. /**
  1272. * Sets a mask for the displayObject. A mask is an object that limits the visibility of an
  1273. * object to the shape of the mask applied to it. In PixiJS a regular mask must be a
  1274. * {@link PIXI.Graphics} or a {@link PIXI.Sprite} object. This allows for much faster masking in canvas as it
  1275. * utilities shape clipping. Furthermore, a mask of an object must be in the subtree of its parent.
  1276. * Otherwise, `getLocalBounds` may calculate incorrect bounds, which makes the container's width and height wrong.
  1277. * To remove a mask, set this property to `null`.
  1278. *
  1279. * For sprite mask both alpha and red channel are used. Black mask is the same as transparent mask.
  1280. * @example
  1281. * const graphics = new PIXI.Graphics();
  1282. * graphics.beginFill(0xFF3300);
  1283. * graphics.drawRect(50, 250, 100, 100);
  1284. * graphics.endFill();
  1285. *
  1286. * const sprite = new PIXI.Sprite(texture);
  1287. * sprite.mask = graphics;
  1288. * @todo At the moment, PIXI.CanvasRenderer doesn't support PIXI.Sprite as mask.
  1289. */
  1290. get: function () {
  1291. return this._mask;
  1292. },
  1293. set: function (value) {
  1294. if (this._mask === value) {
  1295. return;
  1296. }
  1297. if (this._mask) {
  1298. var maskObject = (this._mask.isMaskData
  1299. ? this._mask.maskObject : this._mask);
  1300. if (maskObject) {
  1301. maskObject._maskRefCount--;
  1302. if (maskObject._maskRefCount === 0) {
  1303. maskObject.renderable = true;
  1304. maskObject.isMask = false;
  1305. }
  1306. }
  1307. }
  1308. this._mask = value;
  1309. if (this._mask) {
  1310. var maskObject = (this._mask.isMaskData
  1311. ? this._mask.maskObject : this._mask);
  1312. if (maskObject) {
  1313. if (maskObject._maskRefCount === 0) {
  1314. maskObject.renderable = false;
  1315. maskObject.isMask = true;
  1316. }
  1317. maskObject._maskRefCount++;
  1318. }
  1319. }
  1320. },
  1321. enumerable: false,
  1322. configurable: true
  1323. });
  1324. return DisplayObject;
  1325. }(utils.EventEmitter));
  1326. /**
  1327. * @private
  1328. */
  1329. var TemporaryDisplayObject = /** @class */ (function (_super) {
  1330. __extends(TemporaryDisplayObject, _super);
  1331. function TemporaryDisplayObject() {
  1332. var _this = _super !== null && _super.apply(this, arguments) || this;
  1333. _this.sortDirty = null;
  1334. return _this;
  1335. }
  1336. return TemporaryDisplayObject;
  1337. }(DisplayObject));
  1338. /**
  1339. * DisplayObject default updateTransform, does not update children of container.
  1340. * Will crash if there's no parent element.
  1341. * @memberof PIXI.DisplayObject#
  1342. * @method displayObjectUpdateTransform
  1343. */
  1344. DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform;
  1345. function sortChildren(a, b) {
  1346. if (a.zIndex === b.zIndex) {
  1347. return a._lastSortedIndex - b._lastSortedIndex;
  1348. }
  1349. return a.zIndex - b.zIndex;
  1350. }
  1351. /**
  1352. * Container is a general-purpose display object that holds children. It also adds built-in support for advanced
  1353. * rendering features like masking and filtering.
  1354. *
  1355. * It is the base class of all display objects that act as a container for other objects, including Graphics
  1356. * and Sprite.
  1357. *
  1358. * ```js
  1359. * import { BlurFilter } from '@pixi/filter-blur';
  1360. * import { Container } from '@pixi/display';
  1361. * import { Graphics } from '@pixi/graphics';
  1362. * import { Sprite } from '@pixi/sprite';
  1363. *
  1364. * let container = new Container();
  1365. * let sprite = Sprite.from("https://s3-us-west-2.amazonaws.com/s.cdpn.io/693612/IaUrttj.png");
  1366. *
  1367. * sprite.width = 512;
  1368. * sprite.height = 512;
  1369. *
  1370. * // Adds a sprite as a child to this container. As a result, the sprite will be rendered whenever the container
  1371. * // is rendered.
  1372. * container.addChild(sprite);
  1373. *
  1374. * // Blurs whatever is rendered by the container
  1375. * container.filters = [new BlurFilter()];
  1376. *
  1377. * // Only the contents within a circle at the center should be rendered onto the screen.
  1378. * container.mask = new Graphics()
  1379. * .beginFill(0xffffff)
  1380. * .drawCircle(sprite.width / 2, sprite.height / 2, Math.min(sprite.width, sprite.height) / 2)
  1381. * .endFill();
  1382. * ```
  1383. * @memberof PIXI
  1384. */
  1385. var Container = /** @class */ (function (_super) {
  1386. __extends(Container, _super);
  1387. function Container() {
  1388. var _this = _super.call(this) || this;
  1389. _this.children = [];
  1390. _this.sortableChildren = settings.settings.SORTABLE_CHILDREN;
  1391. _this.sortDirty = false;
  1392. return _this;
  1393. /**
  1394. * Fired when a DisplayObject is added to this Container.
  1395. * @event PIXI.Container#childAdded
  1396. * @param {PIXI.DisplayObject} child - The child added to the Container.
  1397. * @param {PIXI.Container} container - The container that added the child.
  1398. * @param {number} index - The children's index of the added child.
  1399. */
  1400. /**
  1401. * Fired when a DisplayObject is removed from this Container.
  1402. * @event PIXI.DisplayObject#childRemoved
  1403. * @param {PIXI.DisplayObject} child - The child removed from the Container.
  1404. * @param {PIXI.Container} container - The container that removed the child.
  1405. * @param {number} index - The former children's index of the removed child
  1406. */
  1407. }
  1408. /**
  1409. * Overridable method that can be used by Container subclasses whenever the children array is modified.
  1410. * @param _length
  1411. */
  1412. Container.prototype.onChildrenChange = function (_length) {
  1413. /* empty */
  1414. };
  1415. /**
  1416. * Adds one or more children to the container.
  1417. *
  1418. * Multiple items can be added like so: `myContainer.addChild(thingOne, thingTwo, thingThree)`
  1419. * @param {...PIXI.DisplayObject} children - The DisplayObject(s) to add to the container
  1420. * @returns {PIXI.DisplayObject} - The first child that was added.
  1421. */
  1422. Container.prototype.addChild = function () {
  1423. var arguments$1 = arguments;
  1424. var children = [];
  1425. for (var _i = 0; _i < arguments.length; _i++) {
  1426. children[_i] = arguments$1[_i];
  1427. }
  1428. // if there is only one argument we can bypass looping through the them
  1429. if (children.length > 1) {
  1430. // loop through the array and add all children
  1431. for (var i = 0; i < children.length; i++) {
  1432. // eslint-disable-next-line prefer-rest-params
  1433. this.addChild(children[i]);
  1434. }
  1435. }
  1436. else {
  1437. var child = children[0];
  1438. // if the child has a parent then lets remove it as PixiJS objects can only exist in one place
  1439. if (child.parent) {
  1440. child.parent.removeChild(child);
  1441. }
  1442. child.parent = this;
  1443. this.sortDirty = true;
  1444. // ensure child transform will be recalculated
  1445. child.transform._parentID = -1;
  1446. this.children.push(child);
  1447. // ensure bounds will be recalculated
  1448. this._boundsID++;
  1449. // TODO - lets either do all callbacks or all events.. not both!
  1450. this.onChildrenChange(this.children.length - 1);
  1451. this.emit('childAdded', child, this, this.children.length - 1);
  1452. child.emit('added', this);
  1453. }
  1454. return children[0];
  1455. };
  1456. /**
  1457. * Adds a child to the container at a specified index. If the index is out of bounds an error will be thrown
  1458. * @param {PIXI.DisplayObject} child - The child to add
  1459. * @param {number} index - The index to place the child in
  1460. * @returns {PIXI.DisplayObject} The child that was added.
  1461. */
  1462. Container.prototype.addChildAt = function (child, index) {
  1463. if (index < 0 || index > this.children.length) {
  1464. throw new Error(child + "addChildAt: The index " + index + " supplied is out of bounds " + this.children.length);
  1465. }
  1466. if (child.parent) {
  1467. child.parent.removeChild(child);
  1468. }
  1469. child.parent = this;
  1470. this.sortDirty = true;
  1471. // ensure child transform will be recalculated
  1472. child.transform._parentID = -1;
  1473. this.children.splice(index, 0, child);
  1474. // ensure bounds will be recalculated
  1475. this._boundsID++;
  1476. // TODO - lets either do all callbacks or all events.. not both!
  1477. this.onChildrenChange(index);
  1478. child.emit('added', this);
  1479. this.emit('childAdded', child, this, index);
  1480. return child;
  1481. };
  1482. /**
  1483. * Swaps the position of 2 Display Objects within this container.
  1484. * @param child - First display object to swap
  1485. * @param child2 - Second display object to swap
  1486. */
  1487. Container.prototype.swapChildren = function (child, child2) {
  1488. if (child === child2) {
  1489. return;
  1490. }
  1491. var index1 = this.getChildIndex(child);
  1492. var index2 = this.getChildIndex(child2);
  1493. this.children[index1] = child2;
  1494. this.children[index2] = child;
  1495. this.onChildrenChange(index1 < index2 ? index1 : index2);
  1496. };
  1497. /**
  1498. * Returns the index position of a child DisplayObject instance
  1499. * @param child - The DisplayObject instance to identify
  1500. * @returns - The index position of the child display object to identify
  1501. */
  1502. Container.prototype.getChildIndex = function (child) {
  1503. var index = this.children.indexOf(child);
  1504. if (index === -1) {
  1505. throw new Error('The supplied DisplayObject must be a child of the caller');
  1506. }
  1507. return index;
  1508. };
  1509. /**
  1510. * Changes the position of an existing child in the display object container
  1511. * @param child - The child DisplayObject instance for which you want to change the index number
  1512. * @param index - The resulting index number for the child display object
  1513. */
  1514. Container.prototype.setChildIndex = function (child, index) {
  1515. if (index < 0 || index >= this.children.length) {
  1516. throw new Error("The index " + index + " supplied is out of bounds " + this.children.length);
  1517. }
  1518. var currentIndex = this.getChildIndex(child);
  1519. utils.removeItems(this.children, currentIndex, 1); // remove from old position
  1520. this.children.splice(index, 0, child); // add at new position
  1521. this.onChildrenChange(index);
  1522. };
  1523. /**
  1524. * Returns the child at the specified index
  1525. * @param index - The index to get the child at
  1526. * @returns - The child at the given index, if any.
  1527. */
  1528. Container.prototype.getChildAt = function (index) {
  1529. if (index < 0 || index >= this.children.length) {
  1530. throw new Error("getChildAt: Index (" + index + ") does not exist.");
  1531. }
  1532. return this.children[index];
  1533. };
  1534. /**
  1535. * Removes one or more children from the container.
  1536. * @param {...PIXI.DisplayObject} children - The DisplayObject(s) to remove
  1537. * @returns {PIXI.DisplayObject} The first child that was removed.
  1538. */
  1539. Container.prototype.removeChild = function () {
  1540. var arguments$1 = arguments;
  1541. var children = [];
  1542. for (var _i = 0; _i < arguments.length; _i++) {
  1543. children[_i] = arguments$1[_i];
  1544. }
  1545. // if there is only one argument we can bypass looping through the them
  1546. if (children.length > 1) {
  1547. // loop through the arguments property and remove all children
  1548. for (var i = 0; i < children.length; i++) {
  1549. this.removeChild(children[i]);
  1550. }
  1551. }
  1552. else {
  1553. var child = children[0];
  1554. var index = this.children.indexOf(child);
  1555. if (index === -1)
  1556. { return null; }
  1557. child.parent = null;
  1558. // ensure child transform will be recalculated
  1559. child.transform._parentID = -1;
  1560. utils.removeItems(this.children, index, 1);
  1561. // ensure bounds will be recalculated
  1562. this._boundsID++;
  1563. // TODO - lets either do all callbacks or all events.. not both!
  1564. this.onChildrenChange(index);
  1565. child.emit('removed', this);
  1566. this.emit('childRemoved', child, this, index);
  1567. }
  1568. return children[0];
  1569. };
  1570. /**
  1571. * Removes a child from the specified index position.
  1572. * @param index - The index to get the child from
  1573. * @returns The child that was removed.
  1574. */
  1575. Container.prototype.removeChildAt = function (index) {
  1576. var child = this.getChildAt(index);
  1577. // ensure child transform will be recalculated..
  1578. child.parent = null;
  1579. child.transform._parentID = -1;
  1580. utils.removeItems(this.children, index, 1);
  1581. // ensure bounds will be recalculated
  1582. this._boundsID++;
  1583. // TODO - lets either do all callbacks or all events.. not both!
  1584. this.onChildrenChange(index);
  1585. child.emit('removed', this);
  1586. this.emit('childRemoved', child, this, index);
  1587. return child;
  1588. };
  1589. /**
  1590. * Removes all children from this container that are within the begin and end indexes.
  1591. * @param beginIndex - The beginning position.
  1592. * @param endIndex - The ending position. Default value is size of the container.
  1593. * @returns - List of removed children
  1594. */
  1595. Container.prototype.removeChildren = function (beginIndex, endIndex) {
  1596. if (beginIndex === void 0) { beginIndex = 0; }
  1597. if (endIndex === void 0) { endIndex = this.children.length; }
  1598. var begin = beginIndex;
  1599. var end = endIndex;
  1600. var range = end - begin;
  1601. var removed;
  1602. if (range > 0 && range <= end) {
  1603. removed = this.children.splice(begin, range);
  1604. for (var i = 0; i < removed.length; ++i) {
  1605. removed[i].parent = null;
  1606. if (removed[i].transform) {
  1607. removed[i].transform._parentID = -1;
  1608. }
  1609. }
  1610. this._boundsID++;
  1611. this.onChildrenChange(beginIndex);
  1612. for (var i = 0; i < removed.length; ++i) {
  1613. removed[i].emit('removed', this);
  1614. this.emit('childRemoved', removed[i], this, i);
  1615. }
  1616. return removed;
  1617. }
  1618. else if (range === 0 && this.children.length === 0) {
  1619. return [];
  1620. }
  1621. throw new RangeError('removeChildren: numeric values are outside the acceptable range.');
  1622. };
  1623. /** Sorts children by zIndex. Previous order is maintained for 2 children with the same zIndex. */
  1624. Container.prototype.sortChildren = function () {
  1625. var sortRequired = false;
  1626. for (var i = 0, j = this.children.length; i < j; ++i) {
  1627. var child = this.children[i];
  1628. child._lastSortedIndex = i;
  1629. if (!sortRequired && child.zIndex !== 0) {
  1630. sortRequired = true;
  1631. }
  1632. }
  1633. if (sortRequired && this.children.length > 1) {
  1634. this.children.sort(sortChildren);
  1635. }
  1636. this.sortDirty = false;
  1637. };
  1638. /** Updates the transform on all children of this container for rendering. */
  1639. Container.prototype.updateTransform = function () {
  1640. if (this.sortableChildren && this.sortDirty) {
  1641. this.sortChildren();
  1642. }
  1643. this._boundsID++;
  1644. this.transform.updateTransform(this.parent.transform);
  1645. // TODO: check render flags, how to process stuff here
  1646. this.worldAlpha = this.alpha * this.parent.worldAlpha;
  1647. for (var i = 0, j = this.children.length; i < j; ++i) {
  1648. var child = this.children[i];
  1649. if (child.visible) {
  1650. child.updateTransform();
  1651. }
  1652. }
  1653. };
  1654. /**
  1655. * Recalculates the bounds of the container.
  1656. *
  1657. * This implementation will automatically fit the children's bounds into the calculation. Each child's bounds
  1658. * is limited to its mask's bounds or filterArea, if any is applied.
  1659. */
  1660. Container.prototype.calculateBounds = function () {
  1661. this._bounds.clear();
  1662. this._calculateBounds();
  1663. for (var i = 0; i < this.children.length; i++) {
  1664. var child = this.children[i];
  1665. if (!child.visible || !child.renderable) {
  1666. continue;
  1667. }
  1668. child.calculateBounds();
  1669. // TODO: filter+mask, need to mask both somehow
  1670. if (child._mask) {
  1671. var maskObject = (child._mask.isMaskData
  1672. ? child._mask.maskObject : child._mask);
  1673. if (maskObject) {
  1674. maskObject.calculateBounds();
  1675. this._bounds.addBoundsMask(child._bounds, maskObject._bounds);
  1676. }
  1677. else {
  1678. this._bounds.addBounds(child._bounds);
  1679. }
  1680. }
  1681. else if (child.filterArea) {
  1682. this._bounds.addBoundsArea(child._bounds, child.filterArea);
  1683. }
  1684. else {
  1685. this._bounds.addBounds(child._bounds);
  1686. }
  1687. }
  1688. this._bounds.updateID = this._boundsID;
  1689. };
  1690. /**
  1691. * Retrieves the local bounds of the displayObject as a rectangle object.
  1692. *
  1693. * Calling `getLocalBounds` may invalidate the `_bounds` of the whole subtree below. If using it inside a render()
  1694. * call, it is advised to call `getBounds()` immediately after to recalculate the world bounds of the subtree.
  1695. * @param rect - Optional rectangle to store the result of the bounds calculation.
  1696. * @param skipChildrenUpdate - Setting to `true` will stop re-calculation of children transforms,
  1697. * it was default behaviour of pixi 4.0-5.2 and caused many problems to users.
  1698. * @returns - The rectangular bounding area.
  1699. */
  1700. Container.prototype.getLocalBounds = function (rect, skipChildrenUpdate) {
  1701. if (skipChildrenUpdate === void 0) { skipChildrenUpdate = false; }
  1702. var result = _super.prototype.getLocalBounds.call(this, rect);
  1703. if (!skipChildrenUpdate) {
  1704. for (var i = 0, j = this.children.length; i < j; ++i) {
  1705. var child = this.children[i];
  1706. if (child.visible) {
  1707. child.updateTransform();
  1708. }
  1709. }
  1710. }
  1711. return result;
  1712. };
  1713. /**
  1714. * Recalculates the content bounds of this object. This should be overriden to
  1715. * calculate the bounds of this specific object (not including children).
  1716. * @protected
  1717. */
  1718. Container.prototype._calculateBounds = function () {
  1719. // FILL IN//
  1720. };
  1721. /**
  1722. * Renders this object and its children with culling.
  1723. * @protected
  1724. * @param {PIXI.Renderer} renderer - The renderer
  1725. */
  1726. Container.prototype._renderWithCulling = function (renderer) {
  1727. var sourceFrame = renderer.renderTexture.sourceFrame;
  1728. // If the source frame is empty, stop rendering.
  1729. if (!(sourceFrame.width > 0 && sourceFrame.height > 0)) {
  1730. return;
  1731. }
  1732. // Render the content of the container only if its bounds intersect with the source frame.
  1733. // All filters are on the stack at this point, and the filter source frame is bound:
  1734. // therefore, even if the bounds to non intersect the filter frame, the filter
  1735. // is still applied and any filter padding that is in the frame is rendered correctly.
  1736. var bounds;
  1737. var transform;
  1738. // If cullArea is set, we use this rectangle instead of the bounds of the object. The cullArea
  1739. // rectangle must completely contain the container and its children including filter padding.
  1740. if (this.cullArea) {
  1741. bounds = this.cullArea;
  1742. transform = this.worldTransform;
  1743. }
  1744. // If the container doesn't override _render, we can skip the bounds calculation and intersection test.
  1745. else if (this._render !== Container.prototype._render) {
  1746. bounds = this.getBounds(true);
  1747. }
  1748. // Render the container if the source frame intersects the bounds.
  1749. if (bounds && sourceFrame.intersects(bounds, transform)) {
  1750. this._render(renderer);
  1751. }
  1752. // If the bounds are defined by cullArea and do not intersect with the source frame, stop rendering.
  1753. else if (this.cullArea) {
  1754. return;
  1755. }
  1756. // Unless cullArea is set, we cannot skip the children if the bounds of the container do not intersect
  1757. // the source frame, because the children might have filters with nonzero padding, which may intersect
  1758. // with the source frame while the bounds do not: filter padding is not included in the bounds.
  1759. // If cullArea is not set, render the children with culling temporarily enabled so that they are not rendered
  1760. // if they are out of frame; otherwise, render the children normally.
  1761. for (var i = 0, j = this.children.length; i < j; ++i) {
  1762. var child = this.children[i];
  1763. var childCullable = child.cullable;
  1764. child.cullable = childCullable || !this.cullArea;
  1765. child.render(renderer);
  1766. child.cullable = childCullable;
  1767. }
  1768. };
  1769. /**
  1770. * Renders the object using the WebGL renderer.
  1771. *
  1772. * The [_render]{@link PIXI.Container#_render} method is be overriden for rendering the contents of the
  1773. * container itself. This `render` method will invoke it, and also invoke the `render` methods of all
  1774. * children afterward.
  1775. *
  1776. * If `renderable` or `visible` is false or if `worldAlpha` is not positive or if `cullable` is true and
  1777. * the bounds of this object are out of frame, this implementation will entirely skip rendering.
  1778. * See {@link PIXI.DisplayObject} for choosing between `renderable` or `visible`. Generally,
  1779. * setting alpha to zero is not recommended for purely skipping rendering.
  1780. *
  1781. * When your scene becomes large (especially when it is larger than can be viewed in a single screen), it is
  1782. * advised to employ **culling** to automatically skip rendering objects outside of the current screen.
  1783. * See [cullable]{@link PIXI.DisplayObject#cullable} and [cullArea]{@link PIXI.DisplayObject#cullArea}.
  1784. * Other culling methods might be better suited for a large number static objects; see
  1785. * [@pixi-essentials/cull]{@link https://www.npmjs.com/package/@pixi-essentials/cull} and
  1786. * [pixi-cull]{@link https://www.npmjs.com/package/pixi-cull}.
  1787. *
  1788. * The [renderAdvanced]{@link PIXI.Container#renderAdvanced} method is internally used when when masking or
  1789. * filtering is applied on a container. This does, however, break batching and can affect performance when
  1790. * masking and filtering is applied extensively throughout the scene graph.
  1791. * @param renderer - The renderer
  1792. */
  1793. Container.prototype.render = function (renderer) {
  1794. // if the object is not visible or the alpha is 0 then no need to render this element
  1795. if (!this.visible || this.worldAlpha <= 0 || !this.renderable) {
  1796. return;
  1797. }
  1798. // do a quick check to see if this element has a mask or a filter.
  1799. if (this._mask || (this.filters && this.filters.length)) {
  1800. this.renderAdvanced(renderer);
  1801. }
  1802. else if (this.cullable) {
  1803. this._renderWithCulling(renderer);
  1804. }
  1805. else {
  1806. this._render(renderer);
  1807. for (var i = 0, j = this.children.length; i < j; ++i) {
  1808. this.children[i].render(renderer);
  1809. }
  1810. }
  1811. };
  1812. /**
  1813. * Render the object using the WebGL renderer and advanced features.
  1814. * @param renderer - The renderer
  1815. */
  1816. Container.prototype.renderAdvanced = function (renderer) {
  1817. var filters = this.filters;
  1818. var mask = this._mask;
  1819. // push filter first as we need to ensure the stencil buffer is correct for any masking
  1820. if (filters) {
  1821. if (!this._enabledFilters) {
  1822. this._enabledFilters = [];
  1823. }
  1824. this._enabledFilters.length = 0;
  1825. for (var i = 0; i < filters.length; i++) {
  1826. if (filters[i].enabled) {
  1827. this._enabledFilters.push(filters[i]);
  1828. }
  1829. }
  1830. }
  1831. var flush = (filters && this._enabledFilters && this._enabledFilters.length)
  1832. || (mask && (!mask.isMaskData
  1833. || (mask.enabled && (mask.autoDetect || mask.type !== constants.MASK_TYPES.NONE))));
  1834. if (flush) {
  1835. renderer.batch.flush();
  1836. }
  1837. if (filters && this._enabledFilters && this._enabledFilters.length) {
  1838. renderer.filter.push(this, this._enabledFilters);
  1839. }
  1840. if (mask) {
  1841. renderer.mask.push(this, this._mask);
  1842. }
  1843. if (this.cullable) {
  1844. this._renderWithCulling(renderer);
  1845. }
  1846. else {
  1847. this._render(renderer);
  1848. for (var i = 0, j = this.children.length; i < j; ++i) {
  1849. this.children[i].render(renderer);
  1850. }
  1851. }
  1852. if (flush) {
  1853. renderer.batch.flush();
  1854. }
  1855. if (mask) {
  1856. renderer.mask.pop(this);
  1857. }
  1858. if (filters && this._enabledFilters && this._enabledFilters.length) {
  1859. renderer.filter.pop();
  1860. }
  1861. };
  1862. /**
  1863. * To be overridden by the subclasses.
  1864. * @param _renderer - The renderer
  1865. */
  1866. Container.prototype._render = function (_renderer) {
  1867. // this is where content itself gets rendered...
  1868. };
  1869. /**
  1870. * Removes all internal references and listeners as well as removes children from the display list.
  1871. * Do not use a Container after calling `destroy`.
  1872. * @param options - Options parameter. A boolean will act as if all options
  1873. * have been set to that value
  1874. * @param {boolean} [options.children=false] - if set to true, all the children will have their destroy
  1875. * method called as well. 'options' will be passed on to those calls.
  1876. * @param {boolean} [options.texture=false] - Only used for child Sprites if options.children is set to true
  1877. * Should it destroy the texture of the child sprite
  1878. * @param {boolean} [options.baseTexture=false] - Only used for child Sprites if options.children is set to true
  1879. * Should it destroy the base texture of the child sprite
  1880. */
  1881. Container.prototype.destroy = function (options) {
  1882. _super.prototype.destroy.call(this);
  1883. this.sortDirty = false;
  1884. var destroyChildren = typeof options === 'boolean' ? options : options && options.children;
  1885. var oldChildren = this.removeChildren(0, this.children.length);
  1886. if (destroyChildren) {
  1887. for (var i = 0; i < oldChildren.length; ++i) {
  1888. oldChildren[i].destroy(options);
  1889. }
  1890. }
  1891. };
  1892. Object.defineProperty(Container.prototype, "width", {
  1893. /** The width of the Container, setting this will actually modify the scale to achieve the value set. */
  1894. get: function () {
  1895. return this.scale.x * this.getLocalBounds().width;
  1896. },
  1897. set: function (value) {
  1898. var width = this.getLocalBounds().width;
  1899. if (width !== 0) {
  1900. this.scale.x = value / width;
  1901. }
  1902. else {
  1903. this.scale.x = 1;
  1904. }
  1905. this._width = value;
  1906. },
  1907. enumerable: false,
  1908. configurable: true
  1909. });
  1910. Object.defineProperty(Container.prototype, "height", {
  1911. /** The height of the Container, setting this will actually modify the scale to achieve the value set. */
  1912. get: function () {
  1913. return this.scale.y * this.getLocalBounds().height;
  1914. },
  1915. set: function (value) {
  1916. var height = this.getLocalBounds().height;
  1917. if (height !== 0) {
  1918. this.scale.y = value / height;
  1919. }
  1920. else {
  1921. this.scale.y = 1;
  1922. }
  1923. this._height = value;
  1924. },
  1925. enumerable: false,
  1926. configurable: true
  1927. });
  1928. return Container;
  1929. }(DisplayObject));
  1930. /**
  1931. * Container default updateTransform, does update children of container.
  1932. * Will crash if there's no parent element.
  1933. * @memberof PIXI.Container#
  1934. * @method containerUpdateTransform
  1935. */
  1936. Container.prototype.containerUpdateTransform = Container.prototype.updateTransform;
  1937. exports.Bounds = Bounds;
  1938. exports.Container = Container;
  1939. exports.DisplayObject = DisplayObject;
  1940. exports.TemporaryDisplayObject = TemporaryDisplayObject;
  1941. Object.defineProperty(exports, '__esModule', { value: true });
  1942. return exports;
  1943. })({}, PIXI, PIXI, PIXI.utils, PIXI);
  1944. Object.assign(this.PIXI, _pixi_display);
  1945. //# sourceMappingURL=display.js.map