![]() 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 : |
import Vec2 from "absol/src/Math/Vec2"; /*** * * @param {CircuitDiagramEditor} editor * @constructor */ function NodePositionController(editor) { this.editor = editor; for (var i in this) { if (i.startsWith('ev_')) { this[i] = this[i].bind(this); } } } NodePositionController.prototype.addEventControl = function (nodeElt) { nodeElt.$header.on('click', this.ev_clickNode.bind(this, nodeElt)); nodeElt.$header.on('dragstart', this.ev_dragStart.bind(this, nodeElt)); nodeElt.$header.on('dragend', this.ev_dragEnd.bind(this, nodeElt)); nodeElt.$header.on('drag', this.ev_drag.bind(this, nodeElt)); }; NodePositionController.prototype.ev_clickNode = function (node, event) { if (node.__draging) return; this.editor.lineSelectController.unSelectAll(); this.editor.nodeSelectController.toggleSelect(node, event.shiftKey); }; NodePositionController.prototype.ev_dragStart = function (node, event) { if (!node.containsClass('as-selected')) { this.editor.lineSelectController.unSelectAll(); this.editor.nodeSelectController.select(node); } node.__draging = Math.random() + ''; this.dragingNodeHolders = this.editor.nodeSelectController.$selectedNodes.reduce(function (ac, cr) { ac[cr.nodeId] = { elt: cr, pos: new Vec2(cr.x, cr.y) }; return ac; }, {}); }; NodePositionController.prototype.ev_dragEnd = function (node, event) { var currentDragSession = node.__draging; this.dragingNodeHolders = null; setTimeout(function () { if (node.__draging === currentDragSession) { node.__draging = null; } }, 100); this.editor.notifyUnsaved(); }; NodePositionController.prototype.ev_drag = function (node, event) { var d = event.currentPoint.sub(event.startingPoint); var lines = {}; var holder; for (var nodeId in this.dragingNodeHolders) { holder = this.dragingNodeHolders[nodeId]; holder.newPos = holder.pos.add(d); holder.elt.x = holder.newPos.x; holder.elt.y = holder.newPos.y; Object.assign(lines, holder.elt.lines); } for (var lineId in lines) { this.editor.updateLinePosition(lineId); } }; export default NodePositionController;