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");
CurrentValueSet += OnCurrentValueSet;
DefaultValue = new FloatRange();
}
/// <inheritdoc />
@ -25,7 +26,7 @@
private void OnCurrentValueSet(object? sender, LayerPropertyEventArgs e)
{
// 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");
CurrentValueSet += OnCurrentValueSet;
DefaultValue = new IntRange();
}
/// <inheritdoc />
@ -25,7 +26,7 @@
private void OnCurrentValueSet(object? sender, LayerPropertyEventArgs e)
{
// 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;
/// <summary>
/// Creates a new instance of the <see cref="FloatRange" /> class
/// </summary>
public FloatRange()
{
_rand = new Random();
}
/// <summary>
/// Creates a new instance of the <see cref="FloatRange" /> class
/// </summary>

View File

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

View File

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

View File

@ -6,6 +6,18 @@ namespace Artemis.UI.Shared.LayerBrushes
/// <inheritdoc />
public class LayerBrushConfigurationDialog<T> : LayerBrushConfigurationDialog where T : BrushConfigurationViewModel
{
/// <inheritdoc />
public LayerBrushConfigurationDialog()
{
}
/// <inheritdoc />
public LayerBrushConfigurationDialog(int dialogWidth, int dialogHeight)
{
DialogWidth = dialogWidth;
DialogHeight = dialogHeight;
}
/// <inheritdoc />
public override Type Type => typeof(T);
}
@ -15,6 +27,16 @@ namespace Artemis.UI.Shared.LayerBrushes
/// </summary>
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>
/// The type of view model the tab contains
/// </summary>

View File

@ -6,6 +6,19 @@ namespace Artemis.UI.Shared.LayerEffects
/// <inheritdoc />
public class LayerEffectConfigurationDialog<T> : LayerEffectConfigurationDialog where T : EffectConfigurationViewModel
{
/// <inheritdoc />
public LayerEffectConfigurationDialog()
{
}
/// <inheritdoc />
public LayerEffectConfigurationDialog(int dialogWidth, int dialogHeight)
{
DialogWidth = dialogWidth;
DialogHeight = dialogHeight;
}
/// <inheritdoc />
public override Type Type => typeof(T);
}
@ -15,11 +28,15 @@ namespace Artemis.UI.Shared.LayerEffects
/// </summary>
public abstract class LayerEffectConfigurationDialog : ILayerEffectConfigurationDialog
{
// TODO: See if this is still in use
/// <summary>
/// The layer effect this dialog belongs to
/// The default width of the dialog
/// </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>
/// 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);
BrushConfigurationViewModel viewModel = (BrushConfigurationViewModel) layerBrush.Descriptor.Provider.Plugin.Kernel.Get(configurationViewModel.Type, argument);
_layerBrushSettingsWindowVm = new LayerBrushSettingsWindowViewModel(viewModel);
_layerBrushSettingsWindowVm = new LayerBrushSettingsWindowViewModel(viewModel, configurationViewModel);
_windowManager.ShowDialog(_layerBrushSettingsWindowVm);
}
catch (Exception e)
@ -102,7 +102,7 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.Tree
ConstructorArgument argument = new(effectParameter.Name, layerEffect);
EffectConfigurationViewModel viewModel = (EffectConfigurationViewModel) layerEffect.Descriptor.Provider.Plugin.Kernel.Get(configurationViewModel.Type, argument);
_layerEffectSettingsWindowVm = new LayerEffectSettingsWindowViewModel(viewModel);
_layerEffectSettingsWindowVm = new LayerEffectSettingsWindowViewModel(viewModel, configurationViewModel);
_windowManager.ShowDialog(_layerEffectSettingsWindowVm);
}
catch (Exception e)

View File

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

View File

@ -6,10 +6,27 @@ namespace Artemis.UI.Screens.ProfileEditor.Windows
{
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.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)

View File

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

View File

@ -6,10 +6,27 @@ namespace Artemis.UI.Screens.ProfileEditor.Windows
{
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.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)