mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-11 19:36:28 +00:00
Nodes - Tweak pin collection visuals
Nodes - Added counter node that counts from 0.0 to 1.0 Nodes - Added color ramp node Gradient picker - Remove tilt from preview
This commit is contained in:
1 parent
39a52591b6
commit
b4242a2dfc
10 files changed
+153
-4
No files matched your search
@@ -0,0 +1,37 @@
|
||||
using Artemis.Core;
|
||||
using Artemis.VisualScripting.Nodes.Color.Screens;
|
||||
using SkiaSharp;
|
||||
|
||||
namespace Artemis.VisualScripting.Nodes.Color;
|
||||
|
||||
[Node("Color Ramp", "Maps values to colors with the use of a gradient.", "Color", InputType = typeof(Numeric), OutputType = typeof(SKColor))]
|
||||
public class RampSKColorNode : Node<ColorGradient, RampSKColorNodeCustomViewModel>
|
||||
{
|
||||
#region Constructors
|
||||
|
||||
public RampSKColorNode()
|
||||
: base("Color Ramp", "Maps values to colors with the use of a gradient.")
|
||||
{
|
||||
Input = CreateInputPin<Numeric>();
|
||||
Output = CreateOutputPin<SKColor>();
|
||||
Storage = ColorGradient.GetUnicornBarf();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
public override void Evaluate()
|
||||
{
|
||||
Output.Value = Storage?.GetColor(Input.Value) ?? SKColor.Empty;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties & Fields
|
||||
|
||||
public InputPin<Numeric> Input { get; }
|
||||
public OutputPin<SKColor> Output { get; }
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<UserControl xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:screens="clr-namespace:Artemis.VisualScripting.Nodes.Color.Screens"
|
||||
xmlns:gradientPicker="clr-namespace:Artemis.UI.Shared.Controls.GradientPicker;assembly=Artemis.UI.Shared"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
x:Class="Artemis.VisualScripting.Nodes.Color.Screens.RampSKColorNodeCustomView"
|
||||
x:DataType="screens:RampSKColorNodeCustomViewModel">
|
||||
<gradientPicker:GradientPickerButton Width="110"
|
||||
Classes="condensed"
|
||||
ColorGradient="{CompiledBinding Gradient}"
|
||||
VerticalAlignment="Center"
|
||||
FlyoutOpened="GradientPickerButton_OnFlyoutOpened"
|
||||
FlyoutClosed="GradientPickerButton_OnFlyoutClosed"/>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,29 @@
|
||||
using Artemis.UI.Shared.Controls.GradientPicker;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Markup.Xaml;
|
||||
using Avalonia.ReactiveUI;
|
||||
|
||||
namespace Artemis.VisualScripting.Nodes.Color.Screens;
|
||||
|
||||
public partial class RampSKColorNodeCustomView : ReactiveUserControl<RampSKColorNodeCustomViewModel>
|
||||
{
|
||||
public RampSKColorNodeCustomView()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void InitializeComponent()
|
||||
{
|
||||
AvaloniaXamlLoader.Load(this);
|
||||
}
|
||||
|
||||
private void GradientPickerButton_OnFlyoutOpened(GradientPickerButton sender, EventArgs args)
|
||||
{
|
||||
}
|
||||
|
||||
private void GradientPickerButton_OnFlyoutClosed(GradientPickerButton sender, EventArgs args)
|
||||
{
|
||||
ViewModel?.StoreGradient();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
using Artemis.Core;
|
||||
using Artemis.UI.Shared.Services.NodeEditor;
|
||||
using Artemis.UI.Shared.Services.NodeEditor.Commands;
|
||||
using Artemis.UI.Shared.VisualScripting;
|
||||
|
||||
namespace Artemis.VisualScripting.Nodes.Color.Screens;
|
||||
|
||||
public class RampSKColorNodeCustomViewModel : CustomNodeViewModel
|
||||
{
|
||||
private readonly RampSKColorNode _node;
|
||||
private readonly INodeEditorService _nodeEditorService;
|
||||
|
||||
/// <inheritdoc />
|
||||
public RampSKColorNodeCustomViewModel(RampSKColorNode node, INodeScript script, INodeEditorService nodeEditorService) : base(node, script)
|
||||
{
|
||||
_node = node;
|
||||
_nodeEditorService = nodeEditorService;
|
||||
|
||||
Gradient = _node.Storage ?? new ColorGradient();
|
||||
}
|
||||
|
||||
public ColorGradient Gradient { get; }
|
||||
|
||||
public void StoreGradient()
|
||||
{
|
||||
_nodeEditorService.ExecuteCommand(Script, new UpdateStorage<ColorGradient>(_node, Gradient));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
using Artemis.Core;
|
||||
|
||||
namespace Artemis.VisualScripting.Nodes.Mathematics;
|
||||
|
||||
[Node("Counter", "Counts from 0.0 to 1.0 at a configurable rate.", "Mathematics", InputType = typeof(Numeric), OutputType = typeof(Numeric))]
|
||||
public class CounterNode : Node
|
||||
{
|
||||
private DateTime _lastEvaluate = DateTime.MinValue;
|
||||
private float _progress;
|
||||
|
||||
public CounterNode()
|
||||
: base("Counter", "Counts from 0.0 to 1.0 at a configurable rate.")
|
||||
{
|
||||
Time = CreateInputPin<Numeric>("Time (ms)");
|
||||
Output = CreateOutputPin<Numeric>();
|
||||
}
|
||||
|
||||
public override void Evaluate()
|
||||
{
|
||||
DateTime now = DateTime.Now;
|
||||
TimeSpan delta = now - _lastEvaluate;
|
||||
|
||||
if (Time.Value != 0)
|
||||
_progress = (float) (_progress + delta.TotalMilliseconds / Time.Value) % 1.0f;
|
||||
|
||||
Output.Value = new Numeric(MathF.Round(_progress, 4, MidpointRounding.AwayFromZero));
|
||||
_lastEvaluate = now;
|
||||
}
|
||||
|
||||
public InputPin<Numeric> Time { get; set; }
|
||||
public OutputPin<Numeric> Output { get; set; }
|
||||
}
|
||||
@@ -44,7 +44,7 @@ public class MathExpressionNode : Node<string, MathExpressionNodeCustomViewModel
|
||||
try
|
||||
{
|
||||
if (Storage != null)
|
||||
Output.Value = new Numeric(_evaluator.CalcNumber(Storage, _variables));
|
||||
Output.Value = new Numeric(Math.Round(_evaluator.CalcNumber(Storage, _variables), 4, MidpointRounding.AwayFromZero));
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user