AspectRatioExtensions.cs 1.9 KB

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