asciiflow2/js-lib/draw/box.js

45 lines
898 B
JavaScript

import State from '../state';
import Vector from '../vector';
import DrawFunction from './function';
import { drawLine } from './utils';
/**
* @implements {DrawFunction}
*/
export default class DrawBox {
/**
* @param {State} state
*/
constructor(state) {
this.state = state;
/** @type {Vector} */ this.startPosition = null;
/** @type {Vector} */ this.endPosition = null;
}
/** @inheritDoc */
start(position) {
this.startPosition = position;
}
/** @inheritDoc */
move(position) {
this.endPosition = position;
this.state.clearDraw();
drawLine(this.state, this.startPosition, position, true);
drawLine(this.state, this.startPosition, position, false);
}
/** @inheritDoc */
end() {
this.state.commitDraw();
}
/** @inheritDoc */
getCursor(position) {
return 'crosshair';
}
/** @inheritDoc */
handleKey(value) {};
}