From 8066586328fafcfd538b8180361194f8181e8091 Mon Sep 17 00:00:00 2001 From: Robert Date: Thu, 8 Apr 2021 23:51:56 +0200 Subject: [PATCH] Layer brush/effect dialogs - Fixed default location Layer properties - Give it a best effort to avoid null base values --- .../Profile/LayerProperties/LayerProperty.cs | 10 +++++- .../Windows/LayerBrushSettingsWindowView.xaml | 6 ++-- .../LayerBrushSettingsWindowViewModel.cs | 32 ++++++++++++------- .../LayerEffectSettingsWindowView.xaml | 4 +-- .../LayerEffectSettingsWindowViewModel.cs | 32 ++++++++++++------- 5 files changed, 53 insertions(+), 31 deletions(-) diff --git a/src/Artemis.Core/Models/Profile/LayerProperties/LayerProperty.cs b/src/Artemis.Core/Models/Profile/LayerProperties/LayerProperty.cs index ba025df39..e5733c8e2 100644 --- a/src/Artemis.Core/Models/Profile/LayerProperties/LayerProperty.cs +++ b/src/Artemis.Core/Models/Profile/LayerProperties/LayerProperty.cs @@ -34,7 +34,15 @@ namespace Artemis.Core CurrentValue = default!; DefaultValue = default!; - _baseValue = typeof(T).IsValueType ? default! : Activator.CreateInstance(); + // We'll try our best... + // TODO: Consider alternatives + if (typeof(T).IsValueType) + _baseValue = default!; + else if (typeof(T).GetConstructor(Type.EmptyTypes) != null) + _baseValue = Activator.CreateInstance(); + else + _baseValue = default!; + _keyframes = new List>(); } diff --git a/src/Artemis.UI/Screens/ProfileEditor/Windows/LayerBrushSettingsWindowView.xaml b/src/Artemis.UI/Screens/ProfileEditor/Windows/LayerBrushSettingsWindowView.xaml index b904b2b45..25256ee61 100644 --- a/src/Artemis.UI/Screens/ProfileEditor/Windows/LayerBrushSettingsWindowView.xaml +++ b/src/Artemis.UI/Screens/ProfileEditor/Windows/LayerBrushSettingsWindowView.xaml @@ -12,10 +12,8 @@ Background="{DynamicResource MaterialDesignPaper}" FontFamily="pack://application:,,,/MaterialDesignThemes.Wpf;component/Resources/Roboto/#Roboto" UseLayoutRounding="True" - MinWidth="400" - MinHeight="400" - Width="{Binding Width}" - Height="{Binding Height}" + Height="800" + Width="800" d:DesignHeight="800" d:DesignWidth="800" d:DataContext="{d:DesignInstance windows:LayerBrushSettingsWindowViewModel}" diff --git a/src/Artemis.UI/Screens/ProfileEditor/Windows/LayerBrushSettingsWindowViewModel.cs b/src/Artemis.UI/Screens/ProfileEditor/Windows/LayerBrushSettingsWindowViewModel.cs index c183050ab..afeab8cb0 100644 --- a/src/Artemis.UI/Screens/ProfileEditor/Windows/LayerBrushSettingsWindowViewModel.cs +++ b/src/Artemis.UI/Screens/ProfileEditor/Windows/LayerBrushSettingsWindowViewModel.cs @@ -1,4 +1,5 @@ using System; +using System.Windows; using Artemis.UI.Shared.LayerBrushes; using Stylet; @@ -6,28 +7,35 @@ namespace Artemis.UI.Screens.ProfileEditor.Windows { public class LayerBrushSettingsWindowViewModel : Conductor { - private int _height; - private int _width; + private readonly LayerBrushConfigurationDialog _configuration; public LayerBrushSettingsWindowViewModel(BrushConfigurationViewModel configurationViewModel, LayerBrushConfigurationDialog configuration) { + _configuration = configuration; ActiveItem = configurationViewModel ?? throw new ArgumentNullException(nameof(configurationViewModel)); ActiveItem.Closed += ActiveItemOnClosed; - Width = configuration.DialogWidth; - Height = configuration.DialogHeight; } - public int Width + #region Overrides of Screen + + /// + protected override void OnViewLoaded() { - get => _width; - set => SetAndNotify(ref _width, value); + // Setting the width/height via a binding and depending on WindowStartupLocation does not work + Window window = View as Window; + Window mainWindow = Application.Current.MainWindow; + if (window == null || mainWindow == null) + return; + + window.Width = _configuration.DialogWidth; + window.Height = _configuration.DialogHeight; + window.Left = mainWindow.Left + (mainWindow.Width - window.Width) / 2; + window.Top = mainWindow.Top + (mainWindow.Height - window.Height) / 2; + + base.OnViewLoaded(); } - public int Height - { - get => _height; - set => SetAndNotify(ref _height, value); - } + #endregion private void ActiveItemOnClosed(object sender, CloseEventArgs e) { diff --git a/src/Artemis.UI/Screens/ProfileEditor/Windows/LayerEffectSettingsWindowView.xaml b/src/Artemis.UI/Screens/ProfileEditor/Windows/LayerEffectSettingsWindowView.xaml index 2af4dc2ed..a7cb413e4 100644 --- a/src/Artemis.UI/Screens/ProfileEditor/Windows/LayerEffectSettingsWindowView.xaml +++ b/src/Artemis.UI/Screens/ProfileEditor/Windows/LayerEffectSettingsWindowView.xaml @@ -14,8 +14,8 @@ UseLayoutRounding="True" MinWidth="400" MinHeight="400" - Width="{Binding Width}" - Height="{Binding Height}" + Width="800" + Height="800" d:DesignHeight="800" d:DesignWidth="800" d:DataContext="{d:DesignInstance windows:LayerEffectSettingsWindowViewModel}" diff --git a/src/Artemis.UI/Screens/ProfileEditor/Windows/LayerEffectSettingsWindowViewModel.cs b/src/Artemis.UI/Screens/ProfileEditor/Windows/LayerEffectSettingsWindowViewModel.cs index de2144edd..a1a8a4049 100644 --- a/src/Artemis.UI/Screens/ProfileEditor/Windows/LayerEffectSettingsWindowViewModel.cs +++ b/src/Artemis.UI/Screens/ProfileEditor/Windows/LayerEffectSettingsWindowViewModel.cs @@ -1,4 +1,5 @@ using System; +using System.Windows; using Artemis.UI.Shared.LayerEffects; using Stylet; @@ -6,28 +7,35 @@ namespace Artemis.UI.Screens.ProfileEditor.Windows { public class LayerEffectSettingsWindowViewModel : Conductor { - private int _height; - private int _width; + private LayerEffectConfigurationDialog _configuration; public LayerEffectSettingsWindowViewModel(EffectConfigurationViewModel configurationViewModel, LayerEffectConfigurationDialog configuration) { + _configuration = configuration; ActiveItem = configurationViewModel ?? throw new ArgumentNullException(nameof(configurationViewModel)); ActiveItem.Closed += ActiveItemOnClosed; - Width = configuration.DialogWidth; - Height = configuration.DialogHeight; } - public int Width + #region Overrides of Screen + + /// + protected override void OnViewLoaded() { - get => _width; - set => SetAndNotify(ref _width, value); + // Setting the width/height via a binding and depending on WindowStartupLocation does not work + Window window = View as Window; + Window mainWindow = Application.Current.MainWindow; + if (window == null || mainWindow == null) + return; + + window.Width = _configuration.DialogWidth; + window.Height = _configuration.DialogHeight; + window.Left = mainWindow.Left + (mainWindow.Width - window.Width) / 2; + window.Top = mainWindow.Top + (mainWindow.Height - window.Height) / 2; + + base.OnViewLoaded(); } - public int Height - { - get => _height; - set => SetAndNotify(ref _height, value); - } + #endregion private void ActiveItemOnClosed(object sender, CloseEventArgs e) {