"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.MouseScale = void 0;
const core_1 = require("@vived/core");
const MouseInput_1 = require("../../MouseInput");
const Tools_1 = require("../../Tools");
const DragScaleSceneRoot_1 = require("../UC/DragScaleSceneRoot");
class MouseScale extends core_1.AppObjectController {
    get dragScaleRootUC() {
        return this.getCachedLocalComponent(DragScaleSceneRoot_1.DragScaleSceneRootUC.type);
    }
    get toolRepo() {
        return this.getCachedSingleton(Tools_1.ToolRepository.type);
    }
    constructor(appObject) {
        super(appObject, MouseScale.type);
        this.isDollying = false;
        this.allow = (e) => {
            const zoomTool = this.toolRepo?.getTool("ZOOM");
            if (!zoomTool)
                return false;
            const zoomToolIsActive = zoomTool.state === Tools_1.ToolState.ACTIVE;
            if (e.button === 0 && zoomToolIsActive) {
                return true;
            }
            return false;
        };
        this.onDown = (e) => {
            this.isDollying = false;
            if (!this.allow(e))
                return;
            const pixelPosition = e.position;
            this.dragScaleRootUC?.initializeScale(pixelPosition);
            this.isDollying = true;
        };
        this.onMove = (e) => {
            if (!this.isDollying)
                return;
            this.dragScaleRootUC?.doScale(e.position);
        };
        this.onUp = () => {
            this.isDollying = false;
            this.dragScaleRootUC?.finishScaling();
        };
        const mouseInput = MouseInput_1.MouseInputEntity.get(this.appObjects);
        if (mouseInput) {
            mouseInput.registerController(this);
        }
        else {
            this.warn("Unable to find MouseInputEntity");
        }
    }
}
exports.MouseScale = MouseScale;
MouseScale.type = "MouseScale";
//# sourceMappingURL=MouseScale.js.map