Fixed pixel not being drawn when clicking

This commit is contained in:
unsettledgames 2021-06-30 19:40:39 +02:00
parent 25942b206a
commit 48310a4845
2 changed files with 15 additions and 2 deletions

View File

@ -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;
}
}

View File

@ -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);
}
}