From fa6f49dc8aa98f4ca26dda8d37f066af7804a9b2 Mon Sep 17 00:00:00 2001 From: Lesueur Benjamin Date: Wed, 25 Dec 2024 19:08:39 +0100 Subject: [PATCH] Misc UI improvements --- .../Views/Pages/ProfilesPage.xaml.cs | 81 +++++++++--------- .../QuickPages/QuickProfilesPage.xaml.cs | 84 ++++++++++--------- 2 files changed, 85 insertions(+), 80 deletions(-) diff --git a/HandheldCompanion/Views/Pages/ProfilesPage.xaml.cs b/HandheldCompanion/Views/Pages/ProfilesPage.xaml.cs index f734692d1..e20a0c317 100644 --- a/HandheldCompanion/Views/Pages/ProfilesPage.xaml.cs +++ b/HandheldCompanion/Views/Pages/ProfilesPage.xaml.cs @@ -87,10 +87,17 @@ private void MultimediaManager_Initialized() }); } + private bool HasRSRSupport = false; + private bool HasAFMFSupport = false; + private bool HasScalingModeSupport = false; + private bool HasIntegerScalingSupport = false; + private bool HasGPUScalingSupport = false; + private bool IsGPUScalingEnabled = false; + private void GPUManager_Hooked(GPU GPU) { - bool HasRSRSupport = false; - bool HasAFMFSupport = false; + HasRSRSupport = false; + HasAFMFSupport = false; if (GPU is AMDGPU amdGPU) { @@ -104,25 +111,17 @@ private void GPUManager_Hooked(GPU GPU) GPU.IntegerScalingChanged += OnIntegerScalingChanged; GPU.GPUScalingChanged += OnGPUScalingChanged; - bool HasScalingModeSupport = GPU.HasScalingModeSupport(); - bool HasIntegerScalingSupport = GPU.HasIntegerScalingSupport(); - bool HasGPUScalingSupport = GPU.HasGPUScalingSupport(); - bool IsGPUScalingEnabled = GPU.GetGPUScaling(); + HasScalingModeSupport = GPU.HasScalingModeSupport(); + HasIntegerScalingSupport = GPU.HasIntegerScalingSupport(); + HasGPUScalingSupport = GPU.HasGPUScalingSupport(); + IsGPUScalingEnabled = GPU.GetGPUScaling(); // UI thread (async) Application.Current.Dispatcher.BeginInvoke(() => { // GPU-specific settings - StackProfileRSR.Visibility = GPU is AMDGPU ? Visibility.Visible : Visibility.Collapsed; - StackProfileAFMF.Visibility = GPU is AMDGPU ? Visibility.Visible : Visibility.Collapsed; - - StackProfileRSR.IsEnabled = HasGPUScalingSupport && IsGPUScalingEnabled && HasRSRSupport; - StackProfileAFMF.IsEnabled = HasAFMFSupport; - - StackProfileGPUScaling.IsEnabled = HasGPUScalingSupport; - StackProfileIS.IsEnabled = HasGPUScalingSupport && IsGPUScalingEnabled && HasIntegerScalingSupport; - StackProfileRIS.IsEnabled = HasGPUScalingSupport; // check if processor is AMD should be enough - GPUScalingComboBox.IsEnabled = HasScalingModeSupport; + StackProfileRSR.Visibility = GPUManager.GetCurrent() is AMDGPU ? Visibility.Visible : Visibility.Collapsed; + StackProfileAFMF.Visibility = GPUManager.GetCurrent() is AMDGPU ? Visibility.Visible : Visibility.Collapsed; }); } @@ -140,51 +139,55 @@ private void GPUManager_Unhooked(GPU GPU) // UI thread Application.Current.Dispatcher.Invoke(() => { + // GPU-specific settings + StackProfileRSR.Visibility = Visibility.Collapsed; + StackProfileAFMF.Visibility = Visibility.Collapsed; + StackProfileRSR.IsEnabled = false; StackProfileAFMF.IsEnabled = false; + StackProfileGPUScaling.IsEnabled = false; StackProfileIS.IsEnabled = false; - GPUScalingToggle.IsEnabled = false; + StackProfileRIS.IsEnabled = false; GPUScalingComboBox.IsEnabled = false; }); } - private void OnRSRStateChanged(bool Supported, bool Enabled, int Sharpness) + private void UpdateGraphicsSettingsUI() { - // UI thread - Application.Current.Dispatcher.Invoke(() => + // UI thread (async) + Application.Current.Dispatcher.BeginInvoke(() => { - StackProfileRSR.IsEnabled = Supported; + StackProfileRSR.IsEnabled = HasRSRSupport; + StackProfileAFMF.IsEnabled = HasAFMFSupport; + StackProfileGPUScaling.IsEnabled = HasGPUScalingSupport; + StackProfileIS.IsEnabled = HasIntegerScalingSupport; + StackProfileRIS.IsEnabled = HasGPUScalingSupport; // check if processor is AMD should be enough + GPUScalingComboBox.IsEnabled = HasScalingModeSupport; }); } + private void OnRSRStateChanged(bool Supported, bool Enabled, int Sharpness) + { + HasRSRSupport = Supported; + UpdateGraphicsSettingsUI(); + } + private void OnAFMFStateChanged(bool Supported, bool Enabled) { - // UI thread - Application.Current.Dispatcher.Invoke(() => - { - StackProfileAFMF.IsEnabled = Supported; - }); + HasAFMFSupport = Supported; + UpdateGraphicsSettingsUI(); } private void OnGPUScalingChanged(bool Supported, bool Enabled, int Mode) { - // UI thread - Application.Current.Dispatcher.Invoke(() => - { - GPUScalingToggle.IsEnabled = Supported; - StackProfileRIS.IsEnabled = Supported; // check if processor is AMD should be enough - StackProfileRSR.IsEnabled = Supported; - StackProfileIS.IsEnabled = Supported; - }); + HasGPUScalingSupport = Supported; + UpdateGraphicsSettingsUI(); } private void OnIntegerScalingChanged(bool Supported, bool Enabled) { - // UI thread - Application.Current.Dispatcher.Invoke(() => - { - StackProfileIS.IsEnabled = Supported; - }); + HasIntegerScalingSupport = Supported; + UpdateGraphicsSettingsUI(); } private void RTSS_Updated(PlatformStatus status) diff --git a/HandheldCompanion/Views/QuickPages/QuickProfilesPage.xaml.cs b/HandheldCompanion/Views/QuickPages/QuickProfilesPage.xaml.cs index 9c7c0bec3..d6bbf4cbf 100644 --- a/HandheldCompanion/Views/QuickPages/QuickProfilesPage.xaml.cs +++ b/HandheldCompanion/Views/QuickPages/QuickProfilesPage.xaml.cs @@ -170,10 +170,17 @@ private void MultimediaManager_Initialized() }); } + private bool HasRSRSupport = false; + private bool HasAFMFSupport = false; + private bool HasScalingModeSupport = false; + private bool HasIntegerScalingSupport = false; + private bool HasGPUScalingSupport = false; + private bool IsGPUScalingEnabled = false; + private void GPUManager_Hooked(GPU GPU) { - bool HasRSRSupport = false; - bool HasAFMFSupport = false; + HasRSRSupport = false; + HasAFMFSupport = false; if (GPU is AMDGPU amdGPU) { @@ -187,28 +194,18 @@ private void GPUManager_Hooked(GPU GPU) GPU.IntegerScalingChanged += OnIntegerScalingChanged; GPU.GPUScalingChanged += OnGPUScalingChanged; - bool HasScalingModeSupport = GPU.HasScalingModeSupport(); - bool HasIntegerScalingSupport = GPU.HasIntegerScalingSupport(); - bool HasGPUScalingSupport = GPU.HasGPUScalingSupport(); - bool IsGPUScalingEnabled = GPU.GetGPUScaling(); + HasScalingModeSupport = GPU.HasScalingModeSupport(); + HasIntegerScalingSupport = GPU.HasIntegerScalingSupport(); + HasGPUScalingSupport = GPU.HasGPUScalingSupport(); + IsGPUScalingEnabled = GPU.GetGPUScaling(); // UI thread (async) Application.Current.Dispatcher.BeginInvoke(() => { // GPU-specific settings - StackProfileRSR.Visibility = GPU is AMDGPU ? Visibility.Visible : Visibility.Collapsed; - StackProfileAFMF.Visibility = GPU is AMDGPU ? Visibility.Visible : Visibility.Collapsed; + StackProfileRSR.Visibility = GPUManager.GetCurrent() is AMDGPU ? Visibility.Visible : Visibility.Collapsed; + StackProfileAFMF.Visibility = GPUManager.GetCurrent() is AMDGPU ? Visibility.Visible : Visibility.Collapsed; IntegerScalingTypeGrid.Visibility = GPU is IntelGPU ? Visibility.Visible : Visibility.Collapsed; - - StackProfileRSR.IsEnabled = HasGPUScalingSupport && IsGPUScalingEnabled && HasRSRSupport; - StackProfileAFMF.IsEnabled = HasAFMFSupport; - - StackProfileGPUScaling.IsEnabled = HasGPUScalingSupport; - StackProfileIS.IsEnabled = HasGPUScalingSupport && IsGPUScalingEnabled && HasIntegerScalingSupport; - StackProfileRIS.IsEnabled = HasGPUScalingSupport; // check if processor is AMD should be enough - GPUScalingComboBox.IsEnabled = HasScalingModeSupport; - - CurrentDeviceName.Text = GPU.adapterInformation.Details.Description; }); } @@ -226,51 +223,56 @@ private void GPUManager_Unhooked(GPU GPU) // UI thread Application.Current.Dispatcher.Invoke(() => { + // GPU-specific settings + StackProfileRSR.Visibility = Visibility.Collapsed; + StackProfileAFMF.Visibility = Visibility.Collapsed; + IntegerScalingTypeGrid.Visibility = Visibility.Collapsed; + StackProfileRSR.IsEnabled = false; StackProfileAFMF.IsEnabled = false; + StackProfileGPUScaling.IsEnabled = false; StackProfileIS.IsEnabled = false; - GPUScalingToggle.IsEnabled = false; + StackProfileRIS.IsEnabled = false; GPUScalingComboBox.IsEnabled = false; }); } - private void OnRSRStateChanged(bool Supported, bool Enabled, int Sharpness) + private void UpdateGraphicsSettingsUI() { - // UI thread - Application.Current.Dispatcher.Invoke(() => + // UI thread (async) + Application.Current.Dispatcher.BeginInvoke(() => { - StackProfileRSR.IsEnabled = Supported; + StackProfileRSR.IsEnabled = HasRSRSupport; + StackProfileAFMF.IsEnabled = HasAFMFSupport; + StackProfileGPUScaling.IsEnabled = HasGPUScalingSupport; + StackProfileIS.IsEnabled = HasIntegerScalingSupport; + StackProfileRIS.IsEnabled = HasGPUScalingSupport; // check if processor is AMD should be enough + GPUScalingComboBox.IsEnabled = HasScalingModeSupport; }); } + private void OnRSRStateChanged(bool Supported, bool Enabled, int Sharpness) + { + HasRSRSupport = Supported; + UpdateGraphicsSettingsUI(); + } + private void OnAFMFStateChanged(bool Supported, bool Enabled) { - // UI thread - Application.Current.Dispatcher.Invoke(() => - { - StackProfileAFMF.IsEnabled = Supported; - }); + HasAFMFSupport = Supported; + UpdateGraphicsSettingsUI(); } private void OnGPUScalingChanged(bool Supported, bool Enabled, int Mode) { - // UI thread - Application.Current.Dispatcher.Invoke(() => - { - GPUScalingToggle.IsEnabled = Supported; - StackProfileRIS.IsEnabled = Supported; // check if processor is AMD should be enough - StackProfileRSR.IsEnabled = Supported; - StackProfileIS.IsEnabled = Supported; - }); + HasGPUScalingSupport = Supported; + UpdateGraphicsSettingsUI(); } private void OnIntegerScalingChanged(bool Supported, bool Enabled) { - // UI thread - Application.Current.Dispatcher.Invoke(() => - { - StackProfileIS.IsEnabled = Supported; - }); + HasIntegerScalingSupport = Supported; + UpdateGraphicsSettingsUI(); } private void RTSS_Updated(PlatformStatus status)