pixel-editor/js/tools/EraserTool.js
Nicola de2479b007 Started making selection tools more generic
Will also hopefully remove MoveSelection.js and put its functions in SelectionTool
2022-01-05 23:54:29 +01:00

45 lines
1.3 KiB
JavaScript

class EraserTool extends ResizableTool {
constructor(name, options, switchFunction) {
super(name, options);
Events.on('click', this.mainButton, switchFunction, this);
Events.on('click', this.biggerButton, this.increaseSize.bind(this));
Events.on('click', this.smallerButton, this.decreaseSize.bind(this));
}
onStart(mousePos) {
super.onStart(mousePos);
new HistoryState().EditCanvas();
}
onDrag(mousePos, cursorTarget) {
super.onDrag(mousePos);
if (cursorTarget === undefined)
return;
//draw line to current pixel
if (cursorTarget.className == 'drawingCanvas' || cursorTarget.className == 'drawingCanvas') {
currFile.currentLayer.drawLine(Math.floor(this.prevMousePos[0]/currFile.zoom),
Math.floor(this.prevMousePos[1]/currFile.zoom),
Math.floor(this.currMousePos[0]/currFile.zoom),
Math.floor(this.currMousePos[1]/currFile.zoom),
this.currSize, true
);
}
currFile.currentLayer.updateLayerPreview();
}
onEnd(mousePos) {
super.onEnd(mousePos);
this.endMousePos = mousePos;
}
onSelect() {
super.onSelect();
}
onDeselect() {
super.onDeselect();
}
}