From 05066d8cb1ec9570b4f304424b46734d318e61e7 Mon Sep 17 00:00:00 2001 From: Theo Cavignac Date: Sun, 12 Apr 2020 11:39:37 +0200 Subject: [PATCH] Fix pencil size +/- buttons broken from upstream, apply brush preview snapping to rectangle tool, fix pencil broken by merge --- js/_mouseEvents.js | 19 +++++++++++++------ js/_rectangle.js | 14 +++++++------- js/_toolButtons.js | 4 ++-- 3 files changed, 22 insertions(+), 15 deletions(-) diff --git a/js/_mouseEvents.js b/js/_mouseEvents.js index e2d772d..da22efb 100644 --- a/js/_mouseEvents.js +++ b/js/_mouseEvents.js @@ -177,7 +177,7 @@ function draw (mouseEvent) { if (currentTool == 'pencil') { //move the brush preview - setPreviewPosition(brushPreview, cursorLocation, brushSize); + setPreviewPosition(brushPreview, cursorLocation, pencilSize); //hide brush preview outside of canvas / canvas view if (mouseEvent.target.className == 'drawingCanvas'|| mouseEvent.target.className == 'drawingCanvas') @@ -188,7 +188,11 @@ function draw (mouseEvent) { //draw line to current pixel if (dragging) { if (mouseEvent.target.className == 'drawingCanvas' || mouseEvent.target.className == 'drawingCanvas') { - line(Math.floor(lastPos[0]/zoom),Math.floor(lastPos[1]/zoom),Math.floor(cursorLocation[0]/zoom),Math.floor(cursorLocation[1]/zoom)); + line( + Math.floor(lastPos[0]/zoom), Math.floor(lastPos[1]/zoom), + Math.floor(cursorLocation[0]/zoom), Math.floor(cursorLocation[1]/zoom), + pencilSize + ); lastPos = cursorLocation; } } @@ -216,7 +220,11 @@ function draw (mouseEvent) { //draw line to current pixel if (dragging) { if (mouseEvent.target.className == 'drawingCanvas' || mouseEvent.target.className == 'drawingCanvas') { - line(Math.floor(lastPos[0]/zoom),Math.floor(lastPos[1]/zoom),Math.floor(cursorLocation[0]/zoom),Math.floor(cursorLocation[1]/zoom), eraserSize); + line( + Math.floor(lastPos[0]/zoom), Math.floor(lastPos[1]/zoom), + Math.floor(cursorLocation[0]/zoom), Math.floor(cursorLocation[1]/zoom), + eraserSize + ); lastPos = cursorLocation; } } @@ -224,8 +232,7 @@ function draw (mouseEvent) { else if (currentTool == 'rectangle') { //move the brush preview - brushPreview.style.left = cursorLocation[0] + currentLayer.canvas.offsetLeft - rectangleSize * zoom / 2 + 'px'; - brushPreview.style.top = cursorLocation[1] + currentLayer.canvas.offsetTop - rectangleSize * zoom / 2 + 'px'; + setPreviewPosition(brushPreview, cursorLocation, rectangleSize) //hide brush preview outside of canvas / canvas view if (mouseEvent.target.className == 'drawingCanvas'|| mouseEvent.target.className == 'drawingCanvas') @@ -272,7 +279,7 @@ function draw (mouseEvent) { var newBrushSize = prevBrushSize + brushSizeChange; //set the brush to the new size as long as its bigger than 1 - pencilSize = Math.max(1,newBrushSize); + pencilSize = Math.max(1, newBrushSize); //fix offset so the cursor stays centered setPreviewPosition(brushPreview, cursorLocation, pencilSize); diff --git a/js/_rectangle.js b/js/_rectangle.js index c71dcd4..62a2bdb 100644 --- a/js/_rectangle.js +++ b/js/_rectangle.js @@ -20,8 +20,8 @@ function startRectDrawing(mouseEvent) { // Saving the start coords of the rect let cursorPos = getCursorPosition(mouseEvent); - startRectX = Math.round(cursorPos[0] / zoom) - 0.5; - startRectY = Math.round(cursorPos[1] / zoom) - 0.5; + startRectX = Math.floor(cursorPos[0] / zoom) + 0.5; + startRectY = Math.floor(cursorPos[1] / zoom) + 0.5; drawRectangle(startRectX, startRectY); } @@ -30,16 +30,16 @@ function updateRectDrawing(mouseEvent) { let pos = getCursorPosition(mouseEvent); // Drawing the rect - drawRectangle(Math.round(pos[0] / zoom) + 0.5, Math.round(pos[1] / zoom) + 0.5); + drawRectangle(Math.floor(pos[0] / zoom) + 0.5, Math.floor(pos[1] / zoom) + 0.5); } function endRectDrawing(mouseEvent) { // Getting the end position - let currentPos = getCursorPosition(mouseEvent); + let cursorPos = getCursorPosition(mouseEvent); let vfxContext = VFXCanvas.getContext('2d'); - endRectX = Math.round(currentPos[0] / zoom) + 0.5; - endRectY = Math.round(currentPos[1] / zoom) + 0.5; + endRectX = Math.floor(cursorPos[0] / zoom) + 0.5; + endRectY = Math.floor(cursorPos[1] / zoom) + 0.5; // Inverting end and start (start must always be the top left corner) if (endRectX < startRectX) { @@ -118,4 +118,4 @@ function setRectToolSvg() { function applyChanges() { VFXCanvas.style.zIndex = MIN_Z_INDEX; -} \ No newline at end of file +} diff --git a/js/_toolButtons.js b/js/_toolButtons.js index 9a3b7c6..f278453 100644 --- a/js/_toolButtons.js +++ b/js/_toolButtons.js @@ -5,13 +5,13 @@ on('click','pencil-button', function(){ //pencil bigger on('click','pencil-bigger-button', function(){ - brushSize++; + pencilSize++; updateCursor(); }, false); //pencil smaller on('click','pencil-smaller-button', function(){ - if(brushSize > 1) brushSize--; + if(pencilSize > 1) pencilSize--; updateCursor(); }, false);