/src/Rect.js
import Controller from './Controller';
export default class Rect extends Controller {
constructor(appState) {
super(appState);
this.begin = null;
}
down(x, y) {
this.begin = {x, y};
this.state.pixelEditor.pushState();
this.state.pixelEditor.drawPixel(x, y);
}
move(x, y) {
if (this.begin) {
const x0 = x > this.begin.x ? this.begin.x : x;
const y0 = y > this.begin.y ? this.begin.y : y;
const w = Math.abs(x - this.begin.x) + 1;
const h = Math.abs(y - this.begin.y) + 1;
this.state.pixelEditor.resetState();
this.state.pixelEditor.setHLine(x0, this.begin.y, w);
this.state.pixelEditor.setHLine(x0, y, w);
this.state.pixelEditor.setVLine(this.begin.x, y0 + 1, h - 2);
this.state.pixelEditor.setVLine(x, y0 + 1, h - 2);
this.state.pixelEditor.redraw();
this.state.pixelEditor.refresh();
}
}
up(x, y) {
this.begin = null;
}
}