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
+16 -8
View File
@@ -12,13 +12,13 @@ namespace LunaLightXMG
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;}
@@ -52,8 +52,16 @@ namespace LunaLightXMG
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();
}
@@ -61,12 +69,12 @@ namespace LunaLightXMG
{
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;
}
+2 -2
View File
@@ -15,6 +15,6 @@ Here's what the render handler can do.
Trying out zoom using the render target. The render target is set by retroWidth and retroHeight (320x180).
- ZoomIn() should smoothly zoom to 75% retroWidth x retroHeight, 240x135
- ZoomIn() should smoothly zoom to 50% retroWidth x retroHeight, 160x90
- ZoomOut() should smoothly zoom to 125% retroWidth x retroHeight, 400x225
- ZoomOut() should smoothly zoom to 150% retroWidth x retroHeight, 480x270