mirror of
https://github.com/lospec/pixel-editor.git
synced 2023-08-10 21:12:51 +03:00
Fixed pixel not being drawn when clicking
This commit is contained in:
parent
25942b206a
commit
48310a4845
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user