avocado-old/packages/graphics/canvas.js

49 lines
860 B
JavaScript
Raw Normal View History

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],
}),
);
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]) {
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;
}
toImage() {
const image = new Image();
image.texture = this.renderTexture.clone();
return image;
}
2019-03-25 19:03:34 -05:00
}