Merge pull request #6703 from rexrainbow/expand-scale-mode

Add EXPAND scale mode
This commit is contained in:
Richard Davey 2024-01-12 18:05:39 +00:00 committed by GitHub
commit d6d4fc9705
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 60 additions and 2 deletions

View file

@ -431,7 +431,7 @@ var ScaleManager = new Class({
this.fullscreen = game.device.fullscreen;
if (this.scaleMode !== CONST.SCALE_MODE.RESIZE)
if ((this.scaleMode !== CONST.SCALE_MODE.RESIZE) && (this.scaleMode !== CONST.SCALE_MODE.EXPAND))
{
this.displaySize.setAspectMode(this.scaleMode);
}
@ -1047,6 +1047,53 @@ var ScaleManager = new Class({
this.canvas.width = styleWidth;
this.canvas.height = styleHeight;
}
else if (this.scaleMode === CONST.SCALE_MODE.EXPAND)
{
// Resize to match parent, like RESIZE mode
// This will constrain using min/max
this.displaySize.setSize(this.parentSize.width, this.parentSize.height);
styleWidth = this.displaySize.width;
styleHeight = this.displaySize.height;
if (autoRound)
{
styleWidth = Math.floor(styleWidth);
styleHeight = Math.floor(styleHeight);
}
style.width = styleWidth + 'px';
style.height = styleHeight + 'px';
// Expand canvas size to fit game size's width or height
var scaleX = this.parentSize.width / this.gameSize.width;
var scaleY = this.parentSize.height / this.gameSize.height;
if (scaleX < scaleY)
{
this.baseSize.setSize(this.gameSize.width, this.parentSize.height / scaleX);
}
else
{
this.baseSize.setSize(this.displaySize.width / scaleY, this.gameSize.height);
}
styleWidth = this.baseSize.width;
styleHeight = this.baseSize.height;
if (autoRound)
{
styleWidth = Math.floor(styleWidth);
styleHeight = Math.floor(styleHeight);
}
this.canvas.width = styleWidth;
this.canvas.height = styleHeight;
}
else
{
// All other scale modes

View file

@ -87,6 +87,17 @@ module.exports = {
* @const
* @since 3.16.0
*/
RESIZE: 5
RESIZE: 5,
/**
* The Canvas's visible area is resized to fit all available _parent_ space like RESIZE mode,
* and scale canvas size to fit inside the visible area like FIT mode.
*
* @name Phaser.Scale.ScaleModes.EXPAND
* @type {number}
* @const
* @since 3.70.1
*/
EXPAND : 6
};