Skip to content

Commit

Permalink
Add an option to extend width or height and never crop the game area (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
4ian authored Nov 20, 2024
1 parent 44b18cb commit ac6b64b
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 21 deletions.
22 changes: 10 additions & 12 deletions GDJS/Runtime/pixi-renderers/runtimegame-pixi-renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,19 +286,17 @@ namespace gdjs {
if (isFullPage && !this._keepRatio) {
canvasWidth = maxWidth;
canvasHeight = maxHeight;
} else {
if (
(isFullPage && this._keepRatio) ||
canvasWidth > maxWidth ||
canvasHeight > maxHeight
) {
let factor = maxWidth / canvasWidth;
if (canvasHeight * factor > maxHeight) {
factor = maxHeight / canvasHeight;
}
canvasWidth *= factor;
canvasHeight *= factor;
} else if (
(isFullPage && this._keepRatio) ||
canvasWidth > maxWidth ||
canvasHeight > maxHeight
) {
let factor = maxWidth / canvasWidth;
if (canvasHeight * factor > maxHeight) {
factor = maxHeight / canvasHeight;
}
canvasWidth *= factor;
canvasHeight *= factor;
}

// Apply the calculations to the canvas element...
Expand Down
26 changes: 19 additions & 7 deletions GDJS/Runtime/runtimegame.ts
Original file line number Diff line number Diff line change
Expand Up @@ -584,15 +584,27 @@ namespace gdjs {
this._gameResolutionWidth =
(this._gameResolutionHeight * windowInnerWidth) /
windowInnerHeight;
} else {
if (this._resizeMode === 'adaptHeight') {
this._gameResolutionHeight =
(this._gameResolutionWidth * windowInnerHeight) /
windowInnerWidth;
} else if (this._resizeMode === 'adaptHeight') {
this._gameResolutionHeight =
(this._gameResolutionWidth * windowInnerHeight) /
windowInnerWidth;
} else if (this._resizeMode === 'scaleOuter') {
const widthFactor = windowInnerWidth / this._originalWidth;
const heightFactor = windowInnerHeight / this._originalHeight;

if (widthFactor < heightFactor) {
this._gameResolutionWidth = this._originalWidth;
this._gameResolutionHeight = Math.floor(
windowInnerHeight / widthFactor
);
} else {
this._gameResolutionWidth = Math.floor(
windowInnerWidth / heightFactor
);
this._gameResolutionHeight = this._originalHeight;
}
}
}
} else {
}

// Don't alter the game resolution. The renderer
Expand Down Expand Up @@ -1203,7 +1215,7 @@ namespace gdjs {
/**
* Enlarge/reduce the width (or the height) of the game to fill the inner window.
*/
_forceGameResolutionUpdate() {
private _forceGameResolutionUpdate() {
this.setGameResolutionSize(
this._gameResolutionWidth,
this._gameResolutionHeight
Expand Down
8 changes: 6 additions & 2 deletions newIDE/app/src/ProjectManager/ProjectPropertiesDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -624,13 +624,17 @@ const ProjectPropertiesDialog = (props: Props) => {
value=""
label={t`No changes to the game size`}
/>
<SelectOption
value="scaleOuter"
label={t`Extend width or height to fill screen (without cropping the game area)`}
/>
<SelectOption
value="adaptWidth"
label={t`Change width to fit the screen or window size`}
label={t`Adjust width to fill screen (extend or crop)`}
/>
<SelectOption
value="adaptHeight"
label={t`Change height to fit the screen or window size`}
label={t`Adjust height to fill screen (extend or crop)`}
/>
</SelectField>
<Checkbox
Expand Down

0 comments on commit ac6b64b

Please sign in to comment.