display.mjs 72 KB

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