diff --git a/js/_drawLine.js b/js/_drawLine.js index 646ab0c..a91fbe3 100644 --- a/js/_drawLine.js +++ b/js/_drawLine.js @@ -1,6 +1,5 @@ //draw a line between two points on canvas function line(x0,y0,x1,y1, brushSize) { - var dx = Math.abs(x1-x0); var dy = Math.abs(y1-y0); var sx = (x0 < x1 ? 1 : -1); @@ -21,35 +20,17 @@ function line(x0,y0,x1,y1, brushSize) { //if we've reached the end goal, exit the loop if ((x0==x1) && (y0==y1)) break; var e2 = 2*err; - if (e2 >-dy) {err -=dy; x0+=sx;} - if (e2 < dx) {err +=dx; y0+=sy;} - } -} -//draw a line between two points on canvas -function lineOnLayer(x0,y0,x1,y1, brushSize, context) { - - var dx = Math.abs(x1-x0); - var dy = Math.abs(y1-y0); - var sx = (x0 < x1 ? 1 : -1); - var sy = (y0 < y1 ? 1 : -1); - var err = dx-dy; - - while (true) { - //set pixel - // If the current tool is the brush - if (currentTool.name == 'pencil' || currentTool.name == 'rectangle') { - // I fill the rect - context.fillRect(x0-Math.floor(brushSize/2), y0-Math.floor(brushSize/2), brushSize, brushSize); - } else if (currentTool.name == 'eraser') { - // In case I'm using the eraser I must clear the rect - context.clearRect(x0-Math.floor(tool.eraser.brushSize/2), y0-Math.floor(tool.eraser.brushSize/2), tool.eraser.brushSize, tool.eraser.brushSize); + if (e2 >-dy) { + err -=dy; + x0+=sx; } - //if we've reached the end goal, exit the loop - if ((x0==x1) && (y0==y1)) break; - var e2 = 2*err; - if (e2 >-dy) {err -=dy; x0+=sx;} - if (e2 < dx) {err +=dx; y0+=sy;} + if (e2 < dx) { + err +=dx; + y0+=sy; + } + + console.log(x0 + ", " + x1); } -} +} \ No newline at end of file diff --git a/js/_mouseEvents.js b/js/_mouseEvents.js index a53d8cf..d5d818a 100644 --- a/js/_mouseEvents.js +++ b/js/_mouseEvents.js @@ -143,7 +143,7 @@ window.addEventListener("mouseup", function (mouseEvent) { else if (currentTool.name == 'rectselect' && isRectSelecting) { endRectSelection(mouseEvent); } - else if (currentTool.name == 'rectangle') { + else if (currentTool.name == 'rectangle' && isDrawingRect) { endRectDrawing(mouseEvent); currentLayer.updateLayerPreview(); } diff --git a/js/_toolButtons.js b/js/_toolButtons.js index fc23269..c71d5f1 100644 --- a/js/_toolButtons.js +++ b/js/_toolButtons.js @@ -16,6 +16,7 @@ on('click',"pencil-smaller-button", function(){ //eraser on('click',"eraser-button", function(){ + console.log("selecting eraser"); tool.eraser.switchTo(); }, false); @@ -31,7 +32,7 @@ on('click',"eraser-smaller-button", function(e){ }, false); // rectangle -on('click','rectangle-button', function(){ +on('click','rectangle-button', function(e){ // If the user clicks twice on the button, they change the draw mode if (currentTool.name == 'rectangle') { if (drawMode == 'empty') { diff --git a/js/_tools.js b/js/_tools.js index 5493365..a521336 100644 --- a/js/_tools.js +++ b/js/_tools.js @@ -40,9 +40,6 @@ class Tool { //switch to this tool (replaced global changeTool()) switchTo () { - - console.log('changing tool to',this.name) - // Ending any selection in progress if (currentTool.name.includes("select") && !this.name.includes("select") && !selectionCanceled) { endSelection(); diff --git a/views/pixel-editor.hbs b/views/pixel-editor.hbs index 0762d4d..3afca14 100644 --- a/views/pixel-editor.hbs +++ b/views/pixel-editor.hbs @@ -111,8 +111,8 @@