mirror of
https://github.com/lospec/pixel-editor.git
synced 2023-08-10 21:12:51 +03:00
62130ae90d
Now it's possible to use all non-resizable tool and even copy a locked layer to paste it on an unlocked one.
32 lines
988 B
JavaScript
32 lines
988 B
JavaScript
class ResizableTool extends DrawingTool {
|
|
startResizePos = undefined;
|
|
currSize = 1;
|
|
prevSize = 1;
|
|
|
|
constructor(name, options, switchFunc) {
|
|
super(name, options, switchFunc);
|
|
}
|
|
|
|
onRightStart(mousePos, mouseEvent) {
|
|
this.startResizePos = mousePos;
|
|
}
|
|
|
|
onRightDrag(mousePos, mouseEvent) {
|
|
//get new brush size based on x distance from original clicking location
|
|
let distanceFromClick = mousePos[0]/currFile.zoom - this.startResizePos[0]/currFile.zoom;
|
|
|
|
let brushSizeChange = Math.round(distanceFromClick/10);
|
|
let newBrushSize = this.currSize + brushSizeChange;
|
|
|
|
//set the brush to the new size as long as its bigger than 1 and less than 128
|
|
this.currSize = Math.min(Math.max(1,newBrushSize), 128);
|
|
|
|
//fix offset so the cursor stays centered
|
|
this.updateCursor();
|
|
this.onHover(this.startResizePos, mouseEvent);
|
|
}
|
|
|
|
onRightEnd(mousePos, mouseEvent) {
|
|
|
|
}
|
|
} |