babylon.smartPropertyPrim.ts 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654
  1. module BABYLON {
  2. export class Prim2DClassInfo {
  3. }
  4. export class Prim2DPropInfo {
  5. static PROPKIND_MODEL: number = 1;
  6. static PROPKIND_INSTANCE: number = 2;
  7. static PROPKIND_DYNAMIC: number = 3;
  8. id: number;
  9. flagId: number;
  10. kind: number;
  11. name: string;
  12. dirtyBoundingInfo: boolean;
  13. dirtyParentBoundingInfo: boolean;
  14. typeLevelCompare: boolean;
  15. }
  16. /**
  17. * Custom type of the propertyChanged observable
  18. */
  19. export class PropertyChangedInfo {
  20. /**
  21. * Previous value of the property
  22. */
  23. oldValue: any;
  24. /**
  25. * New value of the property
  26. */
  27. newValue: any;
  28. /**
  29. * Name of the property that changed its value
  30. */
  31. propertyName: string;
  32. }
  33. /**
  34. * Property Changed interface
  35. */
  36. export interface IPropertyChanged {
  37. /**
  38. * PropertyChanged observable
  39. */
  40. propertyChanged: Observable<PropertyChangedInfo>;
  41. }
  42. export class ClassTreeInfo<TClass, TProp>{
  43. constructor(baseClass: ClassTreeInfo<TClass, TProp>, type: Object, classContentFactory: (base: TClass) => TClass) {
  44. this._baseClass = baseClass;
  45. this._type = type;
  46. this._subClasses = new Array<{ type: Object, node: ClassTreeInfo<TClass, TProp> }>();
  47. this._levelContent = new StringDictionary<TProp>();
  48. this._classContentFactory = classContentFactory;
  49. }
  50. get classContent(): TClass {
  51. if (!this._classContent) {
  52. this._classContent = this._classContentFactory(this._baseClass ? this._baseClass.classContent : null);
  53. }
  54. return this._classContent;
  55. }
  56. get type(): Object {
  57. return this._type;
  58. }
  59. get levelContent(): StringDictionary<TProp> {
  60. return this._levelContent;
  61. }
  62. get fullContent(): StringDictionary<TProp> {
  63. if (!this._fullContent) {
  64. let dic = new StringDictionary<TProp>();
  65. let curLevel: ClassTreeInfo<TClass, TProp> = this;
  66. while (curLevel) {
  67. curLevel.levelContent.forEach((k, v) => dic.add(k, v));
  68. curLevel = curLevel._baseClass;
  69. }
  70. this._fullContent = dic;
  71. }
  72. return this._fullContent;
  73. }
  74. getLevelOf(type: Object): ClassTreeInfo<TClass, TProp> {
  75. // Are we already there?
  76. if (type === this._type) {
  77. return this;
  78. }
  79. let baseProto = Object.getPrototypeOf(type);
  80. let curProtoContent = this.getOrAddType(Object.getPrototypeOf(baseProto), baseProto);
  81. if (!curProtoContent) {
  82. this.getLevelOf(baseProto);
  83. }
  84. return this.getOrAddType(baseProto, type);
  85. }
  86. getOrAddType(baseType: Object, type: Object): ClassTreeInfo<TClass, TProp> {
  87. // Are we at the level corresponding to the baseType?
  88. // If so, get or add the level we're looking for
  89. if (baseType === this._type) {
  90. for (let subType of this._subClasses) {
  91. if (subType.type === type) {
  92. return subType.node;
  93. }
  94. }
  95. let node = new ClassTreeInfo<TClass, TProp>(this, type, this._classContentFactory);
  96. let info = { type: type, node: node };
  97. this._subClasses.push(info);
  98. return info.node;
  99. }
  100. // Recurse down to keep looking for the node corresponding to the baseTypeName
  101. for (let subType of this._subClasses) {
  102. let info = subType.node.getOrAddType(baseType, type);
  103. if (info) {
  104. return info;
  105. }
  106. }
  107. return null;
  108. }
  109. static get<TClass, TProp>(type: Object): ClassTreeInfo<TClass, TProp> {
  110. let dic = <ClassTreeInfo<TClass, TProp>>type["__classTreeInfo"];
  111. if (!dic) {
  112. return null;
  113. }
  114. return dic.getLevelOf(type);
  115. }
  116. static getOrRegister<TClass, TProp>(type: Object, classContentFactory: (base: TClass) => TClass): ClassTreeInfo<TClass, TProp> {
  117. let dic = <ClassTreeInfo<TClass, TProp>>type["__classTreeInfo"];
  118. if (!dic) {
  119. dic = new ClassTreeInfo<TClass, TProp>(null, type, classContentFactory);
  120. type["__classTreeInfo"] = dic;
  121. }
  122. return dic;
  123. }
  124. private _type: Object;
  125. private _classContent: TClass;
  126. private _baseClass: ClassTreeInfo<TClass, TProp>;
  127. private _subClasses: Array<{ type: Object, node: ClassTreeInfo<TClass, TProp> }>;
  128. private _levelContent: StringDictionary<TProp>;
  129. private _fullContent: StringDictionary<TProp>;
  130. private _classContentFactory: (base: TClass) => TClass;
  131. }
  132. @className("SmartPropertyPrim")
  133. /**
  134. * Base class of the primitives, implementing core crosscutting features
  135. */
  136. export abstract class SmartPropertyPrim implements IPropertyChanged {
  137. constructor() {
  138. this._flags = 0;
  139. this._modelKey = null;
  140. this._instanceDirtyFlags = 0;
  141. this._levelBoundingInfo = new BoundingInfo2D();
  142. this.animations = new Array<Animation>();
  143. }
  144. /**
  145. * An observable that is triggered when a property (using of the XXXXLevelProperty decorator) has its value changing.
  146. * You can add an observer that will be triggered only for a given set of Properties using the Mask feature of the Observable and the corresponding Prim2DPropInfo.flagid value (e.g. Prim2DBase.positionProperty.flagid|Prim2DBase.rotationProperty.flagid to be notified only about position or rotation change)
  147. */
  148. public propertyChanged: Observable<PropertyChangedInfo>;
  149. /**
  150. * Check if the object is disposed or not.
  151. * @returns true if the object is dispose, false otherwise.
  152. */
  153. public get isDisposed(): boolean {
  154. return this._isFlagSet(SmartPropertyPrim.flagIsDisposed);
  155. }
  156. /**
  157. * Disposable pattern, this method must be overloaded by derived types in order to clean up hardware related resources.
  158. * @returns false if the object is already dispose, true otherwise. Your implementation must call super.dispose() and check for a false return and return immediately if it's the case.
  159. */
  160. public dispose(): boolean {
  161. if (this.isDisposed) {
  162. return false;
  163. }
  164. // Don't set to null, it may upset somebody...
  165. this.animations.splice(0);
  166. this._setFlags(SmartPropertyPrim.flagIsDisposed);
  167. return true;
  168. }
  169. /**
  170. * Animation array, more info: http://doc.babylonjs.com/tutorials/Animations
  171. */
  172. public animations: Animation[];
  173. /**
  174. * Returns as a new array populated with the Animatable used by the primitive. Must be overloaded by derived primitives.
  175. * Look at Sprite2D for more information
  176. */
  177. public getAnimatables(): IAnimatable[] {
  178. return new Array<IAnimatable>();
  179. }
  180. /**
  181. * Property giving the Model Key associated to the property.
  182. * This value is constructed from the type of the primitive and all the name/value of its properties declared with the modelLevelProperty decorator
  183. * @returns the model key string.
  184. */
  185. public get modelKey(): string {
  186. // No need to compute it?
  187. if (!this._isFlagSet(SmartPropertyPrim.flagModelDirty) && this._modelKey) {
  188. return this._modelKey;
  189. }
  190. let modelKey = `Class:${Tools.getClassName(this)};`;
  191. let propDic = this.propDic;
  192. propDic.forEach((k, v) => {
  193. if (v.kind === Prim2DPropInfo.PROPKIND_MODEL) {
  194. let propVal = this[v.name];
  195. // Special case, array, this WON'T WORK IN ALL CASES, all entries have to be of the same type and it must be a BJS well known one
  196. if (propVal && propVal.constructor === Array) {
  197. let firstVal = propVal[0];
  198. if (!firstVal) {
  199. propVal = 0;
  200. } else {
  201. propVal = Tools.hashCodeFromStream(Tools.arrayOrStringFeeder(propVal));
  202. }
  203. }
  204. modelKey += v.name + ":" + ((propVal != null) ? ((v.typeLevelCompare) ? Tools.getClassName(propVal) : propVal.toString()) : "[null]") + ";";
  205. }
  206. });
  207. this._clearFlags(SmartPropertyPrim.flagModelDirty);
  208. this._modelKey = modelKey;
  209. return modelKey;
  210. }
  211. /**
  212. * States if the Primitive is dirty and should be rendered again next time.
  213. * @returns true is dirty, false otherwise
  214. */
  215. public get isDirty(): boolean {
  216. return (this._instanceDirtyFlags !== 0) || this._areSomeFlagsSet(SmartPropertyPrim.flagModelDirty | SmartPropertyPrim.flagPositioningDirty | SmartPropertyPrim.flagLayoutDirty);
  217. }
  218. /**
  219. * Access the dictionary of properties metadata. Only properties decorated with XXXXLevelProperty are concerned
  220. * @returns the dictionary, the key is the property name as declared in Javascript, the value is the metadata object
  221. */
  222. private get propDic(): StringDictionary<Prim2DPropInfo> {
  223. if (!this._propInfo) {
  224. let cti = ClassTreeInfo.get<Prim2DClassInfo, Prim2DPropInfo>(Object.getPrototypeOf(this));
  225. if (!cti) {
  226. throw new Error("Can't access the propDic member in class definition, is this class SmartPropertyPrim based?");
  227. }
  228. this._propInfo = cti.fullContent;
  229. }
  230. return this._propInfo;
  231. }
  232. private static _createPropInfo(target: Object, propName: string, propId: number, dirtyBoundingInfo: boolean, dirtyParentBoundingBox: boolean, typeLevelCompare: boolean, kind: number): Prim2DPropInfo {
  233. let dic = ClassTreeInfo.getOrRegister<Prim2DClassInfo, Prim2DPropInfo>(target, () => new Prim2DClassInfo());
  234. var node = dic.getLevelOf(target);
  235. let propInfo = node.levelContent.get(propId.toString());
  236. if (propInfo) {
  237. throw new Error(`The ID ${propId} is already taken by another property declaration named: ${propInfo.name}`);
  238. }
  239. // Create, setup and add the PropInfo object to our prop dictionary
  240. propInfo = new Prim2DPropInfo();
  241. propInfo.id = propId;
  242. propInfo.flagId = Math.pow(2, propId);
  243. propInfo.kind = kind;
  244. propInfo.name = propName;
  245. propInfo.dirtyBoundingInfo = dirtyBoundingInfo;
  246. propInfo.dirtyParentBoundingInfo = dirtyParentBoundingBox;
  247. propInfo.typeLevelCompare = typeLevelCompare;
  248. node.levelContent.add(propName, propInfo);
  249. return propInfo;
  250. }
  251. private static _checkUnchanged(curValue, newValue): boolean {
  252. // Nothing to nothing: nothing to do!
  253. if ((curValue === null && newValue === null) || (curValue === undefined && newValue === undefined)) {
  254. return true;
  255. }
  256. // Check value unchanged
  257. if ((curValue != null) && (newValue != null)) {
  258. if (typeof (curValue.equals) == "function") {
  259. if (curValue.equals(newValue)) {
  260. return true;
  261. }
  262. } else {
  263. if (curValue === newValue) {
  264. return true;
  265. }
  266. }
  267. }
  268. return false;
  269. }
  270. protected _triggerPropertyChanged(propInfo: Prim2DPropInfo, newValue: any) {
  271. if (this.isDisposed) {
  272. return;
  273. }
  274. if (!propInfo) {
  275. return;
  276. }
  277. this._handlePropChanged(undefined, newValue, propInfo.name, propInfo, propInfo.typeLevelCompare);
  278. }
  279. protected _boundingBoxDirty() {
  280. this._setFlags(SmartPropertyPrim.flagLevelBoundingInfoDirty);
  281. // Escalate the dirty flag in the instance hierarchy, stop when a renderable group is found or at the end
  282. if (this instanceof Prim2DBase) {
  283. let curprim: Prim2DBase = (<any>this);
  284. while (curprim) {
  285. curprim._setFlags(SmartPropertyPrim.flagBoundingInfoDirty);
  286. if (curprim.isSizeAuto) {
  287. curprim.onPrimitivePropertyDirty(Prim2DBase.sizeProperty.flagId);
  288. curprim._setFlags(SmartPropertyPrim.flagPositioningDirty);
  289. }
  290. if (curprim instanceof Group2D) {
  291. if (curprim.isRenderableGroup) {
  292. break;
  293. }
  294. }
  295. curprim = curprim.parent;
  296. }
  297. }
  298. }
  299. private static propChangedInfo = new PropertyChangedInfo();
  300. private _handlePropChanged<T>(curValue: T, newValue: T, propName: string, propInfo: Prim2DPropInfo, typeLevelCompare: boolean) {
  301. // If the property change also dirty the boundingInfo, update the boundingInfo dirty flags
  302. if (propInfo.dirtyBoundingInfo) {
  303. this._boundingBoxDirty();
  304. } else if (propInfo.dirtyParentBoundingInfo) {
  305. let p: SmartPropertyPrim = (<any>this)._parent;
  306. if (p != null) {
  307. p._boundingBoxDirty();
  308. }
  309. }
  310. // Trigger property changed
  311. let info = SmartPropertyPrim.propChangedInfo;
  312. info.oldValue = curValue;
  313. info.newValue = newValue;
  314. info.propertyName = propName;
  315. let propMask = propInfo.flagId;
  316. this.propertyChanged.notifyObservers(info, propMask);
  317. // If the property belong to a group, check if it's a cached one, and dirty its render sprite accordingly
  318. if (this instanceof Group2D) {
  319. (<SmartPropertyPrim>this).handleGroupChanged(propInfo);
  320. }
  321. // Check for parent layout dirty
  322. if (this instanceof Prim2DBase) {
  323. let p = (<any>this)._parent;
  324. if (p != null && p.layoutEngine && (p.layoutEngine.layoutDirtyOnPropertyChangedMask & propInfo.flagId) !== 0) {
  325. p._setLayoutDirty();
  326. }
  327. }
  328. // For type level compare, if there's a change of type it's a change of model, otherwise we issue an instance change
  329. var instanceDirty = false;
  330. if (typeLevelCompare && curValue != null && newValue != null) {
  331. var cvProto = (<any>curValue).__proto__;
  332. var nvProto = (<any>newValue).__proto__;
  333. instanceDirty = (cvProto === nvProto);
  334. }
  335. // Set the dirty flags
  336. if (!instanceDirty && (propInfo.kind === Prim2DPropInfo.PROPKIND_MODEL)) {
  337. if (!this.isDirty) {
  338. this._setFlags(SmartPropertyPrim.flagModelDirty);
  339. }
  340. } else if (instanceDirty || (propInfo.kind === Prim2DPropInfo.PROPKIND_INSTANCE) || (propInfo.kind === Prim2DPropInfo.PROPKIND_DYNAMIC)) {
  341. this.onPrimitivePropertyDirty(propMask);
  342. }
  343. }
  344. protected onPrimitivePropertyDirty(propFlagId: number) {
  345. this.onPrimBecomesDirty();
  346. this._instanceDirtyFlags |= propFlagId;
  347. }
  348. protected handleGroupChanged(prop: Prim2DPropInfo) {
  349. }
  350. /**
  351. * Check if a given set of properties are dirty or not.
  352. * @param flags a ORed combination of Prim2DPropInfo.flagId values
  353. * @return true if at least one property is dirty, false if none of them are.
  354. */
  355. public checkPropertiesDirty(flags: number): boolean {
  356. return (this._instanceDirtyFlags & flags) !== 0;
  357. }
  358. /**
  359. * Clear a given set of properties.
  360. * @param flags a ORed combination of Prim2DPropInfo.flagId values
  361. * @return the new set of property still marked as dirty
  362. */
  363. protected clearPropertiesDirty(flags: number): number {
  364. this._instanceDirtyFlags &= ~flags;
  365. return this._instanceDirtyFlags;
  366. }
  367. public _resetPropertiesDirty() {
  368. this._instanceDirtyFlags = 0;
  369. this._clearFlags(SmartPropertyPrim.flagPrimInDirtyList | SmartPropertyPrim.flagNeedRefresh);
  370. }
  371. /**
  372. * Retrieve the boundingInfo for this Primitive, computed based on the primitive itself and NOT its children
  373. */
  374. public get levelBoundingInfo(): BoundingInfo2D {
  375. if (this._isFlagSet(SmartPropertyPrim.flagLevelBoundingInfoDirty)) {
  376. this.updateLevelBoundingInfo();
  377. this._clearFlags(SmartPropertyPrim.flagLevelBoundingInfoDirty);
  378. }
  379. return this._levelBoundingInfo;
  380. }
  381. /**
  382. * This method must be overridden by a given Primitive implementation to compute its boundingInfo
  383. */
  384. protected updateLevelBoundingInfo() {
  385. }
  386. /**
  387. * Property method called when the Primitive becomes dirty
  388. */
  389. protected onPrimBecomesDirty() {
  390. }
  391. static _hookProperty<T>(propId: number, piStore: (pi: Prim2DPropInfo) => void, typeLevelCompare: boolean, dirtyBoundingInfo: boolean, dirtyParentBoundingBox: boolean, kind: number): (target: Object, propName: string | symbol, descriptor: TypedPropertyDescriptor<T>) => void {
  392. return (target: Object, propName: string | symbol, descriptor: TypedPropertyDescriptor<T>) => {
  393. var propInfo = SmartPropertyPrim._createPropInfo(target, <string>propName, propId, dirtyBoundingInfo, dirtyParentBoundingBox, typeLevelCompare, kind);
  394. if (piStore) {
  395. piStore(propInfo);
  396. }
  397. let getter = descriptor.get, setter = descriptor.set;
  398. // Overload the property setter implementation to add our own logic
  399. descriptor.set = function (val) {
  400. // check for disposed first, do nothing
  401. if (this.isDisposed) {
  402. return;
  403. }
  404. let curVal = getter.call(this);
  405. if (SmartPropertyPrim._checkUnchanged(curVal, val)) {
  406. return;
  407. }
  408. // Cast the object we're working one
  409. let prim = <SmartPropertyPrim>this;
  410. // Change the value
  411. setter.call(this, val);
  412. // Notify change, dirty flags update
  413. prim._handlePropChanged(curVal, val, <string>propName, propInfo, typeLevelCompare);
  414. }
  415. }
  416. }
  417. /**
  418. * Add an externally attached data from its key.
  419. * This method call will fail and return false, if such key already exists.
  420. * If you don't care and just want to get the data no matter what, use the more convenient getOrAddExternalDataWithFactory() method.
  421. * @param key the unique key that identifies the data
  422. * @param data the data object to associate to the key for this Engine instance
  423. * @return true if no such key were already present and the data was added successfully, false otherwise
  424. */
  425. public addExternalData<T>(key: string, data: T): boolean {
  426. if (!this._externalData) {
  427. this._externalData = new StringDictionary<Object>();
  428. }
  429. return this._externalData.add(key, data);
  430. }
  431. /**
  432. * Get an externally attached data from its key
  433. * @param key the unique key that identifies the data
  434. * @return the associated data, if present (can be null), or undefined if not present
  435. */
  436. public getExternalData<T>(key: string): T {
  437. if (!this._externalData) {
  438. return null;
  439. }
  440. return <T>this._externalData.get(key);
  441. }
  442. /**
  443. * Get an externally attached data from its key, create it using a factory if it's not already present
  444. * @param key the unique key that identifies the data
  445. * @param factory the factory that will be called to create the instance if and only if it doesn't exists
  446. * @return the associated data, can be null if the factory returned null.
  447. */
  448. public getOrAddExternalDataWithFactory<T>(key: string, factory: (k: string) => T): T {
  449. if (!this._externalData) {
  450. this._externalData = new StringDictionary<Object>();
  451. }
  452. return <T>this._externalData.getOrAddWithFactory(key, factory);
  453. }
  454. /**
  455. * Remove an externally attached data from the Engine instance
  456. * @param key the unique key that identifies the data
  457. * @return true if the data was successfully removed, false if it doesn't exist
  458. */
  459. public removeExternalData(key): boolean {
  460. if (!this._externalData) {
  461. return false;
  462. }
  463. return this._externalData.remove(key);
  464. }
  465. /**
  466. * Check if a given flag is set
  467. * @param flag the flag value
  468. * @return true if set, false otherwise
  469. */
  470. public _isFlagSet(flag: number): boolean {
  471. return (this._flags & flag) !== 0;
  472. }
  473. /**
  474. * Check if all given flags are set
  475. * @param flags the flags ORed
  476. * @return true if all the flags are set, false otherwise
  477. */
  478. public _areAllFlagsSet(flags: number): boolean {
  479. return (this._flags & flags) === flags;
  480. }
  481. /**
  482. * Check if at least one flag of the given flags is set
  483. * @param flags the flags ORed
  484. * @return true if at least one flag is set, false otherwise
  485. */
  486. public _areSomeFlagsSet(flags: number): boolean {
  487. return (this._flags & flags) !== 0;
  488. }
  489. /**
  490. * Clear the given flags
  491. * @param flags the flags to clear
  492. */
  493. public _clearFlags(flags: number) {
  494. this._flags &= ~flags;
  495. }
  496. /**
  497. * Set the given flags to true state
  498. * @param flags the flags ORed to set
  499. * @return the flags state before this call
  500. */
  501. public _setFlags(flags: number): number {
  502. let cur = this._flags;
  503. this._flags |= flags;
  504. return cur;
  505. }
  506. /**
  507. * Change the state of the given flags
  508. * @param flags the flags ORed to change
  509. * @param state true to set them, false to clear them
  510. */
  511. public _changeFlags(flags: number, state: boolean) {
  512. if (state) {
  513. this._flags |= flags;
  514. } else {
  515. this._flags &= ~flags;
  516. }
  517. }
  518. public static flagIsDisposed = 0x0000001; // set if the object is already disposed
  519. public static flagLevelBoundingInfoDirty = 0x0000002; // set if the primitive's level bounding box (not including children) is dirty
  520. public static flagModelDirty = 0x0000004; // set if the model must be changed
  521. public static flagLayoutDirty = 0x0000008; // set if the layout must be computed
  522. public static flagLevelVisible = 0x0000010; // set if the primitive is set as visible for its level only
  523. public static flagBoundingInfoDirty = 0x0000020; // set if the primitive's overall bounding box (including children) is dirty
  524. public static flagIsPickable = 0x0000040; // set if the primitive can be picked during interaction
  525. public static flagIsVisible = 0x0000080; // set if the primitive is concretely visible (use the levelVisible of parents)
  526. public static flagVisibilityChanged = 0x0000100; // set if there was a transition between visible/hidden status
  527. public static flagPositioningDirty = 0x0000200; // set if the primitive positioning must be computed
  528. public static flagTrackedGroup = 0x0000400; // set if the group2D is tracking a scene node
  529. public static flagWorldCacheChanged = 0x0000800; // set if the cached bitmap of a world space canvas changed
  530. public static flagChildrenFlatZOrder = 0x0001000; // set if all the children (direct and indirect) will share the same Z-Order
  531. public static flagZOrderDirty = 0x0002000; // set if the Z-Order for this prim and its children must be recomputed
  532. public static flagActualOpacityDirty = 0x0004000; // set if the actualOpactity should be recomputed
  533. public static flagPrimInDirtyList = 0x0008000; // set if the primitive is in the primDirtyList
  534. public static flagIsContainer = 0x0010000; // set if the primitive is a container
  535. public static flagNeedRefresh = 0x0020000; // set if the primitive wasn't successful at refresh
  536. public static flagActualScaleDirty = 0x0040000; // set if the actualScale property needs to be recomputed
  537. public static flagDontInheritParentScale = 0x0080000; // set if the actualScale must not use its parent's scale to be computed
  538. public static flagGlobalTransformDirty = 0x0100000; // set if the global transform must be recomputed due to a local transform change
  539. public static flagLayoutBoundingInfoDirty = 0x0100000; // set if the layout bounding info is dirty
  540. private _flags : number;
  541. private _externalData : StringDictionary<Object>;
  542. private _modelKey : string;
  543. private _propInfo : StringDictionary<Prim2DPropInfo>;
  544. protected _levelBoundingInfo : BoundingInfo2D;
  545. protected _boundingInfo : BoundingInfo2D;
  546. protected _layoutBoundingInfo : BoundingInfo2D;
  547. protected _instanceDirtyFlags : number;
  548. }
  549. export function modelLevelProperty<T>(propId: number, piStore: (pi: Prim2DPropInfo) => void, typeLevelCompare = false, dirtyBoundingInfo = false, dirtyParentBoundingBox = false): (target: Object, propName: string | symbol, descriptor: TypedPropertyDescriptor<T>) => void {
  550. return SmartPropertyPrim._hookProperty(propId, piStore, typeLevelCompare, dirtyBoundingInfo, dirtyParentBoundingBox, Prim2DPropInfo.PROPKIND_MODEL);
  551. }
  552. export function instanceLevelProperty<T>(propId: number, piStore: (pi: Prim2DPropInfo) => void, typeLevelCompare = false, dirtyBoundingInfo = false, dirtyParentBoundingBox = false): (target: Object, propName: string | symbol, descriptor: TypedPropertyDescriptor<T>) => void {
  553. return SmartPropertyPrim._hookProperty(propId, piStore, typeLevelCompare, dirtyBoundingInfo, dirtyParentBoundingBox, Prim2DPropInfo.PROPKIND_INSTANCE);
  554. }
  555. export function dynamicLevelProperty<T>(propId: number, piStore: (pi: Prim2DPropInfo) => void, typeLevelCompare = false, dirtyBoundingInfo = false, dirtyParentBoundingBox = false): (target: Object, propName: string | symbol, descriptor: TypedPropertyDescriptor<T>) => void {
  556. return SmartPropertyPrim._hookProperty(propId, piStore, typeLevelCompare, dirtyBoundingInfo, dirtyParentBoundingBox, Prim2DPropInfo.PROPKIND_DYNAMIC);
  557. }
  558. }