49 lines
860 B
JavaScript
49 lines
860 B
JavaScript
import {RenderTexture} from '@pixi/core';
|
|
|
|
import {compose} from '@avocado/core';
|
|
import {Vector} from '@avocado/math';
|
|
|
|
import {Image} from './image';
|
|
|
|
const decorate = compose(
|
|
Vector.Mixin('size', 'width', 'height', {
|
|
default: [0, 0],
|
|
}),
|
|
);
|
|
|
|
export class Canvas extends decorate(class {}) {
|
|
|
|
constructor(size = [0, 0]) {
|
|
super();
|
|
this.renderTexture = RenderTexture.create(size[0], size[1]);
|
|
}
|
|
|
|
destroy() {
|
|
this.renderTexture.destroy();
|
|
}
|
|
|
|
get internal() {
|
|
return this.renderTexture;
|
|
}
|
|
|
|
render(renderable, renderer) {
|
|
renderer.render(renderable, this);
|
|
}
|
|
|
|
get size() {
|
|
return super.size;
|
|
}
|
|
|
|
set size(size) {
|
|
this.renderTexture.resize(size[0], size[1]);
|
|
super.size = size;
|
|
}
|
|
|
|
toImage() {
|
|
const image = new Image();
|
|
image.texture = this.renderTexture.clone();
|
|
return image;
|
|
}
|
|
|
|
}
|