VaKeR CYBER ARMY
Logo of a company Server : Apache/2.4.41 (Ubuntu)
System : Linux absol.cf 5.4.0-198-generic #218-Ubuntu SMP Fri Sep 27 20:18:53 UTC 2024 x86_64
User : www-data ( 33)
PHP Version : 7.4.33
Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Directory :  /var/www/html/libs/absol-form/js/ciruiteditor/diagrameditor/controller/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /var/www/html/libs/absol-form/js/ciruiteditor/diagrameditor/controller/ViewBoxController.js
import Hanger from "absol-acomp/js/Hanger";
import {_} from '../../../core/FCore';
import Vec2 from "absol/src/Math/Vec2";

/***
 *
 * @param {CircuitDiagramEditor}  editor
 * @constructor
 */
function ViewBoxController(editor) {
    this.editor = editor;
    for (var i in this) {
        if (i.startsWith('ev_')) {
            this[i] = this[i].bind(this);
        }
    }
}

ViewBoxController.prototype.onCreateView = function () {
    this.$lineLayer = this.editor.$lineLayer;
    this.$lineLayer.on('dragstart', this.ev_dragStart);
    this.$nodeLayer = this.editor.$nodeLayer;
    this.$body = this.editor.$body;
    this.$body.on('wheel', this.ev_wheel);
};

ViewBoxController.prototype.ev_dragStart = function (event) {
    if (event.target === this.$lineLayer) {
        this.startOrigin = this.$lineLayer.box.origin;
        this.$lineLayer.on('drag', this.ev_drag)
            .on('dragend', this.ev_dragEnd)
    }
};

ViewBoxController.prototype.ev_drag = function (event) {
    var d = event.currentPoint.sub(event.startingPoint);
    var newOrigin = this.startOrigin.add(d);
    this.$lineLayer.box.origin = newOrigin;
    this.$nodeLayer.addStyle({
        left: newOrigin.x + 'px',
        top: newOrigin.y + 'px'
    });
};


ViewBoxController.prototype.ev_dragEnd = function (event) {
    this.$lineLayer.off('drag', this.ev_drag)
        .off('dragend', this.ev_dragEnd)
};

ViewBoxController.prototype.ev_wheel = function (event) {
    var d = event.deltaY < 0 ? 100 : -100;
    var newOrigin = this.$lineLayer.box.origin.add(new Vec2(event.shiftKey ? d : 0, event.shiftKey ? 0 : d));
    this.$lineLayer.box.origin = newOrigin;
    this.$nodeLayer.addStyle({
        left: newOrigin.x + 'px',
        top: newOrigin.y + 'px'
    });
};


ViewBoxController.prototype.scrollIntoNodes = function () {
    var nodesBound = this.getNodesBound();
    var maxX = nodesBound.x + nodesBound.width;
    var minX = nodesBound.x;
    var minY = nodesBound.y;
    var maxY = nodesBound.y + nodesBound.height;
    var viewBox = this.$lineLayer.box.viewBox;

    var ox = Math.min(viewBox.x, maxX + 10 - viewBox.width);
    ox = Math.max(ox, minX - 10);
    var oy = Math.min(viewBox.y, maxY + 10 - viewBox.height);
    oy = Math.max(oy, minY - 10);
    var newOrigin = new Vec2(-ox, -oy);

    this.$lineLayer.box.origin = newOrigin;
    this.$nodeLayer.addStyle({
        left: newOrigin.x + 'px',
        top: newOrigin.y + 'px'
    });
};


ViewBoxController.prototype.getNodesBound = function () {
    var minY = Infinity, maxY = -Infinity, minX = Infinity, maxX = -Infinity;
    var nodes = this.editor.$nodes;
    var node;
    var found = false;
    for (var nodeId in nodes) {
        found = true;
        node = nodes[nodeId];
        minX = Math.min(minX, node.x);
        minY = Math.min(minY, node.y);
        maxX = Math.max(maxX, node.x + node.rect.width);
        maxY = Math.max(maxY, node.y + node.rect.height);
    }
    return found ? {
        x: minX,
        y: minY,
        width: maxX - minX,
        height: maxY - minY
    } : {x: 0, y: 0, width: 0, height: 0};
}


export default ViewBoxController;

VaKeR 2022