fantasy/ui/canvas.js

32 lines
757 B
JavaScript
Raw Normal View History

2018-11-19 15:03:05 +00:00
import UI from "./ui.js";
2018-11-18 18:04:50 +00:00
2018-11-19 15:03:05 +00:00
class Canvas extends UI {
constructor(width, height) {
2018-11-19 15:03:05 +00:00
super(document.createElement("canvas"), width, height);
2018-11-18 18:04:50 +00:00
this._ctx = this.element.getContext("2d");
2018-11-19 14:09:43 +00:00
}
clear() {
this.resetStyle();
this._ctx.clearRect(0, 0, this._width, this._height);
2018-11-18 18:09:30 +00:00
}
2018-11-18 18:04:50 +00:00
setFillColor(color) {
this._ctx.fillStyle = color.rgba();
2018-11-18 18:09:30 +00:00
}
2018-11-18 18:04:50 +00:00
resetStyle() {
this._ctx.fillStyle = "";
2018-11-18 18:09:30 +00:00
}
2018-11-18 18:04:50 +00:00
draw(shape) {
2018-11-18 18:20:01 +00:00
this._ctx.fillStyle = shape.color.rgba();
2018-11-18 18:04:50 +00:00
shape.draw(this._ctx);
this.resetStyle();
}
2018-11-19 15:03:05 +00:00
setSize(width, height) {
super.setSize(width, height);
this.element.width = width;
this.element.height = height;
}
2018-11-18 18:04:50 +00:00
}
export default Canvas;