@@ -54,6 +54,16 @@ var InputManager = new Class({
5454 */
5555 this . game = game ;
5656
57+ /**
58+ * A reference to the global Game Scale Manager.
59+ * Used for all bounds checks and pointer scaling.
60+ *
61+ * @name Phaser.Input.InputManager#scaleManager
62+ * @type {Phaser.DOM.ScaleManager }
63+ * @since 3.16.0
64+ */
65+ this . scaleManager ;
66+
5767 /**
5868 * The Canvas that is used for all DOM event input listeners.
5969 *
@@ -298,15 +308,6 @@ var InputManager = new Class({
298308 */
299309 this . dirty = false ;
300310
301- /**
302- * The Scale factor being applied to input coordinates.
303- *
304- * @name Phaser.Input.InputManager#scale
305- * @type { { x:number, y:number } }
306- * @since 3.0.0
307- */
308- this . scale = { x : 1 , y : 1 } ;
309-
310311 /**
311312 * If the top-most Scene in the Scene List receives an input it will stop input from
312313 * propagating any lower down the scene list, i.e. if you have a UI Scene at the top
@@ -396,7 +397,7 @@ var InputManager = new Class({
396397 {
397398 this . canvas = this . game . canvas ;
398399
399- this . updateBounds ( ) ;
400+ this . scaleManager = this . game . scale ;
400401
401402 this . events . emit ( 'boot' ) ;
402403
@@ -405,48 +406,6 @@ var InputManager = new Class({
405406 this . game . events . once ( 'destroy' , this . destroy , this ) ;
406407 } ,
407408
408- /**
409- * Updates the Input Manager bounds rectangle to match the bounding client rectangle of the
410- * canvas element being used to track input events.
411- *
412- * @method Phaser.Input.InputManager#updateBounds
413- * @since 3.0.0
414- */
415- updateBounds : function ( )
416- {
417- var bounds = this . bounds ;
418-
419- var clientRect = this . canvas . getBoundingClientRect ( ) ;
420-
421- bounds . x = clientRect . left + window . pageXOffset - document . documentElement . clientLeft ;
422- bounds . y = clientRect . top + window . pageYOffset - document . documentElement . clientTop ;
423- bounds . width = clientRect . width ;
424- bounds . height = clientRect . height ;
425- } ,
426-
427- /**
428- * Resizes the Input Manager internal values, including the bounds and scale factor.
429- *
430- * @method Phaser.Input.InputManager#resize
431- * @since 3.2.0
432- */
433- resize : function ( )
434- {
435- this . updateBounds ( ) ;
436-
437- // Game config size
438- var gw = this . game . config . width ;
439- var gh = this . game . config . height ;
440-
441- // Actual canvas size
442- var bw = this . bounds . width ;
443- var bh = this . bounds . height ;
444-
445- // Scale factor
446- this . scale . x = gw / bw ;
447- this . scale . y = gh / bh ;
448- } ,
449-
450409 /**
451410 * Internal canvas state change, called automatically by the Mouse Manager.
452411 *
@@ -521,11 +480,6 @@ var InputManager = new Class({
521480
522481 this . dirty = true ;
523482
524- this . updateBounds ( ) ;
525-
526- this . scale . x = this . game . config . width / this . bounds . width ;
527- this . scale . y = this . game . config . height / this . bounds . height ;
528-
529483 // Clears the queue array, and also means we don't work on array data that could potentially
530484 // be modified during the processing phase
531485 var queue = this . queue . splice ( 0 , len ) ;
@@ -1412,8 +1366,8 @@ var InputManager = new Class({
14121366 p1 . y = p0 . y ;
14131367
14141368 // Translate coordinates
1415- var x = ( pageX - this . bounds . left ) * this . scale . x ;
1416- var y = ( pageY - this . bounds . top ) * this . scale . y ;
1369+ var x = this . scaleManager . transformX ( pageX ) ;
1370+ var y = this . scaleManager . transformY ( pageY ) ;
14171371
14181372 var a = pointer . smoothFactor ;
14191373
@@ -1431,88 +1385,6 @@ var InputManager = new Class({
14311385 }
14321386 } ,
14331387
1434- /**
1435- * Transforms the pageX value into the scaled coordinate space of the Input Manager.
1436- *
1437- * @method Phaser.Input.InputManager#transformX
1438- * @since 3.0.0
1439- *
1440- * @param {number } pageX - The DOM pageX value.
1441- *
1442- * @return {number } The translated value.
1443- */
1444- transformX : function ( pageX )
1445- {
1446- return ( pageX - this . bounds . left ) * this . scale . x ;
1447- } ,
1448-
1449- /**
1450- * Transforms the pageY value into the scaled coordinate space of the Input Manager.
1451- *
1452- * @method Phaser.Input.InputManager#transformY
1453- * @since 3.0.0
1454- *
1455- * @param {number } pageY - The DOM pageY value.
1456- *
1457- * @return {number } The translated value.
1458- */
1459- transformY : function ( pageY )
1460- {
1461- return ( pageY - this . bounds . top ) * this . scale . y ;
1462- } ,
1463-
1464- /**
1465- * Returns the left offset of the Input bounds.
1466- *
1467- * @method Phaser.Input.InputManager#getOffsetX
1468- * @since 3.0.0
1469- *
1470- * @return {number } The left bounds value.
1471- */
1472- getOffsetX : function ( )
1473- {
1474- return this . bounds . left ;
1475- } ,
1476-
1477- /**
1478- * Returns the top offset of the Input bounds.
1479- *
1480- * @method Phaser.Input.InputManager#getOffsetY
1481- * @since 3.0.0
1482- *
1483- * @return {number } The top bounds value.
1484- */
1485- getOffsetY : function ( )
1486- {
1487- return this . bounds . top ;
1488- } ,
1489-
1490- /**
1491- * Returns the horizontal Input Scale value.
1492- *
1493- * @method Phaser.Input.InputManager#getScaleX
1494- * @since 3.0.0
1495- *
1496- * @return {number } The horizontal scale factor of the input.
1497- */
1498- getScaleX : function ( )
1499- {
1500- return this . game . config . width / this . bounds . width ;
1501- } ,
1502-
1503- /**
1504- * Returns the vertical Input Scale value.
1505- *
1506- * @method Phaser.Input.InputManager#getScaleY
1507- * @since 3.0.0
1508- *
1509- * @return {number } The vertical scale factor of the input.
1510- */
1511- getScaleY : function ( )
1512- {
1513- return this . game . config . height / this . bounds . height ;
1514- } ,
1515-
15161388 /**
15171389 * Destroys the Input Manager and all of its systems.
15181390 *
0 commit comments