@pixi/core
Version:
Core PixiJS
55 lines (52 loc) • 1.72 kB
JavaScript
import { ExtensionType, extensions } from '@pixi/extensions';
import { Rectangle } from '@pixi/math';
import { settings } from '@pixi/settings';
class ViewSystem {
constructor(renderer) {
this.renderer = renderer;
}
init(options) {
this.screen = new Rectangle(0, 0, options.width, options.height);
this.element = options.view || settings.ADAPTER.createCanvas();
this.resolution = options.resolution || settings.RESOLUTION;
this.autoDensity = !!options.autoDensity;
}
resizeView(desiredScreenWidth, desiredScreenHeight) {
this.element.width = Math.round(desiredScreenWidth * this.resolution);
this.element.height = Math.round(desiredScreenHeight * this.resolution);
const screenWidth = this.element.width / this.resolution;
const screenHeight = this.element.height / this.resolution;
this.screen.width = screenWidth;
this.screen.height = screenHeight;
if (this.autoDensity) {
this.element.style.width = `${screenWidth}px`;
this.element.style.height = `${screenHeight}px`;
}
this.renderer.emit("resize", screenWidth, screenHeight);
this.renderer.runners.resize.emit(this.screen.width, this.screen.height);
}
destroy(removeView) {
if (removeView) {
this.element.parentNode?.removeChild(this.element);
}
this.renderer = null;
this.element = null;
this.screen = null;
}
}
ViewSystem.defaultOptions = {
width: 800,
height: 600,
resolution: settings.RESOLUTION,
autoDensity: false
};
ViewSystem.extension = {
type: [
ExtensionType.RendererSystem,
ExtensionType.CanvasRendererSystem
],
name: "_view"
};
extensions.add(ViewSystem);
export { ViewSystem };
//# sourceMappingURL=ViewSystem.mjs.map