private static void SetAspectRatioTo(decimal aspectRatio, WidthOrHeight dominantInternalCoordinates, int desiredWidth, int desiredHeight) { var resolutionAspectRatio = FlatRedBall.FlatRedBallServices.GraphicsOptions.ResolutionWidth / (decimal)FlatRedBall.FlatRedBallServices.GraphicsOptions.ResolutionHeight; int destinationRectangleWidth; int destinationRectangleHeight; int x = 0; int y = 0; if (aspectRatio > resolutionAspectRatio) { destinationRectangleWidth = FlatRedBall.FlatRedBallServices.GraphicsOptions.ResolutionWidth; destinationRectangleHeight = FlatRedBall.Math.MathFunctions.RoundToInt(destinationRectangleWidth / (float)aspectRatio); y = (FlatRedBall.FlatRedBallServices.GraphicsOptions.ResolutionHeight - destinationRectangleHeight) / 2; } else { destinationRectangleHeight = FlatRedBall.FlatRedBallServices.GraphicsOptions.ResolutionHeight; destinationRectangleWidth = FlatRedBall.Math.MathFunctions.RoundToInt(destinationRectangleHeight * (float)aspectRatio); x = (FlatRedBall.FlatRedBallServices.GraphicsOptions.ResolutionWidth - destinationRectangleWidth) / 2; } FlatRedBall.Camera.Main.DestinationRectangle = new Microsoft.Xna.Framework.Rectangle(x, y, destinationRectangleWidth, destinationRectangleHeight); if (dominantInternalCoordinates == WidthOrHeight.Height) { FlatRedBall.Camera.Main.OrthogonalHeight = desiredHeight; FlatRedBall.Camera.Main.FixAspectRatioYConstant(); } else { FlatRedBall.Camera.Main.OrthogonalWidth = desiredWidth; FlatRedBall.Camera.Main.FixAspectRatioXConstant(); } }
private static void SetAspectRatioTo(decimal aspectRatio, WidthOrHeight dominantInternalCoordinates, int desiredWidth, int desiredHeight) { var resolutionAspectRatio = FlatRedBall.FlatRedBallServices.GraphicsOptions.ResolutionWidth / (decimal)FlatRedBall.FlatRedBallServices.GraphicsOptions.ResolutionHeight; int destinationRectangleWidth; int destinationRectangleHeight; int x = 0; int y = 0; if (aspectRatio > resolutionAspectRatio) { destinationRectangleWidth = FlatRedBall.FlatRedBallServices.GraphicsOptions.ResolutionWidth; destinationRectangleHeight = FlatRedBall.Math.MathFunctions.RoundToInt(destinationRectangleWidth / (float)aspectRatio); y = (FlatRedBall.FlatRedBallServices.GraphicsOptions.ResolutionHeight - destinationRectangleHeight) / 2; } else { destinationRectangleHeight = FlatRedBall.FlatRedBallServices.GraphicsOptions.ResolutionHeight; destinationRectangleWidth = FlatRedBall.Math.MathFunctions.RoundToInt(destinationRectangleHeight * (float)aspectRatio); x = (FlatRedBall.FlatRedBallServices.GraphicsOptions.ResolutionWidth - destinationRectangleWidth) / 2; } foreach (var camera in FlatRedBall.SpriteManager.Cameras) { int currentX = x; int currentY = y; int currentWidth = destinationRectangleWidth; int currentHeight = destinationRectangleHeight; switch (camera.CurrentSplitScreenViewport) { case Camera.SplitScreenViewport.TopLeft: currentWidth /= 2; currentHeight /= 2; break; case Camera.SplitScreenViewport.TopRight: currentX = x + destinationRectangleWidth / 2; currentWidth /= 2; currentHeight /= 2; break; case Camera.SplitScreenViewport.BottomLeft: currentY = y + destinationRectangleHeight / 2; currentWidth /= 2; currentHeight /= 2; break; case Camera.SplitScreenViewport.BottomRight: currentX = x + destinationRectangleWidth / 2; currentY = y + destinationRectangleHeight / 2; currentWidth /= 2; currentHeight /= 2; break; case Camera.SplitScreenViewport.TopHalf: currentHeight /= 2; break; case Camera.SplitScreenViewport.BottomHalf: currentY = y + destinationRectangleHeight / 2; currentHeight /= 2; break; case Camera.SplitScreenViewport.LeftHalf: currentWidth /= 2; break; case Camera.SplitScreenViewport.RightHalf: currentX = x + destinationRectangleWidth / 2; currentWidth /= 2; break; } camera.DestinationRectangle = new Microsoft.Xna.Framework.Rectangle(currentX, currentY, currentWidth, currentHeight); if (dominantInternalCoordinates == WidthOrHeight.Height) { camera.OrthogonalHeight = desiredHeight; camera.FixAspectRatioYConstant(); } else { camera.OrthogonalWidth = desiredWidth; camera.FixAspectRatioXConstant(); } } }