import { AppObjectController } from "@vived/core";
import { TouchInputEntity } from "../../../TouchController";
import { PinchTransformUC } from "../../UC";
export class PinchTransformTC extends AppObjectController {
    constructor(appObject) {
        super(appObject, PinchTransformTC.type);
        this.isPinching = false;
        this.allow = (e) => {
            return true;
        };
        this.onTouchStart = (e) => {
            this.isPinching = false;
            if (e.touches.length !== 2) {
                return;
            }
            if (!this.allow(e)) {
                return;
            }
            this.pinchUC?.initializePinch(e.touches[0].position, e.touches[1].position);
            this.isPinching = true;
        };
        this.onTouchMove = (e) => {
            if (!this.isPinching)
                return;
            if (e.touches.length !== 2)
                return;
            this.pinchUC?.doPinch(e.touches[0].position, e.touches[1].position);
        };
        this.onTouchEnd = () => {
            this.isPinching = false;
            this.pinchUC?.finishPinch();
        };
        const appObjects = appObject.appObjectRepo;
        this.pinchUC = appObject.getComponent(PinchTransformUC.type);
        if (!this.pinchUC) {
            this.error("App Object does not have PinchTransformUC");
            return;
        }
        const touchInput = TouchInputEntity.get(appObjects);
        if (touchInput) {
            touchInput.registerController(this);
        }
        else {
            this.warn("Unable to find TouchInputEntity");
        }
    }
}
PinchTransformTC.type = "PinchTransformTC";
//# sourceMappingURL=PinchTransformTC.js.map