44 * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License }
55 */
66
7- var CONST = require ( './const' ) ;
8- var Class = require ( '../utils/Class' ) ;
97var Clamp = require ( '../math/Clamp' ) ;
8+ var Class = require ( '../utils/Class' ) ;
9+ var CONST = require ( './const' ) ;
10+ var GetOffset = require ( './GetOffset' ) ;
11+ var GetScreenOrientation = require ( './GetScreenOrientation' ) ;
12+ var LayoutBounds = require ( './LayoutBounds' ) ;
1013var Rectangle = require ( '../geom/rectangle/Rectangle' ) ;
1114var SameDimensions = require ( '../geom/rectangle/SameDimensions' ) ;
1215var Vec2 = require ( '../math/Vector2' ) ;
16+ var VisualBounds = require ( './VisualBounds' ) ;
1317
1418/**
1519 * @classdesc
@@ -71,8 +75,7 @@ var ScaleManager = new Class({
7175
7276 this . _createdFullScreenTarget = null ;
7377
74- this . screenOrientation = 'portrait-primary' ;
75- // this.screenOrientation = this.dom.getScreenOrientation();
78+ this . screenOrientation ;
7679
7780 this . scaleFactor = new Vec2 ( 1 , 1 ) ;
7881
@@ -119,7 +122,7 @@ var ScaleManager = new Class({
119122
120123 this . onResizeContext = null ;
121124
122- this . _pendingScaleMode = null ;
125+ this . _pendingScaleMode = game . config . scaleMode ;
123126
124127 this . _fullScreenRestore = null ;
125128
@@ -150,10 +153,6 @@ var ScaleManager = new Class({
150153
151154 boot : function ( )
152155 {
153- // this._innerHeight = this.getInnerHeight();
154- // var gameWidth = this.config.width;
155- // var gameHeight = this.config.height;
156-
157156 // Configure device-dependent compatibility
158157
159158 var game = this . game ;
@@ -187,7 +186,7 @@ var ScaleManager = new Class({
187186 compat . clickTrampoline = '' ;
188187 }
189188
190- // Configure event listeners
189+ // Configure event listeners
191190
192191 var _this = this ;
193192
@@ -201,11 +200,10 @@ var ScaleManager = new Class({
201200 return _this . windowResize ( event ) ;
202201 } ;
203202
204- // This does not appear to be on the standards track
205203 window . addEventListener ( 'orientationchange' , this . _orientationChange , false ) ;
206204 window . addEventListener ( 'resize' , this . _windowResize , false ) ;
207205
208- if ( this . compatibility . supportsFullScreen )
206+ if ( compat . supportsFullScreen )
209207 {
210208 this . _fullScreenChange = function ( event )
211209 {
@@ -230,28 +228,39 @@ var ScaleManager = new Class({
230228 document . addEventListener ( 'MSFullscreenError' , this . _fullScreenError , false ) ;
231229 }
232230
233- this . game . events . on ( 'resume' , this . gameResumed , this ) ;
231+ game . events . on ( 'resume' , this . gameResumed , this ) ;
234232
235233 // Initialize core bounds
236234
237- // this.dom.getOffset(this.game.canvas, this.offset);
235+ // Set-up the Bounds
236+ var isDesktop = os . desktop && ( document . documentElement . clientWidth <= window . innerWidth ) && ( document . documentElement . clientHeight <= window . innerHeight ) ;
237+
238+ VisualBounds . init ( isDesktop ) ;
239+ LayoutBounds . init ( isDesktop ) ;
240+
241+ GetOffset ( game . canvas , this . offset ) ;
238242
239243 this . bounds . setTo ( this . offset . x , this . offset . y , this . width , this . height ) ;
240244
241- this . setGameSize ( this . game . width , this . game . height ) ;
245+ console . log ( this . offset . x , this . offset . y , this . width , this . height ) ;
246+
247+ this . setGameSize ( game . config . width , game . config . height ) ;
242248
243249 // Don't use updateOrientationState so events are not fired
244- // this.screenOrientation = this.dom.getScreenOrientation(this.compatibility .orientationFallback);
250+ this . screenOrientation = GetScreenOrientation ( compat . orientationFallback ) ;
245251
246252 this . _booted = true ;
247253
248254 if ( this . _pendingScaleMode !== null )
249255 {
250256 this . scaleMode = this . _pendingScaleMode ;
257+
251258 this . _pendingScaleMode = null ;
252259 }
253260
254261 game . events . on ( 'prestep' , this . step , this ) ;
262+
263+ this . setupScale ( game . config . width , game . config . height ) ;
255264 } ,
256265
257266 setupScale : function ( width , height )
@@ -270,20 +279,20 @@ var ScaleManager = new Class({
270279 }
271280 else if ( parent && parent . nodeType === 1 )
272281 {
273- // Quick test for a HTMLelement
282+ // Quick test for a HTMLElement
274283 target = parent ;
275284 }
276285 }
277286
278- // Fallback, covers an invalid ID and a non HTMLelement object
287+ // Fallback, covers an invalid ID and a non HTMLElement object
279288 if ( ! target )
280289 {
281290 // Use the full window
282291 this . parentNode = null ;
283292 this . parentIsWindow = true ;
284293
285- rect . width = this . dom . visualBounds . width ;
286- rect . height = this . dom . visualBounds . height ;
294+ rect . width = VisualBounds . width ;
295+ rect . height = VisualBounds . height ;
287296
288297 this . offset . set ( 0 , 0 ) ;
289298 }
@@ -333,6 +342,8 @@ var ScaleManager = new Class({
333342 this . _gameSize . setTo ( 0 , 0 , newWidth , newHeight ) ;
334343
335344 this . updateDimensions ( newWidth , newHeight , false ) ;
345+
346+ console . log ( 'setupscale' , this . _parentBounds ) ;
336347 } ,
337348
338349 gameResumed : function ( )
@@ -418,9 +429,10 @@ var ScaleManager = new Class({
418429 }
419430
420431 var prevThrottle = this . _updateThrottle ;
432+
421433 this . _updateThrottleReset = ( prevThrottle >= 400 ) ? 0 : 100 ;
422434
423- // this.dom.getOffset (this.game.canvas, this.offset);
435+ GetOffset ( this . game . canvas , this . offset ) ;
424436
425437 var prevWidth = this . _parentBounds . width ;
426438 var prevHeight = this . _parentBounds . height ;
@@ -478,28 +490,29 @@ var ScaleManager = new Class({
478490
479491 updateScalingAndBounds : function ( )
480492 {
493+ var game = this . game ;
481494 var config = this . config ;
482495
483- this . scaleFactor . x = this . config . width / this . width ;
484- this . scaleFactor . y = this . config . height / this . height ;
496+ this . scaleFactor . x = config . width / this . width ;
497+ this . scaleFactor . y = config . height / this . height ;
485498
486- this . scaleFactorInversed . x = this . width / this . config . width ;
487- this . scaleFactorInversed . y = this . height / this . config . height ;
499+ this . scaleFactorInversed . x = this . width / config . width ;
500+ this . scaleFactorInversed . y = this . height / config . height ;
488501
489502 this . aspectRatio = this . width / this . height ;
490503
491504 // This can be invoked in boot pre-canvas
492- if ( this . game . canvas )
505+ if ( game . canvas )
493506 {
494- // this.dom.getOffset(this. game.canvas, this.offset);
507+ GetOffset ( game . canvas , this . offset ) ;
495508 }
496509
497510 this . bounds . setTo ( this . offset . x , this . offset . y , this . width , this . height ) ;
498511
499512 // Can be invoked in boot pre-input
500- if ( this . game . input && this . game . input . scale )
513+ if ( game . input && game . input . scale )
501514 {
502- // this. game.input.scale.setTo(this.scaleFactor.x, this.scaleFactor.y);
515+ // game.input.scale.setTo(this.scaleFactor.x, this.scaleFactor.y);
503516 }
504517 } ,
505518
@@ -541,7 +554,7 @@ var ScaleManager = new Class({
541554 var previousOrientation = this . screenOrientation ;
542555 var previouslyIncorrect = this . incorrectOrientation ;
543556
544- // this.screenOrientation = this.dom.getScreenOrientation (this.compatibility.orientationFallback);
557+ this . screenOrientation = GetScreenOrientation ( this . compatibility . orientationFallback ) ;
545558
546559 this . incorrectOrientation = ( this . forceLandscape && ! this . isLandscape ) || ( this . forcePortrait && ! this . isPortrait ) ;
547560
@@ -672,8 +685,8 @@ var ScaleManager = new Class({
672685 if ( bounds === undefined ) { bounds = new Rectangle ( ) ; }
673686 if ( parentNode === undefined ) { parentNode = this . boundingParent ; }
674687
675- var visualBounds = this . dom . visualBounds ;
676- var layoutBounds = this . dom . layoutBounds ;
688+ var visualBounds = VisualBounds ;
689+ var layoutBounds = LayoutBounds ;
677690
678691 if ( ! parentNode )
679692 {
@@ -858,8 +871,8 @@ var ScaleManager = new Class({
858871
859872 setMaximum : function ( )
860873 {
861- this . width = this . dom . visualBounds . width ;
862- this . height = this . dom . visualBounds . height ;
874+ this . width = VisualBounds . width ;
875+ this . height = VisualBounds . height ;
863876 } ,
864877
865878 setShowAll : function ( expanding )
0 commit comments