|
@@ -107,14 +107,13 @@ var BABYLON;
|
|
}
|
|
}
|
|
this.__engineData = engine.getOrAddExternalDataWithFactory("__BJSCANVAS2D__", function (k) { return new Canvas2DEngineBoundData(); });
|
|
this.__engineData = engine.getOrAddExternalDataWithFactory("__BJSCANVAS2D__", function (k) { return new Canvas2DEngineBoundData(); });
|
|
this._cachingStrategy = cachingstrategy;
|
|
this._cachingStrategy = cachingstrategy;
|
|
- this._depthLevel = 0;
|
|
|
|
- this._hierarchyMaxDepth = 100;
|
|
|
|
- this._hierarchyLevelZFactor = 1 / this._hierarchyMaxDepth;
|
|
|
|
- this._hierarchyLevelMaxSiblingCount = 1000;
|
|
|
|
- this._hierarchySiblingZDelta = this._hierarchyLevelZFactor / this._hierarchyLevelMaxSiblingCount;
|
|
|
|
this._primPointerInfo = new BABYLON.PrimitivePointerInfo();
|
|
this._primPointerInfo = new BABYLON.PrimitivePointerInfo();
|
|
this._capturedPointers = new BABYLON.StringDictionary();
|
|
this._capturedPointers = new BABYLON.StringDictionary();
|
|
|
|
+ this._pickStartingPosition = BABYLON.Vector2.Zero();
|
|
this.setupGroup2D(this, null, name, BABYLON.Vector2.Zero(), size, this._cachingStrategy === Canvas2D.CACHESTRATEGY_ALLGROUPS ? BABYLON.Group2D.GROUPCACHEBEHAVIOR_DONTCACHEOVERRIDE : BABYLON.Group2D.GROUPCACHEBEHAVIOR_FOLLOWCACHESTRATEGY);
|
|
this.setupGroup2D(this, null, name, BABYLON.Vector2.Zero(), size, this._cachingStrategy === Canvas2D.CACHESTRATEGY_ALLGROUPS ? BABYLON.Group2D.GROUPCACHEBEHAVIOR_DONTCACHEOVERRIDE : BABYLON.Group2D.GROUPCACHEBEHAVIOR_FOLLOWCACHESTRATEGY);
|
|
|
|
+ this._hierarchyLevelMaxSiblingCount = 100;
|
|
|
|
+ this._hierarchyDepthOffset = 0;
|
|
|
|
+ this._siblingDepthOffset = 1 / this._hierarchyLevelMaxSiblingCount;
|
|
this._scene = scene;
|
|
this._scene = scene;
|
|
this._engine = engine;
|
|
this._engine = engine;
|
|
this._renderingSize = new BABYLON.Size(0, 0);
|
|
this._renderingSize = new BABYLON.Size(0, 0);
|
|
@@ -144,6 +143,13 @@ var BABYLON;
|
|
// this._supprtInstancedArray = false; // TODO REMOVE!!!
|
|
// this._supprtInstancedArray = false; // TODO REMOVE!!!
|
|
this._setupInteraction(enableInteraction);
|
|
this._setupInteraction(enableInteraction);
|
|
};
|
|
};
|
|
|
|
+ Object.defineProperty(Canvas2D.prototype, "hierarchyLevelMaxSiblingCount", {
|
|
|
|
+ get: function () {
|
|
|
|
+ return this._hierarchyLevelMaxSiblingCount;
|
|
|
|
+ },
|
|
|
|
+ enumerable: true,
|
|
|
|
+ configurable: true
|
|
|
|
+ });
|
|
Canvas2D.prototype._setupInteraction = function (enable) {
|
|
Canvas2D.prototype._setupInteraction = function (enable) {
|
|
var _this = this;
|
|
var _this = this;
|
|
// No change detection
|
|
// No change detection
|
|
@@ -178,7 +184,7 @@ var BABYLON;
|
|
catch (e) {
|
|
catch (e) {
|
|
}
|
|
}
|
|
this._primPointerInfo.updateRelatedTarget(primitive, BABYLON.Vector2.Zero());
|
|
this._primPointerInfo.updateRelatedTarget(primitive, BABYLON.Vector2.Zero());
|
|
- this._bubbleNotifyPrimPointerObserver(primitive, BABYLON.PrimitivePointerInfo.PointerGotCapture);
|
|
|
|
|
|
+ this._bubbleNotifyPrimPointerObserver(primitive, BABYLON.PrimitivePointerInfo.PointerGotCapture, null);
|
|
this._capturedPointers.add(pointerId.toString(), primitive);
|
|
this._capturedPointers.add(pointerId.toString(), primitive);
|
|
return true;
|
|
return true;
|
|
};
|
|
};
|
|
@@ -196,7 +202,7 @@ var BABYLON;
|
|
catch (e) {
|
|
catch (e) {
|
|
}
|
|
}
|
|
this._primPointerInfo.updateRelatedTarget(primitive, BABYLON.Vector2.Zero());
|
|
this._primPointerInfo.updateRelatedTarget(primitive, BABYLON.Vector2.Zero());
|
|
- this._bubbleNotifyPrimPointerObserver(primitive, BABYLON.PrimitivePointerInfo.PointerLostCapture);
|
|
|
|
|
|
+ this._bubbleNotifyPrimPointerObserver(primitive, BABYLON.PrimitivePointerInfo.PointerLostCapture, null);
|
|
this._capturedPointers.remove(pointerId.toString());
|
|
this._capturedPointers.remove(pointerId.toString());
|
|
return true;
|
|
return true;
|
|
};
|
|
};
|
|
@@ -234,16 +240,16 @@ var BABYLON;
|
|
this._primPointerInfo.updateRelatedTarget(targetPrim, targetPointerPos);
|
|
this._primPointerInfo.updateRelatedTarget(targetPrim, targetPointerPos);
|
|
// Analyze the pointer event type and fire proper events on the primitive
|
|
// Analyze the pointer event type and fire proper events on the primitive
|
|
if (eventData.type === BABYLON.PointerEventTypes.POINTERWHEEL) {
|
|
if (eventData.type === BABYLON.PointerEventTypes.POINTERWHEEL) {
|
|
- this._bubbleNotifyPrimPointerObserver(targetPrim, BABYLON.PrimitivePointerInfo.PointerMouseWheel);
|
|
|
|
|
|
+ this._bubbleNotifyPrimPointerObserver(targetPrim, BABYLON.PrimitivePointerInfo.PointerMouseWheel, eventData.event);
|
|
}
|
|
}
|
|
else if (eventData.type === BABYLON.PointerEventTypes.POINTERMOVE) {
|
|
else if (eventData.type === BABYLON.PointerEventTypes.POINTERMOVE) {
|
|
- this._bubbleNotifyPrimPointerObserver(targetPrim, BABYLON.PrimitivePointerInfo.PointerMove);
|
|
|
|
|
|
+ this._bubbleNotifyPrimPointerObserver(targetPrim, BABYLON.PrimitivePointerInfo.PointerMove, eventData.event);
|
|
}
|
|
}
|
|
else if (eventData.type === BABYLON.PointerEventTypes.POINTERDOWN) {
|
|
else if (eventData.type === BABYLON.PointerEventTypes.POINTERDOWN) {
|
|
- this._bubbleNotifyPrimPointerObserver(targetPrim, BABYLON.PrimitivePointerInfo.PointerDown);
|
|
|
|
|
|
+ this._bubbleNotifyPrimPointerObserver(targetPrim, BABYLON.PrimitivePointerInfo.PointerDown, eventData.event);
|
|
}
|
|
}
|
|
else if (eventData.type === BABYLON.PointerEventTypes.POINTERUP) {
|
|
else if (eventData.type === BABYLON.PointerEventTypes.POINTERUP) {
|
|
- this._bubbleNotifyPrimPointerObserver(targetPrim, BABYLON.PrimitivePointerInfo.PointerUp);
|
|
|
|
|
|
+ this._bubbleNotifyPrimPointerObserver(targetPrim, BABYLON.PrimitivePointerInfo.PointerUp, eventData.event);
|
|
}
|
|
}
|
|
};
|
|
};
|
|
Canvas2D.prototype._updatePointerInfo = function (eventData) {
|
|
Canvas2D.prototype._updatePointerInfo = function (eventData) {
|
|
@@ -318,12 +324,12 @@ var BABYLON;
|
|
// Notify the previous "over" prim that the pointer is no longer over it
|
|
// Notify the previous "over" prim that the pointer is no longer over it
|
|
if ((capturedPrim && capturedPrim === prevPrim) || (!capturedPrim && prevPrim)) {
|
|
if ((capturedPrim && capturedPrim === prevPrim) || (!capturedPrim && prevPrim)) {
|
|
this._primPointerInfo.updateRelatedTarget(prevPrim, this._previousOverPrimitive.intersectionLocation);
|
|
this._primPointerInfo.updateRelatedTarget(prevPrim, this._previousOverPrimitive.intersectionLocation);
|
|
- this._bubbleNotifyPrimPointerObserver(prevPrim, BABYLON.PrimitivePointerInfo.PointerOut);
|
|
|
|
|
|
+ this._bubbleNotifyPrimPointerObserver(prevPrim, BABYLON.PrimitivePointerInfo.PointerOut, null);
|
|
}
|
|
}
|
|
// Notify the new "over" prim that the pointer is over it
|
|
// Notify the new "over" prim that the pointer is over it
|
|
if ((capturedPrim && capturedPrim === actualPrim) || (!capturedPrim && actualPrim)) {
|
|
if ((capturedPrim && capturedPrim === actualPrim) || (!capturedPrim && actualPrim)) {
|
|
this._primPointerInfo.updateRelatedTarget(actualPrim, this._actualOverPrimitive.intersectionLocation);
|
|
this._primPointerInfo.updateRelatedTarget(actualPrim, this._actualOverPrimitive.intersectionLocation);
|
|
- this._bubbleNotifyPrimPointerObserver(actualPrim, BABYLON.PrimitivePointerInfo.PointerOver);
|
|
|
|
|
|
+ this._bubbleNotifyPrimPointerObserver(actualPrim, BABYLON.PrimitivePointerInfo.PointerOver, null);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
this._hoverStatusRenderId = this.scene.getRenderId();
|
|
this._hoverStatusRenderId = this.scene.getRenderId();
|
|
@@ -354,8 +360,8 @@ var BABYLON;
|
|
debug += "[RID:" + this.scene.getRenderId() + "] [" + prim.hierarchyDepth + "] event:" + BABYLON.PrimitivePointerInfo.getEventTypeName(mask) + ", id: " + prim.id + " (" + BABYLON.Tools.getClassName(prim) + "), primPos: " + pii.primitivePointerPos.toString() + ", canvasPos: " + pii.canvasPointerPos.toString();
|
|
debug += "[RID:" + this.scene.getRenderId() + "] [" + prim.hierarchyDepth + "] event:" + BABYLON.PrimitivePointerInfo.getEventTypeName(mask) + ", id: " + prim.id + " (" + BABYLON.Tools.getClassName(prim) + "), primPos: " + pii.primitivePointerPos.toString() + ", canvasPos: " + pii.canvasPointerPos.toString();
|
|
console.log(debug);
|
|
console.log(debug);
|
|
};
|
|
};
|
|
- Canvas2D.prototype._bubbleNotifyPrimPointerObserver = function (prim, mask) {
|
|
|
|
- var pii = this._primPointerInfo;
|
|
|
|
|
|
+ Canvas2D.prototype._bubbleNotifyPrimPointerObserver = function (prim, mask, eventData) {
|
|
|
|
+ var ppi = this._primPointerInfo;
|
|
// In case of PointerOver/Out we will first notify the children (but the deepest to the closest) with PointerEnter/Leave
|
|
// In case of PointerOver/Out we will first notify the children (but the deepest to the closest) with PointerEnter/Leave
|
|
if ((mask & (BABYLON.PrimitivePointerInfo.PointerOver | BABYLON.PrimitivePointerInfo.PointerOut)) !== 0) {
|
|
if ((mask & (BABYLON.PrimitivePointerInfo.PointerOver | BABYLON.PrimitivePointerInfo.PointerOut)) !== 0) {
|
|
this._notifChildren(prim, mask);
|
|
this._notifChildren(prim, mask);
|
|
@@ -368,10 +374,11 @@ var BABYLON;
|
|
this._updatePrimPointerPos(cur);
|
|
this._updatePrimPointerPos(cur);
|
|
// Exec the observers
|
|
// Exec the observers
|
|
this._debugExecObserver(cur, mask);
|
|
this._debugExecObserver(cur, mask);
|
|
- cur._pointerEventObservable.notifyObservers(pii, mask);
|
|
|
|
|
|
+ cur._pointerEventObservable.notifyObservers(ppi, mask);
|
|
|
|
+ this._triggerActionManager(cur, ppi, mask, eventData);
|
|
// Bubble canceled? If we're not executing PointerOver or PointerOut, quit immediately
|
|
// Bubble canceled? If we're not executing PointerOver or PointerOut, quit immediately
|
|
// If it's PointerOver/Out we have to trigger PointerEnter/Leave no matter what
|
|
// If it's PointerOver/Out we have to trigger PointerEnter/Leave no matter what
|
|
- if (pii.cancelBubble) {
|
|
|
|
|
|
+ if (ppi.cancelBubble) {
|
|
if ((mask & (BABYLON.PrimitivePointerInfo.PointerOver | BABYLON.PrimitivePointerInfo.PointerOut)) === 0) {
|
|
if ((mask & (BABYLON.PrimitivePointerInfo.PointerOver | BABYLON.PrimitivePointerInfo.PointerOut)) === 0) {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
@@ -386,16 +393,91 @@ var BABYLON;
|
|
// Trigger a PointerEnter corresponding to the PointerOver
|
|
// Trigger a PointerEnter corresponding to the PointerOver
|
|
if (mask === BABYLON.PrimitivePointerInfo.PointerOver) {
|
|
if (mask === BABYLON.PrimitivePointerInfo.PointerOver) {
|
|
this._debugExecObserver(cur, BABYLON.PrimitivePointerInfo.PointerEnter);
|
|
this._debugExecObserver(cur, BABYLON.PrimitivePointerInfo.PointerEnter);
|
|
- cur._pointerEventObservable.notifyObservers(pii, BABYLON.PrimitivePointerInfo.PointerEnter);
|
|
|
|
|
|
+ cur._pointerEventObservable.notifyObservers(ppi, BABYLON.PrimitivePointerInfo.PointerEnter);
|
|
}
|
|
}
|
|
else if (mask === BABYLON.PrimitivePointerInfo.PointerOut) {
|
|
else if (mask === BABYLON.PrimitivePointerInfo.PointerOut) {
|
|
this._debugExecObserver(cur, BABYLON.PrimitivePointerInfo.PointerLeave);
|
|
this._debugExecObserver(cur, BABYLON.PrimitivePointerInfo.PointerLeave);
|
|
- cur._pointerEventObservable.notifyObservers(pii, BABYLON.PrimitivePointerInfo.PointerLeave);
|
|
|
|
|
|
+ cur._pointerEventObservable.notifyObservers(ppi, BABYLON.PrimitivePointerInfo.PointerLeave);
|
|
}
|
|
}
|
|
// Loop to the parent
|
|
// Loop to the parent
|
|
cur = cur.parent;
|
|
cur = cur.parent;
|
|
}
|
|
}
|
|
};
|
|
};
|
|
|
|
+ Canvas2D.prototype._triggerActionManager = function (prim, ppi, mask, eventData) {
|
|
|
|
+ var _this = this;
|
|
|
|
+ // Process Trigger related to PointerDown
|
|
|
|
+ if ((mask & BABYLON.PrimitivePointerInfo.PointerDown) !== 0) {
|
|
|
|
+ // On pointer down, record the current position and time to be able to trick PickTrigger and LongPressTrigger
|
|
|
|
+ this._pickStartingPosition = ppi.primitivePointerPos.clone();
|
|
|
|
+ this._pickStartingTime = new Date().getTime();
|
|
|
|
+ this._pickedDownPrim = null;
|
|
|
|
+ if (prim.actionManager) {
|
|
|
|
+ this._pickedDownPrim = prim;
|
|
|
|
+ if (prim.actionManager.hasPickTriggers) {
|
|
|
|
+ var actionEvent = BABYLON.ActionEvent.CreateNewFromPrimitive(prim, ppi.primitivePointerPos, eventData);
|
|
|
|
+ switch (eventData.button) {
|
|
|
|
+ case 0:
|
|
|
|
+ prim.actionManager.processTrigger(BABYLON.ActionManager.OnLeftPickTrigger, actionEvent);
|
|
|
|
+ break;
|
|
|
|
+ case 1:
|
|
|
|
+ prim.actionManager.processTrigger(BABYLON.ActionManager.OnCenterPickTrigger, actionEvent);
|
|
|
|
+ break;
|
|
|
|
+ case 2:
|
|
|
|
+ prim.actionManager.processTrigger(BABYLON.ActionManager.OnRightPickTrigger, actionEvent);
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ prim.actionManager.processTrigger(BABYLON.ActionManager.OnPickDownTrigger, actionEvent);
|
|
|
|
+ }
|
|
|
|
+ if (prim.actionManager.hasSpecificTrigger(BABYLON.ActionManager.OnLongPressTrigger)) {
|
|
|
|
+ window.setTimeout(function () {
|
|
|
|
+ var ppi = _this._primPointerInfo;
|
|
|
|
+ var capturedPrim = _this.getCapturedPrimitive(ppi.pointerId);
|
|
|
|
+ _this._updateIntersectionList(ppi.canvasPointerPos, capturedPrim !== null);
|
|
|
|
+ var ii = new BABYLON.IntersectInfo2D();
|
|
|
|
+ ii.pickPosition = ppi.canvasPointerPos.clone();
|
|
|
|
+ ii.findFirstOnly = false;
|
|
|
|
+ _this.intersect(ii);
|
|
|
|
+ if (ii.isPrimIntersected(prim) !== null) {
|
|
|
|
+ if (prim.actionManager) {
|
|
|
|
+ if (_this._pickStartingTime !== 0 && ((new Date().getTime() - _this._pickStartingTime) > BABYLON.ActionManager.LongPressDelay) && (Math.abs(_this._pickStartingPosition.x - ii.pickPosition.x) < BABYLON.ActionManager.DragMovementThreshold && Math.abs(_this._pickStartingPosition.y - ii.pickPosition.y) < BABYLON.ActionManager.DragMovementThreshold)) {
|
|
|
|
+ _this._pickStartingTime = 0;
|
|
|
|
+ prim.actionManager.processTrigger(BABYLON.ActionManager.OnLongPressTrigger, BABYLON.ActionEvent.CreateNewFromPrimitive(prim, ppi.primitivePointerPos, eventData));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }, BABYLON.ActionManager.LongPressDelay);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ else if ((mask & BABYLON.PrimitivePointerInfo.PointerUp) !== 0) {
|
|
|
|
+ this._pickStartingTime = 0;
|
|
|
|
+ var actionEvent = BABYLON.ActionEvent.CreateNewFromPrimitive(prim, ppi.primitivePointerPos, eventData);
|
|
|
|
+ if (prim.actionManager) {
|
|
|
|
+ // OnPickUpTrigger
|
|
|
|
+ prim.actionManager.processTrigger(BABYLON.ActionManager.OnPickUpTrigger, actionEvent);
|
|
|
|
+ // OnPickTrigger
|
|
|
|
+ if (Math.abs(this._pickStartingPosition.x - ppi.canvasPointerPos.x) < BABYLON.ActionManager.DragMovementThreshold && Math.abs(this._pickStartingPosition.y - ppi.canvasPointerPos.y) < BABYLON.ActionManager.DragMovementThreshold) {
|
|
|
|
+ prim.actionManager.processTrigger(BABYLON.ActionManager.OnPickTrigger, actionEvent);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ // OnPickOutTrigger
|
|
|
|
+ if (this._pickedDownPrim && this._pickedDownPrim.actionManager && (this._pickedDownPrim !== prim)) {
|
|
|
|
+ this._pickedDownPrim.actionManager.processTrigger(BABYLON.ActionManager.OnPickOutTrigger, actionEvent);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ else if ((mask & BABYLON.PrimitivePointerInfo.PointerOver) !== 0) {
|
|
|
|
+ if (prim.actionManager) {
|
|
|
|
+ var actionEvent = BABYLON.ActionEvent.CreateNewFromPrimitive(prim, ppi.primitivePointerPos, eventData);
|
|
|
|
+ prim.actionManager.processTrigger(BABYLON.ActionManager.OnPointerOverTrigger, actionEvent);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ else if ((mask & BABYLON.PrimitivePointerInfo.PointerOut) !== 0) {
|
|
|
|
+ if (prim.actionManager) {
|
|
|
|
+ var actionEvent = BABYLON.ActionEvent.CreateNewFromPrimitive(prim, ppi.primitivePointerPos, eventData);
|
|
|
|
+ prim.actionManager.processTrigger(BABYLON.ActionManager.OnPointerOutTrigger, actionEvent);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ };
|
|
Canvas2D.prototype._notifChildren = function (prim, mask) {
|
|
Canvas2D.prototype._notifChildren = function (prim, mask) {
|
|
var _this = this;
|
|
var _this = this;
|
|
var pii = this._primPointerInfo;
|
|
var pii = this._primPointerInfo;
|
|
@@ -586,30 +668,6 @@ var BABYLON;
|
|
throw Error("Can't use Canvas Background with the caching strategy TOPLEVELGROUPS");
|
|
throw Error("Can't use Canvas Background with the caching strategy TOPLEVELGROUPS");
|
|
}
|
|
}
|
|
};
|
|
};
|
|
- Object.defineProperty(Canvas2D.prototype, "hierarchySiblingZDelta", {
|
|
|
|
- /**
|
|
|
|
- * Read-only property that return the Z delta to apply for each sibling primitives inside of a given one.
|
|
|
|
- * Sibling Primitives are defined in a specific order, the first ones will be draw below the next ones.
|
|
|
|
- * This property define the Z value to apply between each sibling Primitive. Current implementation allows 1000 Siblings Primitives per level.
|
|
|
|
- * @returns The Z Delta
|
|
|
|
- */
|
|
|
|
- get: function () {
|
|
|
|
- return this._hierarchySiblingZDelta;
|
|
|
|
- },
|
|
|
|
- enumerable: true,
|
|
|
|
- configurable: true
|
|
|
|
- });
|
|
|
|
- Object.defineProperty(Canvas2D.prototype, "hierarchyLevelZFactor", {
|
|
|
|
- /**
|
|
|
|
- * Return the Z Factor that will be applied for each new hierarchy level.
|
|
|
|
- * @returns The Z Factor
|
|
|
|
- */
|
|
|
|
- get: function () {
|
|
|
|
- return this._hierarchyLevelZFactor;
|
|
|
|
- },
|
|
|
|
- enumerable: true,
|
|
|
|
- configurable: true
|
|
|
|
- });
|
|
|
|
Canvas2D.prototype._updateCanvasState = function () {
|
|
Canvas2D.prototype._updateCanvasState = function () {
|
|
// Check if the update has already been made for this render Frame
|
|
// Check if the update has already been made for this render Frame
|
|
if (this.scene.getRenderId() === this._updateRenderId) {
|
|
if (this.scene.getRenderId() === this._updateRenderId) {
|