浏览代码

Canvas2D: finishing PCM + LayoutEngine improvement

a layoutData setting is added to all primitive types in order to pass custom data to the layoutEngine of their parent
nockawa 8 年之前
父节点
当前提交
3122eb0661

+ 4 - 0
canvas2D/src/Engine/babylon.canvas2d.ts

@@ -280,6 +280,10 @@
             return Canvas2D._INSTANCES;
         }
 
+        public get primitiveCollisionManager(): PirimitiveCollisionManagerBase {
+            return this._primitiveCollisionManager;
+        }
+
         protected _canvasPreInit(settings: any) {
             let cachingStrategy = (settings.cachingStrategy == null) ? Canvas2D.CACHESTRATEGY_DONTCACHE : settings.cachingStrategy;
             this._cachingStrategy = cachingStrategy;

+ 8 - 0
canvas2D/src/Engine/babylon.canvas2dLayoutEngine.ts

@@ -1,5 +1,9 @@
 module BABYLON {
 
+    export interface ILayoutData {
+        
+    }
+
     @className("LayoutEngineBase", "BABYLON")
     /**
      * This is the base class you have to extend in order to implement your own Layout Engine.
@@ -11,6 +15,10 @@
             this.layoutDirtyOnPropertyChangedMask = 0;
         }
 
+        public newChild(child: Prim2DBase, data: ILayoutData) {
+            
+        }
+
         public updateLayout(prim: Prim2DBase) {
         }
 

+ 2 - 0
canvas2D/src/Engine/babylon.ellipse2d.ts

@@ -232,6 +232,7 @@
          * - childrenFlatZOrder: if true all the children (direct and indirect) will share the same Z-Order. Use this when there's a lot of children which don't overlap. The drawing order IS NOT GUARANTED!
          * - levelCollision: this primitive is an actor of the Collision Manager and only this level will be used for collision (i.e. not the children). Use deepCollision if you want collision detection on the primitives and its children.
          * - deepCollision: this primitive is an actor of the Collision Manager, this level AND ALSO its children will be used for collision (note: you don't need to set the children as level/deepCollision).
+         * - layoutData: a instance of a class implementing the ILayoutData interface that contain data to pass to the primitive parent's layout engine
          * - marginTop: top margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
          * - marginLeft: left margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
          * - marginRight: right margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
@@ -275,6 +276,7 @@
             childrenFlatZOrder    ?: boolean,
             levelCollision        ?: boolean,
             deepCollision         ?: boolean,
+            layoutData            ?: ILayoutData,
             marginTop             ?: number | string,
             marginLeft            ?: number | string,
             marginRight           ?: number | string,

+ 2 - 0
canvas2D/src/Engine/babylon.group2d.ts

@@ -55,6 +55,7 @@
          * - childrenFlatZOrder: if true all the children (direct and indirect) will share the same Z-Order. Use this when there's a lot of children which don't overlap. The drawing order IS NOT GUARANTED!
          * - levelCollision: this primitive is an actor of the Collision Manager and only this level will be used for collision (i.e. not the children). Use deepCollision if you want collision detection on the primitives and its children.
          * - deepCollision: this primitive is an actor of the Collision Manager, this level AND ALSO its children will be used for collision (note: you don't need to set the children as level/deepCollision).
+         * - layoutData: a instance of a class implementing the ILayoutData interface that contain data to pass to the primitive parent's layout engine
          * - marginTop: top margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
          * - marginLeft: left margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
          * - marginRight: right margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
@@ -96,6 +97,7 @@
             childrenFlatZOrder      ?: boolean,
             levelCollision          ?: boolean,
             deepCollision           ?: boolean,
+            layoutData              ?: ILayoutData,
             marginTop               ?: number | string,
             marginLeft              ?: number | string,
             marginRight             ?: number | string,

+ 2 - 0
canvas2D/src/Engine/babylon.lines2d.ts

@@ -351,6 +351,7 @@
          * - childrenFlatZOrder: if true all the children (direct and indirect) will share the same Z-Order. Use this when there's a lot of children which don't overlap. The drawing order IS NOT GUARANTED!
          * - levelCollision: this primitive is an actor of the Collision Manager and only this level will be used for collision (i.e. not the children). Use deepCollision if you want collision detection on the primitives and its children.
          * - deepCollision: this primitive is an actor of the Collision Manager, this level AND ALSO its children will be used for collision (note: you don't need to set the children as level/deepCollision).
+         * - layoutData: a instance of a class implementing the ILayoutData interface that contain data to pass to the primitive parent's layout engine
          * - marginTop: top margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
          * - marginLeft: left margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
          * - marginRight: right margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
@@ -394,6 +395,7 @@
             childrenFlatZOrder    ?: boolean,
             levelCollision        ?: boolean,
             deepCollision         ?: boolean,
+            layoutData            ?: ILayoutData,
             marginTop             ?: number | string,
             marginLeft            ?: number | string,
             marginRight           ?: number | string,

+ 20 - 1
canvas2D/src/Engine/babylon.prim2dBase.ts

@@ -1385,6 +1385,7 @@
             childrenFlatZOrder      ?: boolean,
             levelCollision          ?: boolean,
             deepCollision           ?: boolean,
+            layoutData              ?: ILayoutData,
             marginTop               ?: number | string,
             marginLeft              ?: number | string,
             marginRight             ?: number | string,
@@ -1618,18 +1619,34 @@
                 this.padding.fromString(settings.padding);
             }
 
+            if (settings.layoutData) {
+                let p = this.parent;
+                if (p && p.layoutEngine) {
+                    p.layoutEngine.newChild(this, settings.layoutData);
+                }
+            }
+
             // Dirty layout and positioning
             this._parentLayoutDirty();
             this._positioningDirty();
 
             // Add in the PCM
             if (settings.levelCollision || settings.deepCollision) {
-                this.owner._primitiveCollisionManager.addActor(this, settings.deepCollision===true);
+                this._actorInfo = this.owner._primitiveCollisionManager.addActor(this, settings.deepCollision === true);
                 this._setFlags(SmartPropertyPrim.flagCollisionActor);
+            } else {
+                this._actorInfo = null;
             }
 
         }
 
+        public get intersectWithObservable(): Observable<DictionaryChanged<ActorInfo>> {
+            if (!this._actorInfo) {
+                return null;
+            }
+            return this._actorInfo.intersectWith.dictionaryChanged;
+        }
+
         public get actionManager(): ActionManager {
             if (!this._actionManager) {
                 this._actionManager = new ActionManager(this.owner.scene);
@@ -3204,6 +3221,7 @@
 
             if (this._isFlagSet(SmartPropertyPrim.flagCollisionActor)) {
                 this.owner._primitiveCollisionManager.removeActor(this);
+                this._actorInfo = null;
             }
 
             if (this._pointerEventObservable) {
@@ -3894,6 +3912,7 @@
         private _actualScale : Vector2;
         private _displayDebugAreas: boolean;
         private _debugAreaGroup: Group2D;
+        private _actorInfo: ActorInfo;
 
         // Stores the step of the parent for which the current global transform was computed
         // If the parent has a new step, it means this prim's global transform must be updated

+ 6 - 6
canvas2D/src/Engine/babylon.primitiveCollisionManager.ts

@@ -4,7 +4,7 @@
             this._owner = owner;
         }
 
-        abstract addActor(actor: Prim2DBase, deep: boolean);
+        abstract addActor(actor: Prim2DBase, deep: boolean): ActorInfo;
         abstract removeActor(actor: Prim2DBase);
 
         abstract update();
@@ -19,13 +19,13 @@
 
     }
 
-    class ActorInfo {
+    export class ActorInfo {
         constructor(owner: BasicPrimitiviceCollisionManager, actor: Prim2DBase, deep: boolean) {
             this.owner = owner;
             this.prim = actor;
             this.flags = 0;
             this.presentInClusters = new StringDictionary<ClusterInfo>();
-            this.intersectWith = new StringDictionary<ActorInfo>();
+            this.intersectWith = new ObservableStringDictionary<ActorInfo>(false);
             this.setFlags((deep ? ActorInfo.flagDeep : 0) | ActorInfo.flagDirty);
 
             let bi = (deep ? actor.boundingInfo : actor.levelBoundingInfo);
@@ -93,7 +93,7 @@
         flags: number;
         owner: BasicPrimitiviceCollisionManager;
         presentInClusters: StringDictionary<ClusterInfo>;
-        intersectWith: StringDictionary<ActorInfo>;
+        intersectWith: ObservableStringDictionary<ActorInfo>;
 
         public static flagDeep       = 0x0001;      // set if the actor boundingInfo must be used instead of the levelBoundingInfo
         public static flagEnabled    = 0x0002;      // set if the actor is enabled and should be considered for intersection tests
@@ -164,8 +164,8 @@
             this.debugStats = true;
         }
 
-        addActor(actor: Prim2DBase, deep: boolean) {
-            this._actors.getOrAddWithFactory(actor.uid, () => {
+        addActor(actor: Prim2DBase, deep: boolean): ActorInfo {
+            return this._actors.getOrAddWithFactory(actor.uid, () => {
                 let ai = new ActorInfo(this, actor, deep);
                 this.actorDirty(ai);
                 return ai;

+ 2 - 0
canvas2D/src/Engine/babylon.rectangle2d.ts

@@ -317,6 +317,7 @@
          * - childrenFlatZOrder: if true all the children (direct and indirect) will share the same Z-Order. Use this when there's a lot of children which don't overlap. The drawing order IS NOT GUARANTED!
          * - levelCollision: this primitive is an actor of the Collision Manager and only this level will be used for collision (i.e. not the children). Use deepCollision if you want collision detection on the primitives and its children.
          * - deepCollision: this primitive is an actor of the Collision Manager, this level AND ALSO its children will be used for collision (note: you don't need to set the children as level/deepCollision).
+         * - layoutData: a instance of a class implementing the ILayoutData interface that contain data to pass to the primitive parent's layout engine
          * - marginTop: top margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
          * - marginLeft: left margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
          * - marginRight: right margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
@@ -359,6 +360,7 @@
             childrenFlatZOrder    ?: boolean,
             levelCollision        ?: boolean,
             deepCollision         ?: boolean,
+            layoutData            ?: ILayoutData,
             marginTop             ?: number | string,
             marginLeft            ?: number | string,
             marginRight           ?: number | string,

+ 2 - 0
canvas2D/src/Engine/babylon.sprite2d.ts

@@ -294,6 +294,7 @@
          * - childrenFlatZOrder: if true all the children (direct and indirect) will share the same Z-Order. Use this when there's a lot of children which don't overlap. The drawing order IS NOT GUARANTED!
          * - levelCollision: this primitive is an actor of the Collision Manager and only this level will be used for collision (i.e. not the children). Use deepCollision if you want collision detection on the primitives and its children.
          * - deepCollision: this primitive is an actor of the Collision Manager, this level AND ALSO its children will be used for collision (note: you don't need to set the children as level/deepCollision).
+         * - layoutData: a instance of a class implementing the ILayoutData interface that contain data to pass to the primitive parent's layout engine
          * - marginTop: top margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
          * - marginLeft: left margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
          * - marginRight: right margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
@@ -337,6 +338,7 @@
             childrenFlatZOrder    ?: boolean,
             levelCollision        ?: boolean,
             deepCollision         ?: boolean,
+            layoutData            ?: ILayoutData,
             marginTop             ?: number | string,
             marginLeft            ?: number | string,
             marginRight           ?: number | string,

+ 2 - 0
canvas2D/src/Engine/babylon.text2d.ts

@@ -372,6 +372,7 @@
          * - childrenFlatZOrder: if true all the children (direct and indirect) will share the same Z-Order. Use this when there's a lot of children which don't overlap. The drawing order IS NOT GUARANTED!
          * - levelCollision: this primitive is an actor of the Collision Manager and only this level will be used for collision (i.e. not the children). Use deepCollision if you want collision detection on the primitives and its children.
          * - deepCollision: this primitive is an actor of the Collision Manager, this level AND ALSO its children will be used for collision (note: you don't need to set the children as level/deepCollision).
+         * - layoutData: a instance of a class implementing the ILayoutData interface that contain data to pass to the primitive parent's layout engine
          * - marginTop: top margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
          * - marginLeft: left margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
          * - marginRight: right margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
@@ -419,6 +420,7 @@
             childrenFlatZOrder      ?: boolean,
             levelCollision          ?: boolean,
             deepCollision           ?: boolean,
+            layoutData              ?: ILayoutData,
             marginTop               ?: number | string,
             marginLeft              ?: number | string,
             marginRight             ?: number | string,

+ 2 - 0
canvas2D/src/Engine/babylon.wireFrame2d.ts

@@ -281,6 +281,7 @@
          * - childrenFlatZOrder: if true all the children (direct and indirect) will share the same Z-Order. Use this when there's a lot of children which don't overlap. The drawing order IS NOT GUARANTED!
          * - levelCollision: this primitive is an actor of the Collision Manager and only this level will be used for collision (i.e. not the children). Use deepCollision if you want collision detection on the primitives and its children.
          * - deepCollision: this primitive is an actor of the Collision Manager, this level AND ALSO its children will be used for collision (note: you don't need to set the children as level/deepCollision).
+         * - layoutData: a instance of a class implementing the ILayoutData interface that contain data to pass to the primitive parent's layout engine
          * - marginTop: top margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
          * - marginLeft: left margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
          * - marginRight: right margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
@@ -319,6 +320,7 @@
             childrenFlatZOrder    ?: boolean,
             levelCollision        ?: boolean,
             deepCollision         ?: boolean,
+            layoutData            ?: ILayoutData,
             marginTop             ?: number | string,
             marginLeft            ?: number | string,
             marginRight           ?: number | string,