Selaa lähdekoodia

Make Viewport.style read-only. Improve the code.

customisations
alemart 11 kuukautta sitten
vanhempi
commit
6dff540a11
3 muutettua tiedostoa jossa 27 lisäystä ja 20 poistoa
  1. 1
    1
      docs/api/viewport.md
  2. 2
    18
      src/core/session.ts
  3. 24
    1
      src/core/viewport.ts

+ 1
- 1
docs/api/viewport.md Näytä tiedosto

@@ -67,7 +67,7 @@ A `<canvas>` on which the virtual scene is drawn.
67 67
 
68 68
 ### style
69 69
 
70
-`viewport.style: string`
70
+`viewport.style: string, read-only`
71 71
 
72 72
 The style determines the way the viewport appears on the screen. Different styles are applicable to different [session modes](session.md#mode). The following are valid styles:
73 73
 

+ 2
- 18
src/core/session.ts Näytä tiedosto

@@ -158,28 +158,12 @@ export class Session extends AREventTarget<SessionEventType>
158 158
         this._gizmos.visible = gizmos;
159 159
 
160 160
         // validate the mode
161
-        if(mode == 'immersive') {
162
-            if(viewport.style != 'best-fit' && viewport.style != 'stretch') {
163
-                Utils.warning(`Invalid viewport style \"${viewport.style}\" for the \"${mode}\" mode`);
164
-                viewport.style = 'best-fit';
165
-            }
166
-        }
167
-        else if(mode == 'inline') {
168
-            if(viewport.style != 'inline') {
169
-                Utils.warning(`Invalid viewport style \"${viewport.style}\" for the \"${mode}\" mode`);
170
-                viewport.style = 'inline';
171
-            }
172
-        }
173
-        else
161
+        if(mode != 'immersive' && mode != 'inline')
174 162
             throw new IllegalArgumentError(`Invalid session mode "${mode}"`);
175 163
 
176
-        // get media
177
-        const media = this.media;
178
-        const getMediaSize = () => media.size;
179
-
180 164
         // setup the viewport
181 165
         this._viewport = viewport;
182
-        this._viewport._init(getMediaSize);
166
+        this._viewport._init(() => this.media.size, mode);
183 167
 
184 168
         // setup the main loop
185 169
         this._setupUpdateLoop();

+ 24
- 1
src/core/viewport.ts Näytä tiedosto

@@ -27,6 +27,7 @@ import { SpeedyPromise } from 'speedy-vision/types/core/speedy-promise';
27 27
 import { Nullable } from '../utils/utils';
28 28
 import { Resolution } from '../utils/resolution';
29 29
 import { Utils } from '../utils/utils';
30
+import { SessionMode } from './session';
30 31
 import { HUD, HUDContainer } from './hud';
31 32
 import { FullscreenButton } from '../ui/fullscreen-button';
32 33
 import { AREvent, AREventTarget, AREventListener } from '../utils/ar-events';
@@ -847,6 +848,7 @@ export class Viewport extends ViewportEventTarget
847 848
     /**
848 849
      * Set viewport style
849 850
      */
851
+    /*
850 852
     set style(value: ViewportStyle)
851 853
     {
852 854
         // note: the viewport style is independent of the session mode!
@@ -855,6 +857,7 @@ export class Viewport extends ViewportEventTarget
855 857
             this._style = value;
856 858
         }
857 859
     }
860
+    */
858 861
 
859 862
     /**
860 863
      * HUD
@@ -955,12 +958,32 @@ export class Viewport extends ViewportEventTarget
955 958
 
956 959
     /**
957 960
      * Initialize the viewport (when the session starts)
961
+     * @param getMediaSize
962
+     * @param sessionMode
958 963
      * @internal
959 964
      */
960
-    _init(getMediaSize: ViewportSizeGetter): void
965
+    _init(getMediaSize: ViewportSizeGetter, sessionMode: SessionMode): void
961 966
     {
967
+        // validate if the viewport style matches the session mode
968
+        if(sessionMode == 'immersive') {
969
+            if(this._style != 'best-fit' && this._style != 'stretch') {
970
+                Utils.warning(`Invalid viewport style \"${this._style}\" for the \"${sessionMode}\" mode`);
971
+                this._style = 'best-fit';
972
+                this._resizer.setStrategyByName(this._style);
973
+            }
974
+        }
975
+        else if(sessionMode == 'inline') {
976
+            if(this._style != 'inline') {
977
+                Utils.warning(`Invalid viewport style \"${this._style}\" for the \"${sessionMode}\" mode`);
978
+                this._style = 'inline';
979
+                this._resizer.setStrategyByName(this._style);
980
+            }
981
+        }
982
+
983
+        // set the media size getter
962 984
         this._mediaSize = getMediaSize;
963 985
 
986
+        // initialize the components
964 987
         this._containers.init();
965 988
         this._hud._init(HUD_ZINDEX);
966 989
         this._canvases.init();

Loading…
Peruuta
Tallenna