Browse Source

Fixed undo for drawing (render + merged packets)

flabbet 10 months ago
parent
commit
cdfb747187

+ 2 - 2
src/PixiEditor.ChangeableDocument/Changeables/Graph/Nodes/ImageLayerNode.cs

@@ -22,7 +22,7 @@ public class ImageLayerNode : LayerNode, IReadOnlyImageNode
 
 
     private VecI size;
     private VecI size;
     private ChunkyImage layerImage => keyFrames[0]?.Data as ChunkyImage;
     private ChunkyImage layerImage => keyFrames[0]?.Data as ChunkyImage;
-
+    protected Paint replacePaint = new Paint() { BlendMode = DrawingApi.Core.Surfaces.BlendMode.Src };
 
 
     private static readonly Paint clearPaint = new()
     private static readonly Paint clearPaint = new()
     {
     {
@@ -299,7 +299,7 @@ public class ImageLayerNode : LayerNode, IReadOnlyImageNode
             resolution,
             resolution,
             renderedSurfaces[resolution].DrawingSurface,
             renderedSurfaces[resolution].DrawingSurface,
             chunkPos * resolution.PixelSize(),
             chunkPos * resolution.PixelSize(),
-            blendPaint);
+            replacePaint);
         
         
         renderedSurfaces[resolution].DrawingSurface.Flush();
         renderedSurfaces[resolution].DrawingSurface.Flush();
     }
     }

+ 11 - 9
src/PixiEditor.ChangeableDocument/DocumentChangeTracker.cs

@@ -28,7 +28,7 @@ public class DocumentChangeTracker : IDisposable
     }
     }
 
 
     private UpdateableChange? activeUpdateableChange = null;
     private UpdateableChange? activeUpdateableChange = null;
-    private List<Change>? activePacket = null;
+    private List<(ActionSource source, Change change)>? activePacket = null;
 
 
     private Stack<(ActionSource source, List<Change> changes)> undoStack = new();
     private Stack<(ActionSource source, List<Change> changes)> undoStack = new();
     private Stack<(ActionSource source, List<Change> changes)> redoStack = new();
     private Stack<(ActionSource source, List<Change> changes)> redoStack = new();
@@ -48,7 +48,7 @@ public class DocumentChangeTracker : IDisposable
         if (activePacket != null)
         if (activePacket != null)
         {
         {
             foreach (var change in activePacket)
             foreach (var change in activePacket)
-                change.Dispose();
+                change.change.Dispose();
         }
         }
 
 
         foreach (var list in undoStack)
         foreach (var list in undoStack)
@@ -69,11 +69,11 @@ public class DocumentChangeTracker : IDisposable
         document = new Document();
         document = new Document();
     }
     }
 
 
-    private void AddToUndo(Change change)
+    private void AddToUndo(Change change, ActionSource source)
     {
     {
         if (activePacket is null)
         if (activePacket is null)
             activePacket = new();
             activePacket = new();
-        activePacket.Add(change);
+        activePacket.Add((source, change));
 
 
         foreach (var changesToDispose in redoStack)
         foreach (var changesToDispose in redoStack)
         {
         {
@@ -94,13 +94,15 @@ public class DocumentChangeTracker : IDisposable
             undoStack.Count > 0 &&
             undoStack.Count > 0 &&
             (undoStack.Peek().source == ActionSource.Automated ||
             (undoStack.Peek().source == ActionSource.Automated ||
             (IsHomologous(undoStack.Peek()) &&
             (IsHomologous(undoStack.Peek()) &&
-            undoStack.Peek().changes[^1].IsMergeableWith(activePacket[0]))))
+            undoStack.Peek().changes[^1].IsMergeableWith(activePacket[0].change))))
         {
         {
-            undoStack.Peek().changes.Add(activePacket[0]);
+            undoStack.Peek().changes.Add(activePacket[0].change);
         }
         }
         else
         else
         {
         {
-            undoStack.Push((source, activePacket));
+            undoStack.Push(
+                (activePacket.Any(x => x.source == ActionSource.User) ? ActionSource.User : source,  
+                activePacket.Select(x => x.change).ToList()));
         }
         }
 
 
         activePacket = null;
         activePacket = null;
@@ -205,7 +207,7 @@ public class DocumentChangeTracker : IDisposable
 
 
         var info = change.Apply(document, true, out bool ignoreInUndo);
         var info = change.Apply(document, true, out bool ignoreInUndo);
         if (!ignoreInUndo)
         if (!ignoreInUndo)
-            AddToUndo(change);
+            AddToUndo(change, ActionSource.User);
         else
         else
             change.Dispose();
             change.Dispose();
         return info;
         return info;
@@ -249,7 +251,7 @@ public class DocumentChangeTracker : IDisposable
 
 
         var info = activeUpdateableChange.Apply(document, true, out bool ignoreInUndo);
         var info = activeUpdateableChange.Apply(document, true, out bool ignoreInUndo);
         if (!ignoreInUndo)
         if (!ignoreInUndo)
-            AddToUndo(activeUpdateableChange);
+            AddToUndo(activeUpdateableChange, ActionSource.User);
         else
         else
             activeUpdateableChange.Dispose();
             activeUpdateableChange.Dispose();
         activeUpdateableChange = null;
         activeUpdateableChange = null;