Skip to content

Commit e075a73

Browse files
committed
ScaleManager: back-port of "window constraints".
- Adds `ScaleManager#windowContraints` - In 2.1.3 and prior the scale modes (EXACT_FIT, SHOW_ALL) were actually based off the window dimensions, even though the parent element did not correctly reflect this nature. - When set (the default now is that right and bottom are set) the behavior will mostly correctly mimic the 2.1.3 (minus bugs) and before. - CHANGE (from 2.1.3): The window constraints also affect the RESIZE mode, arguably this is more consistent. - To disable this "constrain to window" behavior, simply set the appropriate property to false, as in: `game.scale.windowConstraints.bottom = false`
1 parent 223d444 commit e075a73

1 file changed

Lines changed: 23 additions & 13 deletions

File tree

src/core/ScaleManager.js

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -316,13 +316,13 @@ Phaser.ScaleManager = function (game, width, height) {
316316
this.event = null;
317317

318318
/**
319-
* If `true` then EXACT_FIT and SHOW_ALL will work to fit within the window bounds
320-
* as well as the bounds of the parent container. This preserves 2.1.3 and prior semantics.
319+
* The borders on which to constrain the Canvas _to_ the Window viewport in _addition_ to any restrictions of the parent container.
321320
* @property {boolean} constrainToWindow
322321
* @public
323322
* @default
323+
* @todo Implement left/top constraints.
324324
*/
325-
this.constrainToWindow = true;
325+
this.windowConstraints = {left: false, top: false, bottom: true, right: true};
326326

327327
/**
328328
* Scale mode to be used when not in full screen.
@@ -1170,19 +1170,29 @@ Phaser.ScaleManager.prototype = {
11701170
{
11711171
var clientRect = parentNode.getBoundingClientRect();
11721172

1173-
bounds.setTo(
1174-
Math.round(clientRect.left), Math.round(clientRect.top),
1175-
Math.round(clientRect.width), Math.round(clientRect.height));
1173+
bounds.setTo(clientRect.left, clientRect.top, clientRect.width, clientRect.height);
11761174

1177-
constrainToWindow = true;
1178-
if (constrainToWindow)
1175+
var wc = this.windowConstraints;
1176+
if (wc.left)
1177+
{
1178+
bounds.left = Math.max(bounds.left, 0);
1179+
}
1180+
if (wc.right)
1181+
{
1182+
bounds.right = Math.min(bounds.right, window.innerWidth);
1183+
}
1184+
if (wc.top)
11791185
{
1180-
var offset = Phaser.Canvas.getOffset(parentNode);
1181-
var toRight = Math.round(window.innerWidth - offset.x);
1182-
var toBottom = Math.round(window.innerHeight - offset.y);
1183-
bounds.width = Phaser.Math.clmap(bounds.width, 0, toRight);
1184-
bounds.height = Phaser.Math.clmap(bounds.height, 0, toBottom);
1186+
bounds.top = Math.max(bounds.top, 0);
11851187
}
1188+
if (wc.bottom)
1189+
{
1190+
bounds.bottom = Math.min(bounds.bottom, window.innerHeight);
1191+
}
1192+
1193+
bounds.setTo(
1194+
Math.round(bounds.x), Math.round(bounds.y),
1195+
Math.round(bounds.width), Math.round(bounds.height));
11861196
}
11871197

11881198
return bounds;

0 commit comments

Comments
 (0)