1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-13 05:48:35 +00:00

Core - Create default instances for properties

UI - Added configurable width/height for brush dialogs
This commit is contained in:
Robert 2021-04-08 00:39:26 +02:00
parent f4e3011957
commit 903e434137
12 changed files with 109 additions and 14 deletions

View File

@ -9,6 +9,7 @@
RegisterDataBindingProperty(() => CurrentValue.End, value => CurrentValue.End = value, new FloatDataBindingConverter<FloatRange>(), "End"); RegisterDataBindingProperty(() => CurrentValue.End, value => CurrentValue.End = value, new FloatDataBindingConverter<FloatRange>(), "End");
CurrentValueSet += OnCurrentValueSet; CurrentValueSet += OnCurrentValueSet;
DefaultValue = new FloatRange();
} }
/// <inheritdoc /> /// <inheritdoc />
@ -25,7 +26,7 @@
private void OnCurrentValueSet(object? sender, LayerPropertyEventArgs e) private void OnCurrentValueSet(object? sender, LayerPropertyEventArgs e)
{ {
// Don't allow the int range to be null // Don't allow the int range to be null
BaseValue ??= DefaultValue ?? new FloatRange(0, 0); BaseValue ??= DefaultValue ?? new FloatRange();
} }
} }
} }

View File

@ -9,6 +9,7 @@
RegisterDataBindingProperty(() => CurrentValue.End, value => CurrentValue.End = value, new IntDataBindingConverter<IntRange>(), "End"); RegisterDataBindingProperty(() => CurrentValue.End, value => CurrentValue.End = value, new IntDataBindingConverter<IntRange>(), "End");
CurrentValueSet += OnCurrentValueSet; CurrentValueSet += OnCurrentValueSet;
DefaultValue = new IntRange();
} }
/// <inheritdoc /> /// <inheritdoc />
@ -25,7 +26,7 @@
private void OnCurrentValueSet(object? sender, LayerPropertyEventArgs e) private void OnCurrentValueSet(object? sender, LayerPropertyEventArgs e)
{ {
// Don't allow the int range to be null // Don't allow the int range to be null
BaseValue ??= DefaultValue ?? new IntRange(0, 0); BaseValue ??= DefaultValue ?? new IntRange();
} }
} }
} }

View File

@ -9,6 +9,14 @@ namespace Artemis.Core
{ {
private readonly Random _rand; private readonly Random _rand;
/// <summary>
/// Creates a new instance of the <see cref="FloatRange" /> class
/// </summary>
public FloatRange()
{
_rand = new Random();
}
/// <summary> /// <summary>
/// Creates a new instance of the <see cref="FloatRange" /> class /// Creates a new instance of the <see cref="FloatRange" /> class
/// </summary> /// </summary>

View File

@ -9,6 +9,14 @@ namespace Artemis.Core
{ {
private readonly Random _rand; private readonly Random _rand;
/// <summary>
/// Creates a new instance of the <see cref="IntRange" /> class
/// </summary>
public IntRange()
{
_rand = new Random();
}
/// <summary> /// <summary>
/// Creates a new instance of the <see cref="IntRange" /> class /// Creates a new instance of the <see cref="IntRange" /> class
/// </summary> /// </summary>

View File

@ -34,7 +34,7 @@ namespace Artemis.Core
CurrentValue = default!; CurrentValue = default!;
DefaultValue = default!; DefaultValue = default!;
_baseValue = default!; _baseValue = typeof(T).IsValueType ? default! : Activator.CreateInstance<T>();
_keyframes = new List<LayerPropertyKeyframe<T>>(); _keyframes = new List<LayerPropertyKeyframe<T>>();
} }

View File

@ -6,6 +6,18 @@ namespace Artemis.UI.Shared.LayerBrushes
/// <inheritdoc /> /// <inheritdoc />
public class LayerBrushConfigurationDialog<T> : LayerBrushConfigurationDialog where T : BrushConfigurationViewModel public class LayerBrushConfigurationDialog<T> : LayerBrushConfigurationDialog where T : BrushConfigurationViewModel
{ {
/// <inheritdoc />
public LayerBrushConfigurationDialog()
{
}
/// <inheritdoc />
public LayerBrushConfigurationDialog(int dialogWidth, int dialogHeight)
{
DialogWidth = dialogWidth;
DialogHeight = dialogHeight;
}
/// <inheritdoc /> /// <inheritdoc />
public override Type Type => typeof(T); public override Type Type => typeof(T);
} }
@ -15,6 +27,16 @@ namespace Artemis.UI.Shared.LayerBrushes
/// </summary> /// </summary>
public abstract class LayerBrushConfigurationDialog : ILayerBrushConfigurationDialog public abstract class LayerBrushConfigurationDialog : ILayerBrushConfigurationDialog
{ {
/// <summary>
/// The default width of the dialog
/// </summary>
public int DialogWidth { get; set; } = 800;
/// <summary>
/// The default height of the dialog
/// </summary>
public int DialogHeight { get; set; } = 800;
/// <summary> /// <summary>
/// The type of view model the tab contains /// The type of view model the tab contains
/// </summary> /// </summary>

View File

@ -6,6 +6,19 @@ namespace Artemis.UI.Shared.LayerEffects
/// <inheritdoc /> /// <inheritdoc />
public class LayerEffectConfigurationDialog<T> : LayerEffectConfigurationDialog where T : EffectConfigurationViewModel public class LayerEffectConfigurationDialog<T> : LayerEffectConfigurationDialog where T : EffectConfigurationViewModel
{ {
/// <inheritdoc />
public LayerEffectConfigurationDialog()
{
}
/// <inheritdoc />
public LayerEffectConfigurationDialog(int dialogWidth, int dialogHeight)
{
DialogWidth = dialogWidth;
DialogHeight = dialogHeight;
}
/// <inheritdoc /> /// <inheritdoc />
public override Type Type => typeof(T); public override Type Type => typeof(T);
} }
@ -15,11 +28,15 @@ namespace Artemis.UI.Shared.LayerEffects
/// </summary> /// </summary>
public abstract class LayerEffectConfigurationDialog : ILayerEffectConfigurationDialog public abstract class LayerEffectConfigurationDialog : ILayerEffectConfigurationDialog
{ {
// TODO: See if this is still in use
/// <summary> /// <summary>
/// The layer effect this dialog belongs to /// The default width of the dialog
/// </summary> /// </summary>
public BaseLayerEffect? LayerEffect { get; set; } public int DialogWidth { get; set; } = 800;
/// <summary>
/// The default height of the dialog
/// </summary>
public int DialogHeight { get; set; } = 800;
/// <summary> /// <summary>
/// The type of view model the tab contains /// The type of view model the tab contains

View File

@ -75,7 +75,7 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.Tree
ConstructorArgument argument = new(brushParameter.Name, layerBrush); ConstructorArgument argument = new(brushParameter.Name, layerBrush);
BrushConfigurationViewModel viewModel = (BrushConfigurationViewModel) layerBrush.Descriptor.Provider.Plugin.Kernel.Get(configurationViewModel.Type, argument); BrushConfigurationViewModel viewModel = (BrushConfigurationViewModel) layerBrush.Descriptor.Provider.Plugin.Kernel.Get(configurationViewModel.Type, argument);
_layerBrushSettingsWindowVm = new LayerBrushSettingsWindowViewModel(viewModel); _layerBrushSettingsWindowVm = new LayerBrushSettingsWindowViewModel(viewModel, configurationViewModel);
_windowManager.ShowDialog(_layerBrushSettingsWindowVm); _windowManager.ShowDialog(_layerBrushSettingsWindowVm);
} }
catch (Exception e) catch (Exception e)
@ -102,7 +102,7 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.Tree
ConstructorArgument argument = new(effectParameter.Name, layerEffect); ConstructorArgument argument = new(effectParameter.Name, layerEffect);
EffectConfigurationViewModel viewModel = (EffectConfigurationViewModel) layerEffect.Descriptor.Provider.Plugin.Kernel.Get(configurationViewModel.Type, argument); EffectConfigurationViewModel viewModel = (EffectConfigurationViewModel) layerEffect.Descriptor.Provider.Plugin.Kernel.Get(configurationViewModel.Type, argument);
_layerEffectSettingsWindowVm = new LayerEffectSettingsWindowViewModel(viewModel); _layerEffectSettingsWindowVm = new LayerEffectSettingsWindowViewModel(viewModel, configurationViewModel);
_windowManager.ShowDialog(_layerEffectSettingsWindowVm); _windowManager.ShowDialog(_layerEffectSettingsWindowVm);
} }
catch (Exception e) catch (Exception e)

View File

@ -12,8 +12,10 @@
Background="{DynamicResource MaterialDesignPaper}" Background="{DynamicResource MaterialDesignPaper}"
FontFamily="pack://application:,,,/MaterialDesignThemes.Wpf;component/Resources/Roboto/#Roboto" FontFamily="pack://application:,,,/MaterialDesignThemes.Wpf;component/Resources/Roboto/#Roboto"
UseLayoutRounding="True" UseLayoutRounding="True"
Width="800" MinWidth="400"
Height="800" MinHeight="400"
Width="{Binding Width}"
Height="{Binding Height}"
d:DesignHeight="800" d:DesignHeight="800"
d:DesignWidth="800" d:DesignWidth="800"
d:DataContext="{d:DesignInstance windows:LayerBrushSettingsWindowViewModel}" d:DataContext="{d:DesignInstance windows:LayerBrushSettingsWindowViewModel}"

View File

@ -6,10 +6,27 @@ namespace Artemis.UI.Screens.ProfileEditor.Windows
{ {
public class LayerBrushSettingsWindowViewModel : Conductor<BrushConfigurationViewModel> public class LayerBrushSettingsWindowViewModel : Conductor<BrushConfigurationViewModel>
{ {
public LayerBrushSettingsWindowViewModel(BrushConfigurationViewModel configurationViewModel) private int _height;
private int _width;
public LayerBrushSettingsWindowViewModel(BrushConfigurationViewModel configurationViewModel, LayerBrushConfigurationDialog configuration)
{ {
ActiveItem = configurationViewModel ?? throw new ArgumentNullException(nameof(configurationViewModel)); ActiveItem = configurationViewModel ?? throw new ArgumentNullException(nameof(configurationViewModel));
ActiveItem.Closed += ActiveItemOnClosed; ActiveItem.Closed += ActiveItemOnClosed;
Width = configuration.DialogWidth;
Height = configuration.DialogHeight;
}
public int Width
{
get => _width;
set => SetAndNotify(ref _width, value);
}
public int Height
{
get => _height;
set => SetAndNotify(ref _height, value);
} }
private void ActiveItemOnClosed(object sender, CloseEventArgs e) private void ActiveItemOnClosed(object sender, CloseEventArgs e)

View File

@ -12,8 +12,10 @@
Background="{DynamicResource MaterialDesignPaper}" Background="{DynamicResource MaterialDesignPaper}"
FontFamily="pack://application:,,,/MaterialDesignThemes.Wpf;component/Resources/Roboto/#Roboto" FontFamily="pack://application:,,,/MaterialDesignThemes.Wpf;component/Resources/Roboto/#Roboto"
UseLayoutRounding="True" UseLayoutRounding="True"
Width="800" MinWidth="400"
Height="800" MinHeight="400"
Width="{Binding Width}"
Height="{Binding Height}"
d:DesignHeight="800" d:DesignHeight="800"
d:DesignWidth="800" d:DesignWidth="800"
d:DataContext="{d:DesignInstance windows:LayerEffectSettingsWindowViewModel}" d:DataContext="{d:DesignInstance windows:LayerEffectSettingsWindowViewModel}"

View File

@ -6,10 +6,27 @@ namespace Artemis.UI.Screens.ProfileEditor.Windows
{ {
public class LayerEffectSettingsWindowViewModel : Conductor<EffectConfigurationViewModel> public class LayerEffectSettingsWindowViewModel : Conductor<EffectConfigurationViewModel>
{ {
public LayerEffectSettingsWindowViewModel(EffectConfigurationViewModel configurationViewModel) private int _height;
private int _width;
public LayerEffectSettingsWindowViewModel(EffectConfigurationViewModel configurationViewModel, LayerEffectConfigurationDialog configuration)
{ {
ActiveItem = configurationViewModel ?? throw new ArgumentNullException(nameof(configurationViewModel)); ActiveItem = configurationViewModel ?? throw new ArgumentNullException(nameof(configurationViewModel));
ActiveItem.Closed += ActiveItemOnClosed; ActiveItem.Closed += ActiveItemOnClosed;
Width = configuration.DialogWidth;
Height = configuration.DialogHeight;
}
public int Width
{
get => _width;
set => SetAndNotify(ref _width, value);
}
public int Height
{
get => _height;
set => SetAndNotify(ref _height, value);
} }
private void ActiveItemOnClosed(object sender, CloseEventArgs e) private void ActiveItemOnClosed(object sender, CloseEventArgs e)