|
@@ -23,8 +23,8 @@ namespace PixiEditor.Models.Tools.Tools
|
|
private Dictionary<Guid, bool> clearedPixels = new Dictionary<Guid, bool>();
|
|
private Dictionary<Guid, bool> clearedPixels = new Dictionary<Guid, bool>();
|
|
private Coordinates[] currentSelection;
|
|
private Coordinates[] currentSelection;
|
|
private Coordinates lastMouseMove;
|
|
private Coordinates lastMouseMove;
|
|
- private Coordinates lastStartMousePos;
|
|
|
|
private Dictionary<Guid, Color[]> startPixelColors;
|
|
private Dictionary<Guid, Color[]> startPixelColors;
|
|
|
|
+ private Dictionary<Guid, Color[]> endPixelColors;
|
|
private Dictionary<Guid, Thickness> startingOffsets;
|
|
private Dictionary<Guid, Thickness> startingOffsets;
|
|
private Coordinates[] startSelection;
|
|
private Coordinates[] startSelection;
|
|
private bool updateViewModelSelection = true;
|
|
private bool updateViewModelSelection = true;
|
|
@@ -58,23 +58,31 @@ namespace PixiEditor.Models.Tools.Tools
|
|
}
|
|
}
|
|
|
|
|
|
public override void AfterAddedUndo(UndoManager undoManager)
|
|
public override void AfterAddedUndo(UndoManager undoManager)
|
|
- {
|
|
|
|
- if (currentSelection != null && currentSelection.Length != 0)
|
|
|
|
- {
|
|
|
|
- // Inject to default undo system change custom changes made by this tool
|
|
|
|
- foreach (var item in startPixelColors)
|
|
|
|
- {
|
|
|
|
- BitmapPixelChanges beforeMovePixels = BitmapPixelChanges.FromArrays(startSelection, item.Value);
|
|
|
|
- Change changes = undoManager.UndoStack.Peek();
|
|
|
|
- Guid layerGuid = item.Key;
|
|
|
|
-
|
|
|
|
- ((LayerChange[])changes.OldValue).First(x => x.LayerGuid == layerGuid).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);
|
|
|
|
|
|
+ {
|
|
|
|
+ if (currentSelection != null && currentSelection.Length > 0)
|
|
|
|
+ {
|
|
|
|
+ Change changes = undoManager.UndoStack.Peek();
|
|
|
|
+
|
|
|
|
+ // 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;
|
|
|
|
+
|
|
|
|
+ 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);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -94,49 +102,50 @@ namespace PixiEditor.Models.Tools.Tools
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- public override LayerChange[] Use(Layer layer, Coordinates[] mouseMove, Color color)
|
|
|
|
- {
|
|
|
|
- Coordinates start = mouseMove[^1];
|
|
|
|
|
|
+ public override void OnStart(Coordinates startPos)
|
|
|
|
+ {
|
|
|
|
+ ResetSelectionValues(startPos);
|
|
|
|
|
|
- // I am aware that this could be moved to OnMouseDown, but it is executed before Use, so I didn't want to complicate for now
|
|
|
|
- if (lastStartMousePos != start)
|
|
|
|
- {
|
|
|
|
- ResetSelectionValues(start);
|
|
|
|
-
|
|
|
|
- // Move offset if no selection
|
|
|
|
- Selection selection = ViewModelMain.Current.BitmapManager.ActiveDocument.ActiveSelection;
|
|
|
|
- if (selection != null && selection.SelectedPoints.Count > 0)
|
|
|
|
- {
|
|
|
|
- currentSelection = selection.SelectedPoints.ToArray();
|
|
|
|
- }
|
|
|
|
- else
|
|
|
|
- {
|
|
|
|
- currentSelection = Array.Empty<Coordinates>();
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (Keyboard.IsKeyDown(Key.LeftCtrl) || MoveAll)
|
|
|
|
- {
|
|
|
|
- affectedLayers = ViewModelMain.Current.BitmapManager.ActiveDocument.Layers.Where(x => x.IsVisible)
|
|
|
|
- .ToArray();
|
|
|
|
- }
|
|
|
|
- else
|
|
|
|
- {
|
|
|
|
- affectedLayers = ViewModelMain.Current.BitmapManager.ActiveDocument
|
|
|
|
- .Layers.Where(x => x.IsActive && x.IsVisible).ToArray();
|
|
|
|
- }
|
|
|
|
|
|
+ // Move offset if no selection
|
|
|
|
+ Selection selection = ViewModelMain.Current.BitmapManager.ActiveDocument.ActiveSelection;
|
|
|
|
+ if (selection != null && selection.SelectedPoints.Count > 0)
|
|
|
|
+ {
|
|
|
|
+ currentSelection = selection.SelectedPoints.ToArray();
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ currentSelection = Array.Empty<Coordinates>();
|
|
|
|
+ }
|
|
|
|
|
|
- startSelection = currentSelection;
|
|
|
|
- startPixelColors = BitmapUtils.GetPixelsForSelection(affectedLayers, startSelection);
|
|
|
|
- startingOffsets = GetOffsets(affectedLayers);
|
|
|
|
- }
|
|
|
|
|
|
+ if (Keyboard.IsKeyDown(Key.LeftCtrl) || MoveAll)
|
|
|
|
+ {
|
|
|
|
+ affectedLayers = ViewModelMain.Current.BitmapManager.ActiveDocument.Layers.Where(x => x.IsVisible)
|
|
|
|
+ .ToArray();
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ affectedLayers = ViewModelMain.Current.BitmapManager.ActiveDocument
|
|
|
|
+ .Layers.Where(x => x.IsActive && x.IsVisible).ToArray();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ startSelection = currentSelection;
|
|
|
|
+ startPixelColors = BitmapUtils.GetPixelsForSelection(affectedLayers, startSelection);
|
|
|
|
+ startingOffsets = GetOffsets(affectedLayers);
|
|
|
|
+ }
|
|
|
|
|
|
|
|
+ public override LayerChange[] Use(Layer layer, Coordinates[] mouseMove, Color color)
|
|
|
|
+ {
|
|
LayerChange[] result = new LayerChange[affectedLayers.Length];
|
|
LayerChange[] result = new LayerChange[affectedLayers.Length];
|
|
- var end = mouseMove[0];
|
|
|
|
|
|
+ var end = mouseMove[0];
|
|
|
|
+ var lastSelection = currentSelection.ToArray();
|
|
for (int i = 0; i < affectedLayers.Length; i++)
|
|
for (int i = 0; i < affectedLayers.Length; i++)
|
|
{
|
|
{
|
|
if (currentSelection.Length > 0)
|
|
if (currentSelection.Length > 0)
|
|
{
|
|
{
|
|
- var changes = MoveSelection(affectedLayers[i], mouseMove);
|
|
|
|
|
|
+ endPixelColors = BitmapUtils.GetPixelsForSelection(affectedLayers, currentSelection);
|
|
|
|
+ var changes = MoveSelection(affectedLayers[i], mouseMove);
|
|
|
|
+ ClearSelectedPixels(affectedLayers[i], lastSelection);
|
|
|
|
+
|
|
changes = RemoveTransparentPixels(changes);
|
|
changes = RemoveTransparentPixels(changes);
|
|
|
|
|
|
result[i] = new LayerChange(changes, affectedLayers[i]);
|
|
result[i] = new LayerChange(changes, affectedLayers[i]);
|
|
@@ -158,13 +167,11 @@ namespace PixiEditor.Models.Tools.Tools
|
|
{
|
|
{
|
|
Coordinates end = mouseMove[0];
|
|
Coordinates end = mouseMove[0];
|
|
|
|
|
|
- currentSelection = TranslateSelection(end, out Coordinates[] previousSelection);
|
|
|
|
|
|
+ currentSelection = TranslateSelection(end);
|
|
if (updateViewModelSelection)
|
|
if (updateViewModelSelection)
|
|
{
|
|
{
|
|
ViewModelMain.Current.BitmapManager.ActiveDocument.ActiveSelection.SetSelection(currentSelection, SelectionType.New);
|
|
ViewModelMain.Current.BitmapManager.ActiveDocument.ActiveSelection.SetSelection(currentSelection, SelectionType.New);
|
|
- }
|
|
|
|
-
|
|
|
|
- ClearSelectedPixels(layer, previousSelection);
|
|
|
|
|
|
+ }
|
|
|
|
|
|
lastMouseMove = end;
|
|
lastMouseMove = end;
|
|
return BitmapPixelChanges.FromArrays(currentSelection, startPixelColors[layer.LayerGuid]);
|
|
return BitmapPixelChanges.FromArrays(currentSelection, startPixelColors[layer.LayerGuid]);
|
|
@@ -204,19 +211,20 @@ namespace PixiEditor.Models.Tools.Tools
|
|
|
|
|
|
private void ResetSelectionValues(Coordinates start)
|
|
private void ResetSelectionValues(Coordinates start)
|
|
{
|
|
{
|
|
- lastStartMousePos = start;
|
|
|
|
lastMouseMove = start;
|
|
lastMouseMove = start;
|
|
clearedPixels = new Dictionary<Guid, bool>();
|
|
clearedPixels = new Dictionary<Guid, bool>();
|
|
|
|
+ endPixelColors = new Dictionary<Guid, Color[]>();
|
|
|
|
+ currentSelection = null;
|
|
|
|
+ affectedLayers = null;
|
|
updateViewModelSelection = true;
|
|
updateViewModelSelection = true;
|
|
startPixelColors = null;
|
|
startPixelColors = null;
|
|
startSelection = null;
|
|
startSelection = null;
|
|
}
|
|
}
|
|
|
|
|
|
- private Coordinates[] TranslateSelection(Coordinates end, out Coordinates[] previousSelection)
|
|
|
|
|
|
+ private Coordinates[] TranslateSelection(Coordinates end)
|
|
{
|
|
{
|
|
Coordinates translation = Transform.GetTranslation(lastMouseMove, end);
|
|
Coordinates translation = Transform.GetTranslation(lastMouseMove, end);
|
|
- previousSelection = currentSelection.ToArray();
|
|
|
|
- return Transform.Translate(previousSelection, translation);
|
|
|
|
|
|
+ return Transform.Translate(currentSelection, translation);
|
|
}
|
|
}
|
|
|
|
|
|
private void ClearSelectedPixels(Layer layer, Coordinates[] selection)
|
|
private void ClearSelectedPixels(Layer layer, Coordinates[] selection)
|