|
@@ -1,4 +1,5 @@
|
|
using PixiEditor.ChangeableDocument.Changeables.Graph.Context;
|
|
using PixiEditor.ChangeableDocument.Changeables.Graph.Context;
|
|
|
|
+using PixiEditor.ChangeableDocument.Enums;
|
|
using PixiEditor.ChangeableDocument.Rendering;
|
|
using PixiEditor.ChangeableDocument.Rendering;
|
|
using PixiEditor.DrawingApi.Core;
|
|
using PixiEditor.DrawingApi.Core;
|
|
using PixiEditor.DrawingApi.Core.ColorsImpl;
|
|
using PixiEditor.DrawingApi.Core.ColorsImpl;
|
|
@@ -21,10 +22,6 @@ public class SeparateColorNode : Node
|
|
|
|
|
|
public FuncOutputProperty<Float1> A { get; }
|
|
public FuncOutputProperty<Float1> A { get; }
|
|
|
|
|
|
-
|
|
|
|
- private FuncContext lastContext;
|
|
|
|
- private Half4 lastColor;
|
|
|
|
-
|
|
|
|
public SeparateColorNode()
|
|
public SeparateColorNode()
|
|
{
|
|
{
|
|
R = CreateFuncOutput<Float1>(nameof(R), "R", ctx => GetColor(ctx).R);
|
|
R = CreateFuncOutput<Float1>(nameof(R), "R", ctx => GetColor(ctx).R);
|
|
@@ -40,63 +37,46 @@ public class SeparateColorNode : Node
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
|
|
|
|
- private Half4 GetColor(FuncContext ctx)
|
|
|
|
- {
|
|
|
|
- if (Mode.Value == CombineSeparateColorMode.HSV)
|
|
|
|
|
|
+ private Half4 GetColor(FuncContext ctx) =>
|
|
|
|
+ Mode.Value switch
|
|
{
|
|
{
|
|
- return GetHsva(ctx);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (Mode.Value == CombineSeparateColorMode.HSL)
|
|
|
|
- {
|
|
|
|
- return GetHsla(ctx);
|
|
|
|
- }
|
|
|
|
|
|
+ CombineSeparateColorMode.RGB => GetRgba(ctx),
|
|
|
|
+ CombineSeparateColorMode.HSV => GetHsva(ctx),
|
|
|
|
+ CombineSeparateColorMode.HSL => GetHsla(ctx)
|
|
|
|
+ };
|
|
|
|
|
|
- Half4 target = null;
|
|
|
|
- if (lastContext == ctx)
|
|
|
|
- {
|
|
|
|
- target = lastColor;
|
|
|
|
- }
|
|
|
|
- else
|
|
|
|
- {
|
|
|
|
- target = Color.Value(ctx);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- lastColor = target;
|
|
|
|
- lastContext = ctx;
|
|
|
|
- return lastColor;
|
|
|
|
- }
|
|
|
|
|
|
+ private Half4 GetRgba(FuncContext ctx) => ctx.Builder.GetOrNewAttachedHalf4(this.GetHashCode(), Color.GetHashCode(), () => Color.Value(ctx));
|
|
|
|
|
|
- private Half4 GetHsla(FuncContext ctx)
|
|
|
|
|
|
+ private Half4 GetHsva(FuncContext ctx)
|
|
{
|
|
{
|
|
if (!ctx.HasContext && ctx.GetValue(Color) is Half4 constantColor)
|
|
if (!ctx.HasContext && ctx.GetValue(Color) is Half4 constantColor)
|
|
{
|
|
{
|
|
var variable = new Half4(string.Empty);
|
|
var variable = new Half4(string.Empty);
|
|
- constantColor.ConstantValue.ToHsl(out float h, out float s, out float l);
|
|
|
|
|
|
+ constantColor.ConstantValue.ToHsv(out float h, out float s, out float l);
|
|
variable.ConstantValue = new Color((byte)(h * 255), (byte)(s * 255), (byte)(l * 255), constantColor.ConstantValue.A);
|
|
variable.ConstantValue = new Color((byte)(h * 255), (byte)(s * 255), (byte)(l * 255), constantColor.ConstantValue.A);
|
|
|
|
|
|
return variable;
|
|
return variable;
|
|
}
|
|
}
|
|
|
|
|
|
- return ctx.Builder.GetOrNewAttachedHalf4(this.GetHashCode(), Color.GetHashCode(), RgbToHslGetter);
|
|
|
|
|
|
+ return ctx.Builder.GetOrNewAttachedHalf4(this.GetHashCode(), Color.GetHashCode(), RgbToHsvGetter);
|
|
|
|
|
|
- Expression RgbToHslGetter() => ctx.Builder.Functions.GetRgbToHsl(ctx.GetValue(Color));
|
|
|
|
|
|
+ Expression RgbToHsvGetter() => ctx.Builder.Functions.GetRgbToHsv(ctx.GetValue(Color));
|
|
}
|
|
}
|
|
|
|
|
|
- private Half4 GetHsva(FuncContext ctx)
|
|
|
|
|
|
+ private Half4 GetHsla(FuncContext ctx)
|
|
{
|
|
{
|
|
if (!ctx.HasContext && ctx.GetValue(Color) is Half4 constantColor)
|
|
if (!ctx.HasContext && ctx.GetValue(Color) is Half4 constantColor)
|
|
{
|
|
{
|
|
var variable = new Half4(string.Empty);
|
|
var variable = new Half4(string.Empty);
|
|
- constantColor.ConstantValue.ToHsv(out float h, out float s, out float l);
|
|
|
|
|
|
+ constantColor.ConstantValue.ToHsl(out float h, out float s, out float l);
|
|
variable.ConstantValue = new Color((byte)(h * 255), (byte)(s * 255), (byte)(l * 255), constantColor.ConstantValue.A);
|
|
variable.ConstantValue = new Color((byte)(h * 255), (byte)(s * 255), (byte)(l * 255), constantColor.ConstantValue.A);
|
|
|
|
|
|
return variable;
|
|
return variable;
|
|
}
|
|
}
|
|
|
|
|
|
- return ctx.Builder.GetOrNewAttachedHalf4(this.GetHashCode(), Color.GetHashCode(), RgbToHsvGetter);
|
|
|
|
|
|
+ return ctx.Builder.GetOrNewAttachedHalf4(this.GetHashCode(), Color.GetHashCode(), RgbToHslGetter);
|
|
|
|
|
|
- Expression RgbToHsvGetter() => ctx.Builder.Functions.GetRgbToHsv(ctx.GetValue(Color));
|
|
|
|
|
|
+ Expression RgbToHslGetter() => ctx.Builder.Functions.GetRgbToHsl(ctx.GetValue(Color));
|
|
}
|
|
}
|
|
|
|
|
|
public override Node CreateCopy() => new SeparateColorNode();
|
|
public override Node CreateCopy() => new SeparateColorNode();
|