UNPKG

@pixi/core

Version:
59 lines (54 loc) 1.85 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var extensions = require('@pixi/extensions'); var math = require('@pixi/math'); var settings = require('@pixi/settings'); class ViewSystem { constructor(renderer) { this.renderer = renderer; } init(options) { this.screen = new math.Rectangle(0, 0, options.width, options.height); this.element = options.view || settings.settings.ADAPTER.createCanvas(); this.resolution = options.resolution || settings.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.settings.RESOLUTION, autoDensity: false }; ViewSystem.extension = { type: [ extensions.ExtensionType.RendererSystem, extensions.ExtensionType.CanvasRendererSystem ], name: "_view" }; extensions.extensions.add(ViewSystem); exports.ViewSystem = ViewSystem; //# sourceMappingURL=ViewSystem.js.map