瀏覽代碼

Merge pull request #1311 from nockawa/Group2DPointerEvent

Canvas2D
Loïc Baumann 9 年之前
父節點
當前提交
c3df6e00cf
共有 2 個文件被更改,包括 17 次插入2 次删除
  1. 16 2
      src/Canvas2d/babylon.prim2dBase.ts
  2. 1 0
      src/Canvas2d/babylon.smartPropertyPrim.ts

+ 16 - 2
src/Canvas2d/babylon.prim2dBase.ts

@@ -1389,7 +1389,7 @@
             this._zOrder = 0;
             this._zMax = 0;
             this._firstZDirtyIndex = Prim2DBase._bigInt;
-            this._setFlags(SmartPropertyPrim.flagIsPickable | SmartPropertyPrim.flagBoundingInfoDirty | SmartPropertyPrim.flagActualOpacityDirty);
+            this._setFlags(SmartPropertyPrim.flagIsPickable | SmartPropertyPrim.flagBoundingInfoDirty | SmartPropertyPrim.flagActualOpacityDirty | SmartPropertyPrim.flagIsContainer);
 
             if (settings.opacity != null) {
                 this._opacity = settings.opacity;
@@ -2196,6 +2196,20 @@
         }
 
         /**
+         * Define if the Primitive acts as a container or not
+         * A container will encapsulate its children for interaction event.
+         * If it's not a container events will be process down to children if the primitive is not pickable.
+         * Default value is true
+         */
+        public get isContainer(): boolean {
+            return this._isFlagSet(SmartPropertyPrim.flagIsContainer);
+        }
+
+        public set isContainer(value: boolean) {
+            this._changeFlags(SmartPropertyPrim.flagIsContainer, value);
+        }
+
+        /**
          * Return the depth level of the Primitive into the Canvas' Graph. A Canvas will be 0, its direct children 1, and so on.
          */
         public get hierarchyDepth(): number {
@@ -2414,7 +2428,7 @@
             if (!levelIntersectRes || !intersectInfo.findFirstOnly) {
                 for (let curChild of this._children) {
                     // Don't test primitive not pick able or if it's hidden and we don't test hidden ones
-                    if (!curChild.isPickable || (!intersectInfo.intersectHidden && !curChild.isVisible)) {
+                    if ((!curChild.isPickable && curChild.isContainer) || (!intersectInfo.intersectHidden && !curChild.isVisible)) {
                         continue;
                     }
 

+ 1 - 0
src/Canvas2d/babylon.smartPropertyPrim.ts

@@ -631,6 +631,7 @@
         public static flagZOrderDirty            = 0x0002000;    // set if the Z-Order for this prim and its children must be recomputed
         public static flagActualOpacityDirty     = 0x0004000;    // set if the actualOpactity should be recomputed
         public static flagPrimInDirtyList        = 0x0008000;    // set if the primitive is in the primDirtyList
+        public static flagIsContainer            = 0x0010000;    // set if the primitive is a container
 
         private   _flags             : number;
         private   _externalData      : StringDictionary<Object>;