Make pen draw continuously with lines
export default class Pen extends Controller {
constructor(appState) {
super(appState);
- this.penIsDown = false;
+ this.previous = null;
}
down(x, y) {
- this.penIsDown = true;
+ this.previous = {x, y};
this.state.pixelEditor.drawPixel(x, y);
}
move(x, y) {
- if (this.penIsDown) {
- this.state.pixelEditor.drawPixel(x, y);
+ if (this.previous) {
+ if (Math.abs(this.previous.x - x) > 1 || Math.abs(this.previous.y - y) > 1) {
+ this.state.pixelEditor.drawLine(x, y, this.previous.x, this.previous.y);
+ } else {
+ this.state.pixelEditor.drawPixel(x, y);
+ }
+ this.previous = {x, y};
}
}
up(x, y) {
this.penIsDown = false;
+ this.previous = null;
}
}