"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.DragScaleTransformTC = void 0;
const core_1 = require("@vived/core");
const TouchController_1 = require("../../../TouchController");
const UC_1 = require("../../UC");
class DragScaleTransformTC extends core_1.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(UC_1.ScaleTransformUC.type);
        if (!this.scaleUC) {
            this.error("App Object that does not have ScaleTransformUC");
            return;
        }
        const touchInput = TouchController_1.TouchInputEntity.get(appObjects);
        if (touchInput) {
            touchInput.registerController(this);
        }
        else {
            this.warn("Unable to find TouchInputEntity");
        }
    }
}
exports.DragScaleTransformTC = DragScaleTransformTC;
DragScaleTransformTC.type = "DragScaleTransformTC";
//# sourceMappingURL=DragScaleTransformTC.js.map