1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, '__esModule', { value: true });
|
4 |
|
5 | var extensions = require('@pixi/extensions');
|
6 | var math = require('@pixi/math');
|
7 | var settings = require('@pixi/settings');
|
8 |
|
9 | class ViewSystem {
|
10 | constructor(renderer) {
|
11 | this.renderer = renderer;
|
12 | }
|
13 | init(options) {
|
14 | this.screen = new math.Rectangle(0, 0, options.width, options.height);
|
15 | this.element = options.view || settings.settings.ADAPTER.createCanvas();
|
16 | this.resolution = options.resolution || settings.settings.RESOLUTION;
|
17 | this.autoDensity = !!options.autoDensity;
|
18 | }
|
19 | resizeView(desiredScreenWidth, desiredScreenHeight) {
|
20 | this.element.width = Math.round(desiredScreenWidth * this.resolution);
|
21 | this.element.height = Math.round(desiredScreenHeight * this.resolution);
|
22 | const screenWidth = this.element.width / this.resolution;
|
23 | const screenHeight = this.element.height / this.resolution;
|
24 | this.screen.width = screenWidth;
|
25 | this.screen.height = screenHeight;
|
26 | if (this.autoDensity) {
|
27 | this.element.style.width = `${screenWidth}px`;
|
28 | this.element.style.height = `${screenHeight}px`;
|
29 | }
|
30 | this.renderer.emit("resize", screenWidth, screenHeight);
|
31 | this.renderer.runners.resize.emit(this.screen.width, this.screen.height);
|
32 | }
|
33 | destroy(removeView) {
|
34 | if (removeView) {
|
35 | this.element.parentNode?.removeChild(this.element);
|
36 | }
|
37 | this.renderer = null;
|
38 | this.element = null;
|
39 | this.screen = null;
|
40 | }
|
41 | }
|
42 | ViewSystem.defaultOptions = {
|
43 | width: 800,
|
44 | height: 600,
|
45 | resolution: settings.settings.RESOLUTION,
|
46 | autoDensity: false
|
47 | };
|
48 | ViewSystem.extension = {
|
49 | type: [
|
50 | extensions.ExtensionType.RendererSystem,
|
51 | extensions.ExtensionType.CanvasRendererSystem
|
52 | ],
|
53 | name: "_view"
|
54 | };
|
55 | extensions.extensions.add(ViewSystem);
|
56 |
|
57 | exports.ViewSystem = ViewSystem;
|
58 |
|