2
0
Эх сурвалжийг харах

Fix delete selected pixels

Equbuxu 3 жил өмнө
parent
commit
c3334e04f9

+ 17 - 11
PixiEditor/Models/Controllers/BitmapOperationsUtility.cs

@@ -3,6 +3,7 @@ using PixiEditor.Models.Layers;
 using PixiEditor.Models.Position;
 using PixiEditor.Models.Tools;
 using PixiEditor.Models.Tools.ToolSettings.Settings;
+using PixiEditor.Models.Undo;
 using PixiEditor.ViewModels.SubViewModels.Main;
 using SkiaSharp;
 using System;
@@ -37,21 +38,26 @@ namespace PixiEditor.Models.Controllers
             {
                 return;
             }
+
+            StorageBasedChange change = new StorageBasedChange(Manager.ActiveDocument, layers, true);
+            
+
             // TODO: Fix
-            //BitmapPixelChanges changes = BitmapPixelChanges.FromSingleColoredArray(pixels, SKColors.Empty);
+            BitmapPixelChanges changes = BitmapPixelChanges.FromSingleColoredArray(pixels, SKColors.Empty);
             //Dictionary<Guid, SKColor[]> oldValues = BitmapUtils.GetPixelsForSelection(layers, pixels);
             //LayerChange[] old = new LayerChange[layers.Length];
             //LayerChange[] newChange = new LayerChange[layers.Length];
-            //for (int i = 0; i < layers.Length; i++)
-            //{
-            //    Guid guid = layers[i].LayerGuid;
-            //    old[i] = new LayerChange(
-            //        BitmapPixelChanges.FromArrays(pixels, oldValues[layers[i].LayerGuid]), guid);
-            //    newChange[i] = new LayerChange(changes, guid);
-            //    layers[i].SetPixels(changes);
-            //}
-
-            //Manager.ActiveDocument.UndoManager.AddUndoChange(new Change("UndoChanges", old, newChange, "Deleted pixels"));
+            for (int i = 0; i < layers.Length; i++)
+            {
+                Guid guid = layers[i].LayerGuid;
+                //old[i] = new LayerChange(
+                    //BitmapPixelChanges.FromArrays(pixels, oldValues[layers[i].LayerGuid]), guid);
+                //newChange[i] = new LayerChange(changes, guid);
+                layers[i].SetPixels(changes);
+            }
+
+            var args = new object[] { change.Document };
+            Manager.ActiveDocument.UndoManager.AddUndoChange(change.ToChange(StorageBasedChange.BasicUndoProcess, args, "Delete selected pixels"));
         }
 
         /// <summary>

+ 1 - 20
PixiEditor/Models/Tools/BitmapOperationTool.cs

@@ -34,7 +34,7 @@ namespace PixiEditor.Models.Tools
             if (!UseDefaultUndoMethod) return;
 
             var args = new object[] { _change.Document };
-            document.UndoManager.AddUndoChange(_change.ToChange(UndoProcess, args));
+            document.UndoManager.AddUndoChange(_change.ToChange(StorageBasedChange.BasicUndoProcess, args));
             _change = null;
         }
 
@@ -46,24 +46,5 @@ namespace PixiEditor.Models.Tools
                 _change = new StorageBasedChange(doc, new[] { doc.ActiveLayer }, true);
             }
         }
-
-        private void UndoProcess(Layer[] layers, UndoLayer[] data, object[] args)
-        {
-            if (args.Length > 0 && args[0] is Document document)
-            {
-                for (int i = 0; i < layers.Length; i++)
-                {
-                    Layer layer = layers[i];
-                    document.Layers.RemoveAt(data[i].LayerIndex);
-
-                    document.Layers.Insert(data[i].LayerIndex, layer);
-                    if (data[i].IsActive)
-                    {
-                        document.SetMainActiveLayer(data[i].LayerIndex);
-                    }
-                }
-
-            }
-        }
     }
 }

+ 19 - 0
PixiEditor/Models/Undo/StorageBasedChange.cs

@@ -252,5 +252,24 @@ namespace PixiEditor.Models.Undo
                 i++;
             }
         }
+
+        public static void BasicUndoProcess(Layer[] layers, UndoLayer[] data, object[] args)
+        {
+            if (args.Length > 0 && args[0] is Document document)
+            {
+                for (int i = 0; i < layers.Length; i++)
+                {
+                    Layer layer = layers[i];
+                    document.Layers.RemoveAt(data[i].LayerIndex);
+
+                    document.Layers.Insert(data[i].LayerIndex, layer);
+                    if (data[i].IsActive)
+                    {
+                        document.SetMainActiveLayer(data[i].LayerIndex);
+                    }
+                }
+
+            }
+        }
     }
 }