1 | "use strict";
|
2 | var extensions = require("@pixi/extensions"), math = require("@pixi/math"), settings = require("@pixi/settings");
|
3 | class ViewSystem {
|
4 | constructor(renderer) {
|
5 | this.renderer = renderer;
|
6 | }
|
7 | |
8 |
|
9 |
|
10 |
|
11 | init(options) {
|
12 | 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;
|
13 | }
|
14 | |
15 |
|
16 |
|
17 |
|
18 |
|
19 | resizeView(desiredScreenWidth, desiredScreenHeight) {
|
20 | this.element.width = Math.round(desiredScreenWidth * this.resolution), this.element.height = Math.round(desiredScreenHeight * this.resolution);
|
21 | const screenWidth = this.element.width / this.resolution, screenHeight = this.element.height / this.resolution;
|
22 | this.screen.width = screenWidth, this.screen.height = screenHeight, 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);
|
23 | }
|
24 | |
25 |
|
26 |
|
27 |
|
28 | destroy(removeView) {
|
29 | removeView && this.element.parentNode?.removeChild(this.element), this.renderer = null, this.element = null, this.screen = null;
|
30 | }
|
31 | }
|
32 | ViewSystem.defaultOptions = {
|
33 | |
34 |
|
35 |
|
36 |
|
37 |
|
38 | width: 800,
|
39 | |
40 |
|
41 |
|
42 |
|
43 |
|
44 | height: 600,
|
45 | |
46 |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 | resolution: void 0,
|
52 | |
53 |
|
54 |
|
55 |
|
56 |
|
57 | autoDensity: !1
|
58 | },
|
59 | ViewSystem.extension = {
|
60 | type: [
|
61 | extensions.ExtensionType.RendererSystem,
|
62 | extensions.ExtensionType.CanvasRendererSystem
|
63 | ],
|
64 | name: "_view"
|
65 | };
|
66 | extensions.extensions.add(ViewSystem);
|
67 | exports.ViewSystem = ViewSystem;
|
68 |
|