mirror of
https://github.com/lospec/pixel-editor.git
synced 2023-08-10 21:12:51 +03:00
Tried to refactor more, snapped the brush preview to the pixel grid
This commit is contained in:
@ -6,9 +6,6 @@ let copiedStartY;
|
|||||||
let copiedEndX;
|
let copiedEndX;
|
||||||
let copiedEndY;
|
let copiedEndY;
|
||||||
|
|
||||||
// BUG: when merging tmp layer to currentLayer there are offset problems
|
|
||||||
// FIX: maybe copy the entire tmp layer and paste it so that the merging happens at 0,0
|
|
||||||
|
|
||||||
function copySelection() {
|
function copySelection() {
|
||||||
copiedEndX = endX;
|
copiedEndX = endX;
|
||||||
copiedEndY = endY;
|
copiedEndY = endY;
|
||||||
@ -65,9 +62,4 @@ function cutSelectionTool() {
|
|||||||
clipboardData = currentLayer.context.getImageData(startX, startY, endX - startX + 1, endY - startY + 1);
|
clipboardData = currentLayer.context.getImageData(startX, startY, endX - startX + 1, endY - startY + 1);
|
||||||
currentLayer.context.clearRect(startX - 0.5, startY - 0.5, endX - startX + 1, endY - startY + 1);
|
currentLayer.context.clearRect(startX - 0.5, startY - 0.5, endX - startX + 1, endY - startY + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Moving those pixels from the current layer to the tmp layer
|
|
||||||
//TMPLayer.context.putImageData(imageDataToMove, startX + 1, startY);
|
|
||||||
|
|
||||||
//originalDataPosition = [currentPos[0], currentPos[1]];
|
|
||||||
}
|
}
|
@ -6,6 +6,8 @@ function getCursorPosition(e) {
|
|||||||
if (e.pageX != undefined && e.pageY != undefined) {
|
if (e.pageX != undefined && e.pageY != undefined) {
|
||||||
x = e.pageX;
|
x = e.pageX;
|
||||||
y = e.pageY;
|
y = e.pageY;
|
||||||
|
|
||||||
|
console.log("passato di qui");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
x = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
|
x = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
|
||||||
@ -15,5 +17,5 @@ function getCursorPosition(e) {
|
|||||||
x -= canvas.offsetLeft;
|
x -= canvas.offsetLeft;
|
||||||
y -= canvas.offsetTop;
|
y -= canvas.offsetTop;
|
||||||
|
|
||||||
return [x,y];
|
return [Math.round(x), Math.round(y)];
|
||||||
}
|
}
|
@ -53,8 +53,6 @@ function endRectDrawing(mouseEvent) {
|
|||||||
startRectY = tmp;
|
startRectY = tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
let hexColor = hexToRgb(currentLayer.context.fillStyle);
|
|
||||||
|
|
||||||
// Resetting this
|
// Resetting this
|
||||||
isDrawingRect = false;
|
isDrawingRect = false;
|
||||||
// Drawing the rect
|
// Drawing the rect
|
||||||
|
@ -95,8 +95,8 @@ class Tool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
moveBrushPreview(cursorLocation) {
|
moveBrushPreview(cursorLocation) {
|
||||||
brushPreview.style.left = cursorLocation[0] + currentLayer.canvas.offsetLeft - this.currentBrushSize * zoom / 2 + 'px';
|
brushPreview.style.left = (Math.ceil(cursorLocation[0] / zoom) * zoom + currentLayer.canvas.offsetLeft - this.currentBrushSize * zoom / 2 - zoom / 2) + 'px';
|
||||||
brushPreview.style.top = cursorLocation[1] + currentLayer.canvas.offsetTop - this.currentBrushSize * zoom / 2 + 'px';
|
brushPreview.style.top = (Math.ceil(cursorLocation[1] / zoom) * zoom + currentLayer.canvas.offsetTop - this.currentBrushSize * zoom / 2 - zoom / 2) + 'px';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user