AspectRatioExtensions.cs 1.7 KB

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