From 42a8ce3c4a3e1bcb40610eed3f4d7b75ea77be25 Mon Sep 17 00:00:00 2001 From: npalomba Date: Sun, 31 Mar 2019 16:01:46 +0200 Subject: [PATCH] Fixed bugs in canvas intialization. Started layers implementation. Signed-off-by: npalomba --- js/_canvas.js | 14 +++++++------- js/_newPixel.js | 24 +++--------------------- js/_variables.js | 1 + 3 files changed, 11 insertions(+), 28 deletions(-) diff --git a/js/_canvas.js b/js/_canvas.js index c8ecf5f..cd39dd4 100644 --- a/js/_canvas.js +++ b/js/_canvas.js @@ -1,16 +1,16 @@ -function Canvas(height, width, canvas) { +function Canvas(width, height, canvas) { this.canvasSize = [width, height], this.canvas = canvas, this.initialize = function() { - var maxHorizontalZoom = Math.floor(window.innerWidth/canvasSize[0]*0.75); - var maxVerticalZoom = Math.floor(window.innerHeight/canvasSize[1]*0.75); + var maxHorizontalZoom = Math.floor(window.innerWidth/this.canvasSize[0]*0.75); + var maxVerticalZoom = Math.floor(window.innerHeight/this.canvasSize[1]*0.75); zoom = Math.min(maxHorizontalZoom,maxVerticalZoom); if (zoom < 1) zoom = 1; //resize canvas - this.canvas.width = canvasSize[0]; - this.canvas.height = canvasSize[1]; + this.canvas.width = this.canvasSize[0]; + this.canvas.height = this.canvasSize[1]; this.canvas.style.width = (this.canvas.width*zoom)+'px'; this.canvas.style.height = (this.canvas.height*zoom)+'px'; @@ -18,8 +18,8 @@ function Canvas(height, width, canvas) { this.canvas.style.display = 'block'; //center canvas in window - this.canvas.style.left = 64+canvasView.clientWidth/2-(canvasSize[0]*zoom/2)+'px'; - this.canvas.style.top = 48+canvasView.clientHeight/2-(canvasSize[1]*zoom/2)+'px'; + this.canvas.style.left = 64+canvasView.clientWidth/2-(this.canvasSize[0]*zoom/2)+'px'; + this.canvas.style.top = 48+canvasView.clientHeight/2-(this.canvasSize[1]*zoom/2)+'px'; }, this.resize = function() { let newWidth = (this.canvas.width*zoom)+'px'; diff --git a/js/_newPixel.js b/js/_newPixel.js index 5b64c5e..4177b37 100644 --- a/js/_newPixel.js +++ b/js/_newPixel.js @@ -1,27 +1,9 @@ function newPixel (width, height, palette) { - - canvasSize = [width,height]; - - var maxHorizontalZoom = Math.floor(window.innerWidth/canvasSize[0]*0.75); - var maxVerticalZoom = Math.floor(window.innerHeight/canvasSize[1]*0.75); - - zoom = Math.min(maxHorizontalZoom,maxVerticalZoom); - if (zoom < 1) zoom = 1; - - //resize canvas - canvas.width = canvasSize[0]; - canvas.height = canvasSize[1]; - canvas.style.width = (canvas.width*zoom)+'px'; - canvas.style.height = (canvas.height*zoom)+'px'; - - //unhide canvas - canvas.style.display = 'block'; - - //center canvas in window - canvas.style.left = 64+canvasView.clientWidth/2-(canvasSize[0]*zoom/2)+'px'; - canvas.style.top = 48+canvasView.clientHeight/2-(canvasSize[1]*zoom/2)+'px'; + var main = new Canvas(width, height, canvas); + main.initialize(); + canvasSize = main.canvasSize; //remove current palette colors = document.getElementsByClassName('color-button'); while (colors.length > 0) { diff --git a/js/_variables.js b/js/_variables.js index c9f21ca..beadf57 100644 --- a/js/_variables.js +++ b/js/_variables.js @@ -12,6 +12,7 @@ var prevEraserSize = 1; var menuOpen = false; var dialogueOpen = false; var documentCreated = false; +var layers = // Checkerboard management var firstCheckerBoardColor = 'rgba(139, 139, 139, 1)';