Skip to content

Commit 75665d3

Browse files
committed
feat(settings): add hardware graphics acceleration toggle and update settings management
1 parent ffef710 commit 75665d3

3 files changed

Lines changed: 43 additions & 10 deletions

File tree

source/RevitDevTool/Application.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
using Autodesk.Revit.UI;
1+
using System.Windows.Interop ;
2+
using System.Windows.Media ;
3+
using Autodesk.Revit.UI;
24
using Nice3point.Revit.Toolkit.External;
35
using RevitDevTool.Commands;
46
using RevitDevTool.Services ;
@@ -14,6 +16,7 @@ public override void OnStartup()
1416
ExternalEventController.Register();
1517
SettingsService.Instance.LoadSettings();
1618
ThemeWatcher.Instance.Initialize();
19+
EnableHardwareRendering();
1720
AddButton(Application);
1821
AddDockable(Application);
1922
}
@@ -24,6 +27,18 @@ public override void OnShutdown()
2427
VisualizationController.Stop();
2528
}
2629

30+
public static void EnableHardwareRendering()
31+
{
32+
if (!SettingsService.Instance.GeneralConfig.UseHardwareRendering) return;
33+
ExternalEventController.ActionEventHandler.Raise(_ => RenderOptions.ProcessRenderMode = RenderMode.Default);
34+
}
35+
36+
public static void DisableHardwareRendering()
37+
{
38+
if (SettingsService.Instance.GeneralConfig.UseHardwareRendering) return;
39+
RenderOptions.ProcessRenderMode = RenderMode.SoftwareOnly;
40+
}
41+
2742
private static void AddDockable(UIControlledApplication application)
2843
{
2944
TraceCommand.RegisterDockablePane(application);

source/RevitDevTool/View/Settings/GeneralSettingsView.xaml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,21 @@
3333
SelectedItem="{Binding Theme}" />
3434
</ui:CardControl>
3535
</StackPanel>
36-
36+
<ui:CardControl
37+
Margin="0,4,0,0"
38+
Icon="{ui:SymbolIcon TopSpeed24}">
39+
<ui:CardControl.Header>
40+
<StackPanel>
41+
<ui:TextBlock Text="Hardware graphics acceleration" />
42+
<ui:TextBlock
43+
Appearance="Secondary"
44+
FontTypography="Caption"
45+
Text="Offloads graphic rendering from the CPU to the GPU"
46+
TextTrimming="CharacterEllipsis" />
47+
</StackPanel>
48+
</ui:CardControl.Header>
49+
<ui:ToggleSwitch IsChecked="{Binding UseHardwareRendering}" />
50+
</ui:CardControl>
3751
<ui:CardAction
3852
Margin="0,4,0,0"
3953
Command="{Binding ResetSettingsCommand}"

source/RevitDevTool/ViewModel/Settings/GeneralSettingsViewModel.cs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,40 +11,44 @@ public partial class GeneralSettingsViewModel : ObservableObject
1111

1212
public static List<ApplicationTheme> Themes
1313
{
14-
#if REVIT2024_OR_GREATER
1514
get =>
1615
[
1716
ApplicationTheme.Light,
1817
ApplicationTheme.Dark,
18+
#if REVIT2024_OR_GREATER
1919
ApplicationTheme.Auto
20-
];
21-
#else
22-
get =>
23-
[
24-
ApplicationTheme.Light,
25-
ApplicationTheme.Dark
26-
];
2720
#endif
21+
];
2822
}
2923

3024
[ObservableProperty] private ApplicationTheme _theme;
25+
[ObservableProperty] private bool _useHardwareRendering;
3126

3227
partial void OnThemeChanged( ApplicationTheme value )
3328
{
3429
SettingsService.Instance.GeneralConfig.Theme = value;
3530
ThemeWatcher.Instance.ApplyTheme();
3631
}
3732

33+
partial void OnUseHardwareRenderingChanged(bool value)
34+
{
35+
SettingsService.Instance.GeneralConfig.UseHardwareRendering = value;
36+
if (value) Application.EnableHardwareRendering();
37+
else Application.DisableHardwareRendering();
38+
}
39+
3840
private GeneralSettingsViewModel()
3941
{
4042
Theme = SettingsService.Instance.GeneralConfig.Theme;
43+
UseHardwareRendering = SettingsService.Instance.GeneralConfig.UseHardwareRendering;
4144
}
4245

4346
[RelayCommand] private void ResetSettings()
4447
{
4548
SettingsService.Instance.ResetVisualizationSettings();
4649
SettingsService.Instance.ResetGeneralSettings();
4750
Theme = SettingsService.Instance.GeneralConfig.Theme;
51+
UseHardwareRendering = SettingsService.Instance.GeneralConfig.UseHardwareRendering;
4852
VisualizationController.Refresh();
4953
Trace.TraceInformation("Reset settings to default");
5054
}

0 commit comments

Comments
 (0)