/src/Pen.js
import Controller from './Controller';

export default class Pen extends Controller {
    constructor(appState) {
        super(appState);
        this.previous = null;
    }

    down(x, y) {
        this.state.pixelEditor.pushState();
        this.previous = {x, y};
        this.state.pixelEditor.drawPixel(x, y);
    }
    move(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;
    }
}