Added back tool shortctus

Made Events an IIFE instead of a class, fixed a bug in the selection tool.
This commit is contained in:
unsettledgames
2021-11-09 12:19:57 +01:00
parent 3c62a1f0fd
commit 2ca5aa75b4
15 changed files with 110 additions and 97 deletions

View File

@ -9,6 +9,7 @@ class BrushTool extends ResizableTool {
onStart(mousePos) {
super.onStart(mousePos);
new HistoryState().EditCanvas();
}
onDrag(mousePos, cursorTarget) {

View File

@ -9,6 +9,7 @@ class EraserTool extends ResizableTool {
onStart(mousePos) {
super.onStart(mousePos);
new HistoryState().EditCanvas();
}
onDrag(mousePos, cursorTarget) {

View File

@ -12,6 +12,8 @@ class FillTool extends Tool {
return;
this.fill(mousePos);
currentLayer.updateLayerPreview();
new HistoryState().EditCanvas();
}
@ -37,9 +39,6 @@ class FillTool extends Tool {
return (r == color[0] && g == color[1] && b == color[2] && a == color[3]);
}
//save history state
new HistoryState().EditCanvas();
//temporary image holds the data while we change it
let tempImage = currentLayer.context.getImageData(0, 0, canvasSize[0], canvasSize[1]);

View File

@ -15,6 +15,8 @@ class LineTool extends ResizableTool {
this.startMousePos[0] = Math.floor(mousePos[0]) + 0.5;
this.startMousePos[1] = Math.floor(mousePos[1]) + 0.5;
new HistoryState().EditCanvas();
}
onDrag(mousePos, cursorTarget) {

View File

@ -88,13 +88,13 @@ class MoveSelectionTool extends Tool {
// don't override the coloured pixels in the canvas
let underlyingImageData = currentLayer.context.getImageData(
this.currSelection.left, this.currSelection.top,
this.currSelection.width, this.currSelection.height
this.currSelection.width+1, this.currSelection.height+1
);
let pasteData = this.currSelection.data.data;
for (let i=0; i<underlyingImageData.data.length; i+=4) {
let currentMovePixel = [
this.currSelection.data.data[i], this.currSelection.data.data[i+1],
this.currSelection.data.data[i+2], this.currSelection.data.data[i+3]
pasteData[i], pasteData[i+1], pasteData[i+2], pasteData[i+3]
];
let currentUnderlyingPixel = [
@ -104,26 +104,25 @@ class MoveSelectionTool extends Tool {
// If the pixel of the clipboard is empty, but the one below it isn't, I use the pixel below
if (Util.isPixelEmpty(currentMovePixel)) {
if (!Util.isPixelEmpty(underlyingImageData)) {
this.currSelection.data.data[i] = currentUnderlyingPixel[0];
this.currSelection.data.data[i+1] = currentUnderlyingPixel[1];
this.currSelection.data.data[i+2] = currentUnderlyingPixel[2];
this.currSelection.data.data[i+3] = currentUnderlyingPixel[3];
if (!Util.isPixelEmpty(currentUnderlyingPixel)) {
pasteData[i] = currentUnderlyingPixel[0];
pasteData[i+1] = currentUnderlyingPixel[1];
pasteData[i+2] = currentUnderlyingPixel[2];
pasteData[i+3] = currentUnderlyingPixel[3];
}
}
}
currentLayer.context.putImageData(
this.currSelection.data,
this.currSelection.left,
this.currSelection.top);
console.log("Paste: " + pasteData.length + ", underlying: " + underlyingImageData.data.length);
currentLayer.context.putImageData(new ImageData(pasteData, this.currSelection.width+1),
this.currSelection.left, this.currSelection.top
);
this.currSelection = undefined;
currentLayer.updateLayerPreview();
VFXLayer.canvas.style.zIndex = MIN_Z_INDEX;
// Saving history
new HistoryState().EditCanvas();
// Switch to brush
this.switchFunc(this.endTool);
}

View File

@ -1,3 +1,5 @@
// TODO: FIX SELECTION
class RectangleTool extends ResizableTool {
// Saving the empty rect svg
emptyRectangleSVG = document.getElementById("rectangle-empty-button-svg");
@ -41,6 +43,8 @@ class RectangleTool extends ResizableTool {
this.startMousePos[0] = Math.floor(mousePos[0] / zoom) + 0.5;
this.startMousePos[1] = Math.floor(mousePos[1] / zoom) + 0.5;
new HistoryState().EditCanvas();
}
onDrag(mousePos, cursorTarget) {

View File

@ -14,8 +14,6 @@ class RectangularSelectionTool extends SelectionTool {
onStart(mousePos) {
super.onStart(mousePos);
// Saving the canvas
new HistoryState().EditCanvas();
// Putting the vfx layer on top of everything
VFXLayer.canvas.style.zIndex = MAX_Z_INDEX;
@ -51,6 +49,7 @@ class RectangularSelectionTool extends SelectionTool {
onEnd(mousePos) {
super.onEnd(mousePos);
new HistoryState().EditCanvas();
// Getting the end position
this.endMousePos[0] = Math.round(this.endMousePos[0] / zoom) + 0.5;