MainStatusBarView.axaml.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. using Avalonia;
  2. using Avalonia.Controls;
  3. using Avalonia.Input;
  4. using Avalonia.Interactivity;
  5. using Ryujinx.Ava.UI.Windows;
  6. using Ryujinx.Common.Configuration;
  7. using Ryujinx.Common.Logging;
  8. using Ryujinx.UI.Common.Configuration;
  9. using System;
  10. namespace Ryujinx.Ava.UI.Views.Main
  11. {
  12. public partial class MainStatusBarView : UserControl
  13. {
  14. public MainWindow Window;
  15. public MainStatusBarView()
  16. {
  17. InitializeComponent();
  18. }
  19. protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e)
  20. {
  21. base.OnAttachedToVisualTree(e);
  22. if (VisualRoot is MainWindow window)
  23. {
  24. Window = window;
  25. }
  26. DataContext = Window.ViewModel;
  27. }
  28. private void VsyncStatus_PointerReleased(object sender, PointerReleasedEventArgs e)
  29. {
  30. Window.ViewModel.AppHost.Device.EnableDeviceVsync = !Window.ViewModel.AppHost.Device.EnableDeviceVsync;
  31. Logger.Info?.Print(LogClass.Application, $"VSync toggled to: {Window.ViewModel.AppHost.Device.EnableDeviceVsync}");
  32. }
  33. private void DockedStatus_PointerReleased(object sender, PointerReleasedEventArgs e)
  34. {
  35. ConfigurationState.Instance.System.EnableDockedMode.Value = !ConfigurationState.Instance.System.EnableDockedMode.Value;
  36. }
  37. private void AspectRatioStatus_OnClick(object sender, RoutedEventArgs e)
  38. {
  39. AspectRatio aspectRatio = ConfigurationState.Instance.Graphics.AspectRatio.Value;
  40. ConfigurationState.Instance.Graphics.AspectRatio.Value = (int)aspectRatio + 1 > Enum.GetNames(typeof(AspectRatio)).Length - 1 ? AspectRatio.Fixed4x3 : aspectRatio + 1;
  41. }
  42. private void Refresh_OnClick(object sender, RoutedEventArgs e)
  43. {
  44. Window.LoadApplications();
  45. }
  46. private void VolumeStatus_OnPointerWheelChanged(object sender, PointerWheelEventArgs e)
  47. {
  48. // Change the volume by 5% at a time
  49. float newValue = Window.ViewModel.Volume + (float)e.Delta.Y * 0.05f;
  50. Window.ViewModel.Volume = newValue switch
  51. {
  52. < 0 => 0,
  53. > 1 => 1,
  54. _ => newValue,
  55. };
  56. e.Handled = true;
  57. }
  58. }
  59. }