Updated RenderHandler zoom functionality.

This commit is contained in:
jme9
2025-03-18 11:51:39 -07:00
parent 0ba801ccff
commit d50de67f82
2 changed files with 21 additions and 13 deletions
+19 -11
View File
@@ -11,14 +11,14 @@ namespace LunaLightXMG
private SpriteBatch spriteBatch;
private RenderTarget2D renderTarget;
private Rectangle renderDestination;
private int retroWidth;
private int retroHeight;
private float retroWidth;
private float retroHeight;
private float zoomLevel = 1.0f;
private float zoomTarget = 1.0f;
private readonly float zoomMin = 0.75f;
private readonly float zoomMin = 0.50f;
private readonly float zoomNorm = 1.0f;
private readonly float zoomMax = 1.25f;
private readonly float zoomMax = 1.50f;
private readonly float zoomSpeed = 0.1f;
public float ZoomLevel {get => zoomLevel;}
@@ -49,24 +49,32 @@ namespace LunaLightXMG
{
zoomTarget = zoomMax;
}
public void UpdateZoom()
{
// interpolate to target
zoomLevel = MathHelper.Lerp(zoomLevel, zoomTarget, zoomSpeed);
// snap to target when we're close enough
if (Math.Abs(zoomLevel - zoomTarget) < 0.001f)
{
zoomLevel = zoomTarget;
}
// stay in bounds (just in case)
zoomLevel = MathHelper.Clamp(zoomLevel, zoomMin, zoomMax);
// calc new zoomed render destination
CalculateRenderDestination();
}
public void CalculateRenderDestination()
{
Point screenSize = graphicsDevice.Viewport.Bounds.Size;
// Calculate the integer scale factor
int scaleX = screenSize.X / (int)(retroWidth * zoomLevel);
int scaleY = screenSize.Y / (int)(retroHeight * zoomLevel);
float scaleX = screenSize.X / (retroWidth * zoomLevel);
float scaleY = screenSize.Y / (retroHeight * zoomLevel);
// Set renderDestination
renderDestination.Width = retroWidth * scaleX;
renderDestination.Height = retroHeight * scaleY;
renderDestination.Width = (int)(retroWidth * scaleX);
renderDestination.Height = (int)(retroHeight * scaleY);
renderDestination.X = (screenSize.X - renderDestination.Width) / 2;
renderDestination.Y = (screenSize.Y - renderDestination.Height) / 2;
}