AspectRatioExtensions.cs
1 using Ryujinx.Common.Utilities; 2 using System.Text.Json.Serialization; 3 4 namespace Ryujinx.Common.Configuration 5 { 6 [JsonConverter(typeof(TypedStringEnumConverter<AspectRatio>))] 7 public enum AspectRatio 8 { 9 Fixed4x3, 10 Fixed16x9, 11 Fixed16x10, 12 Fixed21x9, 13 Fixed32x9, 14 Stretched, 15 } 16 17 public static class AspectRatioExtensions 18 { 19 public static float ToFloat(this AspectRatio aspectRatio) 20 { 21 return aspectRatio.ToFloatX() / aspectRatio.ToFloatY(); 22 } 23 24 public static float ToFloatX(this AspectRatio aspectRatio) 25 { 26 return aspectRatio switch 27 { 28 #pragma warning disable IDE0055 // Disable formatting 29 AspectRatio.Fixed4x3 => 4.0f, 30 AspectRatio.Fixed16x9 => 16.0f, 31 AspectRatio.Fixed16x10 => 16.0f, 32 AspectRatio.Fixed21x9 => 21.0f, 33 AspectRatio.Fixed32x9 => 32.0f, 34 _ => 16.0f, 35 #pragma warning restore IDE0055 36 }; 37 } 38 39 public static float ToFloatY(this AspectRatio aspectRatio) 40 { 41 return aspectRatio switch 42 { 43 #pragma warning disable IDE0055 // Disable formatting 44 AspectRatio.Fixed4x3 => 3.0f, 45 AspectRatio.Fixed16x9 => 9.0f, 46 AspectRatio.Fixed16x10 => 10.0f, 47 AspectRatio.Fixed21x9 => 9.0f, 48 AspectRatio.Fixed32x9 => 9.0f, 49 _ => 9.0f, 50 #pragma warning restore IDE0055 51 }; 52 } 53 54 public static string ToText(this AspectRatio aspectRatio) 55 { 56 return aspectRatio switch 57 { 58 #pragma warning disable IDE0055 // Disable formatting 59 AspectRatio.Fixed4x3 => "4:3", 60 AspectRatio.Fixed16x9 => "16:9", 61 AspectRatio.Fixed16x10 => "16:10", 62 AspectRatio.Fixed21x9 => "21:9", 63 AspectRatio.Fixed32x9 => "32:9", 64 _ => "Stretched", 65 #pragma warning restore IDE0055 66 }; 67 } 68 } 69 }