gravity/select.js

34 lines
610 B
JavaScript

export class Select {
sim = undefined;
box = {
start: undefined,
end: undefined,
};
constructor(sim) {
this.sim = sim;
}
handlePointerDown({x: clientX, y: clientY}) {
this.box.start = this.sim.screenToSim(clientX, clientY);
}
handlePointerMove({x: clientX, y: clientY}) {
this.box.end = this.sim.screenToSim(clientX, clientY);
}
handlePointerUp() {
console.log('selection box', {...this.box});
this.box = {
start: undefined,
end: undefined,
};
}
frame() {
if (!this.box.start) return;
this.sim.display.drawBox(this.box)
}
}