From b2f55217507ba237c94d23ceb9aa011eda1dc345 Mon Sep 17 00:00:00 2001 From: unsettledgames <47360416+unsettledgames@users.noreply.github.com> Date: Mon, 6 Dec 2021 17:37:43 +0100 Subject: [PATCH] Removed all global variables, worked on File class and put canvas resizing functions in File --- js/ColorModule.js | 17 +- js/EditorState.js | 6 +- js/File.js | 327 ++++++++++++++++++++++++++- js/FileManager.js | 30 +-- js/History.js | 76 +++---- js/Input.js | 6 +- js/LayerList.js | 100 ++++---- js/Settings.js | 2 +- js/Startup.js | 51 ++--- js/Tool.js | 18 +- js/ToolManager.js | 2 +- js/_resizeCanvas.js | 311 ------------------------- js/_resizeSprite.js | 40 ++-- js/data/variables.js | 27 --- js/layers/Checkerboard.js | 14 +- js/layers/Layer.js | 60 ++--- js/layers/PixelGrid.js | 2 +- js/lib/jscolor.js | 1 - js/pixel-editor.js | 4 +- js/tools/BrushTool.js | 10 +- js/tools/EraserTool.js | 10 +- js/tools/EyeDropperTool.js | 16 +- js/tools/FillTool.js | 24 +- js/tools/LineTool.js | 24 +- js/tools/MoveSelectionTool.js | 36 +-- js/tools/PanTool.js | 12 +- js/tools/RectangleTool.js | 34 ++- js/tools/RectangularSelectionTool.js | 34 +-- js/tools/ResizableTool.js | 2 +- js/tools/ZoomTool.js | 70 +++--- js/{ => tools}/_ellipse.js | 0 views/main-menu.hbs | 6 +- 32 files changed, 668 insertions(+), 704 deletions(-) delete mode 100644 js/data/variables.js rename js/{ => tools}/_ellipse.js (100%) diff --git a/js/ColorModule.js b/js/ColorModule.js index 80019a2..2a194e6 100644 --- a/js/ColorModule.js +++ b/js/ColorModule.js @@ -318,7 +318,7 @@ const ColorModule = (() => { if (typeof newColor === 'string') newColor = Color.hexToRgb(newColor); //create temporary image from canvas to search through - var tempImage = currentLayer.context.getImageData(0, 0, canvasSize[0], canvasSize[1]); + var tempImage = currFile.currentLayer.context.getImageData(0, 0, currFile.canvasSize[0], currFile.canvasSize[1]); //loop through all pixels for (var i=0;i { } //put temp image back onto canvas - currentLayer.context.putImageData(tempImage,0,0); + currFile.currentLayer.context.putImageData(tempImage,0,0); } function getCurrentPalette() { @@ -395,9 +395,10 @@ const ColorModule = (() => { //create array out of colors object let colorPaletteArray = []; - for (let i=0; i { if (refLayer) color = refLayer.context.fillStyle; - for (let i=0; i { document.getElementById("switch-mode-button").innerHTML = 'Switch to basic mode'; //turn pixel grid off - pixelGrid.togglePixelGrid('off'); + currFile.pixelGrid.togglePixelGrid('off'); } //switch to basic mode else { @@ -32,7 +32,7 @@ const EditorState = (() => { } // Selecting the current layer - currentLayer.selectLayer(); + currFile.currentLayer.selectLayer(); // Flatten the layers LayerList.flatten(true); } @@ -47,7 +47,7 @@ const EditorState = (() => { pixelEditorMode = 'Basic'; document.getElementById("switch-mode-button").innerHTML = 'Switch to advanced mode'; - pixelGrid.togglePixelGrid('on'); + currFile.pixelGrid.togglePixelGrid('on'); } } diff --git a/js/File.js b/js/File.js index 147d5e0..8b0bf82 100644 --- a/js/File.js +++ b/js/File.js @@ -1,12 +1,319 @@ -// A file has layers - // It probably contains the LayerList, which should include the layers array -// A file contains sprite scaling and canvas resizing +class File { + // Canvas, canvas state + canvasSize = []; + zoom = 7; + canvasView = document.getElementById("canvas-view"); -/* - let canvasSize - let canvasView - let layerList + // Layers + layers = []; + currentLayer = undefined; + VFXLayer = undefined; + TMPLayer = undefined; + pixelGrid = undefined; + checkerBoard = undefined - resizeCanvas() - scaleSprite() -*/ \ No newline at end of file + // 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 + + openResizeCanvasWindow() { + // Initializes the inputs + this.initResizeCanvasInputs(); + 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 { if (selectedPalette != 'Choose a palette...'){ var paletteAbbreviation = palettes[selectedPalette].abbreviation; - var fileName = 'pixel-'+paletteAbbreviation+'-'+canvasSize[0]+'x'+canvasSize[1]; + var fileName = 'pixel-'+paletteAbbreviation+'-'+currFile.canvasSize[0]+'x'+currFile.canvasSize[1]; } else { - var fileName = 'pixel-'+canvasSize[0]+'x'+canvasSize[1]; + var fileName = 'pixel-'+currFile.canvasSize[0]+'x'+currFile.canvasSize[1]; selectedPalette = 'none'; } @@ -33,7 +33,7 @@ const FileManager = (() => { var paletteAbbreviation = palettes[selectedPalette].name; var fileName = 'pixel-'+paletteAbbreviation+'-'+canvasSize[0]+'x'+canvasSize[1]+'.png'; } else { - var fileName = 'pixel-'+canvasSize[0]+'x'+canvasSize[1]+'.png'; + var fileName = 'pixel-'+currFile.canvasSize[0]+'x'+currFile.canvasSize[1]+'.png'; selectedPalette = 'none'; } @@ -58,7 +58,7 @@ const FileManager = (() => { linkHolder.click(); if (typeof ga !== 'undefined') - ga('send', 'event', 'Pixel Editor Save', selectedPalette, canvasSize[0]+'/'+canvasSize[1]); /*global ga*/ + ga('send', 'event', 'Pixel Editor Save', selectedPalette, currFile.canvasSize[0]+'/'+currFile.canvasSize[1]); /*global ga*/ } function exportProject() { @@ -70,20 +70,20 @@ const FileManager = (() => { // Creating a tmp canvas to flatten everything var exportCanvas = document.createElement("canvas"); var emptyCanvas = document.createElement("canvas"); - var layersCopy = layers.slice(); + var layersCopy = currFile.layers.slice(); - exportCanvas.width = layers[0].canvasSize[0]; - exportCanvas.height = layers[0].canvasSize[1]; + exportCanvas.width = currFile.canvasSize[0]; + exportCanvas.height = currFile.canvasSize[1]; - emptyCanvas.width = layers[0].canvasSize[0]; - emptyCanvas.height = layers[0].canvasSize[1]; + emptyCanvas.width = currFile.canvasSize[0]; + emptyCanvas.height = currFile.canvasSize[1]; // Sorting the layers by z index layersCopy.sort((a, b) => (a.canvas.style.zIndex > b.canvas.style.zIndex) ? 1 : -1); // Merging every layer on the export canvas for (let i=0; i { //track google event if (typeof ga !== 'undefined') - ga('send', 'event', 'Pixel Editor Export', selectedPalette, canvasSize[0]+'/'+canvasSize[1]); /*global ga*/ + ga('send', 'event', 'Pixel Editor Export', selectedPalette, currFile.canvasSize[0]+'/'+currFile.canvasSize[1]); /*global ga*/ } } @@ -157,7 +157,7 @@ const FileManager = (() => { EditorState.switchMode('Advanced'); //draw the image onto the canvas - currentLayer.context.drawImage(img, 0, 0); + currFile.currentLayer.context.drawImage(img, 0, 0); ColorModule.createPaletteFromLayers(); //track google event @@ -195,11 +195,11 @@ const FileManager = (() => { // use a dictionary let dictionary = {}; // sorting layers by increasing z-index - let layersCopy = layers.slice(); + let layersCopy = currFile.layers.slice(); layersCopy.sort((a, b) => (a.canvas.style.zIndex > b.canvas.style.zIndex) ? 1 : -1); // save canvas size - dictionary['canvasWidth'] = currentLayer.canvasSize[0]; - dictionary['canvasHeight'] = currentLayer.canvasSize[1]; + dictionary['canvasWidth'] = currFile.canvasSize[0]; + dictionary['canvasHeight'] = currFile.canvasSize[1]; // save editor mode dictionary['editorMode'] = EditorState.getCurrentMode(); // save palette diff --git a/js/History.js b/js/History.js index de11904..1afe5d9 100644 --- a/js/History.js +++ b/js/History.js @@ -108,11 +108,11 @@ class HistoryState { resizeSprite(null, [1 / this.xRatio, 1 / this.yRatio]); // Also putting the old data - for (let i=0; i this.index + 1) { - layers[this.index + 1].selectLayer(); + if (currFile.layers.length - nAppLayers > this.index + 1) { + currFile.layers[this.index + 1].selectLayer(); } else { - layers[this.index - 1].selectLayer(); + currFile.layers[this.index - 1].selectLayer(); } this.added.canvas.remove(); this.added.menuEntry.remove(); - layers.splice(index, 1); + currFile.layers.splice(index, 1); }; this.redo = function() { - canvasView.append(this.added.canvas); + currFile.canvasView.append(this.added.canvas); LayerList.getLayerListEntries().prepend(this.added.menuEntry); layers.splice(this.index, 0, this.added); }; @@ -349,12 +349,12 @@ class HistoryState { //prototype for undoing canvas changes EditCanvas() { - this.canvasState = currentLayer.context.getImageData(0, 0, canvasSize[0], canvasSize[1]); - this.layerID = currentLayer.id; + this.canvasState = currFile.currentLayer.context.getImageData(0, 0, currFile.canvasSize[0], currFile.canvasSize[1]); + this.layerID = currFile.currentLayer.id; this.undo = function () { var stateLayer = LayerList.getLayerByID(this.layerID); - var currentCanvas = stateLayer.context.getImageData(0, 0, canvasSize[0], canvasSize[1]); + var currentCanvas = stateLayer.context.getImageData(0, 0, currFile.canvasSize[0], currFile.canvasSize[1]); stateLayer.context.putImageData(this.canvasState, 0, 0); this.canvasState = currentCanvas; @@ -364,7 +364,7 @@ class HistoryState { this.redo = function () { var stateLayer = LayerList.getLayerByID(this.layerID); - var currentCanvas = stateLayer.context.getImageData(0, 0, canvasSize[0], canvasSize[1]); + var currentCanvas = stateLayer.context.getImageData(0, 0, currFile.canvasSize[0], currFile.canvasSize[1]); stateLayer.context.putImageData(this.canvasState, 0, 0); @@ -390,11 +390,11 @@ class HistoryState { //prototype for undoing deleted colors DeleteColor(colorValue) { this.colorValue = colorValue; - this.canvas = currentLayer.context.getImageData(0, 0, canvasSize[0], canvasSize[1]); + this.canvas = currFile.currentLayer.context.getImageData(0, 0, currFile.canvasSize[0], currFile.canvasSize[1]); this.undo = function () { - var currentCanvas = currentLayer.context.getImageData(0, 0, canvasSize[0], canvasSize[1]); - currentLayer.context.putImageData(this.canvas, 0, 0); + var currentCanvas = currFile.currentLayer.context.getImageData(0, 0, currFile.canvasSize[0], currFile.canvasSize[1]); + currFile.currentLayer.context.putImageData(this.canvas, 0, 0); ColorModule.addColor(this.colorValue); @@ -402,8 +402,8 @@ class HistoryState { }; this.redo = function () { - var currentCanvas = currentLayer.context.getImageData(0, 0, canvasSize[0], canvasSize[1]); - currentLayer.context.putImageData(this.canvas, 0, 0); + var currentCanvas = currFile.currentLayer.context.getImageData(0, 0, currFile.canvasSize[0], currFile.canvasSize[1]); + currFile.currentLayer.context.putImageData(this.canvas, 0, 0); ColorModule.deleteColor(this.colorValue); @@ -415,11 +415,11 @@ class HistoryState { EditColor(newColorValue, oldColorValue) { this.newColorValue = newColorValue; this.oldColorValue = oldColorValue; - this.canvas = currentLayer.context.getImageData(0, 0, canvasSize[0], canvasSize[1]); + this.canvas = currFile.currentLayer.context.getImageData(0, 0, currFile.canvasSize[0], currFile.canvasSize[1]); this.undo = function () { - let currentCanvas = currentLayer.context.getImageData(0, 0, canvasSize[0], canvasSize[1]); - currentLayer.context.putImageData(this.canvas, 0, 0); + let currentCanvas = currFile.currentLayer.context.getImageData(0, 0, currFile.canvasSize[0], currFile.canvasSize[1]); + currFile.currentLayer.context.putImageData(this.canvas, 0, 0); //find new color in palette and change it back to old color let colors = document.getElementsByClassName('color-button'); @@ -435,8 +435,8 @@ class HistoryState { }; this.redo = function () { - let currentCanvas = currentLayer.context.getImageData(0, 0, canvasSize[0], canvasSize[1]); - currentLayer.context.putImageData(this.canvas, 0, 0); + let currentCanvas = currFile.currentLayer.context.getImageData(0, 0, currFile.canvasSize[0], currFile.canvasSize[1]); + currFile.currentLayer.context.putImageData(this.canvas, 0, 0); //find old color in palette and change it back to new color let colors = document.getElementsByClassName('color-button'); diff --git a/js/Input.js b/js/Input.js index 2f9fd38..03d6c19 100644 --- a/js/Input.js +++ b/js/Input.js @@ -31,7 +31,7 @@ const Input = (() => { currentMouseEvent = event; dragging = false; - if (currentLayer != null && !Util.isChildOfByClass(event.target, "layers-menu-entry")) { + if (currFile.currentLayer != null && !Util.isChildOfByClass(event.target, "layers-menu-entry")) { LayerList.closeOptionsMenu(); } } @@ -49,8 +49,8 @@ const Input = (() => { y = e.clientY + document.body.scrollTop + document.documentElement.scrollTop; } - x -= currentLayer.canvas.offsetLeft; - y -= currentLayer.canvas.offsetTop; + x -= currFile.currentLayer.canvas.offsetLeft; + y -= currFile.currentLayer.canvas.offsetTop; return [Math.round(x), Math.round(y)]; } diff --git a/js/LayerList.js b/js/LayerList.js index 4407e4b..2b0d546 100644 --- a/js/LayerList.js +++ b/js/LayerList.js @@ -21,11 +21,11 @@ const LayerList = (() => { function addLayer(id, saveHistory = true) { // layers.length - 3 - let index = layers.length - 3; + let index = currFile.layers.length - 3; // Creating a new canvas let newCanvas = document.createElement("canvas"); // Setting up the new canvas - canvasView.append(newCanvas); + currFile.canvasView.append(newCanvas); Layer.maxZIndex+=2; newCanvas.style.zIndex = Layer.maxZIndex; newCanvas.classList.add("drawingCanvas"); @@ -42,11 +42,11 @@ const LayerList = (() => { Layer.layerCount++; // Creating a layer object - let newLayer = new Layer(currentLayer.canvasSize[0], currentLayer.canvasSize[1], newCanvas, toAppend); - newLayer.context.fillStyle = currentLayer.context.fillStyle; - newLayer.copyData(currentLayer); + let newLayer = new Layer(currFile.canvasSize[0], currFile.canvasSize[1], newCanvas, toAppend); + newLayer.context.fillStyle = currFile.currentLayer.context.fillStyle; + newLayer.copyData(currFile.currentLayer); - layers.splice(index, 0, newLayer); + currFile.layers.splice(index, 0, newLayer); // Insert it before the Add layer button layerList.insertBefore(toAppend, layerList.childNodes[0]); @@ -134,10 +134,10 @@ const LayerList = (() => { // Finds a layer given its id function getLayerByID(id) { - for (let i=0; i { // Finds a layer given its name function getLayerByName(name) { - for (let i=0; i { } function startRenamingLayer(event) { - let p = currentLayer.menuEntry.getElementsByTagName("p")[0]; + let p = currFile.currentLayer.menuEntry.getElementsByTagName("p")[0]; - currentLayer.oldLayerName = p.innerHTML; + currFile.currentLayer.oldLayerName = p.innerHTML; p.setAttribute("contenteditable", true); p.classList.add("layer-name-editable"); @@ -182,8 +182,8 @@ const LayerList = (() => { return -1; } - let layerIndex = layers.indexOf(currentLayer); - let toDuplicate = currentLayer; + let layerIndex = currFile.layers.indexOf(currFile.currentLayer); + let toDuplicate = currFile.currentLayer; let menuEntries = layerList.children; // Increasing z-indexes of the layers above @@ -195,14 +195,14 @@ const LayerList = (() => { // Creating a new canvas let newCanvas = document.createElement("canvas"); // Setting up the new canvas - canvasView.append(newCanvas); - newCanvas.style.zIndex = parseInt(currentLayer.canvas.style.zIndex) + 2; + currFile.canvasView.append(newCanvas); + newCanvas.style.zIndex = parseInt(currFile.currentLayer.canvas.style.zIndex) + 2; newCanvas.classList.add("drawingCanvas"); if (!layerListEntry) return console.warn('skipping adding layer because no document'); // Clone the default layer - let toAppend = currentLayer.menuEntry.cloneNode(true); + let toAppend = currFile.currentLayer.menuEntry.cloneNode(true); // Setting the default name for the layer toAppend.getElementsByTagName('p')[0].innerHTML += " copy"; // Removing the selected class @@ -211,41 +211,41 @@ const LayerList = (() => { Layer.layerCount++; // Creating a layer object - let newLayer = new Layer(currentLayer.canvasSize[0], currentLayer.canvasSize[1], newCanvas, toAppend); - newLayer.context.fillStyle = currentLayer.context.fillStyle; - newLayer.copyData(currentLayer); + let newLayer = new Layer(currFile.canvasSize[0], currFile.canvasSize[1], newCanvas, toAppend); + newLayer.context.fillStyle = currFile.currentLayer.context.fillStyle; + newLayer.copyData(currFile.currentLayer); - layers.splice(layerIndex, 0, newLayer); + currFile.layers.splice(layerIndex, 0, newLayer); // Insert it before the Add layer button - layerList.insertBefore(toAppend, currentLayer.menuEntry); + layerList.insertBefore(toAppend, currFile.currentLayer.menuEntry); // Copy the layer content - newLayer.context.putImageData(currentLayer.context.getImageData( - 0, 0, currentLayer.canvasSize[0], currentLayer.canvasSize[1]), 0, 0); + newLayer.context.putImageData(currFile.currentLayer.context.getImageData( + 0, 0, currFile.canvasSize[0], currFile.canvasSize[1]), 0, 0); newLayer.updateLayerPreview(); // Basically "if I'm not adding a layer because redo() is telling meto do so", then I can save the history if (saveHistory) { - new HistoryState().DuplicateLayer(newLayer, currentLayer); + new HistoryState().DuplicateLayer(newLayer, currFile.currentLayer); } } function deleteLayer(saveHistory = true) { // Cannot delete all the layers - if (layers.length != 4) { - let layerIndex = layers.indexOf(currentLayer); - let toDelete = layers[layerIndex]; + if (currFile.layers.length != 4) { + let layerIndex = currFile.layers.indexOf(currFile.currentLayer); + let toDelete = currFile.layers[layerIndex]; let previousSibling = toDelete.menuEntry.previousElementSibling; // Adding the ids to the unused ones Layer.unusedIDs.push(toDelete.id); // Selecting the next layer - if (layerIndex != (layers.length - 4)) { - layers[layerIndex + 1].selectLayer(); + if (layerIndex != (currFile.layers.length - 4)) { + currFile.layers[layerIndex + 1].selectLayer(); } // or the previous one if the next one doesn't exist else { - layers[layerIndex - 1].selectLayer(); + currFile.layers[layerIndex - 1].selectLayer(); } // Deleting canvas and entry @@ -253,7 +253,7 @@ const LayerList = (() => { toDelete.menuEntry.remove(); // Removing the layer from the list - layers.splice(layerIndex, 1); + currFile.layers.splice(layerIndex, 1); if (saveHistory) { new HistoryState().DeleteLayer(toDelete, previousSibling, layerIndex); @@ -266,10 +266,10 @@ const LayerList = (() => { function merge(saveHistory = true) { // Saving the layer that should be merged - let toMerge = currentLayer; - let toMergeIndex = layers.indexOf(toMerge); + let toMerge = currFile.currentLayer; + let toMergeIndex = currFile.layers.indexOf(toMerge); // Getting layer below - let layerBelow = LayerList.getLayerByID(currentLayer.menuEntry.nextElementSibling.id); + let layerBelow = LayerList.getLayerByID(currFile.currentLayer.menuEntry.nextElementSibling.id); // If I have something to merge with if (layerBelow != null) { @@ -278,19 +278,19 @@ const LayerList = (() => { if (saveHistory) { new HistoryState().MergeLayer(toMergeIndex, toMerge, - layerBelow.context.getImageData(0, 0, layerBelow.canvasSize[0], layerBelow.canvasSize[1]), + layerBelow.context.getImageData(0, 0, currFile.canvasSize[0], currFile.canvasSize[1]), layerBelow); } - LayerList.mergeLayers(currentLayer.context, toMerge.context); + LayerList.mergeLayers(currFile.currentLayer.context, toMerge.context); // Deleting the above layer toMerge.canvas.remove(); toMerge.menuEntry.remove(); - layers.splice(toMergeIndex, 1); + currFile.layers.splice(toMergeIndex, 1); // Updating the layer preview - currentLayer.updateLayerPreview(); + currFile.currentLayer.updateLayerPreview(); } } @@ -312,9 +312,9 @@ const LayerList = (() => { let visibleLayers = []; let nToFlatten = 0; - for (let i=0; i { nToFlatten++; console.log(visibleLayers[i].menuEntry.nextElementSibling); new HistoryState().FlattenTwoVisibles( - visibleLayers[i + 1].context.getImageData(0, 0, visibleLayers[i].canvasSize[0], visibleLayers[i].canvasSize[1]), + visibleLayers[i + 1].context.getImageData(0, 0, currFile.canvasSize[0], currFile.canvasSize[1]), visibleLayers[i].menuEntry.nextElementSibling, layers.indexOf(visibleLayers[i]), visibleLayers[i], visibleLayers[i + 1] @@ -339,12 +339,12 @@ const LayerList = (() => { // Deleting the above layer visibleLayers[i].canvas.remove(); visibleLayers[i].menuEntry.remove(); - layers.splice(layers.indexOf(visibleLayers[i]), 1); + currFile.layers.splice(currFile.layers.indexOf(visibleLayers[i]), 1); } new HistoryState().FlattenVisible(nToFlatten); // Updating the layer preview - currentLayer.updateLayerPreview(); + currFile.currentLayer.updateLayerPreview(); } } @@ -369,7 +369,7 @@ const LayerList = (() => { function closeOptionsMenu(event) { Layer.layerOptions.style.visibility = "hidden"; - currentLayer.rename(); + currFile.currentLayer.rename(); renamingLayer = false; } diff --git a/js/Settings.js b/js/Settings.js index 20c6a1a..dd66fa8 100644 --- a/js/Settings.js +++ b/js/Settings.js @@ -45,7 +45,7 @@ const Settings = (() => { settings.numberOfHistoryStates = Util.getValue('setting-numberOfHistoryStates'); settings.pixelGridColour = Util.getValue('setting-pixelGridColour'); // Filling pixel grid again if colour changed - pixelGrid.fillPixelGrid(); + currFile.pixelGrid.fillPixelGrid(); //save settings object to cookie var cookieValue = JSON.stringify(settings); diff --git a/js/Startup.js b/js/Startup.js index 7e4d133..44c5cb3 100644 --- a/js/Startup.js +++ b/js/Startup.js @@ -53,7 +53,7 @@ const Startup = (() => { // Deleting the default layer LayerList.deleteLayer(false); // Selecting the new one - layers[1].selectLayer(); + currFile.layers[1].selectLayer(); } console.log("Starting with mode " + EditorState.getCurrentMode()); @@ -63,17 +63,20 @@ const Startup = (() => { } function initLayers(width, height) { + // Setting the general canvasSize + currFile.canvasSize = [width, height]; + // If this is the first pixel I'm creating since the app has started if (firstPixel) { // Creating the first layer - currentLayer = new Layer(width, height, 'pixel-canvas', ""); - currentLayer.canvas.style.zIndex = 2; + currFile.currentLayer = new Layer(width, height, 'pixel-canvas', ""); + currFile.currentLayer.canvas.style.zIndex = 2; } else { // Deleting all the extra layers and canvases, leaving only one - let nLayers = layers.length; - for (let i=2; i < layers.length - nAppLayers; i++) { - let currentEntry = layers[i].menuEntry; + let nLayers = currFile.layers.length; + for (let i=2; i < currFile.layers.length - nAppLayers; i++) { + let currentEntry = currFile.layers[i].menuEntry; let associatedLayer; if (currentEntry != null) { @@ -84,7 +87,7 @@ const Startup = (() => { associatedLayer.canvas.remove(); // Adding the id to the unused ones - unusedIDs.push(currentEntry.id); + Layer.unusedIDs.push(currentEntry.id); // Removing the entry from the menu currentEntry.remove(); } @@ -92,40 +95,32 @@ const Startup = (() => { // Removing the old layers from the list for (let i=2; i { currTool = tools["brush"]; currTool.onSelect(); - canvasView.style.cursor = 'default'; + currFile.canvasView.style.cursor = 'default'; Events.on("mouseup", window, onMouseUp); Events.on("mousemove", window, onMouseMove); diff --git a/js/_resizeCanvas.js b/js/_resizeCanvas.js index e6e28c1..e69de29 100644 --- a/js/_resizeCanvas.js +++ b/js/_resizeCanvas.js @@ -1,311 +0,0 @@ -// 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 max || Util.isPixelEmpty(selectedColor) || selectedColor === undefined) { - max = layers[i].canvas.style.zIndex; + if (currFile.layers[i].canvas.style.zIndex > max || Util.isPixelEmpty(selectedColor) || selectedColor === undefined) { + max = currFile.layers[i].canvas.style.zIndex; if (!Util.isPixelEmpty(tmpColour)) { selectedColor = tmpColour; diff --git a/js/tools/FillTool.js b/js/tools/FillTool.js index b9f7d45..b96c4fc 100644 --- a/js/tools/FillTool.js +++ b/js/tools/FillTool.js @@ -11,7 +11,7 @@ class FillTool extends Tool { if (target.className != 'drawingCanvas') return; this.fill(mousePos); - currentLayer.updateLayerPreview(); + currFile.currentLayer.updateLayerPreview(); new HistoryState().EditCanvas(); } @@ -40,20 +40,20 @@ class FillTool extends Tool { } //temporary image holds the data while we change it - let tempImage = currentLayer.context.getImageData(0, 0, canvasSize[0], canvasSize[1]); + let tempImage = currFile.currentLayer.context.getImageData(0, 0, canvasSize[0], canvasSize[1]); //this is an array that holds all of the pixels at the top of the cluster - let topmostPixelsArray = [[Math.floor(cursorLocation[0]/zoom), Math.floor(cursorLocation[1]/zoom)]]; + let topmostPixelsArray = [[Math.floor(cursorLocation[0]/currFile.zoom), Math.floor(cursorLocation[1]/currFile.zoom)]]; //console.log('topmostPixelsArray:',topmostPixelsArray) //the offset of the pixel in the temp image data to start with - let startingPosition = (topmostPixelsArray[0][1] * canvasSize[0] + topmostPixelsArray[0][0]) * 4; + let startingPosition = (topmostPixelsArray[0][1] * currFile.canvasSize[0] + topmostPixelsArray[0][0]) * 4; //the color of the cluster that is being filled let clusterColor = [tempImage.data[startingPosition],tempImage.data[startingPosition+1],tempImage.data[startingPosition+2], tempImage.data[startingPosition+3]]; //the color to fill with - let fillColor = Color.hexToRgb(currentLayer.context.fillStyle); + let fillColor = Color.hexToRgb(currFile.currentLayer.context.fillStyle); //if you try to fill with the same color that's already there, exit the function if (clusterColor[0] == fillColor.r && @@ -78,18 +78,18 @@ class FillTool extends Tool { //this variable holds the index of where the starting values for the current pixel are in the data array //we multiply the number of rows down (y) times the width of each row, then add x. at the end we multiply by 4 because //each pixel has 4 values, rgba - let pixelPos = (y * canvasSize[0] + x) * 4; + let pixelPos = (y * currFile.canvasSize[0] + x) * 4; //move up in the image until you reach the top or the pixel you hit was not the right color while (y-- >= 0 && matchStartColor(tempImage, pixelPos, clusterColor)) { - pixelPos -= canvasSize[0] * 4; + pixelPos -= currFile.canvasSize[0] * 4; } - pixelPos += canvasSize[0] * 4; + pixelPos += currFile.canvasSize[0] * 4; ++y; reachLeft = false; reachRight = false; - while (y++ < canvasSize[1] - 1 && matchStartColor(tempImage, pixelPos, clusterColor)) { + while (y++ < currFile.canvasSize[1] - 1 && matchStartColor(tempImage, pixelPos, clusterColor)) { colorPixel(tempImage, pixelPos, fillColor); if (x > 0) { if (matchStartColor(tempImage, pixelPos - 4, clusterColor)) { @@ -103,7 +103,7 @@ class FillTool extends Tool { } } - if (x < canvasSize[0] - 1) { + if (x < currFile.canvasSize[0] - 1) { if (matchStartColor(tempImage, pixelPos + 4, clusterColor)) { if (!reachRight) { topmostPixelsArray.push([x + 1, y]); @@ -115,10 +115,10 @@ class FillTool extends Tool { } } - pixelPos += canvasSize[0] * 4; + pixelPos += currFile.canvasSize[0] * 4; } } - currentLayer.context.putImageData(tempImage, 0, 0); + currFile.currentLayer.context.putImageData(tempImage, 0, 0); } onDrag(mousePos, cursorTarget) { diff --git a/js/tools/LineTool.js b/js/tools/LineTool.js index 78f66b9..8fb8006 100644 --- a/js/tools/LineTool.js +++ b/js/tools/LineTool.js @@ -11,7 +11,7 @@ class LineTool extends ResizableTool { super.onStart(mousePos); // Putting the tmp layer on top of everything - TMPLayer.canvas.style.zIndex = parseInt(currentLayer.canvas.style.zIndex, 10) + 1; + currFile.TMPLayer.canvas.style.zIndex = parseInt(currFile.currentLayer.canvas.style.zIndex, 10) + 1; this.startMousePos[0] = Math.floor(mousePos[0]) + 0.5; this.startMousePos[1] = Math.floor(mousePos[1]) + 0.5; @@ -34,18 +34,18 @@ class LineTool extends ResizableTool { onEnd(mousePos) { super.onEnd(mousePos); - const tmpContext = TMPLayer.context; - const tmpCanvas = TMPLayer.canvas; + const tmpContext = currFile.TMPLayer.context; + const tmpCanvas = currFile.TMPLayer.canvas; // Setting the correct linewidth and colour - currentLayer.context.lineWidth = this.currSize; + currFile.currentLayer.context.lineWidth = this.currSize; // Drawing the line - currentLayer.context.drawImage(tmpCanvas, 0, 0); + currFile.currentLayer.context.drawImage(tmpCanvas, 0, 0); // Update the layer preview - currentLayer.updateLayerPreview(); + currFile.currentLayer.updateLayerPreview(); // Clearing the tmp canvas - tmpContext.clearRect(0, 0, TMPLayer.canvas.width, TMPLayer.canvas.height); + tmpContext.clearRect(0, 0, currFile.TMPLayer.canvas.width, currFile.TMPLayer.canvas.height); } onSelect() { @@ -57,10 +57,10 @@ class LineTool extends ResizableTool { } drawLine(mousePos) { - let x0 = Math.floor(this.startMousePos[0]/zoom); - let y0 = Math.floor(this.startMousePos[1]/zoom); - let x1 = Math.floor(mousePos[0]/zoom); - let y1 = Math.floor(mousePos[1]/zoom); + let x0 = Math.floor(this.startMousePos[0]/currFile.zoom); + let y0 = Math.floor(this.startMousePos[1]/currFile.zoom); + let x1 = Math.floor(mousePos[0]/currFile.zoom); + let y1 = Math.floor(mousePos[1]/currFile.zoom); let dx = Math.abs(x1-x0); let dy = Math.abs(y1-y0); @@ -72,7 +72,7 @@ class LineTool extends ResizableTool { const context = canvas.getContext('2d'); context.clearRect(0, 0, canvas.width, canvas.height); - canvas.style.zIndex = parseInt(currentLayer.canvas.style.zIndex, 10) + 1; + canvas.style.zIndex = parseInt(currFile.currentLayer.canvas.style.zIndex, 10) + 1; while (true) { context.fillRect(x0-Math.floor(this.currSize/2), y0-Math.floor(this.currSize/2), this.currSize, this.currSize); diff --git a/js/tools/MoveSelectionTool.js b/js/tools/MoveSelectionTool.js index bd57383..bc9c2ed 100644 --- a/js/tools/MoveSelectionTool.js +++ b/js/tools/MoveSelectionTool.js @@ -30,7 +30,7 @@ class MoveSelectionTool extends Tool { this.endSelection(); this.currSelection = this.lastCopiedSelection; // Cut the data - currentLayer.context.clearRect(this.currSelection.left-0.5, this.currSelection.top-0.5, + currFile.currentLayer.context.clearRect(this.currSelection.left-0.5, this.currSelection.top-0.5, this.currSelection.width, this.currSelection.height); } @@ -47,7 +47,7 @@ class MoveSelectionTool extends Tool { this.currSelection = this.lastCopiedSelection; // Putting the vfx layer on top of everything - VFXLayer.canvas.style.zIndex = MAX_Z_INDEX; + currFile.VFXLayer.canvas.style.zIndex = MAX_Z_INDEX; this.onDrag(this.currMousePos); new HistoryState().EditCanvas(); @@ -65,16 +65,16 @@ class MoveSelectionTool extends Tool { onDrag(mousePos) { super.onDrag(mousePos); - this.currSelection = this.selectionTool.moveAnts(mousePos[0]/zoom, - mousePos[1]/zoom, this.currSelection.width, this.currSelection.height); + this.currSelection = this.selectionTool.moveAnts(mousePos[0]/currFile.zoom, + mousePos[1]/currFile.zoom, this.currSelection.width, this.currSelection.height); // clear the entire tmp layer - TMPLayer.context.clearRect(0, 0, TMPLayer.canvas.width, TMPLayer.canvas.height); + TMPLayer.context.clearRect(0, 0, currFile.TMPLayer.canvas.width, currFile.TMPLayer.canvas.height); // put the image data on the tmp layer with offset - TMPLayer.context.putImageData( + currFile.TMPLayer.context.putImageData( this.currSelection.data, - Math.round(mousePos[0] / zoom) - this.currSelection.width / 2, - Math.round(mousePos[1] / zoom) - this.currSelection.height / 2); + Math.round(mousePos[0] / currFile.zoom) - this.currSelection.width / 2, + Math.round(mousePos[1] / currFile.zoom) - this.currSelection.height / 2); } onEnd(mousePos) { @@ -99,17 +99,17 @@ class MoveSelectionTool extends Tool { super.onHover(mousePos); if (this.cursorInSelectedArea(mousePos)) { - canvasView.style.cursor = 'move'; + currFile.canvasView.style.cursor = 'move'; } else { - canvasView.style.cursor = 'default'; + currFile.canvasView.style.cursor = 'default'; } } cursorInSelectedArea(cursorPos) { // Getting the coordinates relatively to the canvas - let x = cursorPos[0] / zoom; - let y = cursorPos[1] / zoom; + let x = cursorPos[0] / currFile.zoom; + let y = cursorPos[1] / currFile.zoom; if (this.currSelection.left <= x && x <= this.currSelection.right) { if (y <= this.currSelection.bottom && y >= this.currSelection.top) { @@ -124,12 +124,12 @@ class MoveSelectionTool extends Tool { if (this.currSelection == undefined) return; // Clearing the tmp (move preview) and vfx (ants) layers - TMPLayer.context.clearRect(0, 0, TMPLayer.canvas.width, TMPLayer.canvas.height); - VFXLayer.context.clearRect(0, 0, VFXLayer.canvas.width, VFXLayer.canvas.height); + currFile.TMPLayer.context.clearRect(0, 0, currFile.TMPLayer.canvas.width, currFile.TMPLayer.canvas.height); + currFile.VFXLayer.context.clearRect(0, 0, currFile.VFXLayer.canvas.width, currFile.VFXLayer.canvas.height); // I have to save the underlying data, so that the transparent pixels in the clipboard // don't override the coloured pixels in the canvas - let underlyingImageData = currentLayer.context.getImageData( + let underlyingImageData = currFile.currentLayer.context.getImageData( this.currSelection.left, this.currSelection.top, this.currSelection.width+1, this.currSelection.height+1 ); @@ -162,13 +162,13 @@ class MoveSelectionTool extends Tool { } } - currentLayer.context.putImageData(new ImageData(pasteData, this.currSelection.width+1), + currFile.currentLayer.context.putImageData(new ImageData(pasteData, this.currSelection.width+1), this.currSelection.left, this.currSelection.top ); this.currSelection = undefined; - currentLayer.updateLayerPreview(); - VFXLayer.canvas.style.zIndex = MIN_Z_INDEX; + currFile.currentLayer.updateLayerPreview(); + currFile.VFXLayer.canvas.style.zIndex = MIN_Z_INDEX; // Switch to brush this.switchFunc(this.endTool); diff --git a/js/tools/PanTool.js b/js/tools/PanTool.js index c4fb842..a35f68c 100644 --- a/js/tools/PanTool.js +++ b/js/tools/PanTool.js @@ -8,29 +8,29 @@ class PanTool extends Tool { onStart(mousePos) { super.onStart(mousePos); - canvasView.style.cursor = "url(\'/pixel-editor/pan-held.png\'), auto"; + currFile.canvasView.style.cursor = "url(\'/pixel-editor/pan-held.png\'), auto"; } onDrag(mousePos) { super.onDrag(mousePos); // Setting first layer position - layers[0].setCanvasOffset(layers[0].canvas.offsetLeft + (mousePos[0] - this.startMousePos[0]), layers[0].canvas.offsetTop + (mousePos[1] - this.startMousePos[1])); + currFile.layers[0].setCanvasOffset(currFile.layers[0].canvas.offsetLeft + (mousePos[0] - this.startMousePos[0]), currFile.layers[0].canvas.offsetTop + (mousePos[1] - this.startMousePos[1])); // Copying that position to the other layers - for (let i=1; i currentLayer.canvas.width) { - this.startMousePos[0] = currentLayer.canvas.width; + else if (this.startMousePos[0] > currFile.currentLayer.canvas.width) { + this.startMousePos[0] = currFile.currentLayer.canvas.width; } if (this.startMousePos[1] < 0) { this.startMousePos[1] = 0; } - else if (this.startMousePos[1] > currentLayer.canvas.height) { - this.startMousePos[1] = currentLayer.canvas.height; + else if (this.startMousePos[1] > currFile.currentLayer.canvas.height) { + this.startMousePos[1] = currFile.currentLayer.canvas.height; } // Drawing the rect @@ -44,7 +44,7 @@ class RectangularSelectionTool extends SelectionTool { super.onDrag(mousePos); // Drawing the rect - this.drawSelection(Math.round(mousePos[0] / zoom) + 0.5, Math.round(mousePos[1] / zoom) + 0.5); + this.drawSelection(Math.round(mousePos[0] / currFile.zoom) + 0.5, Math.round(mousePos[1] / currFile.zoom) + 0.5); } onEnd(mousePos) { @@ -52,8 +52,8 @@ class RectangularSelectionTool extends SelectionTool { new HistoryState().EditCanvas(); // Getting the end position - this.endMousePos[0] = Math.round(this.endMousePos[0] / zoom) + 0.5; - this.endMousePos[1] = Math.round(this.endMousePos[1] / zoom) + 0.5; + this.endMousePos[0] = Math.round(this.endMousePos[0] / currFile.zoom) + 0.5; + this.endMousePos[1] = Math.round(this.endMousePos[1] / currFile.zoom) + 0.5; // Inverting end and start (start must always be the top left corner) if (this.endMousePos[0] < this.startMousePos[0]) { @@ -81,17 +81,17 @@ class RectangularSelectionTool extends SelectionTool { width: dataWidth, height: dataHeight, - data: currentLayer.context.getImageData( + data: currFile.currentLayer.context.getImageData( this.startMousePos[0], this.startMousePos[1], dataWidth + 1, dataHeight + 1) }; // Moving the selection to the TMP layer. It will be moved back to the original // layer if the user will cancel or end the selection - currentLayer.context.clearRect(this.startMousePos[0] - 0.5, this.startMousePos[1] - 0.5, + currFile.currentLayer.context.clearRect(this.startMousePos[0] - 0.5, this.startMousePos[1] - 0.5, dataWidth + 1, dataHeight + 1); // Moving those pixels from the current layer to the tmp layer - TMPLayer.context.putImageData(this.currSelection.data, this.startMousePos[0], this.startMousePos[1]); + currFile.TMPLayer.context.putImageData(this.currSelection.data, this.startMousePos[0], this.startMousePos[1]); this.moveTool.setSelectionData(this.currSelection, this); console.log("data set"); @@ -107,10 +107,10 @@ class RectangularSelectionTool extends SelectionTool { drawSelection(x, y) { // Getting the vfx context - let vfxContext = VFXLayer.context; + let vfxContext = currFile.VFXLayer.context; // Clearing the vfx canvas - vfxContext.clearRect(0, 0, VFXLayer.canvas.width, VFXLayer.canvas.height); + vfxContext.clearRect(0, 0, currFile.VFXLayer.canvas.width, currFile.VFXLayer.canvas.height); vfxContext.lineWidth = 1; vfxContext.strokeStyle = 'black'; vfxContext.setLineDash([4]); @@ -133,11 +133,11 @@ class RectangularSelectionTool extends SelectionTool { */ moveAnts(x, y, width, height) { // Getting the vfx context - let vfxContext = VFXLayer.context; + let vfxContext = currFile.VFXLayer.context; let ret = this.currSelection; // Clearing the vfx canvas - vfxContext.clearRect(0, 0, VFXLayer.canvas.width, VFXLayer.canvas.height); + vfxContext.clearRect(0, 0, currFile.VFXLayer.canvas.width, currFile.VFXLayer.canvas.height); vfxContext.lineWidth = 1; vfxContext.setLineDash([4]); diff --git a/js/tools/ResizableTool.js b/js/tools/ResizableTool.js index 29b4214..e291251 100644 --- a/js/tools/ResizableTool.js +++ b/js/tools/ResizableTool.js @@ -13,7 +13,7 @@ class ResizableTool extends Tool { onRightDrag(mousePos, mouseEvent) { //get new brush size based on x distance from original clicking location - let distanceFromClick = mousePos[0]/zoom - this.startResizePos[0]/zoom; + let distanceFromClick = mousePos[0]/currFile.zoom - this.startResizePos[0]/currFile.zoom; let brushSizeChange = Math.round(distanceFromClick/10); let newBrushSize = this.currSize + brushSizeChange; diff --git a/js/tools/ZoomTool.js b/js/tools/ZoomTool.js index e7e0de0..a945bb6 100644 --- a/js/tools/ZoomTool.js +++ b/js/tools/ZoomTool.js @@ -6,77 +6,77 @@ class ZoomTool extends Tool { super.onMouseWheel(mousePos, mode); // Computing current width and height - let oldWidth = canvasSize[0] * zoom; - let oldHeight = canvasSize[1] * zoom; + let oldWidth = currFile.canvasSize[0] * currFile.zoom; + let oldHeight = currFile.canvasSize[1] * currFile.zoom; let newWidth, newHeight; - let prevZoom = zoom; + let prevZoom = currFile.zoom; let zoomed = false; //change zoom level //if you want to zoom out, and the zoom isnt already at the smallest level - if (mode == 'out' && zoom > MIN_ZOOM_LEVEL) { + if (mode == 'out' && currFile.zoom > MIN_ZOOM_LEVEL) { zoomed = true; - if (zoom > 2) - zoom -= Math.ceil(zoom / 10); + if (currFile.zoom > 2) + currFile.zoom -= Math.ceil(currFile.zoom / 10); else - zoom -= Math.ceil(zoom * 2 / 10) / 2; + currFile.zoom -= Math.ceil(currFile.zoom * 2 / 10) / 2; - newWidth = canvasSize[0] * zoom; - newHeight = canvasSize[1] * zoom; + newWidth = currFile.canvasSize[0] * currFile.zoom; + newHeight = currFile.canvasSize[1] * currFile.zoom; //adjust canvas position - layers[0].setCanvasOffset( - layers[0].canvas.offsetLeft + (oldWidth - newWidth) * mousePos[0]/oldWidth, - layers[0].canvas.offsetTop + (oldHeight - newHeight) * mousePos[1]/oldHeight); + currFile.layers[0].setCanvasOffset( + currFile.layers[0].canvas.offsetLeft + (oldWidth - newWidth) * mousePos[0]/oldWidth, + currFile.layers[0].canvas.offsetTop + (oldHeight - newHeight) * mousePos[1]/oldHeight); } //if you want to zoom in - else if (mode == 'in' && zoom + Math.ceil(zoom/10) < window.innerHeight/4) { + else if (mode == 'in' && currFile.zoom + Math.ceil(currFile.zoom/10) < window.innerHeight/4) { zoomed = true; - if (zoom > 2) - zoom += Math.ceil(zoom/10); + if (currFile.zoom > 2) + currFile.zoom += Math.ceil(currFile.zoom/10); else { - if (zoom + zoom/10 > 2) { - zoom += Math.ceil(zoom/10); - zoom = Math.ceil(zoom); + if (currFile.zoom + currFile.zoom/10 > 2) { + currFile.zoom += Math.ceil(currFile.zoom/10); + currFile.zoom = Math.ceil(currFile.zoom); } else { - zoom += Math.ceil(zoom * 2 / 10) / 2; + currFile.zoom += Math.ceil(currFile.zoom * 2 / 10) / 2; } } - newWidth = canvasSize[0] * zoom; - newHeight = canvasSize[1] * zoom; + newWidth = currFile.canvasSize[0] * currFile.zoom; + newHeight = currFile.canvasSize[1] * currFile.zoom; //adjust canvas position - layers[0].setCanvasOffset( - layers[0].canvas.offsetLeft - Math.round((newWidth - oldWidth)*mousePos[0]/oldWidth), - layers[0].canvas.offsetTop - Math.round((newHeight - oldHeight)*mousePos[1]/oldHeight)); + currFile.layers[0].setCanvasOffset( + currFile.layers[0].canvas.offsetLeft - Math.round((newWidth - oldWidth)*mousePos[0]/oldWidth), + currFile.layers[0].canvas.offsetTop - Math.round((newHeight - oldHeight)*mousePos[1]/oldHeight)); } //resize canvas - layers[0].resize(); + currFile.layers[0].resize(); // adjust brush size ToolManager.currentTool().updateCursor(); // Adjust pixel grid thickness if (zoomed) { - if (zoom <= 7) - pixelGrid.disablePixelGrid(); - else if (zoom >= 20 && mode == 'in') { - pixelGrid.enablePixelGrid(); - pixelGrid.repaintPixelGrid((zoom - prevZoom) * 0.6); + if (currFile.zoom <= 7) + currFile.pixelGrid.disablePixelGrid(); + else if (currFile.zoom >= 20 && mode == 'in') { + currFile.pixelGrid.enablePixelGrid(); + currFile.pixelGrid.repaintPixelGrid((currFile.zoom - prevZoom) * 0.6); } else if (prevZoom >= 20 && mode == 'out') { - pixelGrid.enablePixelGrid(); - pixelGrid.repaintPixelGrid((zoom - prevZoom) * 0.6); + currFile.pixelGrid.enablePixelGrid(); + currFile.pixelGrid.repaintPixelGrid((currFile.zoom - prevZoom) * 0.6); } else { - pixelGrid.enablePixelGrid(); + currFile.pixelGrid.enablePixelGrid(); } } - for (let i=1; i
    -
  • -
  • -
  • +
  • +
  • +