mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
Brushes - Allow hiding of properties
This commit is contained in:
parent
9f8fc9f70e
commit
26f9e90fa3
@ -7,12 +7,14 @@ using Artemis.Core.Plugins.Models;
|
||||
using Artemis.Core.Utilities;
|
||||
using Artemis.Storage.Entities.Profile;
|
||||
using Newtonsoft.Json;
|
||||
using Stylet;
|
||||
|
||||
namespace Artemis.Core.Models.Profile.LayerProperties
|
||||
{
|
||||
public abstract class BaseLayerProperty
|
||||
public abstract class BaseLayerProperty : PropertyChangedBase
|
||||
{
|
||||
private object _baseValue;
|
||||
private bool _isHidden;
|
||||
|
||||
protected BaseLayerProperty(Layer layer, PluginInfo pluginInfo, BaseLayerProperty parent, string id, string name, string description, Type type)
|
||||
{
|
||||
@ -118,6 +120,19 @@ namespace Artemis.Core.Models.Profile.LayerProperties
|
||||
/// </summary>
|
||||
public Type Type { get; protected set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets whether this property is hidden in the UI.
|
||||
/// </summary>
|
||||
public bool IsHidden
|
||||
{
|
||||
get => _isHidden;
|
||||
set
|
||||
{
|
||||
_isHidden = value;
|
||||
OnVisibilityChanged();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a list of keyframes defining different values of the property in time, this list contains the untyped
|
||||
/// <see cref="BaseKeyframe" />.
|
||||
@ -337,11 +352,23 @@ namespace Artemis.Core.Models.Profile.LayerProperties
|
||||
/// </summary>
|
||||
public event EventHandler<EventArgs> ValueChanged;
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when this property or any of it's ancestors visibility is changed
|
||||
/// </summary>
|
||||
public event EventHandler<EventArgs> VisibilityChanged;
|
||||
|
||||
protected virtual void OnValueChanged()
|
||||
{
|
||||
ValueChanged?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
protected virtual void OnVisibilityChanged()
|
||||
{
|
||||
VisibilityChanged?.Invoke(this, EventArgs.Empty);
|
||||
foreach (var baseLayerProperty in Children)
|
||||
baseLayerProperty.OnVisibilityChanged();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@ -14,6 +14,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties
|
||||
private readonly IKernel _kernel;
|
||||
private readonly IProfileEditorService _profileEditorService;
|
||||
private bool _keyframesEnabled;
|
||||
private bool _isExpanded;
|
||||
|
||||
public LayerPropertyViewModel(BaseLayerProperty layerProperty, LayerPropertyViewModel parent, IKernel kernel, IProfileEditorService profileEditorService)
|
||||
{
|
||||
@ -34,7 +35,15 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties
|
||||
public LayerPropertyViewModel Parent { get; }
|
||||
public List<LayerPropertyViewModel> Children { get; }
|
||||
|
||||
public bool IsExpanded { get; set; }
|
||||
public bool IsExpanded
|
||||
{
|
||||
get => _isExpanded;
|
||||
set
|
||||
{
|
||||
_isExpanded = value;
|
||||
OnExpandedStateChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public bool KeyframesEnabled
|
||||
{
|
||||
@ -75,5 +84,17 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties
|
||||
|
||||
_profileEditorService.UpdateSelectedProfileElement();
|
||||
}
|
||||
|
||||
#region Events
|
||||
|
||||
public event EventHandler<EventArgs> ExpandedStateChanged;
|
||||
protected virtual void OnExpandedStateChanged()
|
||||
{
|
||||
ExpandedStateChanged?.Invoke(this, EventArgs.Empty);
|
||||
foreach (var layerPropertyViewModel in Children)
|
||||
layerPropertyViewModel.OnExpandedStateChanged();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@ -87,6 +87,7 @@
|
||||
<TreeView.ItemContainerStyle>
|
||||
<Style TargetType="TreeViewItem" BasedOn="{StaticResource PropertyTreeStyle}">
|
||||
<Setter Property="IsExpanded" Value="{Binding LayerPropertyViewModel.IsExpanded, Mode=TwoWay}" />
|
||||
<Setter Property="Visibility" Value="{Binding LayerPropertyViewModel.LayerProperty.IsHidden, Converter={x:Static s:BoolToVisibilityConverter.InverseInstance}}" />
|
||||
</Style>
|
||||
</TreeView.ItemContainerStyle>
|
||||
<TreeView.Resources>
|
||||
|
||||
@ -12,7 +12,7 @@
|
||||
<Border Height="25"
|
||||
BorderThickness="0,0,0,1"
|
||||
BorderBrush="{DynamicResource MaterialDesignDivider}"
|
||||
Visibility="{Binding LayerPropertyViewModel.Parent.IsExpanded, Converter={StaticResource BoolToVisibilityConverter}}">
|
||||
Visibility="{Binding MustDisplay, Converter={StaticResource BoolToVisibilityConverter}}">
|
||||
<ItemsControl ItemsSource="{Binding KeyframeViewModels}"
|
||||
Background="{DynamicResource MaterialDesignToolBarBackground}"
|
||||
HorizontalAlignment="Left">
|
||||
|
||||
@ -19,12 +19,44 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Timeline
|
||||
|
||||
PopulateKeyframes();
|
||||
UpdateKeyframes(PropertyTimelineViewModel.LayerPropertiesViewModel.PixelsPerSecond);
|
||||
|
||||
LayerPropertyViewModel.ExpandedStateChanged += (sender, args) => UpdateMustDisplay();
|
||||
LayerPropertyViewModel.LayerProperty.VisibilityChanged += (sender, args) => UpdateMustDisplay();
|
||||
UpdateMustDisplay();
|
||||
}
|
||||
|
||||
|
||||
public PropertyTimelineViewModel PropertyTimelineViewModel { get; }
|
||||
public LayerPropertyViewModel LayerPropertyViewModel { get; }
|
||||
public BindableCollection<PropertyTrackKeyframeViewModel> KeyframeViewModels { get; set; }
|
||||
public bool MustDisplay { get; set; }
|
||||
|
||||
private void UpdateMustDisplay()
|
||||
{
|
||||
var expandedTest = LayerPropertyViewModel.Parent;
|
||||
while (expandedTest != null)
|
||||
{
|
||||
if (!expandedTest.IsExpanded)
|
||||
{
|
||||
MustDisplay = false;
|
||||
return;
|
||||
}
|
||||
expandedTest = expandedTest.Parent;
|
||||
}
|
||||
|
||||
var visibilityTest = LayerPropertyViewModel.LayerProperty;
|
||||
while (visibilityTest != null)
|
||||
{
|
||||
if (visibilityTest.IsHidden)
|
||||
{
|
||||
MustDisplay = false;
|
||||
return;
|
||||
}
|
||||
visibilityTest = visibilityTest.Parent;
|
||||
}
|
||||
|
||||
MustDisplay = true;
|
||||
}
|
||||
|
||||
public void PopulateKeyframes()
|
||||
{
|
||||
|
||||
@ -19,11 +19,18 @@ namespace Artemis.Plugins.LayerBrushes.Color
|
||||
{
|
||||
GradientTypeProperty = RegisterLayerProperty("Brush.GradientType", "Gradient type", "The type of color brush to draw", GradientType.Solid);
|
||||
GradientTypeProperty.CanUseKeyframes = false;
|
||||
ColorProperty = RegisterLayerProperty("Brush.Color", "Color", "The color of the brush", new SKColor(255, 0, 0));
|
||||
GradientProperty = RegisterLayerProperty("Brush.Gradient", "Gradient", "The gradient of the brush", new ColorGradient());
|
||||
GradientProperty.CanUseKeyframes = false;
|
||||
if (!GradientProperty.Value.Stops.Any())
|
||||
GradientProperty.Value.MakeFabulous();
|
||||
|
||||
UpdateColorProperties();
|
||||
|
||||
Layer.RenderPropertiesUpdated += (sender, args) => CreateShader();
|
||||
GradientTypeProperty.ValueChanged += (sender, args) => UpdateColorProperties();
|
||||
ColorProperty.ValueChanged += (sender, args) => CreateShader();
|
||||
GradientProperty.Value.PropertyChanged += (sender, args) => CreateShader();
|
||||
}
|
||||
|
||||
public LayerProperty<SKColor> ColorProperty { get; set; }
|
||||
@ -57,22 +64,8 @@ namespace Artemis.Plugins.LayerBrushes.Color
|
||||
|
||||
private void UpdateColorProperties()
|
||||
{
|
||||
if (GradientTypeProperty.Value == GradientType.Solid)
|
||||
{
|
||||
UnRegisterLayerProperty(GradientProperty);
|
||||
ColorProperty = RegisterLayerProperty("Brush.Color", "Color", "The color of the brush", new SKColor(255, 0, 0));
|
||||
ColorProperty.ValueChanged += (sender, args) => CreateShader();
|
||||
}
|
||||
else
|
||||
{
|
||||
UnRegisterLayerProperty(ColorProperty);
|
||||
GradientProperty = RegisterLayerProperty("Brush.Gradient", "Gradient", "The gradient of the brush", new ColorGradient());
|
||||
GradientProperty.CanUseKeyframes = false;
|
||||
GradientProperty.Value.PropertyChanged += (sender, args) => CreateShader();
|
||||
|
||||
if (!GradientProperty.Value.Stops.Any())
|
||||
GradientProperty.Value.MakeFabulous();
|
||||
}
|
||||
ColorProperty.IsHidden = GradientTypeProperty.Value != GradientType.Solid;
|
||||
GradientProperty.IsHidden = GradientTypeProperty.Value == GradientType.Solid;
|
||||
|
||||
CreateShader();
|
||||
}
|
||||
|
||||
@ -30,11 +30,11 @@ namespace Artemis.Plugins.LayerBrushes.Noise
|
||||
_y = Rand.Next(0, 4096);
|
||||
_z = Rand.Next(0, 4096);
|
||||
_noise = new OpenSimplexNoise(Rand.Next(0, 4096));
|
||||
DetermineRenderScale();
|
||||
|
||||
ColorTypeProperty = RegisterLayerProperty("Brush.ColorType", "Color mapping type", "The way the noise is converted to colors", ColorMappingType.Simple);
|
||||
ColorTypeProperty.CanUseKeyframes = false;
|
||||
ColorTypeProperty.ValueChanged += (sender, args) => UpdateColorProperties();
|
||||
UpdateColorProperties();
|
||||
|
||||
ScaleProperty = RegisterLayerProperty("Brush.Scale", "Scale", "The scale of the noise.", new SKSize(100, 100));
|
||||
ScaleProperty.MinInputValue = 0f;
|
||||
HardnessProperty = RegisterLayerProperty("Brush.Hardness", "Hardness", "The hardness of the noise, lower means there are gradients in the noise, higher means hard lines", 500f);
|
||||
@ -47,8 +47,16 @@ namespace Artemis.Plugins.LayerBrushes.Noise
|
||||
AnimationSpeedProperty.MinInputValue = 0f;
|
||||
AnimationSpeedProperty.MaxInputValue = 64f;
|
||||
ScaleProperty.InputAffix = "%";
|
||||
MainColorProperty = RegisterLayerProperty("Brush.MainColor", "Main color", "The main color of the noise", new SKColor(255, 0, 0));
|
||||
SecondaryColorProperty = RegisterLayerProperty("Brush.SecondaryColor", "Secondary color", "The secondary color of the noise", new SKColor(0, 0, 255));
|
||||
GradientColorProperty = RegisterLayerProperty("Brush.GradientColor", "Noise gradient map", "The gradient the noise will map it's value to", new ColorGradient());
|
||||
GradientColorProperty.CanUseKeyframes = false;
|
||||
if (!GradientColorProperty.Value.Stops.Any())
|
||||
GradientColorProperty.Value.MakeFabulous();
|
||||
GradientColorProperty.Value.PropertyChanged += CreateColorMap;
|
||||
|
||||
DetermineRenderScale();
|
||||
UpdateColorProperties();
|
||||
CreateColorMap(null, null);
|
||||
}
|
||||
|
||||
|
||||
@ -64,25 +72,9 @@ namespace Artemis.Plugins.LayerBrushes.Noise
|
||||
|
||||
private void UpdateColorProperties()
|
||||
{
|
||||
if (GradientColorProperty != null)
|
||||
GradientColorProperty.Value.PropertyChanged -= CreateColorMap;
|
||||
if (ColorTypeProperty.Value == ColorMappingType.Simple)
|
||||
{
|
||||
UnRegisterLayerProperty(GradientColorProperty);
|
||||
MainColorProperty = RegisterLayerProperty("Brush.MainColor", "Main color", "The main color of the noise", new SKColor(255, 0, 0));
|
||||
SecondaryColorProperty = RegisterLayerProperty("Brush.SecondaryColor", "Secondary color", "The secondary color of the noise", new SKColor(0, 0, 255));
|
||||
}
|
||||
else
|
||||
{
|
||||
UnRegisterLayerProperty(MainColorProperty);
|
||||
UnRegisterLayerProperty(SecondaryColorProperty);
|
||||
GradientColorProperty = RegisterLayerProperty("Brush.GradientColor", "Noise gradient map", "The gradient the noise will map it's value to", new ColorGradient());
|
||||
if (!GradientColorProperty.Value.Stops.Any())
|
||||
GradientColorProperty.Value.MakeFabulous();
|
||||
|
||||
GradientColorProperty.Value.PropertyChanged += CreateColorMap;
|
||||
CreateColorMap(null, null);
|
||||
}
|
||||
GradientColorProperty.IsHidden = ColorTypeProperty.Value != ColorMappingType.Gradient;
|
||||
MainColorProperty.IsHidden = ColorTypeProperty.Value != ColorMappingType.Simple;
|
||||
SecondaryColorProperty.IsHidden = ColorTypeProperty.Value != ColorMappingType.Simple;
|
||||
}
|
||||
|
||||
public override void Update(double deltaTime)
|
||||
@ -136,7 +128,7 @@ namespace Artemis.Plugins.LayerBrushes.Noise
|
||||
else if (gradientColor != null && _colorMap.Length == 101)
|
||||
{
|
||||
var color = _colorMap[(int) Math.Round(alpha / 255f * 100, MidpointRounding.AwayFromZero)];
|
||||
_bitmap.SetPixel(x, y, new SKColor(color.Red, color.Green, color.Blue, 255));
|
||||
_bitmap.SetPixel(x, y, color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user