|
@@ -41,6 +41,8 @@ namespace PixiEditor.Models.Tools.Tools
|
|
|
|
|
|
public bool MoveAll { get; set; } = false;
|
|
|
|
|
|
+ public BitmapManager BitmapManager { get; set; }
|
|
|
+
|
|
|
public override void OnKeyDown(KeyEventArgs e)
|
|
|
{
|
|
|
if (e.Key == Key.LeftCtrl)
|
|
@@ -59,31 +61,33 @@ namespace PixiEditor.Models.Tools.Tools
|
|
|
|
|
|
public override void AfterAddedUndo(UndoManager undoManager)
|
|
|
{
|
|
|
- if (currentSelection != null && currentSelection.Length > 0)
|
|
|
+ if (currentSelection == null || currentSelection.Length == 0)
|
|
|
{
|
|
|
- Change changes = undoManager.UndoStack.Peek();
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
- // Inject to default undo system change custom changes made by this tool
|
|
|
- foreach (var item in startPixelColors)
|
|
|
- {
|
|
|
- BitmapPixelChanges beforeMovePixels = BitmapPixelChanges.FromArrays(startSelection, item.Value);
|
|
|
- BitmapPixelChanges afterMovePixels = BitmapPixelChanges.FromArrays(currentSelection, endPixelColors[item.Key]);
|
|
|
- Guid layerGuid = item.Key;
|
|
|
- var oldValue = (LayerChange[])changes.OldValue;
|
|
|
+ Change changes = undoManager.UndoStack.Peek();
|
|
|
|
|
|
- if (oldValue.Any(x => x.LayerGuid == layerGuid))
|
|
|
- {
|
|
|
- var layer = oldValue.First(x => x.LayerGuid == layerGuid);
|
|
|
- layer.PixelChanges.ChangedPixels.AddRangeOverride(afterMovePixels.ChangedPixels);
|
|
|
- layer.PixelChanges.ChangedPixels
|
|
|
- .AddRangeOverride(beforeMovePixels.ChangedPixels);
|
|
|
+ // Inject to default undo system change custom changes made by this tool
|
|
|
+ foreach (var item in startPixelColors)
|
|
|
+ {
|
|
|
+ BitmapPixelChanges beforeMovePixels = BitmapPixelChanges.FromArrays(startSelection, item.Value);
|
|
|
+ BitmapPixelChanges afterMovePixels = BitmapPixelChanges.FromArrays(currentSelection, endPixelColors[item.Key]);
|
|
|
+ Guid layerGuid = item.Key;
|
|
|
+ var oldValue = (LayerChange[])changes.OldValue;
|
|
|
|
|
|
- ((LayerChange[])changes.NewValue).First(x => x.LayerGuid == layerGuid).PixelChanges.ChangedPixels
|
|
|
- .AddRangeNewOnly(BitmapPixelChanges
|
|
|
- .FromSingleColoredArray(startSelection, System.Windows.Media.Colors.Transparent)
|
|
|
- .ChangedPixels);
|
|
|
- }
|
|
|
- }
|
|
|
+ if (oldValue.Any(x => x.LayerGuid == layerGuid))
|
|
|
+ {
|
|
|
+ var layer = oldValue.First(x => x.LayerGuid == layerGuid);
|
|
|
+ layer.PixelChanges.ChangedPixels.AddRangeOverride(afterMovePixels.ChangedPixels);
|
|
|
+ layer.PixelChanges.ChangedPixels
|
|
|
+ .AddRangeOverride(beforeMovePixels.ChangedPixels);
|
|
|
+
|
|
|
+ ((LayerChange[])changes.NewValue).First(x => x.LayerGuid == layerGuid).PixelChanges.ChangedPixels
|
|
|
+ .AddRangeNewOnly(BitmapPixelChanges
|
|
|
+ .FromSingleColoredArray(startSelection, System.Windows.Media.Colors.Transparent)
|
|
|
+ .ChangedPixels);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -93,7 +97,7 @@ namespace PixiEditor.Models.Tools.Tools
|
|
|
{
|
|
|
if (currentSelection != null && currentSelection.Length == 0)
|
|
|
{
|
|
|
- ViewModelMain.Current.BitmapManager.ActiveDocument.UndoManager.AddUndoChange(new Change(
|
|
|
+ BitmapManager.ActiveDocument.UndoManager.AddUndoChange(new Change(
|
|
|
ApplyOffsets,
|
|
|
new object[] { startingOffsets },
|
|
|
ApplyOffsets,
|
|
@@ -107,7 +111,7 @@ namespace PixiEditor.Models.Tools.Tools
|
|
|
ResetSelectionValues(startPos);
|
|
|
|
|
|
// Move offset if no selection
|
|
|
- var doc = ViewModelMain.Current.BitmapManager.ActiveDocument;
|
|
|
+ Document doc = ViewModelMain.Current.BitmapManager.ActiveDocument;
|
|
|
Selection selection = doc.ActiveSelection;
|
|
|
if (selection != null && selection.SelectedPoints.Count > 0)
|
|
|
{
|
|
@@ -232,7 +236,7 @@ namespace PixiEditor.Models.Tools.Tools
|
|
|
Guid layerGuid = layer.LayerGuid;
|
|
|
if (!clearedPixels.ContainsKey(layerGuid) || clearedPixels[layerGuid] == false)
|
|
|
{
|
|
|
- ViewModelMain.Current.BitmapManager.ActiveDocument.Layers.First(x => x == layer)
|
|
|
+ BitmapManager.ActiveDocument.Layers.First(x => x == layer)
|
|
|
.SetPixels(BitmapPixelChanges.FromSingleColoredArray(selection, System.Windows.Media.Colors.Transparent));
|
|
|
|
|
|
clearedPixels[layerGuid] = true;
|