pixel-editor/js/tools/BrushTool.js

67 lines
2.2 KiB
JavaScript
Raw Normal View History

2021-11-01 15:02:18 +03:00
class BrushTool extends ResizableTool {
2021-10-27 11:43:51 +03:00
constructor(name, options, switchFunction) {
2021-10-27 11:02:21 +03:00
super(name, options);
2021-10-27 11:43:51 +03:00
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));
this.resetTutorial();
this.addTutorialTitle("Pencil tool");
this.addTutorialKey("B", " to select the brush");
this.addTutorialKey("Left drag", " to draw a stroke");
this.addTutorialKey("Right drag", " to resize the brush");
this.addTutorialKey("+ or -", " to resize the brush");
this.addTutorialImg("brush-tutorial.gif");
2021-10-27 11:02:21 +03:00
}
2022-01-23 20:56:55 +03:00
onStart(mousePos, cursorTarget) {
2021-10-27 11:02:21 +03:00
super.onStart(mousePos);
2022-01-23 20:56:55 +03:00
if (cursorTarget === undefined)
return;
new HistoryState().EditCanvas();
2022-01-23 20:56:55 +03:00
//draw line to current pixel
if (cursorTarget.className == 'drawingCanvas' || cursorTarget.className == 'drawingCanvas') {
currFile.currentLayer.drawLine(
Math.floor(mousePos[0]/currFile.zoom),
Math.floor(mousePos[1]/currFile.zoom),
Math.floor(mousePos[0]/currFile.zoom),
Math.floor(mousePos[1]/currFile.zoom),
this.currSize
);
}
currFile.currentLayer.updateLayerPreview();
2021-10-27 11:02:21 +03:00
}
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),
2021-12-30 01:16:16 +03:00
Math.floor(this.currMousePos[1]/currFile.zoom),
2021-10-27 11:02:21 +03:00
this.currSize
);
}
2021-12-30 01:16:16 +03:00
currFile.currentLayer.updateLayerPreview();
2021-10-27 11:02:21 +03:00
}
onEnd(mousePos) {
super.onEnd(mousePos);
}
2021-10-27 11:43:51 +03:00
onSelect() {
super.onSelect();
}
onDeselect() {
super.onDeselect();
}
2021-10-27 11:02:21 +03:00
}