diff --git a/js/_pixelEditorUtility.js b/js/_pixelEditorUtility.js index 5edda7c..77c91b9 100644 --- a/js/_pixelEditorUtility.js +++ b/js/_pixelEditorUtility.js @@ -182,4 +182,12 @@ function resizeImageData (image, width, height, algorithm) { resize(image, result) return result + } + + function getPixelPosition(index) { + let linearIndex = index / 4; + let y = linearIndex / layers[0].canvasSize[0]; + let x = linearIndex - y * layers[0].canvasSize[0]; + + return [x, y]; } \ No newline at end of file diff --git a/js/_resizeCanvas.js b/js/_resizeCanvas.js index 01042e2..fb67937 100644 --- a/js/_resizeCanvas.js +++ b/js/_resizeCanvas.js @@ -166,6 +166,48 @@ function resizeCanvas(event, size) { closeDialogue(); } +function trimCanvas() { + let minX, minY = Infinity; + let maxX, maxY = -Infinity; + + rcPivot = "middle"; + console.log("trimmo"); + + for (let i=1; i maxX) { + maxX = pixelPosition[0]; + } + else if (pixelPosition.x < minX) { + minX = pixelPosition[0]; + } + + if (pixelPosition.y > maxY) { + maxY = pixelPosition[1]; + } + else if (pixelPosition.y < minY) { + minY = pixelPosition[1]; + } + } + } + } + + console.log(maxX + ", " + minX + ", " + maxY + ", " + minY); + + borders.right = maxX - layers[0].canvasSize[0]; + borders.left = -minX; + borders.top = maxY - layers[0].canvasSize[1]; + borders.bottom = minY; + + resizeCanvas(null); +} + function rcUpdateBorders() { // Getting input borders.left = document.getElementById("rc-border-left").value; diff --git a/views/pixel-editor.hbs b/views/pixel-editor.hbs index ac9d69a..7726b00 100644 --- a/views/pixel-editor.hbs +++ b/views/pixel-editor.hbs @@ -54,6 +54,7 @@