/// <summary> /// Returns the extra height added by the top and bottom borders extending before the 4:3 aspect. /// </summary> public float GetBorderHeightY(float actualAspect, float width) { if (actualAspect < AspectRatioLimit) { AspectConverter.WidthToResolution((int)width, actualAspect, out Resolution resolutionOurAspect); AspectConverter.WidthToResolution((int)width, AspectConverter.OriginalGameAspect, out Resolution resolutionGameAspect); return(resolutionOurAspect.Height - resolutionGameAspect.Height); } return(0); }
/// <summary> /// Returns the extra width added by the left and right borders extending beyond the 4:3 aspect. /// </summary> public float GetBorderWidthX(float actualAspect, float height) { if (actualAspect > AspectRatioLimit) { AspectConverter.HeightToResolution((int)height, actualAspect, out Resolution resolutionOurAspect); AspectConverter.HeightToResolution((int)height, AspectConverter.OriginalGameAspect, out Resolution resolutionGameAspect); return(resolutionOurAspect.Width - resolutionGameAspect.Width); } return(0); }
/// <summary> /// Used for shifting item locations of an orthographic projection (e.g. special stage HUD) /// that are relative to the left edge of the screen. /// Note: Assumes resolution is 640x480. /// </summary> /// <param name="originalPosition">Original position of the object.</param> /// <param name="relativeAspectRatio">Relative aspect ratio of the desired aspect compared to game's aspect.</param> /// <param name="actualAspect">The desired aspect ratio.</param> public float ProjectFromOldToNewCanvasX(float originalPosition, float relativeAspectRatio, float actualAspect) { if (actualAspect > AspectRatioLimit) { // Now the projection is the right size, however it is not centered to our screen. AspectConverter.HeightToResolution((int)GameCanvasHeight, actualAspect, out Resolution resolution); // Get resolution with our aspect equal to the height. float borderWidth = resolution.Width - GameCanvasWidth; // Get the extra width (left and right border) float leftBorderOnly = (borderWidth / 2); // We only want left border. float originalPlusLeftBorder = leftBorderOnly + originalPosition; return(originalPlusLeftBorder / relativeAspectRatio); } return(originalPosition); }
/// <summary> /// Used for shifting item locations of an orthographic projection (e.g. special stage HUD) /// that are relative to the top edge of the screen. /// Note: Assumes resolution is 640x480. /// </summary> /// <param name="originalPosition">Original position of the object.</param> /// <param name="relativeAspectRatio">Relative aspect ratio of the desired aspect compared to game's aspect.</param> /// <param name="actualAspect">The desired aspect ratio.</param> public float ProjectFromOldToNewCanvasY(float originalPosition, float relativeAspectRatio, float actualAspect) { if (actualAspect < AspectRatioLimit) { // Now the projection is the right size, however it is not centered to our screen. AspectConverter.WidthToResolution((int)GameCanvasWidth, actualAspect, out Resolution resolution); // Get resolution with our aspect equal to the height. float borderHeight = resolution.Height - GameCanvasHeight; // Get the extra height (top and bottom border) float topBorderOnly = (borderHeight / 2); // We only want top border. float originalPlusTopBorder = topBorderOnly + originalPosition; // Our top border is in the aspect ratio it originated from, // we need to scale it to the new ratio. return(originalPlusTopBorder * relativeAspectRatio); } return(originalPosition); }