/** * Copyright JS Foundation and other contributors, http://js.foundation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. **/ RED.view.tools = (function() { function alignToGrid() { var selection = RED.view.selection(); if (selection.nodes) { var changedNodes = []; selection.nodes.forEach(function(n) { var x = n.w/2 + Math.round((n.x-n.w/2)/RED.view.gridSize())*RED.view.gridSize(); var y = Math.round(n.y/RED.view.gridSize())*RED.view.gridSize(); if (n.x !== x || n.y !== y) { changedNodes.push({ n:n, ox: n.x, oy: n.y, moved: n.moved }); n.x = x; n.y = y; n.dirty = true; n.moved = true; } }); if (changedNodes.length > 0) { RED.history.push({t:"move",nodes:changedNodes,dirty:RED.nodes.dirty()}); RED.nodes.dirty(true); RED.view.redraw(true); } } } var moving_set = null; var endMoveSet = false; function endKeyboardMove() { endMoveSet = false; if (moving_set.length > 0) { var ns = []; for (var i=0;i 0) { var n = selection.nodes.shift(); moving_set.push({n:n}); if (n.type === "group") { selection.nodes = selection.nodes.concat(n.nodes); } } } } if (moving_set && moving_set.length > 0) { if (!endMoveSet) { $(document).one('keyup',endKeyboardMove); endMoveSet = true; } var minX = 0; var minY = 0; var node; for (var i=0;i