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