Browse Source

Use a different estimate for the initial size of the viewport

customisations
alemart 1 year ago
parent
commit
f349a5bbd9
1 changed files with 8 additions and 13 deletions
  1. 8
    13
      src/core/viewport.ts

+ 8
- 13
src/core/viewport.ts View File

24
 import { SpeedySize } from 'speedy-vision/types/core/speedy-size';
24
 import { SpeedySize } from 'speedy-vision/types/core/speedy-size';
25
 import { SpeedyPromise } from 'speedy-vision/types/core/speedy-promise';
25
 import { SpeedyPromise } from 'speedy-vision/types/core/speedy-promise';
26
 import { Nullable } from '../utils/utils';
26
 import { Nullable } from '../utils/utils';
27
-import { Resolution } from './resolution';
27
+import { Resolution } from '../utils/resolution';
28
 import { Utils } from '../utils/utils';
28
 import { Utils } from '../utils/utils';
29
 import { IllegalArgumentError, IllegalOperationError, NotSupportedError, AccessDeniedError } from '../utils/errors';
29
 import { IllegalArgumentError, IllegalOperationError, NotSupportedError, AccessDeniedError } from '../utils/errors';
30
 import { HUD, HUDContainer } from './hud';
30
 import { HUD, HUDContainer } from './hud';
99
 /** Z-index of the HUD */
99
 /** Z-index of the HUD */
100
 const HUD_ZINDEX = BASE_ZINDEX + 2;
100
 const HUD_ZINDEX = BASE_ZINDEX + 2;
101
 
101
 
102
-/** Default viewport width, in pixels */
103
-const DEFAULT_VIEWPORT_WIDTH = 300;
104
-
105
-/** Default viewport height, in pixels */
106
-const DEFAULT_VIEWPORT_HEIGHT = 150;
107
-
108
 
102
 
109
 
103
 
110
 
104
 
199
     /**
193
     /**
200
      * Constructor
194
      * Constructor
201
      * @param parent container for the canvases
195
      * @param parent container for the canvases
196
+     * @param initialSize initial size of the canvases
202
      * @param fgCanvas optional existing foreground canvas
197
      * @param fgCanvas optional existing foreground canvas
203
      */
198
      */
204
-    constructor(parent: HTMLElement, fgCanvas: Nullable<HTMLCanvasElement> = null)
199
+    constructor(parent: HTMLElement, initialSize: SpeedySize, fgCanvas: Nullable<HTMLCanvasElement> = null)
205
     {
200
     {
206
-        const initialSize = Speedy.Size(DEFAULT_VIEWPORT_WIDTH, DEFAULT_VIEWPORT_HEIGHT);
207
-
208
         if(fgCanvas !== null && !(fgCanvas instanceof HTMLCanvasElement))
201
         if(fgCanvas !== null && !(fgCanvas instanceof HTMLCanvasElement))
209
             throw new IllegalArgumentError('Not a canvas: ' + fgCanvas);
202
             throw new IllegalArgumentError('Not a canvas: ' + fgCanvas);
210
 
203
 
730
 
723
 
731
         super();
724
         super();
732
 
725
 
733
-        this._mediaSize = () => Speedy.Size(DEFAULT_VIEWPORT_WIDTH, DEFAULT_VIEWPORT_HEIGHT);
734
-        this._style = null;
726
+        const guessedAspectRatio = window.innerWidth / window.innerHeight;
727
+        const initialSize = Utils.resolution(settings.resolution, guessedAspectRatio);
728
+        this._mediaSize = () => initialSize;
735
 
729
 
736
         this._resolution = settings.resolution;
730
         this._resolution = settings.resolution;
731
+        this._style = null;
737
         this._containers = new ViewportContainers(settings.container);
732
         this._containers = new ViewportContainers(settings.container);
738
         this._hud = new HUD(this._subContainer, settings.hudContainer);
733
         this._hud = new HUD(this._subContainer, settings.hudContainer);
739
-        this._canvases = new ViewportCanvases(this._subContainer, settings.canvas);
734
+        this._canvases = new ViewportCanvases(this._subContainer, initialSize, settings.canvas);
740
 
735
 
741
         this._fullscreen = new ViewportFullscreenHelper(this.container);
736
         this._fullscreen = new ViewportFullscreenHelper(this.container);
742
         this._resizer = new ViewportResizer(this);
737
         this._resizer = new ViewportResizer(this);

Loading…
Cancel
Save