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