Skip to content

Commit

Permalink
FIXED MOVE TOOL FINALLY
Browse files Browse the repository at this point in the history
  • Loading branch information
flabbet committed Mar 8, 2021
1 parent bc836ae commit fa4641d
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions PixiEditor/Models/Tools/Tools/MoveTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ public class MoveTool : BitmapOperationTool
private Dictionary<Guid, bool> clearedPixels = new Dictionary<Guid, bool>();
private Coordinates[] currentSelection;
private Coordinates lastMouseMove;
private Coordinates lastStartMousePos;
private Dictionary<Guid, Color[]> startPixelColors;
private Dictionary<Guid, Color[]> endPixelColors;
private Dictionary<Guid, Thickness> startingOffsets;
private Coordinates[] startSelection;
private bool updateViewModelSelection = true;
Expand Down Expand Up @@ -67,12 +67,15 @@ public override void AfterAddedUndo(UndoManager undoManager)
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))
{
oldValue.First(x => x.LayerGuid == layerGuid).PixelChanges.ChangedPixels
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
Expand Down Expand Up @@ -138,6 +141,7 @@ public override LayerChange[] Use(Layer layer, Coordinates[] mouseMove, Color co
{
if (currentSelection.Length > 0)
{
endPixelColors = BitmapUtils.GetPixelsForSelection(affectedLayers, currentSelection);
var changes = MoveSelection(affectedLayers[i], mouseMove);
changes = RemoveTransparentPixels(changes);

Expand Down Expand Up @@ -206,7 +210,6 @@ private BitmapPixelChanges RemoveTransparentPixels(BitmapPixelChanges pixels)

private void ResetSelectionValues(Coordinates start)
{
lastStartMousePos = start;
lastMouseMove = start;
clearedPixels = new Dictionary<Guid, bool>();
updateViewModelSelection = true;
Expand Down

0 comments on commit fa4641d

Please sign in to comment.