Added back brush with new tool system

This commit is contained in:
unsettledgames
2021-10-27 10:02:21 +02:00
parent 222228a6ce
commit 35cbe31a71
21 changed files with 217 additions and 125 deletions

38
js/tools/BrushTool.js Normal file
View File

@@ -0,0 +1,38 @@
class BrushTool extends Tool {
constructor(name, options) {
super(name, options);
// Selection button, brush size buttons
Events.on('click',"pencil-button", this.onSelect);
Events.on('click',"pencil-bigger-button", this.increaseSize.bind(this));
Events.on('click',"pencil-smaller-button", this.decreaseSize.bind(this));
}
onStart(mousePos) {
super.onStart(mousePos);
this.startMousePos = mousePos;
}
onDrag(mousePos, cursorTarget) {
super.onDrag(mousePos);
if (cursorTarget === undefined)
return;
//draw line to current pixel
if (cursorTarget.className == 'drawingCanvas' || cursorTarget.className == 'drawingCanvas') {
line(Math.floor(this.prevMousePos[0]/zoom),
Math.floor(this.prevMousePos[1]/zoom),
Math.floor(this.currMousePos[0]/zoom),
Math.floor(this.currMousePos[1]/zoom),
this.currSize
);
}
currentLayer.updateLayerPreview();
}
onEnd(mousePos) {
super.onEnd(mousePos);
this.endMousePos = mousePos;
}
}

0
js/tools/EraserTool.js Normal file
View File

View File

0
js/tools/FillTool.js Normal file
View File

0
js/tools/LineTool.js Normal file
View File

0
js/tools/PanTool.js Normal file
View File

0
js/tools/RectagleTool.js Normal file
View File

0
js/tools/ZoomTool.js Normal file
View File

View File

@@ -64,5 +64,6 @@ new Tool('zoom', {
});
//set a default tool
// REFACTOR: move to FileManager
var currentTool = tool.pencil;
var currentToolTemp = tool.pencil;