Browse Source

another batch of fixes

flabbet 1 year ago
parent
commit
248bd089b7

+ 4 - 1
src/PixiEditor.AvaloniaUI/ViewModels/Nodes/NodePropertyViewModel.cs

@@ -168,7 +168,10 @@ internal abstract class NodePropertyViewModel<T> : NodePropertyViewModel
             if (base.Value == null)
                 return default;
 
-            return (T)base.Value;
+            if (base.Value is T value)
+                return value;
+            
+            return default;
         }
         set => base.Value = value;
     }

+ 14 - 2
src/PixiEditor.ChangeableDocument/Changeables/Graph/FuncInputProperty.cs

@@ -26,7 +26,7 @@ public class FuncInputProperty<T> : InputProperty<Func<FuncContext, T>>, IFuncIn
         Func<FuncContext, T> func = f =>
         {
             ConversionTable.TryConvert(delegateToCast.DynamicInvoke(f), typeof(T), out var result);
-            return (T)result;
+            return result == null ? default : (T)result; 
         };
         return func;
     }
@@ -35,6 +35,18 @@ public class FuncInputProperty<T> : InputProperty<Func<FuncContext, T>>, IFuncIn
 
     void IFuncInputProperty.SetFuncConstantValue(object? value)
     {
-        constantNonOverrideValue = value == null ? default : (T)value;
+        if (value is T)
+        {
+            constantNonOverrideValue = (T)value;
+            return;
+        }
+        
+        if(ConversionTable.TryConvert(value, typeof(T), out var result))
+        {
+            constantNonOverrideValue = (T)result;
+            return;
+        }
+
+        constantNonOverrideValue = default;
     }
 }

+ 3 - 3
src/PixiEditor.ChangeableDocument/Changeables/Graph/Nodes/ModifyImageRightNode.cs

@@ -64,13 +64,13 @@ public class ModifyImageRightNode : Node, IPairNodeEnd
             for (int x = 0; x < width; x++)
             {
                 context.UpdateContext(new VecD((double)x / width, (double)y / height), new VecI(width, height));
-                var color = Color.Value(context);
                 var uv = Coordinate.Value(context);
-                var position = new VecD(uv.X * width, uv.Y * height);
+                context.UpdateContext(uv, new VecI(width, height));
+                var color = Color.Value(context);
                 
                 drawingPaint.Color = color;
 
-                surface.DrawingSurface.Canvas.DrawPixel((int)position.X, (int)position.Y, drawingPaint);
+                surface.DrawingSurface.Canvas.DrawPixel(x, y, drawingPaint);
             }
         }
 

+ 5 - 5
src/PixiEditor.DrawingApi.Core/ColorsImpl/Color.cs

@@ -218,12 +218,12 @@ namespace PixiEditor.DrawingApi.Core.ColorsImpl
         return this == Empty ? null : $"{this._colorValue:X8}";
     }
 
-    public static Color Lerp(Color from, Color to, double time)
+    public static Color Lerp(Color from, Color to, double t)
     {
-        byte r = (byte)(from.R + (to.R - from.R) * time);
-        byte g = (byte)(from.G + (to.G - from.G) * time);
-        byte b = (byte)(from.B + (to.B - from.B) * time);
-        byte a = (byte)(from.A + (to.A - from.A) * time);
+        byte r = (byte)(from.R + (to.R - from.R) * t);
+        byte g = (byte)(from.G + (to.G - from.G) * t);
+        byte b = (byte)(from.B + (to.B - from.B) * t);
+        byte a = (byte)(from.A + (to.A - from.A) * t);
         return new Color(r, g, b, a);
     }
   }