diff --git a/js/_mouseEvents.js b/js/_mouseEvents.js index 79ea4bf..dd57ec7 100644 --- a/js/_mouseEvents.js +++ b/js/_mouseEvents.js @@ -202,6 +202,8 @@ function setPreviewPosition(preview, size){ //mouse is moving on canvas window.addEventListener("mousemove", draw, false); +window.addEventListener("mousedown", draw, false); + function draw (mouseEvent) { if (!dialogueOpen) { @@ -229,7 +231,13 @@ function draw (mouseEvent) { //draw line to current pixel if (dragging) { if (mouseEvent.target.className == 'drawingCanvas' || mouseEvent.target.className == 'drawingCanvas') { - line(Math.floor(lastMouseClickPos[0]/zoom),Math.floor(lastMouseClickPos[1]/zoom),Math.floor(cursorLocation[0]/zoom),Math.floor(cursorLocation[1]/zoom), tool.pencil.brushSize); + console.log("Mouse coords: " + (cursorLocation[0] / zoom) + "," + cursorLocation[1] / zoom); + line(Math.floor(lastMouseClickPos[0]/zoom), + Math.floor(lastMouseClickPos[1]/zoom), + Math.floor(cursorLocation[0]/zoom), + Math.floor(cursorLocation[1]/zoom), + tool.pencil.brushSize + ); lastMouseClickPos = cursorLocation; } } diff --git a/js/_tools.js b/js/_tools.js index 3c10d70..a4afc6d 100644 --- a/js/_tools.js +++ b/js/_tools.js @@ -101,8 +101,13 @@ class Tool { toSub = 0.5; } - brushPreview.style.left = (Math.ceil(cursorLocation[0] / zoom) * zoom + currentLayer.canvas.offsetLeft - this.currentBrushSize * zoom / 2 - zoom / 2 - toSub * zoom) + 'px'; + brushPreview.style.left = (Math.ceil(cursorLocation[0] / zoom) * zoom // Stick to pixel grid + + currentLayer.canvas.offsetLeft // Account for canvas offset + - this.currentBrushSize * zoom / 2 // Center the brush preview + - zoom / 2 - toSub * zoom) + 'px'; // ??? brushPreview.style.top = (Math.ceil(cursorLocation[1] / zoom) * zoom + currentLayer.canvas.offsetTop - this.currentBrushSize * zoom / 2 - zoom / 2 - toSub * zoom) + 'px'; + + console.log("Brush coords: " + brushPreview.style.left + "," + brushPreview.style.top); } }