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

Color gradients - Tweaked default rainbow

Events - Hide some properties that shouldn't be visible
Events - Added time since last trigger property
This commit is contained in:
Robert 2021-03-28 13:43:02 +02:00
parent f4b42e2cf2
commit a74c81ba9d
9 changed files with 101 additions and 19 deletions

View File

@ -10,6 +10,19 @@ namespace Artemis.Core
/// </summary>
public class ColorGradient : CorePropertyChanged
{
private static readonly SKColor[] FastLedRainbow =
{
new(0xFFFF0000), // Red
new(0xFFFF9900), // Orange
new(0xFFFFFF00), // Yellow
new(0xFF00FF00), // Green
new(0xFF00FF7E), // Aqua
new(0xFF0078FF), // Blue
new(0xFF9E22FF), // Purple
new(0xFFFF34AE), // Pink
new(0xFFFF0000) // and back to Red
};
/// <summary>
/// Creates a new instance of the <see cref="ColorGradient" /> class
/// </summary>
@ -31,9 +44,9 @@ namespace Artemis.Core
public SKColor[] GetColorsArray(int timesToRepeat = 0)
{
if (timesToRepeat == 0)
return Stops.OrderBy(c => c.Position).Select(c => c.Color).ToArray();
return Stops.Select(c => c.Color).ToArray();
List<SKColor> colors = Stops.OrderBy(c => c.Position).Select(c => c.Color).ToList();
List<SKColor> colors = Stops.Select(c => c.Color).ToList();
List<SKColor> result = new();
for (int i = 0; i <= timesToRepeat; i++)
@ -53,10 +66,10 @@ namespace Artemis.Core
public float[] GetPositionsArray(int timesToRepeat = 0)
{
if (timesToRepeat == 0)
return Stops.OrderBy(c => c.Position).Select(c => c.Position).ToArray();
return Stops.Select(c => c.Position).ToArray();
// Create stops and a list of divided stops
List<float> stops = Stops.OrderBy(c => c.Position).Select(c => c.Position / (timesToRepeat + 1)).ToList();
List<float> stops = Stops.Select(c => c.Position / (timesToRepeat + 1)).ToList();
List<float> result = new();
// For each repeat cycle, add the base stops to the end result
@ -74,6 +87,7 @@ namespace Artemis.Core
/// </summary>
public void OnColorValuesUpdated()
{
Stops.Sort((a, b) => a.Position.CompareTo(b.Position));
OnPropertyChanged(nameof(Stops));
}
@ -86,7 +100,7 @@ namespace Artemis.Core
if (!Stops.Any())
return SKColor.Empty;
ColorGradientStop[] stops = Stops.OrderBy(x => x.Position).ToArray();
ColorGradientStop[] stops = Stops.ToArray();
if (position <= 0) return stops[0].Color;
if (position >= 1) return stops[^1].Color;
ColorGradientStop left = stops[0];
@ -119,15 +133,14 @@ namespace Artemis.Core
/// <returns></returns>
public static ColorGradient GetUnicornBarf()
{
const int amount = 8;
ColorGradient gradient = new();
for (int i = 0; i <= amount; i++)
for (int index = 0; index < FastLedRainbow.Length; index++)
{
float percent = i / (float)amount;
gradient.Stops.Add(new ColorGradientStop(SKColor.FromHsv(360f * percent, 100, 100), percent));
SKColor skColor = FastLedRainbow[index];
float position = 1f / (FastLedRainbow.Length - 1f) * index;
gradient.Stops.Add(new ColorGradientStop(skColor, position));
}
return gradient;
}
}

View File

@ -29,9 +29,13 @@ namespace Artemis.Core
}
/// <inheritdoc />
[DataModelProperty(Name = "Last event trigger", Description = "The time at which the event last triggered")]
[DataModelProperty(Name = "Last trigger", Description = "The time at which the event last triggered")]
public DateTime LastTrigger { get; private set; }
/// <inheritdoc />
[DataModelProperty(Name = "Time since trigger", Description = "The time that has passed since the last trigger")]
public TimeSpan TimeSinceLastTrigger => DateTime.Now - LastTrigger;
/// <summary>
/// Gets the event arguments of the last time the event was triggered
/// </summary>
@ -85,6 +89,7 @@ namespace Artemis.Core
public Type ArgumentsType => typeof(T);
/// <inheritdoc />
[DataModelIgnore]
public string TriggerPastParticiple => "triggered";
/// <inheritdoc />
@ -147,14 +152,18 @@ namespace Artemis.Core
}
/// <inheritdoc />
[DataModelProperty(Name = "Last event trigger", Description = "The time at which the event last triggered")]
[DataModelProperty(Name = "Last trigger", Description = "The time at which the event last triggered")]
public DateTime LastTrigger { get; private set; }
/// <inheritdoc />
[DataModelProperty(Name = "Time since trigger", Description = "The time that has passed since the last trigger")]
public TimeSpan TimeSinceLastTrigger => DateTime.Now - LastTrigger;
/// <summary>
/// Gets the event arguments of the last time the event was triggered
/// </summary>
[DataModelProperty(Description = "The arguments of the last time this event triggered")]
public DataModelEventArgs? LastEventArguments { get; private set; }
public DataModelEventArgs? LastTriggerArguments { get; private set; }
/// <inheritdoc />
[DataModelProperty(Description = "The total amount of times this event has triggered since the module was activated")]
@ -174,7 +183,7 @@ namespace Artemis.Core
{
DataModelEventArgs eventArgs = new() {TriggerTime = DateTime.Now};
LastEventArguments = eventArgs;
LastTriggerArguments = eventArgs;
LastTrigger = DateTime.Now;
TriggerCount++;
@ -201,6 +210,7 @@ namespace Artemis.Core
public Type ArgumentsType => typeof(DataModelEventArgs);
/// <inheritdoc />
[DataModelIgnore]
public string TriggerPastParticiple => "triggered";
/// <inheritdoc />
@ -217,7 +227,7 @@ namespace Artemis.Core
/// <inheritdoc />
[DataModelIgnore]
public DataModelEventArgs? LastEventArgumentsUntyped => LastEventArguments;
public DataModelEventArgs? LastEventArgumentsUntyped => LastTriggerArguments;
/// <inheritdoc />
[DataModelIgnore]

View File

@ -13,6 +13,11 @@ namespace Artemis.Core
/// </summary>
DateTime LastTrigger { get; }
/// <summary>
/// Gets the time that has passed since the last trigger
/// </summary>
TimeSpan TimeSinceLastTrigger { get; }
/// <summary>
/// Gets the amount of times the event was triggered
/// </summary>

View File

@ -14,6 +14,7 @@ namespace Artemis.Core
public T? LastValue { get; private set; }
public T? CurrentValue { get; private set; }
public DateTime LastTrigger { get; private set; }
public TimeSpan TimeSinceLastTrigger => DateTime.Now - LastTrigger;
public int TriggerCount { get; private set; }
public Type ArgumentsType { get; } = typeof(DataModelValueChangedEventArgs<T>);
public string TriggerPastParticiple => "changed";

View File

@ -42,12 +42,12 @@
Margin="-10 0 -10 -5">
<ListBox.ItemTemplate>
<DataTemplate>
<ContentControl s:View.Model="{Binding}" VerticalContentAlignment="Stretch" HorizontalContentAlignment="Stretch" IsTabStop="False" />
<ContentControl s:View.Model="{Binding}" VerticalContentAlignment="Stretch" HorizontalContentAlignment="Stretch" IsTabStop="False"/>
</DataTemplate>
</ListBox.ItemTemplate>
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel />
<VirtualizingStackPanel/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
</ListBox>

View File

@ -44,6 +44,11 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings.Conditio
_profileEditorService.UpdateSelectedProfileElement();
}
public void RemoveCondition(DataBindingCondition<TLayerProperty, TProperty> dataBindingCondition)
{
ConditionalDataBinding.RemoveCondition(dataBindingCondition);
}
protected override void OnInitialActivate()
{
Initialize();

View File

@ -4,9 +4,45 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:s="https://github.com/canton7/Stylet"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Border BorderThickness="0 0 0 1" BorderBrush="{DynamicResource MaterialDesignDivider}" Margin="0 0 0 -4" Padding="0 4">
<Border BorderThickness="0 0 0 1"
BorderBrush="{DynamicResource MaterialDesignDivider}"
Margin="0 0 0 -4"
Padding="0 4"
Background="Transparent">
<Border.ContextMenu>
<ContextMenu>
<MenuItem Header="Add new condition" Command="{s:Action AddCondition}">
<MenuItem.Icon>
<materialDesign:PackIcon Kind="CodeNotEqual" />
</MenuItem.Icon>
</MenuItem>
<Separator />
<MenuItem Header="Duplicate" Command="{s:Action DuplicateCondition}" InputGestureText="Ctrl+D" IsEnabled="False">
<MenuItem.Icon>
<materialDesign:PackIcon Kind="ContentDuplicate" />
</MenuItem.Icon>
</MenuItem>
<MenuItem Header="Copy" Command="{s:Action CopyCondition}" InputGestureText="Ctrl+C" IsEnabled="False">
<MenuItem.Icon>
<materialDesign:PackIcon Kind="ContentCopy" />
</MenuItem.Icon>
</MenuItem>
<MenuItem Header="Paste" Command="{s:Action PasteCondition}" InputGestureText="Ctrl+V" IsEnabled="False">
<MenuItem.Icon>
<materialDesign:PackIcon Kind="ContentPaste" />
</MenuItem.Icon>
</MenuItem>
<Separator />
<MenuItem Header="Delete" Command="{s:Action RemoveCondition}" InputGestureText="Del">
<MenuItem.Icon>
<materialDesign:PackIcon Kind="TrashCan" />
</MenuItem.Icon>
</MenuItem>
</ContextMenu>
</Border.ContextMenu>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />

View File

@ -61,6 +61,17 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings.Conditio
ActiveItem?.Evaluate();
}
public void AddCondition()
{
((ConditionalDataBindingModeViewModel<TLayerProperty, TProperty>) Parent).AddCondition();
}
public void RemoveCondition()
{
((ConditionalDataBindingModeViewModel<TLayerProperty, TProperty>)Parent).RemoveCondition(DataBindingCondition);
}
#region IDisposable
/// <inheritdoc />

View File

@ -251,6 +251,7 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings
if (Registration.DataBinding == null)
return;
ActiveItem = null;
Registration.LayerProperty.DisableDataBinding(Registration.DataBinding);
Update();