From ab070db6a3c95cd336e44ddce48eaf56b99cba4c Mon Sep 17 00:00:00 2001 From: npalomba Date: Mon, 1 Apr 2019 22:16:07 +0200 Subject: [PATCH] Fixed bug that caused the eraser preview to be shifted from the actual mouse position. Signed-off-by: npalomba --- js/_drawLine.js | 2 +- js/_mouseEvents.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/js/_drawLine.js b/js/_drawLine.js index 324f9d4..7008a7b 100644 --- a/js/_drawLine.js +++ b/js/_drawLine.js @@ -15,7 +15,7 @@ function line(x0,y0,x1,y1) { currentLayer.context.fillRect(x0-Math.floor(brushSize/2), y0-Math.floor(brushSize/2), brushSize, brushSize); } else if (currentTool == 'eraser') { // In case I'm using the eraser I must clear the rect - currentLayer.context.clearRect(x0-Math.floor(brushSize/2), y0-Math.floor(brushSize/2), eraserSize, eraserSize); + currentLayer.context.clearRect(x0-Math.floor(eraserSize/2), y0-Math.floor(eraserSize/2), eraserSize, eraserSize); } //if we've reached the end goal, exit the loop diff --git a/js/_mouseEvents.js b/js/_mouseEvents.js index dfe4723..02895e8 100644 --- a/js/_mouseEvents.js +++ b/js/_mouseEvents.js @@ -160,8 +160,8 @@ function draw (mouseEvent) { else if (currentTool == 'eraser') { // Uses the same preview as the brush //move the brush preview - brushPreview.style.left = cursorLocation[0] + canvas.offsetLeft - brushSize * zoom / 2 + 'px'; - brushPreview.style.top = cursorLocation[1] + canvas.offsetTop - brushSize * zoom / 2 + 'px'; + brushPreview.style.left = cursorLocation[0] + canvas.offsetLeft - eraserSize * zoom / 2 + 'px'; + brushPreview.style.top = cursorLocation[1] + canvas.offsetTop - eraserSize * zoom / 2 + 'px'; //hide brush preview outside of canvas / canvas view if (mouseEvent.target == currentLayer.canvas || mouseEvent.target == canvasView)