More screen stretch modes plugin

Introduction
Add 2 new screen stetch modes. They can be toggled with F3.
Original(contain) strech: the game screen stretches to fit inside the window while keeping its aspect ratio.
1721866194144.png

Full stretch: the game screen stetches to fit both width and height.
1721866215297.png

Cover strech: the game screen stretches to cover the entire window, while keeping its aspect ratio. The contents outside the window will be clipped.
1721866145382.png

No stretch: turn off stretch mode.
1721866283074.png


Terms
You can use it in any project, credit is not required.

How to Use
Save the code as a js file and put it in plugins directory. There are no parameters for this plugin, just turn it on in the editor.

JavaScript:
//=============================================================================
// ScreenStretch.js
//=============================================================================

/*:
 * @plugindesc Add new stetch modes.
 * @author utunnels
 *
 * @help Add 2 new screen stetch modes. They can be toggled with F3.
 Original(contain) strech: the game screen stretches to fit inside the window
 while keeping its aspect ratio.
 Full stretch: the game screen stetches to fit both width and height.
 Cover strech: the game screen stretches to cover the entire window, while
 keeping its aspect ratio. The contents outside the window will be clipped.
 No stretch: turn off stretch mode.
 */
Graphics._defaultStretchMode = function() {
    return (Utils.isNwjs() || Utils.isMobileDevice())?2:0;
};

Graphics._switchStretchMode = function() {
    this._stretchEnabled++;
    if(this._stretchEnabled>3) this._stretchEnabled = 0;
    this._updateAllElements();
};

Graphics._updateRealScale = function() {
    if (this._stretchEnabled) {
        const h = this._stretchWidth() / this._width;
        const v = this._stretchHeight() / this._height;
        this._realScale = (this._stretchEnabled==3?Math.max:Math.min)(h, v);
        this._realScaleX = h;
        this._realScaleY = v;
        window.scrollTo(0, 0);
    } else {
        this._realScale = this._scale;
        this._realScaleX = this._scale;
        this._realScaleY = this._scale;
    }
};

Graphics._stretchWidth = Graphics._stretchWidth||function() {
    if (Utils.isMobileDevice()) {
        return document.documentElement.clientWidth;
    } else {
        return window.innerWidth;
    }
};

Graphics._stretchHeight = Graphics._stretchHeight||function() {
    if (Utils.isMobileDevice()) {
        return document.documentElement.clientHeight;
    } else {
        return window.innerHeight;
    }
};

Graphics._centerElement = function(element) {
    var width = element.width * (this._stretchEnabled!=2?this._realScale:this._realScaleX);
    var height = element.height * (this._stretchEnabled!=2?this._realScale:this._realScaleY);
    element.style.position = 'absolute';
    element.style.margin = 0;
    element.style.left = (window.innerWidth-width)/2 + 'px';
    element.style.top = (window.innerHeight-height)/2 + 'px';
    element.style.width = width + 'px';
    element.style.height = height + 'px';
    document.body.style.overflow = 'hidden';
};

Graphics.pageToCanvasX = function(x) {
    if (this._canvas) {
        var left = this._canvas.offsetLeft;
        var scalex = this._canvas.clientWidth/this._canvas.width;
        return Math.round((x - left) / scalex);
    } else {
        return 0;
    }
};

Graphics.pageToCanvasY = function(y) {
    if (this._canvas) {
        var top = this._canvas.offsetTop;
        var scaley = this._canvas.clientHeight/this._canvas.height;
        return Math.round((y - top) / scaley);
    } else {
        return 0;
    }
};
It might be helpful for people if you added some screenshots of what these different modes look like with the same sample map.
You are right. I just added some screenshots.
I guess nowadays most of the players are using 16:9 monitor. But I saw some game which has both a mobile and pc version.
The mobile version basically extends the sceen and put unimportant things beyond the 16:9 area, like a deorative frame, a menu background, etc.

Original thread: https://forums.rpgmakerweb.com/threads/more-screen-stretch-modes-plugin.170575/