mirror of
https://github.com/lospec/pixel-editor.git
synced 2023-08-10 21:12:51 +03:00
Fixed brush preview snapping
This commit is contained in:
parent
c27a355904
commit
37a532236b
@ -157,16 +157,23 @@ window.addEventListener("mouseup", function (mouseEvent) {
|
|||||||
}, false);
|
}, false);
|
||||||
|
|
||||||
// TODO: Make it snap to the pixel grid
|
// TODO: Make it snap to the pixel grid
|
||||||
function setPreviewPosition(preview, cursor, size){
|
function setPreviewPosition(preview, size){
|
||||||
|
let toAdd = 0;
|
||||||
|
|
||||||
|
// This prevents the brush to be placed in the middle of pixels
|
||||||
|
if (size % 2 == 0) {
|
||||||
|
toAdd = 0.5;
|
||||||
|
}
|
||||||
|
|
||||||
preview.style.left = (
|
preview.style.left = (
|
||||||
currentLayer.canvas.offsetLeft
|
currentLayer.canvas.offsetLeft
|
||||||
+ Math.floor(cursor[0]/zoom) * zoom
|
+ Math.floor(cursor[0]/zoom) * zoom
|
||||||
- Math.floor(size / 2) * zoom
|
- Math.floor(size / 2) * zoom + toAdd
|
||||||
) + 'px';
|
) + 'px';
|
||||||
preview.style.top = (
|
preview.style.top = (
|
||||||
currentLayer.canvas.offsetTop
|
currentLayer.canvas.offsetTop
|
||||||
+ Math.floor(cursor[1]/zoom) * zoom
|
+ Math.floor(cursor[1]/zoom) * zoom
|
||||||
- Math.floor(size / 2) * zoom
|
- Math.floor(size / 2) * zoom + toAdd
|
||||||
) + 'px';
|
) + 'px';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
10
js/_tools.js
10
js/_tools.js
@ -95,8 +95,14 @@ class Tool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
moveBrushPreview(cursorLocation) {
|
moveBrushPreview(cursorLocation) {
|
||||||
brushPreview.style.left = (Math.ceil(cursorLocation[0] / zoom) * zoom + currentLayer.canvas.offsetLeft - this.currentBrushSize * zoom / 2 - zoom / 2) + 'px';
|
let toSub = 0;
|
||||||
brushPreview.style.top = (Math.ceil(cursorLocation[1] / zoom) * zoom + currentLayer.canvas.offsetTop - this.currentBrushSize * zoom / 2 - zoom / 2) + 'px';
|
// Prevents the brush to be put in the middle of pixels
|
||||||
|
if (this.currentBrushSize % 2 == 0) {
|
||||||
|
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.top = (Math.ceil(cursorLocation[1] / zoom) * zoom + currentLayer.canvas.offsetTop - this.currentBrushSize * zoom / 2 - zoom / 2 - toSub * zoom) + 'px';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user