Skip to content

Commit

Permalink
Add integer scaling feature
Browse files Browse the repository at this point in the history
  • Loading branch information
SadPencil authored Sep 28, 2024
1 parent 2c170f4 commit 7341533
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions WindowManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,11 @@ public XNAControl SelectedControl
private RenderTarget2D renderTarget;
private RenderTarget2D doubledRenderTarget;

/// <summary>
/// If set, only scales the rendered screen by integer scaling factors. Unfilled space is filled with black.
/// </summary>
public bool IntegerScalingOnly { get; set; }

/// <summary>
/// Sets the rendering (back buffer) resolution of the game.
/// Does not affect the size of the actual game window.
Expand Down Expand Up @@ -182,6 +187,12 @@ private void RecalculateScaling()
double xRatio = (clientAreaWidth) / (double)RenderResolutionX;
double yRatio = (clientAreaHeight) / (double)RenderResolutionY;

if (IntegerScalingOnly && clientAreaWidth >= RenderResolutionX && clientAreaHeight >= RenderResolutionY)
{
xRatio = clientAreaWidth / RenderResolutionX;
yRatio = clientAreaHeight / RenderResolutionY;
}

double ratio;

int texturePositionX = 0;
Expand All @@ -192,12 +203,22 @@ private void RecalculateScaling()
ratio = yRatio;
int textureWidth = (int)(RenderResolutionX * ratio);
texturePositionX = (clientAreaWidth - textureWidth) / 2;
if (IntegerScalingOnly)
{
int textureHeight = (int)(RenderResolutionY * ratio);
texturePositionY = (clientAreaHeight - textureHeight) / 2;
}
}
else
{
ratio = xRatio;
int textureHeight = (int)(RenderResolutionY * ratio);
texturePositionY = (clientAreaHeight - textureHeight) / 2;
if (IntegerScalingOnly)
{
int textureWidth = (int)(RenderResolutionX * ratio);
texturePositionX = (clientAreaWidth - textureWidth) / 2;
}
}

ScaleRatio = ratio;
Expand Down

0 comments on commit 7341533

Please sign in to comment.