// REFACTOR: method of File class probably /* This scripts contains all the code used to handle the canvas resizing */ // Resize canvas pop up window let resizeCanvasContainer = document.getElementById("resize-canvas"); // Start pivot let rcPivot = "middle"; // Selected pivot button let currentPivotObject; // Border offsets let rcBorders = {left: 0, right: 0, top: 0, bottom: 0}; /** Opens the canvas resize window * */ function openResizeCanvasWindow() { // Initializes the inputs initResizeCanvasInputs(); Dialogue.showDialogue('resize-canvas'); } /** Initializes the canvas resizing input * */ function initResizeCanvasInputs() { // Getting the pivot buttons let buttons = document.getElementsByClassName("pivot-button"); // Adding the event handlers for them for (let i=0; i= 0; i-=4) { if (!Util.isPixelEmpty( [imageData.data[i - 3], imageData.data[i - 2], -imageData.data[i - 1], imageData.data[i]])) { pixelPosition = getPixelPosition(i); // max x if (pixelPosition[0] > maxX) { maxX = pixelPosition[0]; } // min x if (pixelPosition[0] < minX) { minX = pixelPosition[0]; } // max y if (pixelPosition[1] > maxY) { maxY = pixelPosition[1]; } // min y if (pixelPosition[1] < minY) { minY = pixelPosition[1]; } } } } tmp = minY; minY = maxY; maxY = tmp; minY = layers[0].canvasSize[1] - minY; maxY = layers[0].canvasSize[1] - maxY; // Setting the borders coherently with the values I've just computed rcBorders.right = (maxX - layers[0].canvasSize[0]) + 1; rcBorders.left = -minX; rcBorders.top = maxY - layers[0].canvasSize[1] + 1; rcBorders.bottom = -minY; // Saving the data for (let i=0; i