mirror of
https://github.com/lospec/pixel-editor.git
synced 2023-08-10 21:12:51 +03:00
mirror eraser
This commit is contained in:
@@ -47,7 +47,6 @@ class BrushTool extends ResizableTool {
|
|||||||
console.log("Drawing under the horizontal axis");
|
console.log("Drawing under the horizontal axis");
|
||||||
mirrorPrevY = Math.floor(midY - Math.abs(midY - prevMousePosY));
|
mirrorPrevY = Math.floor(midY - Math.abs(midY - prevMousePosY));
|
||||||
mirrorCurrentY = Math.floor(midY - Math.abs(midY - currMousePosY));
|
mirrorCurrentY = Math.floor(midY - Math.abs(midY - currMousePosY));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.mirrorDraw(
|
this.mirrorDraw(
|
||||||
|
@@ -27,51 +27,82 @@ class EraserTool extends ResizableTool {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let midX = (currFile.canvasSize[0] / 2);
|
||||||
|
let midY = (currFile.canvasSize[1] / 2);
|
||||||
|
let prevMousePosX = Math.floor(this.prevMousePos[0] / currFile.zoom);
|
||||||
|
let prevMousePosY = Math.floor(this.prevMousePos[1] / currFile.zoom);
|
||||||
|
let currMousePosX = Math.floor(this.currMousePos[0] / currFile.zoom);
|
||||||
|
let currMousePosY = Math.floor(this.currMousePos[1] / currFile.zoom);
|
||||||
|
let mirrorPrevX, mirrorPrevY, mirrorCurrentX, mirrorCurrentY;
|
||||||
|
|
||||||
// If Horizontal Symmetry mode is activated
|
// If Horizontal Symmetry mode is activated
|
||||||
// draw specular
|
// draw specular
|
||||||
if (currFile.hSymmetricLayer.isEnabled) {
|
if (currFile.hSymmetricLayer.isEnabled) {
|
||||||
// if the current mouse position is over the horizontal axis
|
// if the current mouse position is over the horizontal axis
|
||||||
let originalSize = currFile.canvasSize;
|
|
||||||
let midY = (originalSize[1] / 2);
|
|
||||||
let prevMousePosY = Math.floor(this.prevMousePos[1] / currFile.zoom);
|
|
||||||
let currMousePosY = Math.floor(this.currMousePos[1] / currFile.zoom);
|
|
||||||
|
|
||||||
console.log("midY: " + midY);
|
|
||||||
console.log("currMouseY: " + currMousePosY);
|
|
||||||
|
|
||||||
if (currMousePosY <= midY) {
|
if (currMousePosY <= midY) {
|
||||||
console.log("Drawing over the horizontal axis");
|
mirrorPrevY = Math.floor(midY + Math.abs(midY - prevMousePosY));
|
||||||
let mirrorPrevY = Math.floor(midY + Math.abs(midY - prevMousePosY));
|
mirrorCurrentY = Math.floor(midY + Math.abs(midY - currMousePosY));
|
||||||
let mirrorCurrentY = Math.floor(midY + Math.abs(midY - currMousePosY));
|
|
||||||
|
|
||||||
this.mirrorDraw(mirrorPrevY, mirrorCurrentY);
|
|
||||||
} else {
|
} else {
|
||||||
console.log("Drawing under the horizontal axis");
|
mirrorPrevY = Math.floor(midY - Math.abs(midY - prevMousePosY));
|
||||||
let mirrorPrevY = Math.floor(midY - Math.abs(midY - prevMousePosY));
|
mirrorCurrentY = Math.floor(midY - Math.abs(midY - currMousePosY));
|
||||||
let mirrorCurrentY = Math.floor(midY - Math.abs(midY - currMousePosY));
|
|
||||||
|
|
||||||
this.mirrorDraw(mirrorPrevY, mirrorCurrentY);
|
|
||||||
}
|
}
|
||||||
|
this.mirrorErase(
|
||||||
|
Math.floor(this.prevMousePos[0] / currFile.zoom),
|
||||||
|
mirrorPrevY,
|
||||||
|
Math.floor(this.currMousePos[0] / currFile.zoom),
|
||||||
|
mirrorCurrentY,
|
||||||
|
true, false
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (currFile.vSymmetricLayer.isEnabled) {
|
||||||
|
// console.log("midX => " + midX);
|
||||||
|
// console.log("currMouseX => " + currMousePosX);
|
||||||
|
|
||||||
|
// if the current mouse position is over the horizontal axis
|
||||||
|
if (currMousePosX <= midX) {
|
||||||
|
mirrorPrevX = Math.floor(midX + Math.abs(midX - prevMousePosX));
|
||||||
|
mirrorCurrentX = Math.floor(midX + Math.abs(midX - currMousePosX));
|
||||||
|
} else {
|
||||||
|
mirrorPrevX = Math.floor(midX - Math.abs(midX - prevMousePosX));
|
||||||
|
mirrorCurrentX = Math.floor(midX - Math.abs(midX - currMousePosX));
|
||||||
|
}
|
||||||
|
|
||||||
|
this.mirrorErase(
|
||||||
|
mirrorPrevX,
|
||||||
|
Math.floor(this.prevMousePos[1] / currFile.zoom),
|
||||||
|
mirrorCurrentX,
|
||||||
|
Math.floor(this.currMousePos[1] / currFile.zoom),
|
||||||
|
false, true
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (currFile.hSymmetricLayer.isEnabled && currFile.vSymmetricLayer.isEnabled) {
|
||||||
|
// Based on current mouse position we can infer which quadrant is the remaining one
|
||||||
|
this.mirrorErase(mirrorPrevX, mirrorPrevY, mirrorCurrentX, mirrorCurrentY, true, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
currFile.currentLayer.updateLayerPreview();
|
currFile.currentLayer.updateLayerPreview();
|
||||||
}
|
}
|
||||||
|
|
||||||
mirrorDraw(mirrorPrevY, mirrorCurrentY) {
|
mirrorErase(prevX, prevY, currX, currY, isHorizontal, isVertical) {
|
||||||
|
let horizontalFactor = (isHorizontal) ? 1 : 0;
|
||||||
|
let verticalFactor = (isVertical) ? 1 : 0;
|
||||||
if (this.currSize % 2 === 0) {
|
if (this.currSize % 2 === 0) {
|
||||||
currFile.currentLayer.drawLine(
|
currFile.currentLayer.drawLine(
|
||||||
Math.floor(this.prevMousePos[0] / currFile.zoom),
|
prevX,
|
||||||
Math.floor(mirrorPrevY),
|
prevY,
|
||||||
Math.floor(this.currMousePos[0] / currFile.zoom),
|
currX,
|
||||||
Math.floor(mirrorCurrentY),
|
currY,
|
||||||
this.currSize
|
this.currSize
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
currFile.currentLayer.drawLine(
|
currFile.currentLayer.drawLine(
|
||||||
Math.floor(this.prevMousePos[0] / currFile.zoom),
|
prevX - verticalFactor,
|
||||||
Math.floor(mirrorPrevY - 1),
|
prevY - horizontalFactor,
|
||||||
Math.floor(this.currMousePos[0] / currFile.zoom),
|
currX - verticalFactor,
|
||||||
Math.floor(mirrorCurrentY - 1),
|
currY - horizontalFactor,
|
||||||
this.currSize
|
this.currSize
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user