|
@@ -44,11 +44,12 @@ export abstract class BaseCameraPointersInput implements ICameraInput<Camera> {
|
|
|
*/
|
|
|
public attachControl(element: HTMLElement, noPreventDefault?: boolean): void {
|
|
|
var engine = this.camera.getEngine();
|
|
|
- var pointA: Nullable<PointerTouch> = null;
|
|
|
- var pointB: Nullable<PointerTouch> = null;
|
|
|
var previousPinchSquaredDistance = 0;
|
|
|
var previousMultiTouchPanPosition: Nullable<PointerTouch> = null;
|
|
|
|
|
|
+ this.pointA = null;
|
|
|
+ this.pointB = null;
|
|
|
+
|
|
|
this._altKey = false;
|
|
|
this._ctrlKey = false;
|
|
|
this._metaKey = false;
|
|
@@ -89,8 +90,8 @@ export abstract class BaseCameraPointersInput implements ICameraInput<Camera> {
|
|
|
0;
|
|
|
|
|
|
this.onTouch(null, offsetX, offsetY);
|
|
|
- pointA = null;
|
|
|
- pointB = null;
|
|
|
+ this.pointA = null;
|
|
|
+ this.pointB = null;
|
|
|
} else if (p.type === PointerEventTypes.POINTERDOWN && srcElement) {
|
|
|
try {
|
|
|
srcElement.setPointerCapture(evt.pointerId);
|
|
@@ -98,19 +99,19 @@ export abstract class BaseCameraPointersInput implements ICameraInput<Camera> {
|
|
|
//Nothing to do with the error. Execution will continue.
|
|
|
}
|
|
|
|
|
|
- if (pointA === null) {
|
|
|
- pointA = {x: evt.clientX,
|
|
|
+ if (this.pointA === null) {
|
|
|
+ this.pointA = {x: evt.clientX,
|
|
|
y: evt.clientY,
|
|
|
pointerId: evt.pointerId,
|
|
|
type: evt.pointerType };
|
|
|
- } else if (pointB === null) {
|
|
|
- pointB = {x: evt.clientX,
|
|
|
+ } else if (this.pointB === null) {
|
|
|
+ this.pointB = {x: evt.clientX,
|
|
|
y: evt.clientY,
|
|
|
pointerId: evt.pointerId,
|
|
|
type: evt.pointerType };
|
|
|
}
|
|
|
|
|
|
- this.onButtonDown(evt, pointB ? 2 : 1);
|
|
|
+ this.onButtonDown(evt);
|
|
|
|
|
|
if (!noPreventDefault) {
|
|
|
evt.preventDefault();
|
|
@@ -126,7 +127,7 @@ export abstract class BaseCameraPointersInput implements ICameraInput<Camera> {
|
|
|
}
|
|
|
|
|
|
if (!isTouch) {
|
|
|
- pointB = null; // Mouse and pen are mono pointer
|
|
|
+ this.pointB = null; // Mouse and pen are mono pointer
|
|
|
}
|
|
|
|
|
|
//would be better to use pointers.remove(evt.pointerId) for multitouch gestures,
|
|
@@ -135,17 +136,18 @@ export abstract class BaseCameraPointersInput implements ICameraInput<Camera> {
|
|
|
//one pointer stay pressed forever if we don't release all pointers
|
|
|
//will be ok to put back pointers.remove(evt.pointerId); when iPhone bug corrected
|
|
|
if (engine._badOS) {
|
|
|
- pointA = pointB = null;
|
|
|
+ this.pointA = this.pointB = null;
|
|
|
} else {
|
|
|
//only remove the impacted pointer in case of multitouch allowing on most
|
|
|
//platforms switching from rotate to zoom and pan seamlessly.
|
|
|
- if (pointB && pointA && pointA.pointerId == evt.pointerId) {
|
|
|
- pointA = pointB;
|
|
|
- pointB = null;
|
|
|
- } else if (pointA && pointB && pointB.pointerId == evt.pointerId) {
|
|
|
- pointB = null;
|
|
|
+ if (this.pointB && this.pointA && this.pointA.pointerId == evt.pointerId) {
|
|
|
+ this.pointA = this.pointB;
|
|
|
+ this.pointB = null;
|
|
|
+ } else if (this.pointA && this.pointB &&
|
|
|
+ this.pointB.pointerId == evt.pointerId) {
|
|
|
+ this.pointB = null;
|
|
|
} else {
|
|
|
- pointA = pointB = null;
|
|
|
+ this.pointA = this.pointB = null;
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -153,8 +155,8 @@ export abstract class BaseCameraPointersInput implements ICameraInput<Camera> {
|
|
|
// Previous pinch data is populated but a button has been lifted
|
|
|
// so pinch has ended.
|
|
|
this.onMultiTouch(
|
|
|
- pointA,
|
|
|
- pointB,
|
|
|
+ this.pointA,
|
|
|
+ this.pointB,
|
|
|
previousPinchSquaredDistance,
|
|
|
0, // pinchSquaredDistance
|
|
|
previousMultiTouchPanPosition,
|
|
@@ -175,30 +177,31 @@ export abstract class BaseCameraPointersInput implements ICameraInput<Camera> {
|
|
|
}
|
|
|
|
|
|
// One button down
|
|
|
- if (pointA && pointB === null) {
|
|
|
- var offsetX = evt.clientX - pointA.x;
|
|
|
- var offsetY = evt.clientY - pointA.y;
|
|
|
- this.onTouch(pointA, offsetX, offsetY);
|
|
|
+ if (this.pointA && this.pointB === null) {
|
|
|
+ var offsetX = evt.clientX - this.pointA.x;
|
|
|
+ var offsetY = evt.clientY - this.pointA.y;
|
|
|
+ this.onTouch(this.pointA, offsetX, offsetY);
|
|
|
|
|
|
- pointA.x = evt.clientX;
|
|
|
- pointA.y = evt.clientY;
|
|
|
+ this.pointA.x = evt.clientX;
|
|
|
+ this.pointA.y = evt.clientY;
|
|
|
}
|
|
|
// Two buttons down: pinch
|
|
|
- else if (pointA && pointB) {
|
|
|
- var ed = (pointA.pointerId === evt.pointerId) ? pointA : pointB;
|
|
|
+ else if (this.pointA && this.pointB) {
|
|
|
+ var ed = (this.pointA.pointerId === evt.pointerId) ?
|
|
|
+ this.pointA : this.pointB;
|
|
|
ed.x = evt.clientX;
|
|
|
ed.y = evt.clientY;
|
|
|
- var distX = pointA.x - pointB.x;
|
|
|
- var distY = pointA.y - pointB.y;
|
|
|
+ var distX = this.pointA.x - this.pointB.x;
|
|
|
+ var distY = this.pointA.y - this.pointB.y;
|
|
|
var pinchSquaredDistance = (distX * distX) + (distY * distY);
|
|
|
- var multiTouchPanPosition = {x: (pointA.x + pointB.x) / 2,
|
|
|
- y: (pointA.y + pointB.y) / 2,
|
|
|
+ var multiTouchPanPosition = {x: (this.pointA.x + this.pointB.x) / 2,
|
|
|
+ y: (this.pointA.y + this.pointB.y) / 2,
|
|
|
pointerId: evt.pointerId,
|
|
|
type: p.type};
|
|
|
|
|
|
this.onMultiTouch(
|
|
|
- pointA,
|
|
|
- pointB,
|
|
|
+ this.pointA,
|
|
|
+ this.pointB,
|
|
|
previousPinchSquaredDistance,
|
|
|
pinchSquaredDistance,
|
|
|
previousMultiTouchPanPosition,
|
|
@@ -216,7 +219,7 @@ export abstract class BaseCameraPointersInput implements ICameraInput<Camera> {
|
|
|
PointerEventTypes.POINTERMOVE);
|
|
|
|
|
|
this._onLostFocus = () => {
|
|
|
- pointA = pointB = null;
|
|
|
+ this.pointA = this.pointB = null;
|
|
|
previousPinchSquaredDistance = 0;
|
|
|
previousMultiTouchPanPosition = null;
|
|
|
this.onLostFocus();
|
|
@@ -316,7 +319,7 @@ export abstract class BaseCameraPointersInput implements ICameraInput<Camera> {
|
|
|
* press.
|
|
|
* Override this method to provide functionality.
|
|
|
*/
|
|
|
- protected onButtonDown(evt: PointerEvent, buttonCount: number): void {
|
|
|
+ protected onButtonDown(evt: PointerEvent): void {
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -337,4 +340,6 @@ export abstract class BaseCameraPointersInput implements ICameraInput<Camera> {
|
|
|
private _pointerInput: (p: PointerInfo, s: EventState) => void;
|
|
|
private _observer: Nullable<Observer<PointerInfo>>;
|
|
|
private _onLostFocus: Nullable<(e: FocusEvent) => any>;
|
|
|
+ private pointA: Nullable<PointerTouch>;
|
|
|
+ private pointB: Nullable<PointerTouch>;
|
|
|
}
|