class File { // Canvas, canvas state canvasSize = []; zoom = 7; canvasView = document.getElementById("canvas-view") ?? document.createElement("div"); inited = false; // Layers layers = []; sublayers = []; currentLayer = undefined; VFXLayer = undefined; TMPLayer = undefined; pixelGrid = undefined; checkerBoard = undefined // Canvas resize attributes // Resize canvas pop up window resizeCanvasContainer = document.getElementById("resize-canvas"); // Start pivot rcPivot = "middle"; // Selected pivot button currentPivotObject = undefined; // Border offsets rcBorders = {left: 0, right: 0, top: 0, bottom: 0}; // Sprite scaling attributes // Should I keep the sprite ratio? keepRatio = true; // Used to store the current ratio currentRatio = undefined; // The currenty selected resizing algorithm (nearest-neighbor or bilinear-interpolation) currentAlgo = 'nearest-neighbor'; // Current resize data data = {width: 0, height: 0, widthPercentage: 100, heightPercentage: 100}; // Start resize data startData = {width: 0, height:0, widthPercentage: 100, heightPercentage: 100}; openResizeCanvasWindow() { if (!this.inited) { this.initResizeCanvasInputs(); this.inited = true; } // Initializes the inputs Dialogue.showDialogue('resize-canvas'); } 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 = currFile.canvasSize[1] - minY; maxY = currFile.canvasSize[1] - maxY; // Setting the borders coherently with the values I've just computed this.rcBorders.right = (maxX - currFile.canvasSize[0]) + 1; this.rcBorders.left = -minX; this.rcBorders.top = maxY - currFile.canvasSize[1] + 1; this.rcBorders.bottom = -minY; // Saving the data for (let i=0; i