Browse Source

Prepared controllers for multi-layer editing

flabbet 5 years ago
parent
commit
53b24436e3

+ 25 - 14
PixiEditor/Models/Controllers/BitmapOperationsUtility.cs

@@ -1,4 +1,5 @@
-using PixiEditor.Models.Position;
+using PixiEditor.Models.DataHolders;
+using PixiEditor.Models.Position;
 using PixiEditor.Models.Tools;
 using PixiEditor.Models.Tools;
 using System;
 using System;
 using System.Collections.Generic;
 using System.Collections.Generic;
@@ -13,7 +14,7 @@ namespace PixiEditor.Models.Controllers
     {
     {
 
 
         private Coordinates _lastMousePos;
         private Coordinates _lastMousePos;
-        private BitmapPixelChanges _lastChangedPixels;
+        private LayerChange[] _lastModifiedLayers;
 
 
         public event EventHandler<BitmapChangedEventArgs> BitmapChanged;
         public event EventHandler<BitmapChangedEventArgs> BitmapChanged;
 
 
@@ -38,10 +39,14 @@ namespace PixiEditor.Models.Controllers
 
 
         public void StopAction()
         public void StopAction()
         {
         {
-            BitmapPixelChanges oldValues = GetOldPixelsValues(_lastChangedPixels.ChangedPixels.Keys.ToArray());
-            Manager.ActiveLayer.ApplyPixels(_lastChangedPixels);
-            BitmapChanged?.Invoke(this, new BitmapChangedEventArgs(_lastChangedPixels, oldValues, Manager.ActiveLayerIndex));
-            Manager.PreviewLayer.Clear();
+            for (int i = 0; i < _lastModifiedLayers.Length; i++)
+            {
+                BitmapPixelChanges oldValues = GetOldPixelsValues(_lastModifiedLayers[i].PixelChanges.ChangedPixels.Keys.ToArray());
+                Manager.ActiveDocument.Layers[_lastModifiedLayers[i].LayerIndex].ApplyPixels(_lastModifiedLayers[i].PixelChanges);
+                BitmapChanged?.Invoke(this, new BitmapChangedEventArgs(_lastModifiedLayers[i].PixelChanges, 
+                    oldValues, _lastModifiedLayers[i].LayerIndex));
+                Manager.PreviewLayer.Clear();
+            }
         }
         }
 
 
 
 
@@ -54,10 +59,16 @@ namespace PixiEditor.Models.Controllers
             };
             };
             if (!tool.RequiresPreviewLayer)
             if (!tool.RequiresPreviewLayer)
             {
             {
-                BitmapPixelChanges changedPixels = tool.Use(Manager.ActiveLayer, mouseMoveCords.ToArray(), color);
-                BitmapPixelChanges oldPixelsValues = GetOldPixelsValues(changedPixels.ChangedPixels.Keys.ToArray());
-                Manager.ActiveLayer.ApplyPixels(changedPixels);
-                BitmapChanged?.Invoke(this, new BitmapChangedEventArgs(changedPixels, oldPixelsValues, Manager.ActiveLayerIndex));
+                LayerChange[] modifiedLayers = tool.Use(Manager.ActiveLayer, mouseMoveCords.ToArray(), color);
+                LayerChange[] oldPixelsValues = new LayerChange[modifiedLayers.Length];
+                for (int i = 0; i < modifiedLayers.Length; i++)
+                {
+                    oldPixelsValues[i] = new LayerChange(GetOldPixelsValues(modifiedLayers[i].PixelChanges.ChangedPixels.Keys.ToArray()), 
+                        modifiedLayers[i].LayerIndex);
+                    Manager.ActiveDocument.Layers[modifiedLayers[i].LayerIndex].ApplyPixels(modifiedLayers[i].PixelChanges);
+                    BitmapChanged?.Invoke(this, new BitmapChangedEventArgs(modifiedLayers[i].PixelChanges, 
+                        oldPixelsValues[i].PixelChanges, modifiedLayers[i].LayerIndex));
+                }              
             }
             }
             else
             else
             {
             {
@@ -107,14 +118,14 @@ namespace PixiEditor.Models.Controllers
 
 
         private void UseToolOnPreviewLayer(List<Coordinates> mouseMove)
         private void UseToolOnPreviewLayer(List<Coordinates> mouseMove)
         {
         {
-            BitmapPixelChanges changedPixels;
+            LayerChange[] modifiedLayers;
             if (mouseMove.Count > 0 && mouseMove[0] != _lastMousePos)
             if (mouseMove.Count > 0 && mouseMove[0] != _lastMousePos)
             {
             {
                 Manager.GeneratePreviewLayer();
                 Manager.GeneratePreviewLayer();
                 Manager.PreviewLayer.Clear();
                 Manager.PreviewLayer.Clear();
-                changedPixels = ((BitmapOperationTool)Manager.SelectedTool).Use(Manager.ActiveDocument.ActiveLayer, mouseMove.ToArray(), Manager.PrimaryColor);
-                Manager.PreviewLayer.ApplyPixels(changedPixels);
-                _lastChangedPixels = changedPixels;
+                modifiedLayers = ((BitmapOperationTool)Manager.SelectedTool).Use(Manager.ActiveDocument.ActiveLayer, mouseMove.ToArray(), Manager.PrimaryColor);
+                Manager.PreviewLayer.ApplyPixels(modifiedLayers[0].PixelChanges);
+                _lastModifiedLayers = modifiedLayers;
             }
             }
         }
         }
     }
     }

+ 48 - 19
PixiEditor/Models/Controllers/PixelChangesController.cs

@@ -1,4 +1,5 @@
 using PixiEditor.Models.DataHolders;
 using PixiEditor.Models.DataHolders;
+using PixiEditor.Models.Layers;
 using PixiEditor.Models.Position;
 using PixiEditor.Models.Position;
 using PixiEditor.Models.Tools;
 using PixiEditor.Models.Tools;
 using System;
 using System;
@@ -10,55 +11,83 @@ namespace PixiEditor.Models.Controllers
 {
 {
     public class PixelChangesController
     public class PixelChangesController
     {
     {
-        LayerChanges LastChanges { get; set; }
-        LayerChanges LastOldValues { get; set; }
+        Dictionary<int, LayerChange> LastChanges { get; set; }
+        Dictionary<int, LayerChange> LastOldValues { get; set; }
 
 
-        public void AddChanges(LayerChanges changes, LayerChanges oldValues)
+        public void AddChanges(LayerChange changes, LayerChange oldValues)
         {
         {
-            if (LastChanges == null)
+            if (changes.PixelChanges.ChangedPixels.Count > 0)
             {
             {
-                LastChanges = changes;
-                LastOldValues = oldValues;
-                return;
+                if (LastChanges == null)
+                {
+                    LastChanges = new Dictionary<int, LayerChange> { { changes.LayerIndex, changes } };
+                    LastOldValues = new Dictionary<int, LayerChange> { { oldValues.LayerIndex, oldValues } };
+                }
+                else if (LastChanges.ContainsKey(changes.LayerIndex))
+                {
+                    AddToExistingLayerChange(changes, oldValues);
+                }
+                else
+                {
+                    AddNewLayerChange(changes, oldValues);
+                }
             }
             }
+        }
 
 
-            foreach (var change in changes.PixelChanges.ChangedPixels)
+        private void AddNewLayerChange(LayerChange changes, LayerChange oldValues)
+        {
+            LastChanges[changes.LayerIndex] = changes;
+            LastOldValues[changes.LayerIndex] = oldValues;
+        }
+
+        private void AddToExistingLayerChange(LayerChange layerChange, LayerChange oldValues)
+        {
+            foreach (var change in layerChange.PixelChanges.ChangedPixels)
             {
             {
-                if (LastChanges.PixelChanges.ChangedPixels.ContainsKey(change.Key))
+                if (LastChanges[layerChange.LayerIndex].PixelChanges.ChangedPixels.ContainsKey(change.Key))
                 {
                 {
                     continue;
                     continue;
                 }
                 }
                 else
                 else
                 {
                 {
-                    LastChanges.PixelChanges.ChangedPixels.Add(change.Key, change.Value);
+                    LastChanges[layerChange.LayerIndex].PixelChanges.ChangedPixels.Add(change.Key, change.Value);
                 }
                 }
             }
             }
 
 
             foreach (var change in oldValues.PixelChanges.ChangedPixels)
             foreach (var change in oldValues.PixelChanges.ChangedPixels)
             {
             {
-                if (LastOldValues.PixelChanges.ChangedPixels.ContainsKey(change.Key))
+                if (LastOldValues[layerChange.LayerIndex].PixelChanges.ChangedPixels.ContainsKey(change.Key))
                 {
                 {
                     continue;
                     continue;
                 }
                 }
                 else
                 else
                 {
                 {
-                    LastOldValues.PixelChanges.ChangedPixels.Add(change.Key, change.Value);
+                    LastOldValues[layerChange.LayerIndex].PixelChanges.ChangedPixels.Add(change.Key, change.Value);
                 }
                 }
             }
             }
         }
         }
 
 
-        public Tuple<LayerChanges, LayerChanges> PopChanges()
+        public Tuple<LayerChange, LayerChange>[] PopChanges()
         {
         {
-            Dictionary<Coordinates, Color> pixelChanges = LastChanges.PixelChanges.ChangedPixels.ToDictionary(entry => entry.Key, entry => entry.Value);
-            Dictionary<Coordinates, Color> oldValues = LastOldValues.PixelChanges.ChangedPixels.ToDictionary(entry => entry.Key, entry => entry.Value);
+            //Maybe replace Tuple with custom data type
+            if (LastChanges == null) return null;
+            Tuple<LayerChange, LayerChange>[] result = new Tuple<LayerChange, LayerChange>[LastChanges.Count];
+            int i = 0;
+            foreach (var change in LastChanges)
+            {
+                Dictionary<Coordinates, Color> pixelChanges = change.Value.PixelChanges.ChangedPixels.ToDictionary(entry => entry.Key, entry => entry.Value);
+                Dictionary<Coordinates, Color> oldValues = LastOldValues[change.Key].PixelChanges.ChangedPixels.ToDictionary(entry => entry.Key, entry => entry.Value);
+
+                var tmp = new LayerChange(new BitmapPixelChanges(pixelChanges), change.Key);
+                var oldValuesTmp = new LayerChange(new BitmapPixelChanges(oldValues), change.Key);
 
 
-            var tmp = new LayerChanges(new BitmapPixelChanges(pixelChanges), LastChanges.LayerIndex);
-            var oldValuesTmp = new LayerChanges(new BitmapPixelChanges(oldValues), LastOldValues.LayerIndex);
+                result[i] = new Tuple<LayerChange, LayerChange>(tmp, oldValuesTmp);
+                i++;
+            }
 
 
-            Tuple<LayerChanges, LayerChanges> outputChanges = new Tuple<LayerChanges, LayerChanges>(tmp, oldValuesTmp);
             LastChanges = null;
             LastChanges = null;
             LastOldValues = null;
             LastOldValues = null;
-            return outputChanges;
+            return result;
         }
         }
     }
     }
 }
 }

+ 11 - 3
PixiEditor/Models/DataHolders/LayerChanges.cs

@@ -1,16 +1,24 @@
-using PixiEditor.Models.Tools;
+using PixiEditor.Models.Layers;
+using PixiEditor.Models.Tools;
+using PixiEditor.ViewModels;
 
 
 namespace PixiEditor.Models.DataHolders
 namespace PixiEditor.Models.DataHolders
 {
 {
-    public class LayerChanges
+    public class LayerChange
     {
     {
         public BitmapPixelChanges PixelChanges { get; set; }
         public BitmapPixelChanges PixelChanges { get; set; }
         public int LayerIndex { get; set; }
         public int LayerIndex { get; set; }
 
 
-        public LayerChanges(BitmapPixelChanges pixelChanges, int layerIndex)
+        public LayerChange(BitmapPixelChanges pixelChanges, int layerIndex)
         {
         {
             PixelChanges = pixelChanges;
             PixelChanges = pixelChanges;
             LayerIndex = layerIndex;
             LayerIndex = layerIndex;
         }
         }
+
+        public LayerChange(BitmapPixelChanges pixelChanges, Layer layer)
+        {
+            PixelChanges = pixelChanges;
+            LayerIndex = ViewModelMain.Current.BitmapManager.ActiveDocument.Layers.IndexOf(layer);
+        }
     }
     }
 }
 }

+ 1 - 1
PixiEditor/Models/IO/PixiFilesManager.cs → PixiEditor/Models/IO/FilesManager.cs

@@ -5,7 +5,7 @@ using System.IO;
 
 
 namespace PixiEditor.Models.IO
 namespace PixiEditor.Models.IO
 {
 {
-    public static class PixiFilesManager
+    public static class FilesManager
     {
     {
 
 
         public static string TempFolderPath
         public static string TempFolderPath

+ 3 - 2
PixiEditor/Models/Tools/BitmapOperationTool.cs

@@ -1,4 +1,5 @@
-using PixiEditor.Models.Layers;
+using PixiEditor.Models.DataHolders;
+using PixiEditor.Models.Layers;
 using PixiEditor.Models.Position;
 using PixiEditor.Models.Position;
 using System.Windows.Media;
 using System.Windows.Media;
 
 
@@ -6,7 +7,7 @@ namespace PixiEditor.Models.Tools
 {
 {
     public abstract class BitmapOperationTool : Tool
     public abstract class BitmapOperationTool : Tool
     {
     {
-        public abstract BitmapPixelChanges Use(Layer layer, Coordinates[] mouseMove, Color color);
+        public abstract LayerChange[] Use(Layer layer, Coordinates[] mouseMove, Color color);
         public bool RequiresPreviewLayer { get; set; }
         public bool RequiresPreviewLayer { get; set; }
         public bool UseDefaultUndoMethod { get; set; } = true;
         public bool UseDefaultUndoMethod { get; set; } = true;
 
 

+ 3 - 2
PixiEditor/Models/Tools/ShapeTool.cs

@@ -1,4 +1,5 @@
-using PixiEditor.Models.Layers;
+using PixiEditor.Models.DataHolders;
+using PixiEditor.Models.Layers;
 using PixiEditor.Models.Position;
 using PixiEditor.Models.Position;
 using PixiEditor.Models.Tools.ToolSettings;
 using PixiEditor.Models.Tools.ToolSettings;
 using System.Collections.Generic;
 using System.Collections.Generic;
@@ -12,7 +13,7 @@ namespace PixiEditor.Models.Tools
     {
     {
         public override abstract ToolType ToolType { get; }
         public override abstract ToolType ToolType { get; }
 
 
-        public abstract override BitmapPixelChanges Use(Layer layer, Coordinates[] coordinates, Color color);
+        public abstract override LayerChange[] Use(Layer layer, Coordinates[] coordinates, Color color);
 
 
         public ShapeTool()
         public ShapeTool()
         {
         {

+ 9 - 3
PixiEditor/Models/Tools/Tools/BrightnessTool.cs

@@ -1,4 +1,5 @@
 using PixiEditor.Models.Colors;
 using PixiEditor.Models.Colors;
+using PixiEditor.Models.DataHolders;
 using PixiEditor.Models.Layers;
 using PixiEditor.Models.Layers;
 using PixiEditor.Models.Position;
 using PixiEditor.Models.Position;
 using PixiEditor.Models.Tools.ToolSettings;
 using PixiEditor.Models.Tools.ToolSettings;
@@ -21,15 +22,20 @@ namespace PixiEditor.Models.Tools.Tools
             Toolbar = new BrightnessToolToolbar(CorrectionFactor);
             Toolbar = new BrightnessToolToolbar(CorrectionFactor);
         }
         }
 
 
-        public override BitmapPixelChanges Use(Layer layer, Coordinates[] coordinates, Color color)
+        public override LayerChange[] Use(Layer layer, Coordinates[] coordinates, Color color)
         {
         {
             int toolSize = (int)Toolbar.GetSetting("ToolSize").Value;
             int toolSize = (int)Toolbar.GetSetting("ToolSize").Value;
             float correctionFactor = (float)Toolbar.GetSetting("CorrectionFactor").Value;
             float correctionFactor = (float)Toolbar.GetSetting("CorrectionFactor").Value;
+            LayerChange[] layersChanges = new LayerChange[1];
             if (Keyboard.IsKeyDown(Key.LeftCtrl))
             if (Keyboard.IsKeyDown(Key.LeftCtrl))
             {
             {
-                return ChangeBrightness(layer, coordinates[0], toolSize, -correctionFactor);
+                layersChanges[0] = new LayerChange(ChangeBrightness(layer, coordinates[0], toolSize, -correctionFactor), layer);
             }
             }
-            return ChangeBrightness(layer, coordinates[0], toolSize, correctionFactor);
+            else
+            {
+                layersChanges[0] = new LayerChange(ChangeBrightness(layer, coordinates[0], toolSize, correctionFactor), layer);
+            }
+            return layersChanges;
         }
         }
 
 
         private BitmapPixelChanges ChangeBrightness(Layer layer, Coordinates coordinates, int toolSize, float correctionFactor)
         private BitmapPixelChanges ChangeBrightness(Layer layer, Coordinates coordinates, int toolSize, float correctionFactor)

+ 3 - 2
PixiEditor/Models/Tools/Tools/CircleTool.cs

@@ -1,4 +1,5 @@
 using PixiEditor.Helpers.Extensions;
 using PixiEditor.Helpers.Extensions;
+using PixiEditor.Models.DataHolders;
 using PixiEditor.Models.Layers;
 using PixiEditor.Models.Layers;
 using PixiEditor.Models.Position;
 using PixiEditor.Models.Position;
 using System.Collections.Generic;
 using System.Collections.Generic;
@@ -16,7 +17,7 @@ namespace PixiEditor.Models.Tools.Tools
             Tooltip = "Draws circle on cavnas (C)";
             Tooltip = "Draws circle on cavnas (C)";
         }
         }
 
 
-        public override BitmapPixelChanges Use(Layer layer, Coordinates[] coordinates, Color color)
+        public override LayerChange[] Use(Layer layer, Coordinates[] coordinates, Color color)
         {
         {
             int thickness = (int)Toolbar.GetSetting("ToolSize").Value;
             int thickness = (int)Toolbar.GetSetting("ToolSize").Value;
             DoubleCords fixedCoordinates = CalculateCoordinatesForShapeRotation(coordinates[^1], coordinates[0]);
             DoubleCords fixedCoordinates = CalculateCoordinatesForShapeRotation(coordinates[^1], coordinates[0]);
@@ -29,7 +30,7 @@ namespace PixiEditor.Models.Tools.Tools
                     BitmapPixelChanges.FromSingleColoredArray(CalculateFillForEllipse(outline), fillColor).ChangedPixels);
                     BitmapPixelChanges.FromSingleColoredArray(CalculateFillForEllipse(outline), fillColor).ChangedPixels);
             }
             }
 
 
-            return pixels;
+            return new LayerChange[] { new LayerChange(pixels, layer) };
         }
         }
 
 
         public Coordinates[] CreateEllipse(Coordinates startCoordinates, Coordinates endCoordinates, int thickness)
         public Coordinates[] CreateEllipse(Coordinates startCoordinates, Coordinates endCoordinates, int thickness)

+ 1 - 1
PixiEditor/Models/Tools/Tools/ColorPickerTool.cs

@@ -11,7 +11,7 @@ namespace PixiEditor.Models.Tools.Tools
         public ColorPickerTool()
         public ColorPickerTool()
         {
         {
             HideHighlight = true;
             HideHighlight = true;
-            Tooltip = "Swaps primary color with selected on canvas.";
+            Tooltip = "Swaps primary color with selected on canvas. (O)";
         }
         }
 
 
         public override void Use(Coordinates[] coordinates)
         public override void Use(Coordinates[] coordinates)

+ 5 - 3
PixiEditor/Models/Tools/Tools/EarserTool.cs

@@ -1,4 +1,5 @@
-using PixiEditor.Models.Layers;
+using PixiEditor.Models.DataHolders;
+using PixiEditor.Models.Layers;
 using PixiEditor.Models.Position;
 using PixiEditor.Models.Position;
 using PixiEditor.Models.Tools.ToolSettings;
 using PixiEditor.Models.Tools.ToolSettings;
 using System.Windows.Media;
 using System.Windows.Media;
@@ -15,10 +16,11 @@ namespace PixiEditor.Models.Tools.Tools
             Toolbar = new BasicToolbar();
             Toolbar = new BasicToolbar();
         }
         }
 
 
-        public override BitmapPixelChanges Use(Layer layer, Coordinates[] coordinates, Color color)
+        public override LayerChange[] Use(Layer layer, Coordinates[] coordinates, Color color)
         {
         {
             PenTool pen = new PenTool();
             PenTool pen = new PenTool();
-            return pen.Draw(coordinates[0], System.Windows.Media.Colors.Transparent, (int)Toolbar.GetSetting("ToolSize").Value);
+            var pixels = pen.Draw(coordinates[0], System.Windows.Media.Colors.Transparent, (int)Toolbar.GetSetting("ToolSize").Value);
+            return new LayerChange[] { new LayerChange(pixels, layer) };
         }
         }
     }
     }
 }
 }

+ 5 - 4
PixiEditor/Models/Tools/Tools/FloodFill.cs

@@ -1,4 +1,5 @@
-using PixiEditor.Models.Layers;
+using PixiEditor.Models.DataHolders;
+using PixiEditor.Models.Layers;
 using PixiEditor.Models.Position;
 using PixiEditor.Models.Position;
 using System;
 using System;
 using System.Collections.Generic;
 using System.Collections.Generic;
@@ -16,9 +17,9 @@ namespace PixiEditor.Models.Tools.Tools
             Tooltip = "Fills area with color (G)";
             Tooltip = "Fills area with color (G)";
         }
         }
 
 
-        public override BitmapPixelChanges Use(Layer layer, Coordinates[] coordinates, Color color)
-        {
-            return ForestFire(layer, coordinates[0], color);
+        public override LayerChange[] Use(Layer layer, Coordinates[] coordinates, Color color)
+        {
+            return new LayerChange[] { new LayerChange(ForestFire(layer, coordinates[0], color), layer) };
         }
         }
 
 
         public BitmapPixelChanges ForestFire(Layer layer, Coordinates startingCoords, Color newColor)
         public BitmapPixelChanges ForestFire(Layer layer, Coordinates startingCoords, Color newColor)

+ 5 - 3
PixiEditor/Models/Tools/Tools/LineTool.cs

@@ -1,4 +1,5 @@
-using PixiEditor.Models.Layers;
+using PixiEditor.Models.DataHolders;
+using PixiEditor.Models.Layers;
 using PixiEditor.Models.Position;
 using PixiEditor.Models.Position;
 using PixiEditor.Models.Tools.ToolSettings;
 using PixiEditor.Models.Tools.ToolSettings;
 using System.Collections.Generic;
 using System.Collections.Generic;
@@ -17,9 +18,10 @@ namespace PixiEditor.Models.Tools.Tools
             Toolbar = new BasicToolbar();
             Toolbar = new BasicToolbar();
         }
         }
 
 
-        public override BitmapPixelChanges Use(Layer layer, Coordinates[] coordinates, Color color)
+        public override LayerChange[] Use(Layer layer, Coordinates[] coordinates, Color color)
         {
         {
-            return BitmapPixelChanges.FromSingleColoredArray(CreateLine(coordinates, (int)Toolbar.GetSetting("ToolSize").Value), color);
+            var pixels = BitmapPixelChanges.FromSingleColoredArray(CreateLine(coordinates, (int)Toolbar.GetSetting("ToolSize").Value), color);
+            return new LayerChange[] { new LayerChange(pixels, layer) };
         }
         }
 
 
         public Coordinates[] CreateLine(Coordinates[] coordinates, int thickness)
         public Coordinates[] CreateLine(Coordinates[] coordinates, int thickness)

+ 9 - 8
PixiEditor/Models/Tools/Tools/MoveTool.cs

@@ -25,7 +25,7 @@ namespace PixiEditor.Models.Tools.Tools
 
 
         public MoveTool()
         public MoveTool()
         {
         {
-            Tooltip = "Moves selected pixels. (M)";
+            Tooltip = "Moves selected pixels. (V)";
             Cursor = Cursors.Arrow;
             Cursor = Cursors.Arrow;
             HideHighlight = true;
             HideHighlight = true;
             RequiresPreviewLayer = true;
             RequiresPreviewLayer = true;
@@ -34,16 +34,16 @@ namespace PixiEditor.Models.Tools.Tools
 
 
         public override void AfterAddedUndo()
         public override void AfterAddedUndo()
         {
         {
-            //Injecting to default undo system change custom changes made by this tool
+            //Inject to default undo system change custom changes made by this tool
             BitmapPixelChanges beforeMovePixels = BitmapPixelChanges.FromArrays(_startSelection, _startPixelColors);
             BitmapPixelChanges beforeMovePixels = BitmapPixelChanges.FromArrays(_startSelection, _startPixelColors);
             Change changes = UndoManager.UndoStack.Peek();
             Change changes = UndoManager.UndoStack.Peek();
-            (changes.OldValue as LayerChanges).PixelChanges.ChangedPixels.
+            (changes.OldValue as LayerChange[])[0].PixelChanges.ChangedPixels.
                 AddRangeOverride(beforeMovePixels.ChangedPixels);
                 AddRangeOverride(beforeMovePixels.ChangedPixels);
-            (changes.NewValue as LayerChanges).PixelChanges.ChangedPixels.AddRangeOverride(_clearedPixelsChange.ChangedPixels);
+            (changes.NewValue as LayerChange[])[0].PixelChanges.ChangedPixels.AddRangeOverride(_clearedPixelsChange.ChangedPixels);
 
 
         }
         }
 
 
-        public override BitmapPixelChanges Use(Layer layer, Coordinates[] mouseMove, Color color)
+        public override LayerChange[] Use(Layer layer, Coordinates[] mouseMove, Color color)
         {
         {
             Coordinates start = mouseMove[^1];
             Coordinates start = mouseMove[^1];
             if (_lastStartMousePos != start) //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) //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
@@ -68,13 +68,15 @@ namespace PixiEditor.Models.Tools.Tools
             {
             {
                 selection.ChangedPixels.Remove(item.Key);
                 selection.ChangedPixels.Remove(item.Key);
             }
             }
-            return selection;
+            return new LayerChange[] { new LayerChange(selection, layer) };
         }
         }
 
 
         public BitmapPixelChanges MoveSelection(Layer layer, Coordinates[] mouseMove)
         public BitmapPixelChanges MoveSelection(Layer layer, Coordinates[] mouseMove)
         {
         {
             Coordinates end = mouseMove[0];
             Coordinates end = mouseMove[0];
 
 
+            Layer[] affectedLayers = new Layer[] { layer };
+
             _currentSelection = TranslateSelection(end, out Coordinates[] previousSelection);
             _currentSelection = TranslateSelection(end, out Coordinates[] previousSelection);
             if (_updateViewModelSelection)
             if (_updateViewModelSelection)
             {
             {
@@ -84,8 +86,7 @@ namespace PixiEditor.Models.Tools.Tools
 
 
 
 
             _lastMouseMove = end;
             _lastMouseMove = end;
-            return BitmapPixelChanges.FromArrays(
-                        _currentSelection, _startPixelColors);
+            return BitmapPixelChanges.FromArrays(_currentSelection, _startPixelColors);
         }
         }
 
 
         private void ResetSelectionValues(Coordinates start)
         private void ResetSelectionValues(Coordinates start)

+ 5 - 3
PixiEditor/Models/Tools/Tools/PenTool.cs

@@ -1,4 +1,5 @@
-using PixiEditor.Models.Layers;
+using PixiEditor.Models.DataHolders;
+using PixiEditor.Models.Layers;
 using PixiEditor.Models.Position;
 using PixiEditor.Models.Position;
 using PixiEditor.Models.Tools.ToolSettings;
 using PixiEditor.Models.Tools.ToolSettings;
 using System.Windows.Input;
 using System.Windows.Input;
@@ -19,9 +20,10 @@ namespace PixiEditor.Models.Tools.Tools
             _toolSizeIndex = Toolbar.Settings.IndexOf(Toolbar.GetSetting("ToolSize"));
             _toolSizeIndex = Toolbar.Settings.IndexOf(Toolbar.GetSetting("ToolSize"));
         }
         }
 
 
-        public override BitmapPixelChanges Use(Layer layer, Coordinates[] coordinates, Color color)
+        public override LayerChange[] Use(Layer layer, Coordinates[] coordinates, Color color)
         {
         {
-            return Draw(coordinates[0], color, (int)Toolbar.Settings[_toolSizeIndex].Value);
+            var pixels = Draw(coordinates[0], color, (int)Toolbar.Settings[_toolSizeIndex].Value);
+            return new LayerChange[] { new LayerChange(pixels, layer) };
         }
         }
 
 
         public BitmapPixelChanges Draw(Coordinates startingCoords, Color color, int toolSize)
         public BitmapPixelChanges Draw(Coordinates startingCoords, Color color, int toolSize)

+ 4 - 3
PixiEditor/Models/Tools/Tools/RectangleTool.cs

@@ -1,4 +1,5 @@
 using PixiEditor.Helpers.Extensions;
 using PixiEditor.Helpers.Extensions;
+using PixiEditor.Models.DataHolders;
 using PixiEditor.Models.Layers;
 using PixiEditor.Models.Layers;
 using PixiEditor.Models.Position;
 using PixiEditor.Models.Position;
 using System;
 using System;
@@ -18,7 +19,7 @@ namespace PixiEditor.Models.Tools.Tools
             Tooltip = "Draws rectanlge on cavnas (R)";
             Tooltip = "Draws rectanlge on cavnas (R)";
         }
         }
 
 
-        public override BitmapPixelChanges Use(Layer layer, Coordinates[] coordinates, Color color)
+        public override LayerChange[] Use(Layer layer, Coordinates[] coordinates, Color color)
         {
         {
             int thickness = (int)Toolbar.GetSetting("ToolSize").Value;
             int thickness = (int)Toolbar.GetSetting("ToolSize").Value;
             BitmapPixelChanges pixels = BitmapPixelChanges.FromSingleColoredArray(CreateRectangle(coordinates, thickness), color);
             BitmapPixelChanges pixels = BitmapPixelChanges.FromSingleColoredArray(CreateRectangle(coordinates, thickness), color);
@@ -28,8 +29,8 @@ namespace PixiEditor.Models.Tools.Tools
                 pixels.ChangedPixels.AddRangeOverride(
                 pixels.ChangedPixels.AddRangeOverride(
                     BitmapPixelChanges.FromSingleColoredArray
                     BitmapPixelChanges.FromSingleColoredArray
                     (CalculateFillForRectangle(coordinates[^1], coordinates[0], thickness), fillColor).ChangedPixels);
                     (CalculateFillForRectangle(coordinates[^1], coordinates[0], thickness), fillColor).ChangedPixels);
-            }
-            return pixels;
+            }
+            return new LayerChange[] { new LayerChange(pixels, layer) };
         }
         }
 
 
         public Coordinates[] CreateRectangle(Coordinates[] coordinates, int thickness)
         public Coordinates[] CreateRectangle(Coordinates[] coordinates, int thickness)

+ 5 - 0
PixiEditor/Models/Tools/Tools/SelectTool.cs

@@ -14,6 +14,11 @@ namespace PixiEditor.Models.Tools.Tools
 
 
         Selection _oldSelection = null;
         Selection _oldSelection = null;
 
 
+        public SelectTool()
+        {
+            Tooltip = "Selects area. (M)";
+        }
+
         public override void OnMouseDown()
         public override void OnMouseDown()
         {
         {
             _oldSelection = null;
             _oldSelection = null;

+ 17 - 9
PixiEditor/ViewModels/ViewModelMain.cs

@@ -108,15 +108,19 @@ namespace PixiEditor.ViewModels
 
 
         public ObservableCollection<Tool> ToolSet { get; set; }
         public ObservableCollection<Tool> ToolSet { get; set; }
 
 
-        private LayerChanges _undoChanges;
+        private LayerChange[] _undoChanges;
 
 
-        public LayerChanges UndoChanges
+        public LayerChange[] UndoChanges
         {
         {
             get { return _undoChanges; }
             get { return _undoChanges; }
             set
             set
             {
             {
                 _undoChanges = value;
                 _undoChanges = value;
-                BitmapManager.ActiveDocument.Layers[value.LayerIndex].ApplyPixels(value.PixelChanges);
+                for (int i = 0; i < value.Length; i++)
+                {
+                    BitmapManager.ActiveDocument.Layers[value[i].LayerIndex].ApplyPixels(value[i].PixelChanges);
+
+                }
             }
             }
         }
         }
 
 
@@ -152,7 +156,7 @@ namespace PixiEditor.ViewModels
 
 
         public ViewModelMain()
         public ViewModelMain()
         {
         {
-            PixiFilesManager.InitializeTempDirectories();
+            FilesManager.InitializeTempDirectories();
             BitmapManager = new BitmapManager();
             BitmapManager = new BitmapManager();
             BitmapManager.BitmapOperations.BitmapChanged += BitmapUtility_BitmapChanged;
             BitmapManager.BitmapOperations.BitmapChanged += BitmapUtility_BitmapChanged;
             BitmapManager.MouseController.StoppedRecordingChanges += MouseController_StoppedRecordingChanges;
             BitmapManager.MouseController.StoppedRecordingChanges += MouseController_StoppedRecordingChanges;
@@ -197,6 +201,8 @@ namespace PixiEditor.ViewModels
                     new Shortcut(Key.L, SelectToolCommand, ToolType.Line),
                     new Shortcut(Key.L, SelectToolCommand, ToolType.Line),
                     new Shortcut(Key.G, SelectToolCommand, ToolType.Bucket),
                     new Shortcut(Key.G, SelectToolCommand, ToolType.Bucket),
                     new Shortcut(Key.U, SelectToolCommand, ToolType.Brightness),
                     new Shortcut(Key.U, SelectToolCommand, ToolType.Brightness),
+                    new Shortcut(Key.V, SelectToolCommand, ToolType.Move),
+                    new Shortcut(Key.M, SelectToolCommand, ToolType.Select),
                     new Shortcut(Key.Y, RedoCommand, modifier: ModifierKeys.Control),
                     new Shortcut(Key.Y, RedoCommand, modifier: ModifierKeys.Control),
                     new Shortcut(Key.Z, UndoCommand),
                     new Shortcut(Key.Z, UndoCommand),
                     new Shortcut(Key.S, SaveFileCommand, modifier: ModifierKeys.Control),
                     new Shortcut(Key.S, SaveFileCommand, modifier: ModifierKeys.Control),
@@ -297,10 +303,12 @@ namespace PixiEditor.ViewModels
             if (BitmapManager.IsOperationTool(BitmapManager.SelectedTool) 
             if (BitmapManager.IsOperationTool(BitmapManager.SelectedTool) 
                 && (BitmapManager.SelectedTool as BitmapOperationTool).UseDefaultUndoMethod)
                 && (BitmapManager.SelectedTool as BitmapOperationTool).UseDefaultUndoMethod)
             {
             {
-                Tuple<LayerChanges, LayerChanges> changes = ChangesController.PopChanges();
-                if (changes.Item1.PixelChanges.ChangedPixels.Count > 0)
+                Tuple<LayerChange, LayerChange>[] changes = ChangesController.PopChanges();
+                if (changes != null && changes.Length > 0)
                 {
                 {
-                    UndoManager.AddUndoChange(new Change("UndoChanges", changes.Item2, changes.Item1)); //Item2 is old value
+                    LayerChange[] newValues = changes.Select(x => x.Item1).ToArray();
+                    LayerChange[] oldValues = changes.Select(x => x.Item2).ToArray();
+                    UndoManager.AddUndoChange(new Change("UndoChanges", oldValues, newValues)); 
                     BitmapManager.SelectedTool.AfterAddedUndo();
                     BitmapManager.SelectedTool.AfterAddedUndo();
                 }
                 }
             }
             }
@@ -308,8 +316,8 @@ namespace PixiEditor.ViewModels
 
 
         private void BitmapUtility_BitmapChanged(object sender, BitmapChangedEventArgs e)
         private void BitmapUtility_BitmapChanged(object sender, BitmapChangedEventArgs e)
         {
         {
-            ChangesController.AddChanges(new LayerChanges(e.PixelsChanged, e.ChangedLayerIndex),
-                new LayerChanges(e.OldPixelsValues, e.ChangedLayerIndex));
+            ChangesController.AddChanges(new LayerChange(e.PixelsChanged, e.ChangedLayerIndex),
+                new LayerChange(e.OldPixelsValues, e.ChangedLayerIndex));
         }
         }
 
 
         public void SwapColors(object parameter)
         public void SwapColors(object parameter)

BIN
Zadania_Uzasadnij_tekst.pdf