Browse Source

Texture changed rerender

flabbet 1 year ago
parent
commit
0619dc4eb6

+ 9 - 0
src/PixiEditor.DrawingApi.Core/Texture.cs

@@ -13,6 +13,7 @@ public class Texture : IDisposable
     public VecI Size { get; }
     public VecI Size { get; }
     public DrawingSurface Surface { get; }
     public DrawingSurface Surface { get; }
 
 
+    public event SurfaceChangedEventHandler? Changed;
     
     
     public bool IsDisposed { get; private set; }
     public bool IsDisposed { get; private set; }
 
 
@@ -26,8 +27,15 @@ public class Texture : IDisposable
                     GpuBacked = true
                     GpuBacked = true
                 });
                 });
         
         
+        Surface.Changed += SurfaceOnChanged;
     }
     }
 
 
+    private void SurfaceOnChanged(RectD? changedRect)
+    {
+        Changed?.Invoke(changedRect);
+    }
+
+
     public static Texture Load(string path)
     public static Texture Load(string path)
     {
     {
         if (!File.Exists(path))
         if (!File.Exists(path))
@@ -99,6 +107,7 @@ public class Texture : IDisposable
             return;
             return;
 
 
         IsDisposed = true;
         IsDisposed = true;
+        Surface.Changed -= SurfaceOnChanged;
         Surface.Dispose();
         Surface.Dispose();
     }
     }
 }
 }

+ 1 - 1
src/PixiEditor.DrawingApi.Skia/Implementations/SkiaSurfaceImplementation.cs

@@ -152,7 +152,7 @@ namespace PixiEditor.DrawingApi.Skia.Implementations
 
 
         public void Flush(DrawingSurface drawingSurface)
         public void Flush(DrawingSurface drawingSurface)
         {
         {
-            ManagedInstances[drawingSurface.ObjectPointer].Flush(true, false);
+            ManagedInstances[drawingSurface.ObjectPointer].Flush(true, true);
         }
         }
     }
     }
 }
 }

+ 19 - 0
src/PixiEditor/Views/Visuals/TextureControl.cs

@@ -41,6 +41,7 @@ public class TextureControl : Control
     public TextureControl()
     public TextureControl()
     {
     {
         ClipToBounds = true;
         ClipToBounds = true;
+        TextureProperty.Changed.Subscribe(OnTextureChanged);
     }
     }
 
 
     /// <summary>
     /// <summary>
@@ -100,6 +101,24 @@ public class TextureControl : Control
 
 
         context.Custom(drawOperation);
         context.Custom(drawOperation);
     }
     }
+    
+    private void OnTextureChanged(AvaloniaPropertyChangedEventArgs<Texture> args)
+    {
+        if (args.OldValue.Value != null)
+        {
+            args.OldValue.Value.Changed -= TextureOnChanged;
+        }
+        
+        if (args.NewValue.Value != null)
+        {
+            args.NewValue.Value.Changed += TextureOnChanged;
+        }
+    }
+    
+    private void TextureOnChanged(RectD? changedRect)
+    {
+        Dispatcher.UIThread.Post(InvalidateVisual, DispatcherPriority.Render);
+    }
 }
 }
 
 
 internal class DrawTextureOperation : SkiaDrawOperation
 internal class DrawTextureOperation : SkiaDrawOperation