2019-10-27 13:34:44 -05:00
|
|
|
import {RenderTexture} from '@pixi/core';
|
2019-03-25 19:03:34 -05:00
|
|
|
|
|
|
|
import {compose} from '@avocado/core';
|
|
|
|
import {Vector} from '@avocado/math';
|
|
|
|
|
2019-09-19 03:19:24 -05:00
|
|
|
import {Image} from './image';
|
2019-03-25 19:03:34 -05:00
|
|
|
|
|
|
|
const decorate = compose(
|
|
|
|
Vector.Mixin('size', 'width', 'height', {
|
|
|
|
default: [0, 0],
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
|
2019-03-27 16:18:27 -05:00
|
|
|
export class Canvas extends decorate(class {}) {
|
2019-03-25 19:03:34 -05:00
|
|
|
|
2019-03-25 20:25:19 -05:00
|
|
|
constructor(size = [0, 0]) {
|
2019-03-27 16:18:27 -05:00
|
|
|
super();
|
2019-10-27 13:34:44 -05:00
|
|
|
this.renderTexture = RenderTexture.create(size[0], size[1]);
|
2019-03-25 19:03:34 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
destroy() {
|
|
|
|
this.renderTexture.destroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
get internal() {
|
|
|
|
return this.renderTexture;
|
|
|
|
}
|
|
|
|
|
2019-03-25 20:27:07 -05:00
|
|
|
render(renderable, renderer) {
|
2019-03-25 19:03:34 -05:00
|
|
|
renderer.render(renderable, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
get size() {
|
|
|
|
return super.size;
|
|
|
|
}
|
|
|
|
|
|
|
|
set size(size) {
|
|
|
|
this.renderTexture.resize(size[0], size[1]);
|
|
|
|
super.size = size;
|
|
|
|
}
|
|
|
|
|
2019-03-27 16:18:27 -05:00
|
|
|
toImage() {
|
|
|
|
const image = new Image();
|
|
|
|
image.texture = this.renderTexture.clone();
|
|
|
|
return image;
|
|
|
|
}
|
|
|
|
|
2019-03-25 19:03:34 -05:00
|
|
|
}
|