Skip to content

Commit

Permalink
Fix delete selected pixels
Browse files Browse the repository at this point in the history
  • Loading branch information
Equbuxu committed Dec 6, 2021
1 parent 1e7f911 commit c3334e0
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 31 deletions.
28 changes: 17 additions & 11 deletions PixiEditor/Models/Controllers/BitmapOperationsUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
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;
Expand Down Expand Up @@ -37,21 +38,26 @@ public void DeletePixels(Layer[] layers, Coordinates[] pixels)
{
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>
Expand Down
21 changes: 1 addition & 20 deletions PixiEditor/Models/Tools/BitmapOperationTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public override void AddUndoProcess(Document document)
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;
}

Expand All @@ -46,24 +46,5 @@ public override void OnRecordingLeftMouseDown(MouseEventArgs e)
_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 changes: 19 additions & 0 deletions PixiEditor/Models/Undo/StorageBasedChange.cs
Original file line number Diff line number Diff line change
Expand Up @@ -252,5 +252,24 @@ private void GenerateUndoLayers()
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);
}
}

}
}
}
}

0 comments on commit c3334e0

Please sign in to comment.