babylon.prim2dBase.js 124 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771
  1. var __extends = (this && this.__extends) || function (d, b) {
  2. for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  3. function __() { this.constructor = d; }
  4. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  5. };
  6. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  7. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  8. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  9. else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  10. return c > 3 && r && Object.defineProperty(target, key, r), r;
  11. };
  12. var BABYLON;
  13. (function (BABYLON) {
  14. var PrepareRender2DContext = (function () {
  15. function PrepareRender2DContext() {
  16. this.forceRefreshPrimitive = false;
  17. }
  18. return PrepareRender2DContext;
  19. }());
  20. BABYLON.PrepareRender2DContext = PrepareRender2DContext;
  21. var Render2DContext = (function () {
  22. function Render2DContext(renderMode) {
  23. this._renderMode = renderMode;
  24. this.useInstancing = false;
  25. this.groupInfoPartData = null;
  26. this.partDataStartIndex = this.partDataEndIndex = null;
  27. this.instancedBuffers = null;
  28. }
  29. Object.defineProperty(Render2DContext.prototype, "renderMode", {
  30. /**
  31. * Define which render Mode should be used to render the primitive: one of Render2DContext.RenderModeXxxx property
  32. */
  33. get: function () {
  34. return this._renderMode;
  35. },
  36. enumerable: true,
  37. configurable: true
  38. });
  39. Object.defineProperty(Render2DContext, "RenderModeOpaque", {
  40. /**
  41. * The set of primitives to render is opaque.
  42. * This is the first rendering pass. All Opaque primitives are rendered. Depth Compare and Write are both enabled.
  43. */
  44. get: function () {
  45. return Render2DContext._renderModeOpaque;
  46. },
  47. enumerable: true,
  48. configurable: true
  49. });
  50. Object.defineProperty(Render2DContext, "RenderModeAlphaTest", {
  51. /**
  52. * The set of primitives to render is using Alpha Test (aka masking).
  53. * Alpha Blend is enabled, the AlphaMode must be manually set, the render occurs after the RenderModeOpaque and is depth independent (i.e. primitives are not sorted by depth). Depth Compare and Write are both enabled.
  54. */
  55. get: function () {
  56. return Render2DContext._renderModeAlphaTest;
  57. },
  58. enumerable: true,
  59. configurable: true
  60. });
  61. Object.defineProperty(Render2DContext, "RenderModeTransparent", {
  62. /**
  63. * The set of primitives to render is transparent.
  64. * Alpha Blend is enabled, the AlphaMode must be manually set, the render occurs after the RenderModeAlphaTest and is depth dependent (i.e. primitives are stored by depth and rendered back to front). Depth Compare is on, but Depth write is Off.
  65. */
  66. get: function () {
  67. return Render2DContext._renderModeTransparent;
  68. },
  69. enumerable: true,
  70. configurable: true
  71. });
  72. Render2DContext._renderModeOpaque = 1;
  73. Render2DContext._renderModeAlphaTest = 2;
  74. Render2DContext._renderModeTransparent = 3;
  75. return Render2DContext;
  76. }());
  77. BABYLON.Render2DContext = Render2DContext;
  78. /**
  79. * This class store information for the pointerEventObservable Observable.
  80. * The Observable is divided into many sub events (using the Mask feature of the Observable pattern): PointerOver, PointerEnter, PointerDown, PointerMouseWheel, PointerMove, PointerUp, PointerDown, PointerLeave, PointerGotCapture and PointerLostCapture.
  81. */
  82. var PrimitivePointerInfo = (function () {
  83. function PrimitivePointerInfo() {
  84. this.primitivePointerPos = BABYLON.Vector2.Zero();
  85. this.tilt = BABYLON.Vector2.Zero();
  86. this.cancelBubble = false;
  87. }
  88. Object.defineProperty(PrimitivePointerInfo, "PointerOver", {
  89. // The behavior is based on the HTML specifications of the Pointer Events (https://www.w3.org/TR/pointerevents/#list-of-pointer-events). This is not 100% compliant and not meant to be, but still, it's based on these specs for most use cases to be programmed the same way (as closest as possible) as it would have been in HTML.
  90. /**
  91. * This event type is raised when a pointing device is moved into the hit test boundaries of a primitive.
  92. * Bubbles: yes
  93. */
  94. get: function () {
  95. return PrimitivePointerInfo._pointerOver;
  96. },
  97. enumerable: true,
  98. configurable: true
  99. });
  100. Object.defineProperty(PrimitivePointerInfo, "PointerEnter", {
  101. /**
  102. * This event type is raised when a pointing device is moved into the hit test boundaries of a primitive or one of its descendants.
  103. * Bubbles: no
  104. */
  105. get: function () {
  106. return PrimitivePointerInfo._pointerEnter;
  107. },
  108. enumerable: true,
  109. configurable: true
  110. });
  111. Object.defineProperty(PrimitivePointerInfo, "PointerDown", {
  112. /**
  113. * This event type is raised when a pointer enters the active button state (non-zero value in the buttons property). For mouse it's when the device transitions from no buttons depressed to at least one button depressed. For touch/pen this is when a physical contact is made.
  114. * Bubbles: yes
  115. */
  116. get: function () {
  117. return PrimitivePointerInfo._pointerDown;
  118. },
  119. enumerable: true,
  120. configurable: true
  121. });
  122. Object.defineProperty(PrimitivePointerInfo, "PointerMouseWheel", {
  123. /**
  124. * This event type is raised when the pointer is a mouse and it's wheel is rolling
  125. * Bubbles: yes
  126. */
  127. get: function () {
  128. return PrimitivePointerInfo._pointerMouseWheel;
  129. },
  130. enumerable: true,
  131. configurable: true
  132. });
  133. Object.defineProperty(PrimitivePointerInfo, "PointerMove", {
  134. /**
  135. * This event type is raised when a pointer change coordinates or when a pointer changes button state, pressure, tilt, or contact geometry and the circumstances produce no other pointers events.
  136. * Bubbles: yes
  137. */
  138. get: function () {
  139. return PrimitivePointerInfo._pointerMove;
  140. },
  141. enumerable: true,
  142. configurable: true
  143. });
  144. Object.defineProperty(PrimitivePointerInfo, "PointerUp", {
  145. /**
  146. * This event type is raised when the pointer leaves the active buttons states (zero value in the buttons property). For mouse, this is when the device transitions from at least one button depressed to no buttons depressed. For touch/pen, this is when physical contact is removed.
  147. * Bubbles: yes
  148. */
  149. get: function () {
  150. return PrimitivePointerInfo._pointerUp;
  151. },
  152. enumerable: true,
  153. configurable: true
  154. });
  155. Object.defineProperty(PrimitivePointerInfo, "PointerOut", {
  156. /**
  157. * This event type is raised when a pointing device is moved out of the hit test the boundaries of a primitive.
  158. * Bubbles: yes
  159. */
  160. get: function () {
  161. return PrimitivePointerInfo._pointerOut;
  162. },
  163. enumerable: true,
  164. configurable: true
  165. });
  166. Object.defineProperty(PrimitivePointerInfo, "PointerLeave", {
  167. /**
  168. * This event type is raised when a pointing device is moved out of the hit test boundaries of a primitive and all its descendants.
  169. * Bubbles: no
  170. */
  171. get: function () {
  172. return PrimitivePointerInfo._pointerLeave;
  173. },
  174. enumerable: true,
  175. configurable: true
  176. });
  177. Object.defineProperty(PrimitivePointerInfo, "PointerGotCapture", {
  178. /**
  179. * This event type is raised when a primitive receives the pointer capture. This event is fired at the element that is receiving pointer capture. Subsequent events for that pointer will be fired at this element.
  180. * Bubbles: yes
  181. */
  182. get: function () {
  183. return PrimitivePointerInfo._pointerGotCapture;
  184. },
  185. enumerable: true,
  186. configurable: true
  187. });
  188. Object.defineProperty(PrimitivePointerInfo, "PointerLostCapture", {
  189. /**
  190. * This event type is raised after pointer capture is released for a pointer.
  191. * Bubbles: yes
  192. */
  193. get: function () {
  194. return PrimitivePointerInfo._pointerLostCapture;
  195. },
  196. enumerable: true,
  197. configurable: true
  198. });
  199. Object.defineProperty(PrimitivePointerInfo, "MouseWheelPrecision", {
  200. get: function () {
  201. return PrimitivePointerInfo._mouseWheelPrecision;
  202. },
  203. enumerable: true,
  204. configurable: true
  205. });
  206. PrimitivePointerInfo.prototype.updateRelatedTarget = function (prim, primPointerPos) {
  207. this.relatedTarget = prim;
  208. this.relatedTargetPointerPos = primPointerPos;
  209. };
  210. PrimitivePointerInfo.getEventTypeName = function (mask) {
  211. switch (mask) {
  212. case PrimitivePointerInfo.PointerOver: return "PointerOver";
  213. case PrimitivePointerInfo.PointerEnter: return "PointerEnter";
  214. case PrimitivePointerInfo.PointerDown: return "PointerDown";
  215. case PrimitivePointerInfo.PointerMouseWheel: return "PointerMouseWheel";
  216. case PrimitivePointerInfo.PointerMove: return "PointerMove";
  217. case PrimitivePointerInfo.PointerUp: return "PointerUp";
  218. case PrimitivePointerInfo.PointerOut: return "PointerOut";
  219. case PrimitivePointerInfo.PointerLeave: return "PointerLeave";
  220. case PrimitivePointerInfo.PointerGotCapture: return "PointerGotCapture";
  221. case PrimitivePointerInfo.PointerLostCapture: return "PointerLostCapture";
  222. }
  223. };
  224. PrimitivePointerInfo._pointerOver = 0x0001;
  225. PrimitivePointerInfo._pointerEnter = 0x0002;
  226. PrimitivePointerInfo._pointerDown = 0x0004;
  227. PrimitivePointerInfo._pointerMouseWheel = 0x0008;
  228. PrimitivePointerInfo._pointerMove = 0x0010;
  229. PrimitivePointerInfo._pointerUp = 0x0020;
  230. PrimitivePointerInfo._pointerOut = 0x0040;
  231. PrimitivePointerInfo._pointerLeave = 0x0080;
  232. PrimitivePointerInfo._pointerGotCapture = 0x0100;
  233. PrimitivePointerInfo._pointerLostCapture = 0x0200;
  234. PrimitivePointerInfo._mouseWheelPrecision = 3.0;
  235. return PrimitivePointerInfo;
  236. }());
  237. BABYLON.PrimitivePointerInfo = PrimitivePointerInfo;
  238. /**
  239. * Defines the horizontal and vertical alignment information for a Primitive.
  240. */
  241. var PrimitiveAlignment = (function () {
  242. function PrimitiveAlignment(changeCallback) {
  243. this._changedCallback = changeCallback;
  244. this._horizontal = PrimitiveAlignment.AlignLeft;
  245. this._vertical = PrimitiveAlignment.AlignBottom;
  246. }
  247. Object.defineProperty(PrimitiveAlignment, "AlignLeft", {
  248. /**
  249. * Alignment is made relative to the left edge of the Primitive. Valid for horizontal alignment only.
  250. */
  251. get: function () { return PrimitiveAlignment._AlignLeft; },
  252. enumerable: true,
  253. configurable: true
  254. });
  255. Object.defineProperty(PrimitiveAlignment, "AlignTop", {
  256. /**
  257. * Alignment is made relative to the top edge of the Primitive. Valid for vertical alignment only.
  258. */
  259. get: function () { return PrimitiveAlignment._AlignTop; },
  260. enumerable: true,
  261. configurable: true
  262. });
  263. Object.defineProperty(PrimitiveAlignment, "AlignRight", {
  264. /**
  265. * Alignment is made relative to the right edge of the Primitive. Valid for horizontal alignment only.
  266. */
  267. get: function () { return PrimitiveAlignment._AlignRight; },
  268. enumerable: true,
  269. configurable: true
  270. });
  271. Object.defineProperty(PrimitiveAlignment, "AlignBottom", {
  272. /**
  273. * Alignment is made relative to the bottom edge of the Primitive. Valid for vertical alignment only.
  274. */
  275. get: function () { return PrimitiveAlignment._AlignBottom; },
  276. enumerable: true,
  277. configurable: true
  278. });
  279. Object.defineProperty(PrimitiveAlignment, "AlignCenter", {
  280. /**
  281. * Alignment is made to center the content from equal distance to the opposite edges of the Primitive
  282. */
  283. get: function () { return PrimitiveAlignment._AlignCenter; },
  284. enumerable: true,
  285. configurable: true
  286. });
  287. Object.defineProperty(PrimitiveAlignment, "AlignStretch", {
  288. /**
  289. * The content is stretched toward the opposite edges of the Primitive
  290. */
  291. get: function () { return PrimitiveAlignment._AlignStretch; },
  292. enumerable: true,
  293. configurable: true
  294. });
  295. Object.defineProperty(PrimitiveAlignment.prototype, "horizontal", {
  296. /**
  297. * Get/set the horizontal alignment. Use one of the AlignXXX static properties of this class
  298. */
  299. get: function () {
  300. return this._horizontal;
  301. },
  302. set: function (value) {
  303. if (this._horizontal === value) {
  304. return;
  305. }
  306. this._horizontal = value;
  307. this._changedCallback();
  308. },
  309. enumerable: true,
  310. configurable: true
  311. });
  312. Object.defineProperty(PrimitiveAlignment.prototype, "vertical", {
  313. /**
  314. * Get/set the vertical alignment. Use one of the AlignXXX static properties of this class
  315. */
  316. get: function () {
  317. return this._vertical;
  318. },
  319. set: function (value) {
  320. if (this._vertical === value) {
  321. return;
  322. }
  323. this._vertical = value;
  324. this._changedCallback();
  325. },
  326. enumerable: true,
  327. configurable: true
  328. });
  329. /**
  330. * Set the horizontal alignment from a string value.
  331. * @param text can be either: 'left','right','center','stretch'
  332. */
  333. PrimitiveAlignment.prototype.setHorizontal = function (text) {
  334. var v = text.trim().toLocaleLowerCase();
  335. switch (v) {
  336. case "left":
  337. this.horizontal = PrimitiveAlignment.AlignLeft;
  338. return;
  339. case "right":
  340. this.horizontal = PrimitiveAlignment.AlignRight;
  341. return;
  342. case "center":
  343. this.horizontal = PrimitiveAlignment.AlignCenter;
  344. return;
  345. case "stretch":
  346. this.horizontal = PrimitiveAlignment.AlignStretch;
  347. return;
  348. }
  349. };
  350. /**
  351. * Set the vertical alignment from a string value.
  352. * @param text can be either: 'top','bottom','center','stretch'
  353. */
  354. PrimitiveAlignment.prototype.setVertical = function (text) {
  355. var v = text.trim().toLocaleLowerCase();
  356. switch (v) {
  357. case "top":
  358. this.vertical = PrimitiveAlignment.AlignTop;
  359. return;
  360. case "bottom":
  361. this.vertical = PrimitiveAlignment.AlignBottom;
  362. return;
  363. case "center":
  364. this.vertical = PrimitiveAlignment.AlignCenter;
  365. return;
  366. case "stretch":
  367. this.vertical = PrimitiveAlignment.AlignStretch;
  368. return;
  369. }
  370. };
  371. /**
  372. * Set the horizontal and or vertical alignments from a string value.
  373. * @param text can be: [<h:|horizontal:><left|right|center|stretch>], [<v:|vertical:><top|bottom|center|stretch>]
  374. */
  375. PrimitiveAlignment.prototype.fromString = function (value) {
  376. var m = value.trim().split(",");
  377. for (var _i = 0, m_1 = m; _i < m_1.length; _i++) {
  378. var v = m_1[_i];
  379. v = v.toLocaleLowerCase().trim();
  380. // Horizontal
  381. var i = v.indexOf("h:");
  382. if (i === -1) {
  383. i = v.indexOf("horizontal:");
  384. }
  385. if (i !== -1) {
  386. v = v.substr(v.indexOf(":") + 1);
  387. this.setHorizontal(v);
  388. continue;
  389. }
  390. // Vertical
  391. i = v.indexOf("v:");
  392. if (i === -1) {
  393. i = v.indexOf("vertical:");
  394. }
  395. if (i !== -1) {
  396. v = v.substr(v.indexOf(":") + 1);
  397. this.setVertical(v);
  398. continue;
  399. }
  400. }
  401. };
  402. PrimitiveAlignment._AlignLeft = 1;
  403. PrimitiveAlignment._AlignTop = 1; // Same as left
  404. PrimitiveAlignment._AlignRight = 2;
  405. PrimitiveAlignment._AlignBottom = 2; // Same as right
  406. PrimitiveAlignment._AlignCenter = 3;
  407. PrimitiveAlignment._AlignStretch = 4;
  408. return PrimitiveAlignment;
  409. }());
  410. BABYLON.PrimitiveAlignment = PrimitiveAlignment;
  411. /**
  412. * Stores information about a Primitive that was intersected
  413. */
  414. var PrimitiveIntersectedInfo = (function () {
  415. function PrimitiveIntersectedInfo(prim, intersectionLocation) {
  416. this.prim = prim;
  417. this.intersectionLocation = intersectionLocation;
  418. }
  419. return PrimitiveIntersectedInfo;
  420. }());
  421. BABYLON.PrimitiveIntersectedInfo = PrimitiveIntersectedInfo;
  422. /**
  423. * Define a thickness toward every edges of a Primitive to allow margin and padding.
  424. * The thickness can be expressed as pixels, percentages, inherit the value of the parent primitive or be auto.
  425. */
  426. var PrimitiveThickness = (function () {
  427. function PrimitiveThickness(parentAccess, changedCallback) {
  428. this._parentAccess = parentAccess;
  429. this._changedCallback = changedCallback;
  430. this._pixels = new Array(4);
  431. this._percentages = new Array(4);
  432. this._setType(0, PrimitiveThickness.Auto);
  433. this._setType(1, PrimitiveThickness.Auto);
  434. this._setType(2, PrimitiveThickness.Auto);
  435. this._setType(3, PrimitiveThickness.Auto);
  436. this._pixels[0] = 0;
  437. this._pixels[1] = 0;
  438. this._pixels[2] = 0;
  439. this._pixels[3] = 0;
  440. }
  441. /**
  442. * Set the thickness from a string value
  443. * @param thickness format is "top: <value>, left:<value>, right:<value>, bottom:<value>" or "<value>" (same for all edges) each are optional, auto will be set if it's omitted.
  444. * Values are: 'auto', 'inherit', 'XX%' for percentage, 'XXpx' or 'XX' for pixels.
  445. */
  446. PrimitiveThickness.prototype.fromString = function (thickness) {
  447. this._clear();
  448. var m = thickness.trim().split(",");
  449. // Special case, one value to apply to all edges
  450. if (m.length === 1 && thickness.indexOf(":") === -1) {
  451. this._setStringValue(m[0], 0, false);
  452. this._setStringValue(m[0], 1, false);
  453. this._setStringValue(m[0], 2, false);
  454. this._setStringValue(m[0], 3, false);
  455. this._changedCallback();
  456. return;
  457. }
  458. var res = false;
  459. for (var _i = 0, m_2 = m; _i < m_2.length; _i++) {
  460. var cm = m_2[_i];
  461. res = this._extractString(cm, false) || res;
  462. }
  463. if (!res) {
  464. throw new Error("Can't parse the string to create a PrimitiveMargin object, format must be: 'top: <value>, left:<value>, right:<value>, bottom:<value>");
  465. }
  466. // Check the margin that weren't set and set them in auto
  467. if ((this._flags & 0x000F) === 0)
  468. this._flags |= PrimitiveThickness.Pixel << 0;
  469. if ((this._flags & 0x00F0) === 0)
  470. this._flags |= PrimitiveThickness.Pixel << 4;
  471. if ((this._flags & 0x0F00) === 0)
  472. this._flags |= PrimitiveThickness.Pixel << 8;
  473. if ((this._flags & 0xF000) === 0)
  474. this._flags |= PrimitiveThickness.Pixel << 12;
  475. this._changedCallback();
  476. };
  477. /**
  478. * Set the thickness from multiple string
  479. * Possible values are: 'auto', 'inherit', 'XX%' for percentage, 'XXpx' or 'XX' for pixels.
  480. * @param top the top thickness to set
  481. * @param left the left thickness to set
  482. * @param right the right thickness to set
  483. * @param bottom the bottom thickness to set
  484. */
  485. PrimitiveThickness.prototype.fromStrings = function (top, left, right, bottom) {
  486. this._clear();
  487. this._setStringValue(top, 0, false);
  488. this._setStringValue(left, 1, false);
  489. this._setStringValue(right, 2, false);
  490. this._setStringValue(bottom, 3, false);
  491. this._changedCallback();
  492. return this;
  493. };
  494. /**
  495. * Set the thickness from pixel values
  496. * @param top the top thickness in pixels to set
  497. * @param left the left thickness in pixels to set
  498. * @param right the right thickness in pixels to set
  499. * @param bottom the bottom thickness in pixels to set
  500. */
  501. PrimitiveThickness.prototype.fromPixels = function (top, left, right, bottom) {
  502. this._clear();
  503. this._pixels[0] = top;
  504. this._pixels[1] = left;
  505. this._pixels[2] = right;
  506. this._pixels[3] = bottom;
  507. this._changedCallback();
  508. return this;
  509. };
  510. /**
  511. * Apply the same pixel value to all edges
  512. * @param margin the value to set, in pixels.
  513. */
  514. PrimitiveThickness.prototype.fromUniformPixels = function (margin) {
  515. this._clear();
  516. this._pixels[0] = margin;
  517. this._pixels[1] = margin;
  518. this._pixels[2] = margin;
  519. this._pixels[3] = margin;
  520. this._changedCallback();
  521. return this;
  522. };
  523. /**
  524. * Set all edges in auto
  525. */
  526. PrimitiveThickness.prototype.auto = function () {
  527. this._clear();
  528. this._flags = (PrimitiveThickness.Auto << 0) | (PrimitiveThickness.Auto << 4) | (PrimitiveThickness.Auto << 8) | (PrimitiveThickness.Auto << 12);
  529. this._pixels[0] = 0;
  530. this._pixels[1] = 0;
  531. this._pixels[2] = 0;
  532. this._pixels[3] = 0;
  533. this._changedCallback();
  534. return this;
  535. };
  536. PrimitiveThickness.prototype._clear = function () {
  537. this._flags = 0;
  538. this._pixels[0] = 0;
  539. this._pixels[1] = 0;
  540. this._pixels[2] = 0;
  541. this._pixels[3] = 0;
  542. this._percentages[0] = null;
  543. this._percentages[1] = null;
  544. this._percentages[2] = null;
  545. this._percentages[3] = null;
  546. };
  547. PrimitiveThickness.prototype._extractString = function (value, emitChanged) {
  548. var v = value.trim().toLocaleLowerCase();
  549. if (v.indexOf("top:") === 0) {
  550. v = v.substr(4).trim();
  551. return this._setStringValue(v, 0, emitChanged);
  552. }
  553. if (v.indexOf("left:") === 0) {
  554. v = v.substr(5).trim();
  555. return this._setStringValue(v, 1, emitChanged);
  556. }
  557. if (v.indexOf("right:") === 0) {
  558. v = v.substr(6).trim();
  559. return this._setStringValue(v, 2, emitChanged);
  560. }
  561. if (v.indexOf("bottom:") === 0) {
  562. v = v.substr(7).trim();
  563. return this._setStringValue(v, 3, emitChanged);
  564. }
  565. return false;
  566. };
  567. PrimitiveThickness.prototype._setStringValue = function (value, index, emitChanged) {
  568. // Check for auto
  569. var v = value.trim().toLocaleLowerCase();
  570. if (v === "auto") {
  571. if (this._isType(index, PrimitiveThickness.Auto)) {
  572. return true;
  573. }
  574. this._setType(index, PrimitiveThickness.Auto);
  575. this._pixels[index] = 0;
  576. if (emitChanged) {
  577. this._changedCallback();
  578. }
  579. }
  580. else if (v === "inherit") {
  581. if (this._isType(index, PrimitiveThickness.Inherit)) {
  582. return true;
  583. }
  584. this._setType(index, PrimitiveThickness.Inherit);
  585. this._pixels[index] = null;
  586. if (emitChanged) {
  587. this._changedCallback();
  588. }
  589. }
  590. else {
  591. var pI = v.indexOf("%");
  592. // Check for percentage
  593. if (pI !== -1) {
  594. var n_1 = v.substr(0, pI);
  595. var number_1 = Math.round(Number(n_1)) / 100; // Normalize the percentage to [0;1] with a 0.01 precision
  596. if (this._isType(index, PrimitiveThickness.Percentage) && (this._percentages[index] === number_1)) {
  597. return true;
  598. }
  599. this._setType(index, PrimitiveThickness.Percentage);
  600. if (isNaN(number_1)) {
  601. return false;
  602. }
  603. this._percentages[index] = number_1;
  604. if (emitChanged) {
  605. this._changedCallback();
  606. }
  607. return true;
  608. }
  609. // Check for pixel
  610. var n = void 0;
  611. pI = v.indexOf("px");
  612. if (pI !== -1) {
  613. n = v.substr(0, pI).trim();
  614. }
  615. else {
  616. n = v;
  617. }
  618. var number = Number(n);
  619. if (this._isType(index, PrimitiveThickness.Pixel) && (this._pixels[index] === number)) {
  620. return true;
  621. }
  622. if (isNaN(number)) {
  623. return false;
  624. }
  625. this._pixels[index] = number;
  626. this._setType(index, PrimitiveThickness.Pixel);
  627. if (emitChanged) {
  628. this._changedCallback();
  629. }
  630. return true;
  631. }
  632. };
  633. PrimitiveThickness.prototype._setPixels = function (value, index, emitChanged) {
  634. // Round the value because, well, it's the thing to do! Otherwise we'll have sub-pixel stuff, and the no change comparison just below will almost never work for PrimitiveThickness values inside a hierarchy of Primitives
  635. value = Math.round(value);
  636. if (this._isType(index, PrimitiveThickness.Pixel) && this._pixels[index] === value) {
  637. return;
  638. }
  639. this._setType(index, PrimitiveThickness.Pixel);
  640. this._pixels[index] = value;
  641. if (emitChanged) {
  642. this._changedCallback();
  643. }
  644. };
  645. PrimitiveThickness.prototype._setPercentage = function (value, index, emitChanged) {
  646. // Clip Value to bounds
  647. value = Math.min(1, value);
  648. value = Math.max(0, value);
  649. value = Math.round(value * 100) / 100; // 0.01 precision
  650. if (this._isType(index, PrimitiveThickness.Percentage) && this._percentages[index] === value) {
  651. return;
  652. }
  653. this._setType(index, PrimitiveThickness.Percentage);
  654. this._percentages[index] = value;
  655. if (emitChanged) {
  656. this._changedCallback();
  657. }
  658. };
  659. PrimitiveThickness.prototype._getStringValue = function (index) {
  660. var f = (this._flags >> (index * 4)) & 0xF;
  661. switch (f) {
  662. case PrimitiveThickness.Auto:
  663. return "auto";
  664. case PrimitiveThickness.Pixel:
  665. return this._pixels[index] + "px";
  666. case PrimitiveThickness.Percentage:
  667. return this._percentages[index] * 100 + "%";
  668. case PrimitiveThickness.Inherit:
  669. return "inherit";
  670. }
  671. return "";
  672. };
  673. PrimitiveThickness.prototype._isType = function (index, type) {
  674. var f = (this._flags >> (index * 4)) & 0xF;
  675. return f === type;
  676. };
  677. PrimitiveThickness.prototype._getType = function (index, processInherit) {
  678. var t = (this._flags >> (index * 4)) & 0xF;
  679. if (processInherit && (t === PrimitiveThickness.Inherit)) {
  680. var p = this._parentAccess();
  681. if (p) {
  682. return p._getType(index, true);
  683. }
  684. return PrimitiveThickness.Auto;
  685. }
  686. return t;
  687. };
  688. PrimitiveThickness.prototype._setType = function (index, type) {
  689. this._flags &= ~(0xF << (index * 4));
  690. this._flags |= type << (index * 4);
  691. };
  692. PrimitiveThickness.prototype.setTop = function (value) {
  693. if (typeof value === "string") {
  694. this._setStringValue(value, 0, true);
  695. }
  696. else {
  697. this.topPixels = value;
  698. }
  699. };
  700. PrimitiveThickness.prototype.setLeft = function (value) {
  701. if (typeof value === "string") {
  702. this._setStringValue(value, 1, true);
  703. }
  704. else {
  705. this.leftPixels = value;
  706. }
  707. };
  708. PrimitiveThickness.prototype.setRight = function (value) {
  709. if (typeof value === "string") {
  710. this._setStringValue(value, 2, true);
  711. }
  712. else {
  713. this.rightPixels = value;
  714. }
  715. };
  716. PrimitiveThickness.prototype.setBottom = function (value) {
  717. if (typeof value === "string") {
  718. this._setStringValue(value, 3, true);
  719. }
  720. else {
  721. this.bottomPixels = value;
  722. }
  723. };
  724. Object.defineProperty(PrimitiveThickness.prototype, "top", {
  725. /**
  726. * Get/set the top thickness. Possible values are: 'auto', 'inherit', 'XX%' for percentage, 'XXpx' or 'XX' for pixels.
  727. */
  728. get: function () {
  729. return this._getStringValue(0);
  730. },
  731. set: function (value) {
  732. this._setStringValue(value, 0, true);
  733. },
  734. enumerable: true,
  735. configurable: true
  736. });
  737. Object.defineProperty(PrimitiveThickness.prototype, "left", {
  738. /**
  739. * Get/set the left thickness. Possible values are: 'auto', 'inherit', 'XX%' for percentage, 'XXpx' or 'XX' for pixels.
  740. */
  741. get: function () {
  742. return this._getStringValue(1);
  743. },
  744. set: function (value) {
  745. this._setStringValue(value, 1, true);
  746. },
  747. enumerable: true,
  748. configurable: true
  749. });
  750. Object.defineProperty(PrimitiveThickness.prototype, "right", {
  751. /**
  752. * Get/set the right thickness. Possible values are: 'auto', 'inherit', 'XX%' for percentage, 'XXpx' or 'XX' for pixels.
  753. */
  754. get: function () {
  755. return this._getStringValue(2);
  756. },
  757. set: function (value) {
  758. this._setStringValue(value, 2, true);
  759. },
  760. enumerable: true,
  761. configurable: true
  762. });
  763. Object.defineProperty(PrimitiveThickness.prototype, "bottom", {
  764. /**
  765. * Get/set the bottom thickness. Possible values are: 'auto', 'inherit', 'XX%' for percentage, 'XXpx' or 'XX' for pixels.
  766. */
  767. get: function () {
  768. return this._getStringValue(3);
  769. },
  770. set: function (value) {
  771. this._setStringValue(value, 3, true);
  772. },
  773. enumerable: true,
  774. configurable: true
  775. });
  776. Object.defineProperty(PrimitiveThickness.prototype, "topPixels", {
  777. /**
  778. * Get/set the top thickness in pixel.
  779. */
  780. get: function () {
  781. return this._pixels[0];
  782. },
  783. set: function (value) {
  784. this._setPixels(value, 0, true);
  785. },
  786. enumerable: true,
  787. configurable: true
  788. });
  789. Object.defineProperty(PrimitiveThickness.prototype, "leftPixels", {
  790. /**
  791. * Get/set the left thickness in pixel.
  792. */
  793. get: function () {
  794. return this._pixels[1];
  795. },
  796. set: function (value) {
  797. this._setPixels(value, 1, true);
  798. },
  799. enumerable: true,
  800. configurable: true
  801. });
  802. Object.defineProperty(PrimitiveThickness.prototype, "rightPixels", {
  803. /**
  804. * Get/set the right thickness in pixel.
  805. */
  806. get: function () {
  807. return this._pixels[2];
  808. },
  809. set: function (value) {
  810. this._setPixels(value, 2, true);
  811. },
  812. enumerable: true,
  813. configurable: true
  814. });
  815. Object.defineProperty(PrimitiveThickness.prototype, "bottomPixels", {
  816. /**
  817. * Get/set the bottom thickness in pixel.
  818. */
  819. get: function () {
  820. return this._pixels[3];
  821. },
  822. set: function (value) {
  823. this._setPixels(value, 3, true);
  824. },
  825. enumerable: true,
  826. configurable: true
  827. });
  828. Object.defineProperty(PrimitiveThickness.prototype, "topPercentage", {
  829. /**
  830. * Get/set the top thickness in percentage.
  831. * The get will return a valid value only if the edge type is percentage.
  832. * The Set will change the edge mode if needed
  833. */
  834. get: function () {
  835. return this._percentages[0];
  836. },
  837. set: function (value) {
  838. this._setPercentage(value, 0, true);
  839. },
  840. enumerable: true,
  841. configurable: true
  842. });
  843. Object.defineProperty(PrimitiveThickness.prototype, "leftPercentage", {
  844. /**
  845. * Get/set the left thickness in percentage.
  846. * The get will return a valid value only if the edge mode is percentage.
  847. * The Set will change the edge mode if needed
  848. */
  849. get: function () {
  850. return this._percentages[1];
  851. },
  852. set: function (value) {
  853. this._setPercentage(value, 1, true);
  854. },
  855. enumerable: true,
  856. configurable: true
  857. });
  858. Object.defineProperty(PrimitiveThickness.prototype, "rightPercentage", {
  859. /**
  860. * Get/set the right thickness in percentage.
  861. * The get will return a valid value only if the edge mode is percentage.
  862. * The Set will change the edge mode if needed
  863. */
  864. get: function () {
  865. return this._percentages[2];
  866. },
  867. set: function (value) {
  868. this._setPercentage(value, 2, true);
  869. },
  870. enumerable: true,
  871. configurable: true
  872. });
  873. Object.defineProperty(PrimitiveThickness.prototype, "bottomPercentage", {
  874. /**
  875. * Get/set the bottom thickness in percentage.
  876. * The get will return a valid value only if the edge mode is percentage.
  877. * The Set will change the edge mode if needed
  878. */
  879. get: function () {
  880. return this._percentages[3];
  881. },
  882. set: function (value) {
  883. this._setPercentage(value, 3, true);
  884. },
  885. enumerable: true,
  886. configurable: true
  887. });
  888. Object.defineProperty(PrimitiveThickness.prototype, "topMode", {
  889. /**
  890. * Get/set the top mode. The setter shouldn't be used, other setters with value should be preferred
  891. */
  892. get: function () {
  893. return this._getType(0, false);
  894. },
  895. set: function (mode) {
  896. this._setType(0, mode);
  897. },
  898. enumerable: true,
  899. configurable: true
  900. });
  901. Object.defineProperty(PrimitiveThickness.prototype, "leftMode", {
  902. /**
  903. * Get/set the left mode. The setter shouldn't be used, other setters with value should be preferred
  904. */
  905. get: function () {
  906. return this._getType(1, false);
  907. },
  908. set: function (mode) {
  909. this._setType(1, mode);
  910. },
  911. enumerable: true,
  912. configurable: true
  913. });
  914. Object.defineProperty(PrimitiveThickness.prototype, "rightMode", {
  915. /**
  916. * Get/set the right mode. The setter shouldn't be used, other setters with value should be preferred
  917. */
  918. get: function () {
  919. return this._getType(2, false);
  920. },
  921. set: function (mode) {
  922. this._setType(2, mode);
  923. },
  924. enumerable: true,
  925. configurable: true
  926. });
  927. Object.defineProperty(PrimitiveThickness.prototype, "bottomMode", {
  928. /**
  929. * Get/set the bottom mode. The setter shouldn't be used, other setters with value should be preferred
  930. */
  931. get: function () {
  932. return this._getType(3, false);
  933. },
  934. set: function (mode) {
  935. this._setType(3, mode);
  936. },
  937. enumerable: true,
  938. configurable: true
  939. });
  940. PrimitiveThickness.prototype._computePixels = function (index, sourceArea, emitChanged) {
  941. var type = this._getType(index, false);
  942. if (type === PrimitiveThickness.Inherit) {
  943. this._parentAccess()._computePixels(index, sourceArea, emitChanged);
  944. return;
  945. }
  946. if (type !== PrimitiveThickness.Percentage) {
  947. return;
  948. }
  949. var pixels = ((index === 0 || index === 3) ? sourceArea.height : sourceArea.width) * this._percentages[index];
  950. this._pixels[index] = pixels;
  951. if (emitChanged) {
  952. this._changedCallback();
  953. }
  954. };
  955. /**
  956. * Compute the positioning/size of an area considering the thickness of this object and a given alignment
  957. * @param sourceArea the source area
  958. * @param contentSize the content size to position/resize
  959. * @param alignment the alignment setting
  960. * @param dstOffset the position of the content
  961. * @param dstArea the new size of the content
  962. */
  963. PrimitiveThickness.prototype.computeWithAlignment = function (sourceArea, contentSize, alignment, dstOffset, dstArea) {
  964. // Fetch some data
  965. var topType = this._getType(0, true);
  966. var leftType = this._getType(1, true);
  967. var rightType = this._getType(2, true);
  968. var bottomType = this._getType(3, true);
  969. var hasWidth = contentSize && (contentSize.width != null);
  970. var hasHeight = contentSize && (contentSize.height != null);
  971. var width = hasWidth ? contentSize.width : 0;
  972. var height = hasHeight ? contentSize.height : 0;
  973. var isTopAuto = topType === PrimitiveThickness.Auto;
  974. var isLeftAuto = leftType === PrimitiveThickness.Auto;
  975. var isRightAuto = rightType === PrimitiveThickness.Auto;
  976. var isBottomAuto = bottomType === PrimitiveThickness.Auto;
  977. switch (alignment.horizontal) {
  978. case PrimitiveAlignment.AlignLeft:
  979. {
  980. if (isLeftAuto) {
  981. dstOffset.x = 0;
  982. }
  983. else {
  984. this._computePixels(1, sourceArea, true);
  985. dstOffset.x = this.leftPixels;
  986. }
  987. dstArea.width = width;
  988. break;
  989. }
  990. case PrimitiveAlignment.AlignRight:
  991. {
  992. if (isRightAuto) {
  993. dstOffset.x = Math.round(sourceArea.width - width);
  994. }
  995. else {
  996. this._computePixels(2, sourceArea, true);
  997. dstOffset.x = Math.round(sourceArea.width - (width + this.rightPixels));
  998. }
  999. dstArea.width = width;
  1000. break;
  1001. }
  1002. case PrimitiveAlignment.AlignStretch:
  1003. {
  1004. if (isLeftAuto) {
  1005. dstOffset.x = 0;
  1006. }
  1007. else {
  1008. this._computePixels(1, sourceArea, true);
  1009. dstOffset.x = this.leftPixels;
  1010. }
  1011. var right = 0;
  1012. if (!isRightAuto) {
  1013. this._computePixels(2, sourceArea, true);
  1014. right = this.rightPixels;
  1015. }
  1016. dstArea.width = sourceArea.width - (dstOffset.x + right);
  1017. break;
  1018. }
  1019. case PrimitiveAlignment.AlignCenter:
  1020. {
  1021. if (!isLeftAuto) {
  1022. this._computePixels(1, sourceArea, true);
  1023. }
  1024. if (!isRightAuto) {
  1025. this._computePixels(2, sourceArea, true);
  1026. }
  1027. var offset = (isLeftAuto ? 0 : this.leftPixels) - (isRightAuto ? 0 : this.rightPixels);
  1028. dstOffset.x = Math.round(((sourceArea.width - width) / 2) + offset);
  1029. dstArea.width = width;
  1030. break;
  1031. }
  1032. }
  1033. switch (alignment.vertical) {
  1034. case PrimitiveAlignment.AlignTop:
  1035. {
  1036. if (isTopAuto) {
  1037. dstOffset.y = sourceArea.height - height;
  1038. }
  1039. else {
  1040. this._computePixels(0, sourceArea, true);
  1041. dstOffset.y = Math.round(sourceArea.height - (height + this.topPixels));
  1042. }
  1043. dstArea.height = height;
  1044. break;
  1045. }
  1046. case PrimitiveAlignment.AlignBottom:
  1047. {
  1048. if (isBottomAuto) {
  1049. dstOffset.y = 0;
  1050. }
  1051. else {
  1052. this._computePixels(3, sourceArea, true);
  1053. dstOffset.y = this.bottomPixels;
  1054. }
  1055. dstArea.height = height;
  1056. break;
  1057. }
  1058. case PrimitiveAlignment.AlignStretch:
  1059. {
  1060. if (isBottomAuto) {
  1061. dstOffset.y = 0;
  1062. }
  1063. else {
  1064. this._computePixels(3, sourceArea, true);
  1065. dstOffset.y = this.bottomPixels;
  1066. }
  1067. var top_1 = 0;
  1068. if (!isTopAuto) {
  1069. this._computePixels(0, sourceArea, true);
  1070. top_1 = this.topPixels;
  1071. }
  1072. dstArea.height = sourceArea.height - (dstOffset.y + top_1);
  1073. break;
  1074. }
  1075. case PrimitiveAlignment.AlignCenter:
  1076. {
  1077. if (!isTopAuto) {
  1078. this._computePixels(0, sourceArea, true);
  1079. }
  1080. if (!isBottomAuto) {
  1081. this._computePixels(3, sourceArea, true);
  1082. }
  1083. var offset = (isBottomAuto ? 0 : this.bottomPixels) - (isTopAuto ? 0 : this.topPixels);
  1084. dstOffset.y = Math.round(((sourceArea.height - height) / 2) + offset);
  1085. dstArea.height = height;
  1086. break;
  1087. }
  1088. }
  1089. };
  1090. /**
  1091. * Compute an area and its position considering this thickness properties based on a given source area
  1092. * @param sourceArea the source area
  1093. * @param dstOffset the position of the resulting area
  1094. * @param dstArea the size of the resulting area
  1095. */
  1096. PrimitiveThickness.prototype.compute = function (sourceArea, dstOffset, dstArea) {
  1097. this._computePixels(0, sourceArea, true);
  1098. this._computePixels(1, sourceArea, true);
  1099. this._computePixels(2, sourceArea, true);
  1100. this._computePixels(3, sourceArea, true);
  1101. dstOffset.x = this.leftPixels;
  1102. dstArea.width = sourceArea.width - (dstOffset.x + this.rightPixels);
  1103. dstOffset.y = this.bottomPixels;
  1104. dstArea.height = sourceArea.height - (dstOffset.y + this.topPixels);
  1105. };
  1106. /**
  1107. * Compute an area considering this thickness properties based on a given source area
  1108. * @param sourceArea the source area
  1109. * @param result the resulting area
  1110. */
  1111. PrimitiveThickness.prototype.computeArea = function (sourceArea, result) {
  1112. this._computePixels(0, sourceArea, true);
  1113. this._computePixels(1, sourceArea, true);
  1114. this._computePixels(2, sourceArea, true);
  1115. this._computePixels(3, sourceArea, true);
  1116. result.width = this.leftPixels + sourceArea.width + this.rightPixels;
  1117. result.height = this.bottomPixels + sourceArea.height + this.topPixels;
  1118. };
  1119. PrimitiveThickness.prototype.enlarge = function (sourceArea, dstOffset, enlargedArea) {
  1120. this._computePixels(0, sourceArea, true);
  1121. this._computePixels(1, sourceArea, true);
  1122. this._computePixels(2, sourceArea, true);
  1123. this._computePixels(3, sourceArea, true);
  1124. dstOffset.x = this.leftPixels;
  1125. enlargedArea.width = sourceArea.width + (dstOffset.x + this.rightPixels);
  1126. dstOffset.y = this.bottomPixels;
  1127. enlargedArea.height = sourceArea.height + (dstOffset.y + this.topPixels);
  1128. };
  1129. PrimitiveThickness.Auto = 0x1;
  1130. PrimitiveThickness.Inherit = 0x2;
  1131. PrimitiveThickness.Percentage = 0x4;
  1132. PrimitiveThickness.Pixel = 0x8;
  1133. return PrimitiveThickness;
  1134. }());
  1135. BABYLON.PrimitiveThickness = PrimitiveThickness;
  1136. /**
  1137. * Main class used for the Primitive Intersection API
  1138. */
  1139. var IntersectInfo2D = (function () {
  1140. function IntersectInfo2D() {
  1141. this.findFirstOnly = false;
  1142. this.intersectHidden = false;
  1143. this.pickPosition = BABYLON.Vector2.Zero();
  1144. }
  1145. Object.defineProperty(IntersectInfo2D.prototype, "isIntersected", {
  1146. /**
  1147. * true if at least one primitive intersected during the test
  1148. */
  1149. get: function () {
  1150. return this.intersectedPrimitives && this.intersectedPrimitives.length > 0;
  1151. },
  1152. enumerable: true,
  1153. configurable: true
  1154. });
  1155. IntersectInfo2D.prototype.isPrimIntersected = function (prim) {
  1156. for (var _i = 0, _a = this.intersectedPrimitives; _i < _a.length; _i++) {
  1157. var cur = _a[_i];
  1158. if (cur.prim === prim) {
  1159. return cur.intersectionLocation;
  1160. }
  1161. }
  1162. return null;
  1163. };
  1164. // Internals, don't use
  1165. IntersectInfo2D.prototype._exit = function (firstLevel) {
  1166. if (firstLevel) {
  1167. this._globalPickPosition = null;
  1168. }
  1169. };
  1170. return IntersectInfo2D;
  1171. }());
  1172. BABYLON.IntersectInfo2D = IntersectInfo2D;
  1173. var Prim2DBase = (function (_super) {
  1174. __extends(Prim2DBase, _super);
  1175. function Prim2DBase(settings) {
  1176. // Avoid checking every time if the object exists
  1177. if (settings == null) {
  1178. settings = {};
  1179. }
  1180. // BASE CLASS CALL
  1181. _super.call(this);
  1182. // Fetch the owner, parent. There're many ways to do it and we can end up with nothing for both
  1183. var owner;
  1184. var parent;
  1185. if (Prim2DBase._isCanvasInit) {
  1186. owner = this;
  1187. parent = null;
  1188. this._canvasPreInit(settings);
  1189. }
  1190. else {
  1191. if (settings.parent != null) {
  1192. parent = settings.parent;
  1193. owner = settings.parent.owner;
  1194. if (!owner) {
  1195. throw new Error("Parent " + parent.id + " of " + settings.id + " doesn't have a valid owner!");
  1196. }
  1197. if (!(this instanceof BABYLON.Group2D) && !(this instanceof BABYLON.Sprite2D && settings.id != null && settings.id.indexOf("__cachedSpriteOfGroup__") === 0) && (owner.cachingStrategy === BABYLON.Canvas2D.CACHESTRATEGY_TOPLEVELGROUPS) && (parent === owner)) {
  1198. throw new Error("Can't create a primitive with the canvas as direct parent when the caching strategy is TOPLEVELGROUPS. You need to create a Group below the canvas and use it as the parent for the primitive");
  1199. }
  1200. }
  1201. }
  1202. // Fields initialization
  1203. this._layoutEngine = BABYLON.CanvasLayoutEngine.Singleton;
  1204. this._size = null; //Size.Zero();
  1205. this._actualSize = null;
  1206. this._boundingSize = BABYLON.Size.Zero();
  1207. this._layoutArea = BABYLON.Size.Zero();
  1208. this._layoutAreaPos = BABYLON.Vector2.Zero();
  1209. this._marginOffset = BABYLON.Vector2.Zero();
  1210. this._paddingOffset = BABYLON.Vector2.Zero();
  1211. this._parentPaddingOffset = BABYLON.Vector2.Zero();
  1212. this._parentContentArea = BABYLON.Size.Zero();
  1213. this._lastAutoSizeArea = BABYLON.Size.Zero();
  1214. this._contentArea = new BABYLON.Size(null, null);
  1215. this._pointerEventObservable = new BABYLON.Observable();
  1216. this._boundingInfo = new BABYLON.BoundingInfo2D();
  1217. this._owner = owner;
  1218. this._parent = null;
  1219. this._margin = null;
  1220. this._padding = null;
  1221. this._marginAlignment = null;
  1222. this._id = settings.id;
  1223. this.propertyChanged = new BABYLON.Observable();
  1224. this._children = new Array();
  1225. this._localTransform = new BABYLON.Matrix();
  1226. this._globalTransform = null;
  1227. this._invGlobalTransform = null;
  1228. this._globalTransformProcessStep = 0;
  1229. this._globalTransformStep = 0;
  1230. this._renderGroup = null;
  1231. this._primLinearPosition = 0;
  1232. this._manualZOrder = null;
  1233. this._zOrder = 0;
  1234. this._zMax = 0;
  1235. this._firstZDirtyIndex = Prim2DBase._bigInt;
  1236. this._setFlags(BABYLON.SmartPropertyPrim.flagIsPickable | BABYLON.SmartPropertyPrim.flagBoundingInfoDirty | BABYLON.SmartPropertyPrim.flagActualOpacityDirty);
  1237. if (settings.opacity != null) {
  1238. this._opacity = settings.opacity;
  1239. }
  1240. else {
  1241. this._opacity = 1;
  1242. }
  1243. if (settings.childrenFlatZOrder) {
  1244. this._setFlags(BABYLON.SmartPropertyPrim.flagChildrenFlatZOrder);
  1245. }
  1246. // If the parent is given, initialize the hierarchy/owner related data
  1247. if (parent != null) {
  1248. parent.addChild(this);
  1249. this._patchHierarchy(parent.owner);
  1250. }
  1251. // If it's a group, detect its own states
  1252. if (this.owner && this instanceof BABYLON.Group2D) {
  1253. var group = this;
  1254. group.detectGroupStates();
  1255. }
  1256. // Time to insert children if some are specified
  1257. if (settings.children != null) {
  1258. for (var _i = 0, _a = settings.children; _i < _a.length; _i++) {
  1259. var child = _a[_i];
  1260. this.addChild(child);
  1261. // Good time to patch the hierarchy, it won't go very far if there's no need to
  1262. child._patchHierarchy(this.owner);
  1263. }
  1264. }
  1265. // Set the model related properties
  1266. if (settings.position != null) {
  1267. this.position = settings.position;
  1268. }
  1269. else if (settings.x != null || settings.y != null) {
  1270. this.position = new BABYLON.Vector2(settings.x || 0, settings.y || 0);
  1271. }
  1272. else {
  1273. this._position = null;
  1274. }
  1275. this.rotation = (settings.rotation == null) ? 0 : settings.rotation;
  1276. this.scale = (settings.scale == null) ? 1 : settings.scale;
  1277. this.levelVisible = (settings.isVisible == null) ? true : settings.isVisible;
  1278. this.origin = settings.origin || new BABYLON.Vector2(0.5, 0.5);
  1279. // Layout Engine
  1280. if (settings.layoutEngine != null) {
  1281. if (typeof settings.layoutEngine === "string") {
  1282. var name_1 = settings.layoutEngine.toLocaleLowerCase().trim();
  1283. if (name_1 === "canvas" || name_1 === "canvaslayoutengine") {
  1284. this.layoutEngine = BABYLON.CanvasLayoutEngine.Singleton;
  1285. }
  1286. else if (name_1.indexOf("stackpanel") === 0 || name_1.indexOf("horizontalstackpanel") === 0) {
  1287. this.layoutEngine = BABYLON.StackPanelLayoutEngine.Horizontal;
  1288. }
  1289. else if (name_1.indexOf("verticalstackpanel") === 0) {
  1290. this.layoutEngine = BABYLON.StackPanelLayoutEngine.Vertical;
  1291. }
  1292. }
  1293. else if (settings.layoutEngine instanceof BABYLON.LayoutEngineBase) {
  1294. this.layoutEngine = settings.layoutEngine;
  1295. }
  1296. }
  1297. // Set the layout/margin stuffs
  1298. if (settings.marginTop) {
  1299. this.margin.setTop(settings.marginTop);
  1300. }
  1301. if (settings.marginLeft) {
  1302. this.margin.setLeft(settings.marginLeft);
  1303. }
  1304. if (settings.marginRight) {
  1305. this.margin.setRight(settings.marginRight);
  1306. }
  1307. if (settings.marginBottom) {
  1308. this.margin.setBottom(settings.marginBottom);
  1309. }
  1310. if (settings.margin) {
  1311. if (typeof settings.margin === "string") {
  1312. this.margin.fromString(settings.margin);
  1313. }
  1314. else {
  1315. this.margin.fromUniformPixels(settings.margin);
  1316. }
  1317. }
  1318. if (settings.marginHAlignment) {
  1319. this.marginAlignment.horizontal = settings.marginHAlignment;
  1320. }
  1321. if (settings.marginVAlignment) {
  1322. this.marginAlignment.vertical = settings.marginVAlignment;
  1323. }
  1324. if (settings.marginAlignment) {
  1325. this.marginAlignment.fromString(settings.marginAlignment);
  1326. }
  1327. if (settings.paddingTop) {
  1328. this.padding.setTop(settings.paddingTop);
  1329. }
  1330. if (settings.paddingLeft) {
  1331. this.padding.setLeft(settings.paddingLeft);
  1332. }
  1333. if (settings.paddingRight) {
  1334. this.padding.setRight(settings.paddingRight);
  1335. }
  1336. if (settings.paddingBottom) {
  1337. this.padding.setBottom(settings.paddingBottom);
  1338. }
  1339. if (settings.padding) {
  1340. this.padding.fromString(settings.padding);
  1341. }
  1342. // Dirty layout and positioning
  1343. this._parentLayoutDirty();
  1344. this._positioningDirty();
  1345. }
  1346. Object.defineProperty(Prim2DBase.prototype, "actionManager", {
  1347. get: function () {
  1348. if (!this._actionManager) {
  1349. this._actionManager = new BABYLON.ActionManager(this.owner.scene);
  1350. }
  1351. return this._actionManager;
  1352. },
  1353. enumerable: true,
  1354. configurable: true
  1355. });
  1356. /**
  1357. * From 'this' primitive, traverse up (from parent to parent) until the given predicate is true
  1358. * @param predicate the predicate to test on each parent
  1359. * @return the first primitive where the predicate was successful
  1360. */
  1361. Prim2DBase.prototype.traverseUp = function (predicate) {
  1362. var p = this;
  1363. while (p != null) {
  1364. if (predicate(p)) {
  1365. return p;
  1366. }
  1367. p = p._parent;
  1368. }
  1369. return null;
  1370. };
  1371. Object.defineProperty(Prim2DBase.prototype, "owner", {
  1372. /**
  1373. * Retrieve the owner Canvas2D
  1374. */
  1375. get: function () {
  1376. return this._owner;
  1377. },
  1378. enumerable: true,
  1379. configurable: true
  1380. });
  1381. Object.defineProperty(Prim2DBase.prototype, "parent", {
  1382. /**
  1383. * Get the parent primitive (can be the Canvas, only the Canvas has no parent)
  1384. */
  1385. get: function () {
  1386. return this._parent;
  1387. },
  1388. enumerable: true,
  1389. configurable: true
  1390. });
  1391. Object.defineProperty(Prim2DBase.prototype, "children", {
  1392. /**
  1393. * The array of direct children primitives
  1394. */
  1395. get: function () {
  1396. return this._children;
  1397. },
  1398. enumerable: true,
  1399. configurable: true
  1400. });
  1401. Object.defineProperty(Prim2DBase.prototype, "id", {
  1402. /**
  1403. * The identifier of this primitive, may not be unique, it's for information purpose only
  1404. */
  1405. get: function () {
  1406. return this._id;
  1407. },
  1408. enumerable: true,
  1409. configurable: true
  1410. });
  1411. Object.defineProperty(Prim2DBase.prototype, "actualPosition", {
  1412. get: function () {
  1413. if (this._actualPosition != null) {
  1414. return this._actualPosition;
  1415. }
  1416. if (this._position != null) {
  1417. return this._position;
  1418. }
  1419. // At least return 0,0, we can't return null on actualPosition
  1420. return Prim2DBase._nullPosition;
  1421. },
  1422. /**
  1423. * DO NOT INVOKE for internal purpose only
  1424. */
  1425. set: function (val) {
  1426. this._actualPosition = val;
  1427. },
  1428. enumerable: true,
  1429. configurable: true
  1430. });
  1431. Object.defineProperty(Prim2DBase.prototype, "actualX", {
  1432. /**
  1433. * Shortcut to actualPosition.x
  1434. */
  1435. get: function () {
  1436. return this.actualPosition.x;
  1437. },
  1438. enumerable: true,
  1439. configurable: true
  1440. });
  1441. Object.defineProperty(Prim2DBase.prototype, "actualY", {
  1442. /**
  1443. * Shortcut to actualPosition.y
  1444. */
  1445. get: function () {
  1446. return this.actualPosition.y;
  1447. },
  1448. enumerable: true,
  1449. configurable: true
  1450. });
  1451. Object.defineProperty(Prim2DBase.prototype, "position", {
  1452. /**
  1453. * Position of the primitive, relative to its parent.
  1454. * BEWARE: if you change only position.x or y it won't trigger a property change and you won't have the expected behavior.
  1455. * Use this property to set a new Vector2 object, otherwise to change only the x/y use Prim2DBase.x or y properties.
  1456. * Setting this property may have no effect is specific alignment are in effect.
  1457. */
  1458. get: function () {
  1459. return this._position || Prim2DBase._nullPosition;
  1460. },
  1461. set: function (value) {
  1462. if (!this._checkPositionChange()) {
  1463. return;
  1464. }
  1465. this._position = value;
  1466. this.markAsDirty("actualPosition");
  1467. },
  1468. enumerable: true,
  1469. configurable: true
  1470. });
  1471. Object.defineProperty(Prim2DBase.prototype, "x", {
  1472. /**
  1473. * Direct access to the position.x value of the primitive
  1474. * Use this property when you only want to change one component of the position property
  1475. */
  1476. get: function () {
  1477. if (!this._position) {
  1478. return null;
  1479. }
  1480. return this._position.x;
  1481. },
  1482. set: function (value) {
  1483. if (!this._checkPositionChange()) {
  1484. return;
  1485. }
  1486. if (!this._position) {
  1487. this._position = BABYLON.Vector2.Zero();
  1488. }
  1489. if (this._position.x === value) {
  1490. return;
  1491. }
  1492. this._position.x = value;
  1493. this.markAsDirty("position");
  1494. this.markAsDirty("actualPosition");
  1495. },
  1496. enumerable: true,
  1497. configurable: true
  1498. });
  1499. Object.defineProperty(Prim2DBase.prototype, "y", {
  1500. /**
  1501. * Direct access to the position.y value of the primitive
  1502. * Use this property when you only want to change one component of the position property
  1503. */
  1504. get: function () {
  1505. if (!this._position) {
  1506. return null;
  1507. }
  1508. return this._position.y;
  1509. },
  1510. set: function (value) {
  1511. if (!this._checkPositionChange()) {
  1512. return;
  1513. }
  1514. if (!this._position) {
  1515. this._position = BABYLON.Vector2.Zero();
  1516. }
  1517. if (this._position.y === value) {
  1518. return;
  1519. }
  1520. this._position.y = value;
  1521. this.markAsDirty("position");
  1522. this.markAsDirty("actualPosition");
  1523. },
  1524. enumerable: true,
  1525. configurable: true
  1526. });
  1527. Object.defineProperty(Prim2DBase.prototype, "size", {
  1528. /**
  1529. * Size of the primitive or its bounding area
  1530. * BEWARE: if you change only size.width or height it won't trigger a property change and you won't have the expected behavior.
  1531. * Use this property to set a new Size object, otherwise to change only the width/height use Prim2DBase.width or height properties.
  1532. */
  1533. get: function () {
  1534. if (!this._size || this._size.width == null || this._size.height == null) {
  1535. if (Prim2DBase.boundinbBoxReentrency) {
  1536. return Prim2DBase.nullSize;
  1537. }
  1538. if (!this._isFlagSet(BABYLON.SmartPropertyPrim.flagBoundingInfoDirty)) {
  1539. return this._boundingSize;
  1540. }
  1541. Prim2DBase.boundinbBoxReentrency = true;
  1542. var b = this.boundingInfo;
  1543. Prim2DBase.boundinbBoxReentrency = false;
  1544. return this._boundingSize;
  1545. }
  1546. return this._size;
  1547. },
  1548. set: function (value) {
  1549. this._size = value;
  1550. },
  1551. enumerable: true,
  1552. configurable: true
  1553. });
  1554. Object.defineProperty(Prim2DBase.prototype, "width", {
  1555. /**
  1556. * Direct access to the size.width value of the primitive
  1557. * Use this property when you only want to change one component of the size property
  1558. */
  1559. get: function () {
  1560. if (!this.size) {
  1561. return null;
  1562. }
  1563. return this.size.width;
  1564. },
  1565. set: function (value) {
  1566. if (!this.size) {
  1567. this.size = new BABYLON.Size(value, 0);
  1568. return;
  1569. }
  1570. if (this.size.width === value) {
  1571. return;
  1572. }
  1573. this.size.width = value;
  1574. this.markAsDirty("size");
  1575. this._positioningDirty();
  1576. },
  1577. enumerable: true,
  1578. configurable: true
  1579. });
  1580. Object.defineProperty(Prim2DBase.prototype, "height", {
  1581. /**
  1582. * Direct access to the size.height value of the primitive
  1583. * Use this property when you only want to change one component of the size property
  1584. */
  1585. get: function () {
  1586. if (!this.size) {
  1587. return null;
  1588. }
  1589. return this.size.height;
  1590. },
  1591. set: function (value) {
  1592. if (!this.size) {
  1593. this.size = new BABYLON.Size(0, value);
  1594. return;
  1595. }
  1596. if (this.size.height === value) {
  1597. return;
  1598. }
  1599. this.size.height = value;
  1600. this.markAsDirty("size");
  1601. this._positioningDirty();
  1602. },
  1603. enumerable: true,
  1604. configurable: true
  1605. });
  1606. Object.defineProperty(Prim2DBase.prototype, "rotation", {
  1607. get: function () {
  1608. return this._rotation;
  1609. },
  1610. set: function (value) {
  1611. this._rotation = value;
  1612. },
  1613. enumerable: true,
  1614. configurable: true
  1615. });
  1616. Object.defineProperty(Prim2DBase.prototype, "scale", {
  1617. get: function () {
  1618. return this._scale;
  1619. },
  1620. set: function (value) {
  1621. this._scale = value;
  1622. },
  1623. enumerable: true,
  1624. configurable: true
  1625. });
  1626. Object.defineProperty(Prim2DBase.prototype, "actualSize", {
  1627. /**
  1628. * Return the size of the primitive as it's being rendered into the target.
  1629. * This value may be different of the size property when layout/alignment is used or specific primitive types can implement a custom logic through this property.
  1630. * BEWARE: don't use the setter, it's for internal purpose only
  1631. * Note to implementers: you have to override this property and declare if necessary a @xxxxInstanceLevel decorator
  1632. */
  1633. get: function () {
  1634. if (this._actualSize) {
  1635. return this._actualSize;
  1636. }
  1637. return this._size;
  1638. },
  1639. set: function (value) {
  1640. if (this._actualSize.equals(value)) {
  1641. return;
  1642. }
  1643. this._actualSize = value;
  1644. },
  1645. enumerable: true,
  1646. configurable: true
  1647. });
  1648. Object.defineProperty(Prim2DBase.prototype, "actualZOffset", {
  1649. get: function () {
  1650. if (this._manualZOrder != null) {
  1651. return this._manualZOrder;
  1652. }
  1653. if (this._isFlagSet(BABYLON.SmartPropertyPrim.flagZOrderDirty)) {
  1654. this._updateZOrder();
  1655. }
  1656. return (1 - this._zOrder);
  1657. },
  1658. enumerable: true,
  1659. configurable: true
  1660. });
  1661. Object.defineProperty(Prim2DBase.prototype, "minSize", {
  1662. /**
  1663. * Get or set the minimal size the Layout Engine should respect when computing the primitive's actualSize.
  1664. * The Primitive's size won't be less than specified.
  1665. * The default value depends of the Primitive type
  1666. */
  1667. get: function () {
  1668. return this._minSize;
  1669. },
  1670. set: function (value) {
  1671. if (this._minSize && value && this._minSize.equals(value)) {
  1672. return;
  1673. }
  1674. this._minSize = value;
  1675. this._parentLayoutDirty();
  1676. },
  1677. enumerable: true,
  1678. configurable: true
  1679. });
  1680. Object.defineProperty(Prim2DBase.prototype, "maxSize", {
  1681. /**
  1682. * Get or set the maximal size the Layout Engine should respect when computing the primitive's actualSize.
  1683. * The Primitive's size won't be more than specified.
  1684. * The default value depends of the Primitive type
  1685. */
  1686. get: function () {
  1687. return this._maxSize;
  1688. },
  1689. set: function (value) {
  1690. if (this._maxSize && value && this._maxSize.equals(value)) {
  1691. return;
  1692. }
  1693. this._maxSize = value;
  1694. this._parentLayoutDirty();
  1695. },
  1696. enumerable: true,
  1697. configurable: true
  1698. });
  1699. Object.defineProperty(Prim2DBase.prototype, "origin", {
  1700. /**
  1701. * The origin defines the normalized coordinate of the center of the primitive, from the bottom/left corner.
  1702. * The origin is used only to compute transformation of the primitive, it has no meaning in the primitive local frame of reference
  1703. * For instance:
  1704. * 0,0 means the center is bottom/left. Which is the default for Canvas2D instances
  1705. * 0.5,0.5 means the center is at the center of the primitive, which is default of all types of Primitives
  1706. * 0,1 means the center is top/left
  1707. * @returns The normalized center.
  1708. */
  1709. get: function () {
  1710. return this._origin;
  1711. },
  1712. set: function (value) {
  1713. this._origin = value;
  1714. },
  1715. enumerable: true,
  1716. configurable: true
  1717. });
  1718. Object.defineProperty(Prim2DBase.prototype, "levelVisible", {
  1719. get: function () {
  1720. return this._isFlagSet(BABYLON.SmartPropertyPrim.flagLevelVisible);
  1721. },
  1722. set: function (value) {
  1723. this._changeFlags(BABYLON.SmartPropertyPrim.flagLevelVisible, value);
  1724. },
  1725. enumerable: true,
  1726. configurable: true
  1727. });
  1728. Object.defineProperty(Prim2DBase.prototype, "isVisible", {
  1729. get: function () {
  1730. return this._isFlagSet(BABYLON.SmartPropertyPrim.flagIsVisible);
  1731. },
  1732. set: function (value) {
  1733. this._changeFlags(BABYLON.SmartPropertyPrim.flagIsVisible, value);
  1734. },
  1735. enumerable: true,
  1736. configurable: true
  1737. });
  1738. Object.defineProperty(Prim2DBase.prototype, "zOrder", {
  1739. get: function () {
  1740. return this._manualZOrder;
  1741. },
  1742. set: function (value) {
  1743. if (this._manualZOrder === value) {
  1744. return;
  1745. }
  1746. this._manualZOrder = value;
  1747. this.onZOrderChanged();
  1748. if (this._actualZOrderChangedObservable && this._actualZOrderChangedObservable.hasObservers()) {
  1749. this._actualZOrderChangedObservable.notifyObservers(value);
  1750. }
  1751. },
  1752. enumerable: true,
  1753. configurable: true
  1754. });
  1755. Object.defineProperty(Prim2DBase.prototype, "isManualZOrder", {
  1756. get: function () {
  1757. return this._manualZOrder != null;
  1758. },
  1759. enumerable: true,
  1760. configurable: true
  1761. });
  1762. Object.defineProperty(Prim2DBase.prototype, "margin", {
  1763. get: function () {
  1764. var _this = this;
  1765. if (!this._margin) {
  1766. this._margin = new PrimitiveThickness(function () {
  1767. if (!_this.parent) {
  1768. return null;
  1769. }
  1770. return _this.parent.margin;
  1771. }, function () { return _this._positioningDirty(); });
  1772. }
  1773. return this._margin;
  1774. },
  1775. enumerable: true,
  1776. configurable: true
  1777. });
  1778. Object.defineProperty(Prim2DBase.prototype, "_hasMargin", {
  1779. get: function () {
  1780. return (this._margin !== null) || (this._marginAlignment !== null);
  1781. },
  1782. enumerable: true,
  1783. configurable: true
  1784. });
  1785. Object.defineProperty(Prim2DBase.prototype, "padding", {
  1786. get: function () {
  1787. var _this = this;
  1788. if (!this._padding) {
  1789. this._padding = new PrimitiveThickness(function () {
  1790. if (!_this.parent) {
  1791. return null;
  1792. }
  1793. return _this.parent.padding;
  1794. }, function () { return _this._positioningDirty(); });
  1795. }
  1796. return this._padding;
  1797. },
  1798. enumerable: true,
  1799. configurable: true
  1800. });
  1801. Object.defineProperty(Prim2DBase.prototype, "_hasPadding", {
  1802. get: function () {
  1803. return this._padding !== null;
  1804. },
  1805. enumerable: true,
  1806. configurable: true
  1807. });
  1808. Object.defineProperty(Prim2DBase.prototype, "marginAlignment", {
  1809. get: function () {
  1810. var _this = this;
  1811. if (!this._marginAlignment) {
  1812. this._marginAlignment = new PrimitiveAlignment(function () { return _this._positioningDirty(); });
  1813. }
  1814. return this._marginAlignment;
  1815. },
  1816. enumerable: true,
  1817. configurable: true
  1818. });
  1819. Object.defineProperty(Prim2DBase.prototype, "opacity", {
  1820. get: function () {
  1821. return this._opacity;
  1822. },
  1823. set: function (value) {
  1824. if (value < 0) {
  1825. value = 0;
  1826. }
  1827. else if (value > 1) {
  1828. value = 1;
  1829. }
  1830. if (this._opacity === value) {
  1831. return;
  1832. }
  1833. this._opacity = value;
  1834. this._updateRenderMode();
  1835. this._setFlags(BABYLON.SmartPropertyPrim.flagActualOpacityDirty);
  1836. this._spreadActualOpacityChanged();
  1837. },
  1838. enumerable: true,
  1839. configurable: true
  1840. });
  1841. Object.defineProperty(Prim2DBase.prototype, "actualOpacity", {
  1842. get: function () {
  1843. if (this._isFlagSet(BABYLON.SmartPropertyPrim.flagActualOpacityDirty)) {
  1844. var cur = this.parent;
  1845. var op = this.opacity;
  1846. while (cur) {
  1847. op *= cur.opacity;
  1848. cur = cur.parent;
  1849. }
  1850. this._actualOpacity = op;
  1851. this._clearFlags(BABYLON.SmartPropertyPrim.flagActualOpacityDirty);
  1852. }
  1853. return this._actualOpacity;
  1854. },
  1855. enumerable: true,
  1856. configurable: true
  1857. });
  1858. Object.defineProperty(Prim2DBase.prototype, "layoutEngine", {
  1859. /**
  1860. * Get/set the layout engine to use for this primitive.
  1861. * The default layout engine is the CanvasLayoutEngine.
  1862. */
  1863. get: function () {
  1864. if (!this._layoutEngine) {
  1865. this._layoutEngine = BABYLON.CanvasLayoutEngine.Singleton;
  1866. }
  1867. return this._layoutEngine;
  1868. },
  1869. set: function (value) {
  1870. if (this._layoutEngine === value) {
  1871. return;
  1872. }
  1873. this._changeLayoutEngine(value);
  1874. },
  1875. enumerable: true,
  1876. configurable: true
  1877. });
  1878. Object.defineProperty(Prim2DBase.prototype, "layoutArea", {
  1879. /**
  1880. * Get/set the layout are of this primitive.
  1881. * The Layout area is the zone allocated by the Layout Engine for this particular primitive. Margins/Alignment will be computed based on this area.
  1882. * The setter should only be called by a Layout Engine class.
  1883. */
  1884. get: function () {
  1885. return this._layoutArea;
  1886. },
  1887. set: function (val) {
  1888. if (this._layoutArea.equals(val)) {
  1889. return;
  1890. }
  1891. this._positioningDirty();
  1892. this._layoutArea = val;
  1893. },
  1894. enumerable: true,
  1895. configurable: true
  1896. });
  1897. Object.defineProperty(Prim2DBase.prototype, "layoutAreaPos", {
  1898. /**
  1899. * Get/set the layout area position (relative to the parent primitive).
  1900. * The setter should only be called by a Layout Engine class.
  1901. */
  1902. get: function () {
  1903. return this._layoutAreaPos;
  1904. },
  1905. set: function (val) {
  1906. if (this._layoutAreaPos.equals(val)) {
  1907. return;
  1908. }
  1909. this._positioningDirty();
  1910. this._layoutAreaPos = val;
  1911. },
  1912. enumerable: true,
  1913. configurable: true
  1914. });
  1915. Object.defineProperty(Prim2DBase.prototype, "isPickable", {
  1916. /**
  1917. * Define if the Primitive can be subject to intersection test or not (default is true)
  1918. */
  1919. get: function () {
  1920. return this._isFlagSet(BABYLON.SmartPropertyPrim.flagIsPickable);
  1921. },
  1922. set: function (value) {
  1923. this._changeFlags(BABYLON.SmartPropertyPrim.flagIsPickable, value);
  1924. },
  1925. enumerable: true,
  1926. configurable: true
  1927. });
  1928. Object.defineProperty(Prim2DBase.prototype, "hierarchyDepth", {
  1929. /**
  1930. * Return the depth level of the Primitive into the Canvas' Graph. A Canvas will be 0, its direct children 1, and so on.
  1931. */
  1932. get: function () {
  1933. return this._hierarchyDepth;
  1934. },
  1935. enumerable: true,
  1936. configurable: true
  1937. });
  1938. Object.defineProperty(Prim2DBase.prototype, "renderGroup", {
  1939. /**
  1940. * Retrieve the Group that is responsible to render this primitive
  1941. */
  1942. get: function () {
  1943. return this._renderGroup;
  1944. },
  1945. enumerable: true,
  1946. configurable: true
  1947. });
  1948. Object.defineProperty(Prim2DBase.prototype, "globalTransform", {
  1949. /**
  1950. * Get the global transformation matrix of the primitive
  1951. */
  1952. get: function () {
  1953. return this._globalTransform;
  1954. },
  1955. enumerable: true,
  1956. configurable: true
  1957. });
  1958. /**
  1959. * return the global position of the primitive, relative to its canvas
  1960. */
  1961. Prim2DBase.prototype.getGlobalPosition = function () {
  1962. var v = new BABYLON.Vector2(0, 0);
  1963. this.getGlobalPositionByRef(v);
  1964. return v;
  1965. };
  1966. /**
  1967. * return the global position of the primitive, relative to its canvas
  1968. * @param v the valid Vector2 object where the global position will be stored
  1969. */
  1970. Prim2DBase.prototype.getGlobalPositionByRef = function (v) {
  1971. v.x = this.globalTransform.m[12];
  1972. v.y = this.globalTransform.m[13];
  1973. };
  1974. Object.defineProperty(Prim2DBase.prototype, "invGlobalTransform", {
  1975. /**
  1976. * Get invert of the global transformation matrix of the primitive
  1977. */
  1978. get: function () {
  1979. return this._invGlobalTransform;
  1980. },
  1981. enumerable: true,
  1982. configurable: true
  1983. });
  1984. Object.defineProperty(Prim2DBase.prototype, "localTransform", {
  1985. /**
  1986. * Get the local transformation of the primitive
  1987. */
  1988. get: function () {
  1989. this._updateLocalTransform();
  1990. return this._localTransform;
  1991. },
  1992. enumerable: true,
  1993. configurable: true
  1994. });
  1995. Object.defineProperty(Prim2DBase.prototype, "boundingInfo", {
  1996. /**
  1997. * Get the boundingInfo associated to the primitive and its children.
  1998. * The value is supposed to be always up to date
  1999. */
  2000. get: function () {
  2001. if (this._isFlagSet(BABYLON.SmartPropertyPrim.flagBoundingInfoDirty)) {
  2002. if (this.owner) {
  2003. this.owner.boundingInfoRecomputeCounter.addCount(1, false);
  2004. }
  2005. if (this.isSizedByContent) {
  2006. this._boundingInfo.clear();
  2007. }
  2008. else {
  2009. this._boundingInfo.copyFrom(this.levelBoundingInfo);
  2010. }
  2011. var bi = this._boundingInfo;
  2012. var tps = new BABYLON.BoundingInfo2D();
  2013. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  2014. var curChild = _a[_i];
  2015. curChild.boundingInfo.transformToRef(curChild.localTransform, tps);
  2016. bi.unionToRef(tps, bi);
  2017. }
  2018. this._boundingInfo.maxToRef(Prim2DBase._bMax);
  2019. this._boundingSize.copyFromFloats((!this._size || this._size.width == null) ? Math.ceil(Prim2DBase._bMax.x) : this._size.width, (!this._size || this._size.height == null) ? Math.ceil(Prim2DBase._bMax.y) : this._size.height);
  2020. this._clearFlags(BABYLON.SmartPropertyPrim.flagBoundingInfoDirty);
  2021. }
  2022. return this._boundingInfo;
  2023. },
  2024. enumerable: true,
  2025. configurable: true
  2026. });
  2027. Object.defineProperty(Prim2DBase.prototype, "isSizeAuto", {
  2028. /**
  2029. * Determine if the size is automatically computed or fixed because manually specified.
  2030. * Use the actualSize property to get the final/real size of the primitive
  2031. * @returns true if the size is automatically computed, false if it were manually specified.
  2032. */
  2033. get: function () {
  2034. return this._size == null;
  2035. },
  2036. enumerable: true,
  2037. configurable: true
  2038. });
  2039. Object.defineProperty(Prim2DBase.prototype, "isSizedByContent", {
  2040. /**
  2041. * Return true if this prim has an auto size which is set by the children's global bounding box
  2042. */
  2043. get: function () {
  2044. return (this._size == null) && (this._children.length > 0);
  2045. },
  2046. enumerable: true,
  2047. configurable: true
  2048. });
  2049. Object.defineProperty(Prim2DBase.prototype, "isPositionAuto", {
  2050. /**
  2051. * Determine if the position is automatically computed or fixed because manually specified.
  2052. * Use the actualPosition property to get the final/real position of the primitive
  2053. * @returns true if the position is automatically computed, false if it were manually specified.
  2054. */
  2055. get: function () {
  2056. return this._position == null;
  2057. },
  2058. enumerable: true,
  2059. configurable: true
  2060. });
  2061. Object.defineProperty(Prim2DBase.prototype, "pointerEventObservable", {
  2062. /**
  2063. * Interaction with the primitive can be create using this Observable. See the PrimitivePointerInfo class for more information
  2064. */
  2065. get: function () {
  2066. return this._pointerEventObservable;
  2067. },
  2068. enumerable: true,
  2069. configurable: true
  2070. });
  2071. Object.defineProperty(Prim2DBase.prototype, "zActualOrderChangedObservable", {
  2072. get: function () {
  2073. if (!this._actualZOrderChangedObservable) {
  2074. this._actualZOrderChangedObservable = new BABYLON.Observable();
  2075. }
  2076. return this._actualZOrderChangedObservable;
  2077. },
  2078. enumerable: true,
  2079. configurable: true
  2080. });
  2081. Prim2DBase.prototype.findById = function (id) {
  2082. if (this._id === id) {
  2083. return this;
  2084. }
  2085. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  2086. var child = _a[_i];
  2087. var r = child.findById(id);
  2088. if (r != null) {
  2089. return r;
  2090. }
  2091. }
  2092. };
  2093. Prim2DBase.prototype.onZOrderChanged = function () {
  2094. };
  2095. Prim2DBase.prototype.levelIntersect = function (intersectInfo) {
  2096. return false;
  2097. };
  2098. /**
  2099. * Capture all the Events of the given PointerId for this primitive.
  2100. * Don't forget to call releasePointerEventsCapture when done.
  2101. * @param pointerId the Id of the pointer to capture the events from.
  2102. */
  2103. Prim2DBase.prototype.setPointerEventCapture = function (pointerId) {
  2104. return this.owner._setPointerCapture(pointerId, this);
  2105. };
  2106. /**
  2107. * Release a captured pointer made with setPointerEventCapture.
  2108. * @param pointerId the Id of the pointer to release the capture from.
  2109. */
  2110. Prim2DBase.prototype.releasePointerEventsCapture = function (pointerId) {
  2111. return this.owner._releasePointerCapture(pointerId, this);
  2112. };
  2113. /**
  2114. * Make an intersection test with the primitive, all inputs/outputs are stored in the IntersectInfo2D class, see its documentation for more information.
  2115. * @param intersectInfo contains the settings of the intersection to perform, to setup before calling this method as well as the result, available after a call to this method.
  2116. */
  2117. Prim2DBase.prototype.intersect = function (intersectInfo) {
  2118. if (!intersectInfo) {
  2119. return false;
  2120. }
  2121. // If this is null it means this method is call for the first level, initialize stuffs
  2122. var firstLevel = !intersectInfo._globalPickPosition;
  2123. if (firstLevel) {
  2124. // Compute the pickPosition in global space and use it to find the local position for each level down, always relative from the world to get the maximum accuracy (and speed). The other way would have been to compute in local every level down relative to its parent's local, which wouldn't be as accurate (even if javascript number is 80bits accurate).
  2125. intersectInfo._globalPickPosition = BABYLON.Vector2.Zero();
  2126. BABYLON.Vector2.TransformToRef(intersectInfo.pickPosition, this.globalTransform, intersectInfo._globalPickPosition);
  2127. intersectInfo._localPickPosition = intersectInfo.pickPosition.clone();
  2128. intersectInfo.intersectedPrimitives = new Array();
  2129. intersectInfo.topMostIntersectedPrimitive = null;
  2130. }
  2131. if (!intersectInfo.intersectHidden && !this.isVisible) {
  2132. return false;
  2133. }
  2134. // Fast rejection test with boundingInfo
  2135. if (this.isPickable && !this.boundingInfo.doesIntersect(intersectInfo._localPickPosition)) {
  2136. // Important to call this before each return to allow a good recursion next time this intersectInfo is reused
  2137. intersectInfo._exit(firstLevel);
  2138. return false;
  2139. }
  2140. // We hit the boundingInfo that bounds this primitive and its children, now we have to test on the primitive of this level
  2141. var levelIntersectRes = false;
  2142. if (this.isPickable) {
  2143. levelIntersectRes = this.levelIntersect(intersectInfo);
  2144. if (levelIntersectRes) {
  2145. var pii = new PrimitiveIntersectedInfo(this, intersectInfo._localPickPosition.clone());
  2146. intersectInfo.intersectedPrimitives.push(pii);
  2147. if (!intersectInfo.topMostIntersectedPrimitive || (intersectInfo.topMostIntersectedPrimitive.prim.actualZOffset > pii.prim.actualZOffset)) {
  2148. intersectInfo.topMostIntersectedPrimitive = pii;
  2149. }
  2150. // If we must stop at the first intersection, we're done, quit!
  2151. if (intersectInfo.findFirstOnly) {
  2152. intersectInfo._exit(firstLevel);
  2153. return true;
  2154. }
  2155. }
  2156. }
  2157. // Recurse to children if needed
  2158. if (!levelIntersectRes || !intersectInfo.findFirstOnly) {
  2159. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  2160. var curChild = _a[_i];
  2161. // Don't test primitive not pick able or if it's hidden and we don't test hidden ones
  2162. if (!curChild.isPickable || (!intersectInfo.intersectHidden && !curChild.isVisible)) {
  2163. continue;
  2164. }
  2165. // Must compute the localPickLocation for the children level
  2166. BABYLON.Vector2.TransformToRef(intersectInfo._globalPickPosition, curChild.invGlobalTransform, intersectInfo._localPickPosition);
  2167. // If we got an intersection with the child and we only need to find the first one, quit!
  2168. if (curChild.intersect(intersectInfo) && intersectInfo.findFirstOnly) {
  2169. intersectInfo._exit(firstLevel);
  2170. return true;
  2171. }
  2172. }
  2173. }
  2174. intersectInfo._exit(firstLevel);
  2175. return intersectInfo.isIntersected;
  2176. };
  2177. Prim2DBase.prototype.moveChild = function (child, previous) {
  2178. if (child.parent !== this) {
  2179. return false;
  2180. }
  2181. var childIndex = this._children.indexOf(child);
  2182. var prevIndex = previous ? this._children.indexOf(previous) : -1;
  2183. if (!this._isFlagSet(BABYLON.SmartPropertyPrim.flagChildrenFlatZOrder)) {
  2184. this._setFlags(BABYLON.SmartPropertyPrim.flagZOrderDirty);
  2185. this._firstZDirtyIndex = Math.min(this._firstZDirtyIndex, prevIndex + 1);
  2186. }
  2187. this._children.splice(prevIndex + 1, 0, this._children.splice(childIndex, 1)[0]);
  2188. };
  2189. Prim2DBase.prototype.addChild = function (child) {
  2190. child._parent = this;
  2191. this._boundingBoxDirty();
  2192. var flat = this._isFlagSet(BABYLON.SmartPropertyPrim.flagChildrenFlatZOrder);
  2193. if (flat) {
  2194. child._setFlags(BABYLON.SmartPropertyPrim.flagChildrenFlatZOrder);
  2195. child._setZOrder(this._zOrder, true);
  2196. child._zMax = this._zOrder;
  2197. }
  2198. else {
  2199. this._setFlags(BABYLON.SmartPropertyPrim.flagZOrderDirty);
  2200. }
  2201. var length = this._children.push(child);
  2202. this._firstZDirtyIndex = Math.min(this._firstZDirtyIndex, length - 1);
  2203. };
  2204. /**
  2205. * Dispose the primitive, remove it from its parent.
  2206. */
  2207. Prim2DBase.prototype.dispose = function () {
  2208. if (!_super.prototype.dispose.call(this)) {
  2209. return false;
  2210. }
  2211. if (this._actionManager) {
  2212. this._actionManager.dispose();
  2213. this._actionManager = null;
  2214. }
  2215. // If there's a parent, remove this object from its parent list
  2216. if (this._parent) {
  2217. var i = this._parent._children.indexOf(this);
  2218. if (i !== undefined) {
  2219. this._parent._children.splice(i, 1);
  2220. }
  2221. this._parent = null;
  2222. }
  2223. // Recurse dispose to children
  2224. if (this._children) {
  2225. while (this._children.length > 0) {
  2226. this._children[this._children.length - 1].dispose();
  2227. }
  2228. }
  2229. return true;
  2230. };
  2231. Prim2DBase.prototype.onPrimBecomesDirty = function () {
  2232. if (this._renderGroup && !this._isFlagSet(BABYLON.SmartPropertyPrim.flagPrimInDirtyList)) {
  2233. this._renderGroup._addPrimToDirtyList(this);
  2234. this._setFlags(BABYLON.SmartPropertyPrim.flagPrimInDirtyList);
  2235. }
  2236. };
  2237. Prim2DBase.prototype._needPrepare = function () {
  2238. return this._areSomeFlagsSet(BABYLON.SmartPropertyPrim.flagVisibilityChanged | BABYLON.SmartPropertyPrim.flagModelDirty) || (this._instanceDirtyFlags !== 0) || (this._globalTransformProcessStep !== this._globalTransformStep);
  2239. };
  2240. Prim2DBase.prototype._prepareRender = function (context) {
  2241. this._prepareRenderPre(context);
  2242. this._prepareRenderPost(context);
  2243. };
  2244. Prim2DBase.prototype._prepareRenderPre = function (context) {
  2245. };
  2246. Prim2DBase.prototype._prepareRenderPost = function (context) {
  2247. // Don't recurse if it's a renderable group, the content will be processed by the group itself
  2248. if (this instanceof BABYLON.Group2D) {
  2249. var self = this;
  2250. if (self.isRenderableGroup) {
  2251. return;
  2252. }
  2253. }
  2254. // Check if we need to recurse the prepare to children primitives
  2255. // - must have children
  2256. // - the global transform of this level have changed, or
  2257. // - the visible state of primitive has changed
  2258. if (this._children.length > 0 && ((this._globalTransformProcessStep !== this._globalTransformStep) ||
  2259. this.checkPropertiesDirty(Prim2DBase.isVisibleProperty.flagId))) {
  2260. this._children.forEach(function (c) {
  2261. // As usual stop the recursion if we meet a renderable group
  2262. if (!(c instanceof BABYLON.Group2D && c.isRenderableGroup)) {
  2263. c._prepareRender(context);
  2264. }
  2265. });
  2266. }
  2267. // Finally reset the dirty flags as we've processed everything
  2268. this._clearFlags(BABYLON.SmartPropertyPrim.flagModelDirty);
  2269. this._instanceDirtyFlags = 0;
  2270. };
  2271. Prim2DBase.prototype._canvasPreInit = function (settings) {
  2272. };
  2273. Prim2DBase.CheckParent = function (parent) {
  2274. //if (!Prim2DBase._isCanvasInit && !parent) {
  2275. // throw new Error("A Primitive needs a valid Parent, it can be any kind of Primitives based types, even the Canvas (with the exception that only Group2D can be direct child of a Canvas if the cache strategy used is TOPLEVELGROUPS)");
  2276. //}
  2277. };
  2278. Prim2DBase.prototype.updateCachedStatesOf = function (list, recurse) {
  2279. for (var _i = 0, list_1 = list; _i < list_1.length; _i++) {
  2280. var cur = list_1[_i];
  2281. cur.updateCachedStates(recurse);
  2282. }
  2283. };
  2284. Prim2DBase.prototype._parentLayoutDirty = function () {
  2285. if (!this._parent || this._parent.isDisposed) {
  2286. return;
  2287. }
  2288. this._parent._setLayoutDirty();
  2289. };
  2290. Prim2DBase.prototype._setLayoutDirty = function () {
  2291. this.onPrimBecomesDirty();
  2292. this._setFlags(BABYLON.SmartPropertyPrim.flagLayoutDirty);
  2293. };
  2294. Prim2DBase.prototype._checkPositionChange = function () {
  2295. if (this.parent && this.parent.layoutEngine.isChildPositionAllowed === false) {
  2296. console.log("Can't manually set the position of " + this.id + ", the Layout Engine of its parent doesn't allow it");
  2297. return false;
  2298. }
  2299. return true;
  2300. };
  2301. Prim2DBase.prototype._positioningDirty = function () {
  2302. this.onPrimBecomesDirty();
  2303. this._setFlags(BABYLON.SmartPropertyPrim.flagPositioningDirty);
  2304. };
  2305. Prim2DBase.prototype._spreadActualOpacityChanged = function () {
  2306. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  2307. var child = _a[_i];
  2308. child._setFlags(BABYLON.SmartPropertyPrim.flagActualOpacityDirty);
  2309. child._spreadActualOpacityChanged();
  2310. }
  2311. };
  2312. Prim2DBase.prototype._changeLayoutEngine = function (engine) {
  2313. this._layoutEngine = engine;
  2314. };
  2315. Prim2DBase.prototype._updateLocalTransform = function () {
  2316. var tflags = Prim2DBase.actualPositionProperty.flagId | Prim2DBase.rotationProperty.flagId | Prim2DBase.scaleProperty.flagId | Prim2DBase.originProperty.flagId;
  2317. if (this.checkPropertiesDirty(tflags)) {
  2318. if (this.owner) {
  2319. this.owner.addupdateLocalTransformCounter(1);
  2320. }
  2321. var rot = BABYLON.Quaternion.RotationAxis(new BABYLON.Vector3(0, 0, 1), this._rotation);
  2322. var local;
  2323. var pos = this.position;
  2324. if (this._origin.x === 0 && this._origin.y === 0) {
  2325. local = BABYLON.Matrix.Compose(new BABYLON.Vector3(this._scale, this._scale, 1), rot, new BABYLON.Vector3(pos.x, pos.y, 0));
  2326. this._localTransform = local;
  2327. }
  2328. else {
  2329. // -Origin offset
  2330. var as = this.actualSize;
  2331. BABYLON.Matrix.TranslationToRef((-as.width * this._origin.x), (-as.height * this._origin.y), 0, Prim2DBase._t0);
  2332. // -Origin * rotation
  2333. rot.toRotationMatrix(Prim2DBase._t1);
  2334. Prim2DBase._t0.multiplyToRef(Prim2DBase._t1, Prim2DBase._t2);
  2335. // -Origin * rotation * scale
  2336. BABYLON.Matrix.ScalingToRef(this._scale, this._scale, 1, Prim2DBase._t0);
  2337. Prim2DBase._t2.multiplyToRef(Prim2DBase._t0, Prim2DBase._t1);
  2338. // -Origin * rotation * scale * (Origin + Position)
  2339. BABYLON.Matrix.TranslationToRef((as.width * this._origin.x) + pos.x, (as.height * this._origin.y) + pos.y, 0, Prim2DBase._t2);
  2340. Prim2DBase._t1.multiplyToRef(Prim2DBase._t2, this._localTransform);
  2341. }
  2342. this.clearPropertiesDirty(tflags);
  2343. return true;
  2344. }
  2345. return false;
  2346. };
  2347. Prim2DBase.prototype.updateCachedStates = function (recurse) {
  2348. if (this.isDisposed) {
  2349. return;
  2350. }
  2351. this.owner.addCachedGroupRenderCounter(1);
  2352. // Check if the parent is synced
  2353. if (this._parent && ((this._parent._globalTransformProcessStep !== this.owner._globalTransformProcessStep) || this._parent._areSomeFlagsSet(BABYLON.SmartPropertyPrim.flagLayoutDirty | BABYLON.SmartPropertyPrim.flagPositioningDirty | BABYLON.SmartPropertyPrim.flagZOrderDirty))) {
  2354. this._parent.updateCachedStates(false);
  2355. }
  2356. // Update Z-Order if needed
  2357. if (this._isFlagSet(BABYLON.SmartPropertyPrim.flagZOrderDirty)) {
  2358. this._updateZOrder();
  2359. }
  2360. // Update actualSize only if there' not positioning to recompute and the size changed
  2361. // Otherwise positioning will take care of it.
  2362. var sizeDirty = this.checkPropertiesDirty(Prim2DBase.sizeProperty.flagId);
  2363. if (!this._isFlagSet(BABYLON.SmartPropertyPrim.flagLayoutDirty) && !this._isFlagSet(BABYLON.SmartPropertyPrim.flagPositioningDirty) && sizeDirty) {
  2364. var size = this.size;
  2365. if (size) {
  2366. if (this.size.width != null) {
  2367. this.actualSize.width = this.size.width;
  2368. }
  2369. if (this.size.height != null) {
  2370. this.actualSize.height = this.size.height;
  2371. }
  2372. this.clearPropertiesDirty(Prim2DBase.sizeProperty.flagId);
  2373. }
  2374. }
  2375. // Check for layout update
  2376. var positioningDirty = this._isFlagSet(BABYLON.SmartPropertyPrim.flagPositioningDirty);
  2377. if (this._isFlagSet(BABYLON.SmartPropertyPrim.flagLayoutDirty)) {
  2378. this.owner.addUpdateLayoutCounter(1);
  2379. this._layoutEngine.updateLayout(this);
  2380. this._clearFlags(BABYLON.SmartPropertyPrim.flagLayoutDirty);
  2381. }
  2382. var positioningComputed = positioningDirty && !this._isFlagSet(BABYLON.SmartPropertyPrim.flagPositioningDirty);
  2383. var autoContentChanged = false;
  2384. if (this.isSizeAuto) {
  2385. if (!this._lastAutoSizeArea) {
  2386. autoContentChanged = this.size !== null;
  2387. }
  2388. else {
  2389. autoContentChanged = (!this._lastAutoSizeArea.equals(this.size));
  2390. }
  2391. }
  2392. // Check for positioning update
  2393. if (!positioningComputed && (autoContentChanged || sizeDirty || this._isFlagSet(BABYLON.SmartPropertyPrim.flagPositioningDirty) || (this._parent && !this._parent.contentArea.equals(this._parentContentArea)))) {
  2394. this._updatePositioning();
  2395. this._clearFlags(BABYLON.SmartPropertyPrim.flagPositioningDirty);
  2396. if (sizeDirty) {
  2397. this.clearPropertiesDirty(Prim2DBase.sizeProperty.flagId);
  2398. }
  2399. positioningComputed = true;
  2400. }
  2401. if (positioningComputed && this._parent) {
  2402. this._parentContentArea.copyFrom(this._parent.contentArea);
  2403. }
  2404. // Check if we must update this prim
  2405. if (this === this.owner || this._globalTransformProcessStep !== this.owner._globalTransformProcessStep) {
  2406. this.owner.addUpdateGlobalTransformCounter(1);
  2407. var curVisibleState = this.isVisible;
  2408. this.isVisible = (!this._parent || this._parent.isVisible) && this.levelVisible;
  2409. // Detect a change of visibility
  2410. this._changeFlags(BABYLON.SmartPropertyPrim.flagVisibilityChanged, curVisibleState !== this.isVisible);
  2411. // Get/compute the localTransform
  2412. var localDirty = this._updateLocalTransform();
  2413. var parentPaddingChanged = false;
  2414. var parentPaddingOffset = Prim2DBase._v0;
  2415. if (this._parent) {
  2416. parentPaddingOffset = this._parent._paddingOffset;
  2417. parentPaddingChanged = !parentPaddingOffset.equals(this._parentPaddingOffset);
  2418. }
  2419. // Check if there are changes in the parent that will force us to update the global matrix
  2420. var parentDirty = (this._parent != null) ? (this._parent._globalTransformStep !== this._parentTransformStep) : false;
  2421. // Check if we have to update the globalTransform
  2422. if (!this._globalTransform || localDirty || parentDirty || parentPaddingChanged) {
  2423. var globalTransform = this._parent ? this._parent._globalTransform : null;
  2424. var localTransform = void 0;
  2425. Prim2DBase._transMtx.copyFrom(this._localTransform);
  2426. Prim2DBase._transMtx.m[12] += this._layoutAreaPos.x + this._marginOffset.x + parentPaddingOffset.x;
  2427. Prim2DBase._transMtx.m[13] += this._layoutAreaPos.y + this._marginOffset.y + parentPaddingOffset.y;
  2428. localTransform = Prim2DBase._transMtx;
  2429. this._globalTransform = this._parent ? localTransform.multiply(globalTransform) : localTransform.clone();
  2430. this._invGlobalTransform = BABYLON.Matrix.Invert(this._globalTransform);
  2431. this._globalTransformStep = this.owner._globalTransformProcessStep + 1;
  2432. this._parentTransformStep = this._parent ? this._parent._globalTransformStep : 0;
  2433. }
  2434. this._globalTransformProcessStep = this.owner._globalTransformProcessStep;
  2435. }
  2436. if (recurse) {
  2437. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  2438. var child = _a[_i];
  2439. // Stop the recursion if we meet a renderable group
  2440. child.updateCachedStates(!(child instanceof BABYLON.Group2D && child.isRenderableGroup));
  2441. }
  2442. }
  2443. };
  2444. Prim2DBase.prototype._updatePositioning = function () {
  2445. if (this.owner) {
  2446. this.owner.addUpdatePositioningCounter(1);
  2447. }
  2448. // From this point we assume that the primitive layoutArea is computed and up to date.
  2449. // We know have to :
  2450. // 1. Determine the PaddingArea and the ActualPosition based on the margin/marginAlignment properties, which will also set the size property of the primitive
  2451. // 2. Determine the contentArea based on the padding property.
  2452. // Auto Create PaddingArea if there's no actualSize on width&|height to allocate the whole content available to the paddingArea where the actualSize is null
  2453. if (!this._hasMargin && (this.actualSize.width == null || this.actualSize.height == null)) {
  2454. if (this.actualSize.width == null) {
  2455. this.marginAlignment.horizontal = PrimitiveAlignment.AlignStretch;
  2456. }
  2457. if (this.actualSize.height == null) {
  2458. this.marginAlignment.vertical = PrimitiveAlignment.AlignStretch;
  2459. }
  2460. }
  2461. // Apply margin
  2462. if (this._hasMargin) {
  2463. this.margin.computeWithAlignment(this.layoutArea, this.size, this.marginAlignment, this._marginOffset, Prim2DBase._size);
  2464. this.actualSize = Prim2DBase._size.clone();
  2465. }
  2466. var isSizeAuto = this.isSizeAuto;
  2467. if (this._hasPadding) {
  2468. // Two cases from here: the size of the Primitive is Auto, its content can't be shrink, so me resize the primitive itself
  2469. if (isSizeAuto) {
  2470. var content = this.size.clone();
  2471. this._getActualSizeFromContentToRef(content, Prim2DBase._icArea);
  2472. this.padding.enlarge(Prim2DBase._icArea, this._paddingOffset, Prim2DBase._size);
  2473. this._contentArea.copyFrom(content);
  2474. this.actualSize = Prim2DBase._size.clone();
  2475. // Changing the padding has resize the prim, which forces us to recompute margin again
  2476. if (this._hasMargin) {
  2477. this.margin.computeWithAlignment(this.layoutArea, Prim2DBase._size, this.marginAlignment, this._marginOffset, Prim2DBase._size);
  2478. }
  2479. }
  2480. else {
  2481. this._getInitialContentAreaToRef(this.actualSize, Prim2DBase._icPos, Prim2DBase._icArea);
  2482. Prim2DBase._icArea.width = Math.max(0, Prim2DBase._icArea.width);
  2483. Prim2DBase._icArea.height = Math.max(0, Prim2DBase._icArea.height);
  2484. this.padding.compute(Prim2DBase._icArea, this._paddingOffset, Prim2DBase._size);
  2485. this._paddingOffset.x += Prim2DBase._icPos.x;
  2486. this._paddingOffset.y += Prim2DBase._icPos.y;
  2487. this._contentArea.copyFrom(Prim2DBase._size);
  2488. }
  2489. }
  2490. else {
  2491. this._getInitialContentAreaToRef(this.actualSize, Prim2DBase._icPos, Prim2DBase._icArea);
  2492. Prim2DBase._icArea.width = Math.max(0, Prim2DBase._icArea.width);
  2493. Prim2DBase._icArea.height = Math.max(0, Prim2DBase._icArea.height);
  2494. this._paddingOffset.copyFrom(Prim2DBase._icPos);
  2495. this._contentArea.copyFrom(Prim2DBase._icArea);
  2496. }
  2497. var aPos = new BABYLON.Vector2(this._layoutAreaPos.x + this._marginOffset.x, this._layoutAreaPos.y + this._marginOffset.y);
  2498. this.actualPosition = aPos;
  2499. if (isSizeAuto) {
  2500. this._lastAutoSizeArea = this.size;
  2501. }
  2502. };
  2503. Object.defineProperty(Prim2DBase.prototype, "contentArea", {
  2504. /**
  2505. * Get the content are of this primitive, this area is computed using the padding property and also possibly the primitive type itself.
  2506. * Children of this primitive will be positioned relative to the bottom/left corner of this area.
  2507. */
  2508. get: function () {
  2509. // Check for positioning update
  2510. if (this._isFlagSet(BABYLON.SmartPropertyPrim.flagPositioningDirty)) {
  2511. this._updatePositioning();
  2512. this._clearFlags(BABYLON.SmartPropertyPrim.flagPositioningDirty);
  2513. }
  2514. return this._contentArea;
  2515. },
  2516. enumerable: true,
  2517. configurable: true
  2518. });
  2519. Prim2DBase.prototype._patchHierarchy = function (owner) {
  2520. this._owner = owner;
  2521. // The only place we initialize the _renderGroup is this method, if it's set, we already been there, no need to execute more
  2522. if (this._renderGroup != null) {
  2523. return;
  2524. }
  2525. if (this instanceof BABYLON.Group2D) {
  2526. var group = this;
  2527. group.detectGroupStates();
  2528. if (group._trackedNode && !group._isFlagSet(BABYLON.SmartPropertyPrim.flagTrackedGroup)) {
  2529. group.owner._registerTrackedNode(this);
  2530. }
  2531. }
  2532. if (this._parent) {
  2533. this._renderGroup = this.parent.traverseUp(function (p) { return p instanceof BABYLON.Group2D && p.isRenderableGroup; });
  2534. this._parentLayoutDirty();
  2535. }
  2536. // Make sure the prim is in the dirtyList if it should be
  2537. if (this._renderGroup && this.isDirty) {
  2538. var list = this._renderGroup._renderableData._primDirtyList;
  2539. var i = list.indexOf(this);
  2540. if (i === -1) {
  2541. list.push(this);
  2542. }
  2543. }
  2544. // Recurse
  2545. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  2546. var child = _a[_i];
  2547. child._hierarchyDepth = this._hierarchyDepth + 1;
  2548. child._patchHierarchy(owner);
  2549. }
  2550. };
  2551. Prim2DBase.prototype._updateZOrder = function () {
  2552. var prevLinPos = this._primLinearPosition;
  2553. var startI = 0;
  2554. var startZ = this._zOrder;
  2555. // We must start rebuilding Z-Order from the Prim before the first one that changed, because we know its Z-Order is correct, so are its children, but it's better to recompute everything from this point instead of finding the last valid children
  2556. var childrenCount = this._children.length;
  2557. if (this._firstZDirtyIndex > 0) {
  2558. if ((this._firstZDirtyIndex - 1) < childrenCount) {
  2559. var prevPrim = this._children[this._firstZDirtyIndex - 1];
  2560. prevLinPos = prevPrim._primLinearPosition;
  2561. startI = this._firstZDirtyIndex - 1;
  2562. startZ = prevPrim._zOrder;
  2563. }
  2564. }
  2565. var startPos = prevLinPos;
  2566. // Update the linear position of the primitive from the first one to the last inside this primitive, compute the total number of prim traversed
  2567. Prim2DBase._totalCount = 0;
  2568. for (var i = startI; i < childrenCount; i++) {
  2569. var child = this._children[i];
  2570. prevLinPos = child._updatePrimitiveLinearPosition(prevLinPos);
  2571. }
  2572. // Compute the new Z-Order for all the primitives
  2573. // Add 20% to the current total count to reserve space for future insertions, except if we're rebuilding due to a zMinDelta reached
  2574. var zDelta = (this._zMax - startZ) / (Prim2DBase._totalCount * (Prim2DBase._zRebuildReentrency ? 1 : 1.2));
  2575. // If the computed delta is less than the smallest allowed by the depth buffer, we rebuild the Z-Order from the very beginning of the primitive's children (that is, the first) to redistribute uniformly the Z.
  2576. if (zDelta < BABYLON.Canvas2D._zMinDelta) {
  2577. // Check for re-entrance, if the flag is true we already attempted a rebuild but couldn't get a better zDelta, go up in the hierarchy to rebuilt one level up, hoping to get this time a decent delta, otherwise, recurse until we got it or when no parent is reached, which would mean the canvas would have more than 16 millions of primitives...
  2578. if (Prim2DBase._zRebuildReentrency) {
  2579. var p = this._parent;
  2580. if (p == null) {
  2581. // Can't find a good Z delta and we're in the canvas, which mean we're dealing with too many objects (which should never happen, but well...)
  2582. console.log("Can't compute Z-Order for " + this.id + "'s children, zDelta is too small, Z-Order is now in an unstable state");
  2583. Prim2DBase._zRebuildReentrency = false;
  2584. return;
  2585. }
  2586. p._firstZDirtyIndex = 0;
  2587. return p._updateZOrder();
  2588. }
  2589. Prim2DBase._zRebuildReentrency = true;
  2590. this._firstZDirtyIndex = 0;
  2591. this._updateZOrder();
  2592. Prim2DBase._zRebuildReentrency = false;
  2593. }
  2594. for (var i = startI; i < childrenCount; i++) {
  2595. var child = this._children[i];
  2596. child._updatePrimitiveZOrder(startPos, startZ, zDelta);
  2597. }
  2598. // Notify the Observers that we found during the Z change (we do it after to avoid any kind of re-entrance)
  2599. for (var _i = 0, _a = Prim2DBase._zOrderChangedNotifList; _i < _a.length; _i++) {
  2600. var p = _a[_i];
  2601. p._actualZOrderChangedObservable.notifyObservers(p.actualZOffset);
  2602. }
  2603. Prim2DBase._zOrderChangedNotifList.splice(0);
  2604. this._firstZDirtyIndex = Prim2DBase._bigInt;
  2605. this._clearFlags(BABYLON.SmartPropertyPrim.flagZOrderDirty);
  2606. };
  2607. Prim2DBase.prototype._updatePrimitiveLinearPosition = function (prevLinPos) {
  2608. if (this.isManualZOrder) {
  2609. return prevLinPos;
  2610. }
  2611. this._primLinearPosition = ++prevLinPos;
  2612. Prim2DBase._totalCount++;
  2613. // Check for the FlatZOrder, which means the children won't have a dedicated Z-Order but will all share the same (unique) one.
  2614. if (!this._isFlagSet(BABYLON.SmartPropertyPrim.flagChildrenFlatZOrder)) {
  2615. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  2616. var child = _a[_i];
  2617. prevLinPos = child._updatePrimitiveLinearPosition(prevLinPos);
  2618. }
  2619. }
  2620. return prevLinPos;
  2621. };
  2622. Prim2DBase.prototype._updatePrimitiveZOrder = function (startPos, startZ, deltaZ) {
  2623. if (this.isManualZOrder) {
  2624. return null;
  2625. }
  2626. var newZ = startZ + ((this._primLinearPosition - startPos) * deltaZ);
  2627. var isFlat = this._isFlagSet(BABYLON.SmartPropertyPrim.flagChildrenFlatZOrder);
  2628. this._setZOrder(newZ, false);
  2629. if (this._isFlagSet(BABYLON.SmartPropertyPrim.flagZOrderDirty)) {
  2630. this._firstZDirtyIndex = Prim2DBase._bigInt;
  2631. this._clearFlags(BABYLON.SmartPropertyPrim.flagZOrderDirty);
  2632. }
  2633. var curZ = newZ;
  2634. // Check for the FlatZOrder, which means the children won't have a dedicated Z-Order but will all share the same (unique) one.
  2635. if (isFlat) {
  2636. if (this._children.length > 0) {
  2637. //let childrenZOrder = startZ + ((this._children[0]._primLinearPosition - startPos) * deltaZ);
  2638. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  2639. var child = _a[_i];
  2640. child._updatePrimitiveFlatZOrder(this._zOrder);
  2641. }
  2642. }
  2643. }
  2644. else {
  2645. for (var _b = 0, _c = this._children; _b < _c.length; _b++) {
  2646. var child = _c[_b];
  2647. var r = child._updatePrimitiveZOrder(startPos, startZ, deltaZ);
  2648. if (r != null) {
  2649. curZ = r;
  2650. }
  2651. }
  2652. }
  2653. this._zMax = isFlat ? newZ : (curZ + deltaZ);
  2654. return curZ;
  2655. };
  2656. Prim2DBase.prototype._updatePrimitiveFlatZOrder = function (newZ) {
  2657. if (this.isManualZOrder) {
  2658. return;
  2659. }
  2660. this._setZOrder(newZ, false);
  2661. this._zMax = newZ;
  2662. if (this._isFlagSet(BABYLON.SmartPropertyPrim.flagZOrderDirty)) {
  2663. this._firstZDirtyIndex = Prim2DBase._bigInt;
  2664. this._clearFlags(BABYLON.SmartPropertyPrim.flagZOrderDirty);
  2665. }
  2666. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  2667. var child = _a[_i];
  2668. child._updatePrimitiveFlatZOrder(newZ);
  2669. }
  2670. };
  2671. Prim2DBase.prototype._setZOrder = function (newZ, directEmit) {
  2672. if (newZ !== this._zOrder) {
  2673. this._zOrder = newZ;
  2674. this.onPrimBecomesDirty();
  2675. this.onZOrderChanged();
  2676. if (this._actualZOrderChangedObservable && this._actualZOrderChangedObservable.hasObservers()) {
  2677. if (directEmit) {
  2678. this._actualZOrderChangedObservable.notifyObservers(newZ);
  2679. }
  2680. else {
  2681. Prim2DBase._zOrderChangedNotifList.push(this);
  2682. }
  2683. }
  2684. }
  2685. };
  2686. Prim2DBase.prototype._updateRenderMode = function () {
  2687. };
  2688. /**
  2689. * This method is used to alter the contentArea of the Primitive before margin is applied.
  2690. * In most of the case you won't need to override this method, but it can prove some usefulness, check the Rectangle2D class for a concrete application.
  2691. * @param primSize the current size of the primitive
  2692. * @param initialContentPosition the position of the initial content area to compute, a valid object is passed, you have to set its properties. PLEASE ROUND the values, we're talking about pixels and fraction of them is not a good thing!
  2693. * @param initialContentArea the size of the initial content area to compute, a valid object is passed, you have to set its properties. PLEASE ROUND the values, we're talking about pixels and fraction of them is not a good thing!
  2694. */
  2695. Prim2DBase.prototype._getInitialContentAreaToRef = function (primSize, initialContentPosition, initialContentArea) {
  2696. initialContentArea.copyFrom(primSize);
  2697. initialContentPosition.x = initialContentPosition.y = 0;
  2698. };
  2699. /**
  2700. * This method is used to calculate the new size of the primitive based on the content which must stay the same
  2701. * Check the Rectangle2D implementation for a concrete application.
  2702. * @param primSize the current size of the primitive
  2703. * @param newPrimSize the new size of the primitive. PLEASE ROUND THE values, we're talking about pixels and fraction of them are not our friends!
  2704. */
  2705. Prim2DBase.prototype._getActualSizeFromContentToRef = function (primSize, newPrimSize) {
  2706. newPrimSize.copyFrom(primSize);
  2707. };
  2708. Prim2DBase.PRIM2DBASE_PROPCOUNT = 15;
  2709. Prim2DBase._bigInt = Math.pow(2, 30);
  2710. Prim2DBase._nullPosition = BABYLON.Vector2.Zero();
  2711. Prim2DBase.boundinbBoxReentrency = false;
  2712. Prim2DBase.nullSize = BABYLON.Size.Zero();
  2713. Prim2DBase._bMax = BABYLON.Vector2.Zero();
  2714. Prim2DBase._isCanvasInit = false;
  2715. Prim2DBase._t0 = new BABYLON.Matrix();
  2716. Prim2DBase._t1 = new BABYLON.Matrix();
  2717. Prim2DBase._t2 = new BABYLON.Matrix();
  2718. Prim2DBase._v0 = BABYLON.Vector2.Zero(); // Must stay with the value 0,0
  2719. Prim2DBase._transMtx = BABYLON.Matrix.Zero();
  2720. Prim2DBase._icPos = BABYLON.Vector2.Zero();
  2721. Prim2DBase._icArea = BABYLON.Size.Zero();
  2722. Prim2DBase._size = BABYLON.Size.Zero();
  2723. Prim2DBase._zOrderChangedNotifList = new Array();
  2724. Prim2DBase._zRebuildReentrency = false;
  2725. Prim2DBase._totalCount = 0;
  2726. __decorate([
  2727. BABYLON.instanceLevelProperty(1, function (pi) { return Prim2DBase.actualPositionProperty = pi; }, false, false, true)
  2728. ], Prim2DBase.prototype, "actualPosition", null);
  2729. __decorate([
  2730. BABYLON.dynamicLevelProperty(2, function (pi) { return Prim2DBase.positionProperty = pi; }, false, false, true)
  2731. ], Prim2DBase.prototype, "position", null);
  2732. __decorate([
  2733. BABYLON.dynamicLevelProperty(3, function (pi) { return Prim2DBase.sizeProperty = pi; }, false, true)
  2734. ], Prim2DBase.prototype, "size", null);
  2735. __decorate([
  2736. BABYLON.instanceLevelProperty(4, function (pi) { return Prim2DBase.rotationProperty = pi; }, false, true)
  2737. ], Prim2DBase.prototype, "rotation", null);
  2738. __decorate([
  2739. BABYLON.instanceLevelProperty(5, function (pi) { return Prim2DBase.scaleProperty = pi; }, false, true)
  2740. ], Prim2DBase.prototype, "scale", null);
  2741. __decorate([
  2742. BABYLON.dynamicLevelProperty(6, function (pi) { return Prim2DBase.originProperty = pi; }, false, true)
  2743. ], Prim2DBase.prototype, "origin", null);
  2744. __decorate([
  2745. BABYLON.dynamicLevelProperty(7, function (pi) { return Prim2DBase.levelVisibleProperty = pi; })
  2746. ], Prim2DBase.prototype, "levelVisible", null);
  2747. __decorate([
  2748. BABYLON.instanceLevelProperty(8, function (pi) { return Prim2DBase.isVisibleProperty = pi; })
  2749. ], Prim2DBase.prototype, "isVisible", null);
  2750. __decorate([
  2751. BABYLON.instanceLevelProperty(9, function (pi) { return Prim2DBase.zOrderProperty = pi; })
  2752. ], Prim2DBase.prototype, "zOrder", null);
  2753. __decorate([
  2754. BABYLON.dynamicLevelProperty(10, function (pi) { return Prim2DBase.marginProperty = pi; })
  2755. ], Prim2DBase.prototype, "margin", null);
  2756. __decorate([
  2757. BABYLON.dynamicLevelProperty(11, function (pi) { return Prim2DBase.paddingProperty = pi; })
  2758. ], Prim2DBase.prototype, "padding", null);
  2759. __decorate([
  2760. BABYLON.dynamicLevelProperty(12, function (pi) { return Prim2DBase.marginAlignmentProperty = pi; })
  2761. ], Prim2DBase.prototype, "marginAlignment", null);
  2762. __decorate([
  2763. BABYLON.instanceLevelProperty(13, function (pi) { return Prim2DBase.opacityProperty = pi; })
  2764. ], Prim2DBase.prototype, "opacity", null);
  2765. Prim2DBase = __decorate([
  2766. BABYLON.className("Prim2DBase")
  2767. ], Prim2DBase);
  2768. return Prim2DBase;
  2769. }(BABYLON.SmartPropertyPrim));
  2770. BABYLON.Prim2DBase = Prim2DBase;
  2771. })(BABYLON || (BABYLON = {}));