|
@@ -24,7 +24,7 @@ import Speedy from 'speedy-vision';
|
24
|
24
|
import { SpeedySize } from 'speedy-vision/types/core/speedy-size';
|
25
|
25
|
import { SpeedyPromise } from 'speedy-vision/types/core/speedy-promise';
|
26
|
26
|
import { Nullable } from '../utils/utils';
|
27
|
|
-import { Resolution } from './resolution';
|
|
27
|
+import { Resolution } from '../utils/resolution';
|
28
|
28
|
import { Utils } from '../utils/utils';
|
29
|
29
|
import { IllegalArgumentError, IllegalOperationError, NotSupportedError, AccessDeniedError } from '../utils/errors';
|
30
|
30
|
import { HUD, HUDContainer } from './hud';
|
|
@@ -99,12 +99,6 @@ const FOREGROUND_ZINDEX = BASE_ZINDEX + 1;
|
99
|
99
|
/** Z-index of the HUD */
|
100
|
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,12 +193,11 @@ class ViewportCanvases
|
199
|
193
|
/**
|
200
|
194
|
* Constructor
|
201
|
195
|
* @param parent container for the canvases
|
|
196
|
+ * @param initialSize initial size of the canvases
|
202
|
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
|
201
|
if(fgCanvas !== null && !(fgCanvas instanceof HTMLCanvasElement))
|
209
|
202
|
throw new IllegalArgumentError('Not a canvas: ' + fgCanvas);
|
210
|
203
|
|
|
@@ -730,13 +723,15 @@ export class Viewport extends ViewportEventTarget
|
730
|
723
|
|
731
|
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
|
730
|
this._resolution = settings.resolution;
|
|
731
|
+ this._style = null;
|
737
|
732
|
this._containers = new ViewportContainers(settings.container);
|
738
|
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
|
736
|
this._fullscreen = new ViewportFullscreenHelper(this.container);
|
742
|
737
|
this._resizer = new ViewportResizer(this);
|