Browse Source

Displaying layers wip

Frytek 5 years ago
parent
commit
1cf596847c
42 changed files with 220 additions and 146 deletions
  1. 1 1
      PixiEditorDotNetCore3/Models/Colors/ExColor.cs
  2. 50 3
      PixiEditorDotNetCore3/Models/Controllers/BitmapOperationsUtility.cs
  3. 2 1
      PixiEditorDotNetCore3/Models/Controllers/MouseMovementController.cs
  4. 1 1
      PixiEditorDotNetCore3/Models/Controllers/UndoManager.cs
  5. 1 1
      PixiEditorDotNetCore3/Models/DataHolders/Change.cs
  6. 4 4
      PixiEditorDotNetCore3/Models/DataHolders/StackEx.cs
  7. 1 1
      PixiEditorDotNetCore3/Models/DataHolders/Tuple.cs
  8. 1 1
      PixiEditorDotNetCore3/Models/Dialogs/CustomDialog.cs
  9. 1 1
      PixiEditorDotNetCore3/Models/Dialogs/ExportFileDialog.cs
  10. 1 1
      PixiEditorDotNetCore3/Models/Dialogs/ImportFileDialog.cs
  11. 1 1
      PixiEditorDotNetCore3/Models/Dialogs/NewFileDialog.cs
  12. 1 1
      PixiEditorDotNetCore3/Models/Enums/FileType.cs
  13. 2 2
      PixiEditorDotNetCore3/Models/Enums/LayerAction.cs
  14. 3 3
      PixiEditorDotNetCore3/Models/IO/Exporter.cs
  15. 1 1
      PixiEditorDotNetCore3/Models/IO/Importer.cs
  16. 1 1
      PixiEditorDotNetCore3/Models/IO/PixiFilesManager.cs
  17. 1 1
      PixiEditorDotNetCore3/Models/Images/BitmapConverter.cs
  18. 1 1
      PixiEditorDotNetCore3/Models/Images/ImageGenerator.cs
  19. 1 1
      PixiEditorDotNetCore3/Models/Layers/BasicLayer.cs
  20. 20 8
      PixiEditorDotNetCore3/Models/Layers/Layer.cs
  21. 2 2
      PixiEditorDotNetCore3/Models/Layers/LayerGenerator.cs
  22. 1 1
      PixiEditorDotNetCore3/Models/Layers/LightLayer.cs
  23. 27 27
      PixiEditorDotNetCore3/Models/Position/Coordinates.cs
  24. 1 1
      PixiEditorDotNetCore3/Models/Position/CoordinatesCalculator.cs
  25. 1 1
      PixiEditorDotNetCore3/Models/Position/DoubleCords.cs
  26. 2 2
      PixiEditorDotNetCore3/Models/Position/MousePositionConverter.cs
  27. 10 10
      PixiEditorDotNetCore3/Models/Tools/BitmapPixelChanges.cs
  28. 3 3
      PixiEditorDotNetCore3/Models/Tools/ShapeTool.cs
  29. 3 3
      PixiEditorDotNetCore3/Models/Tools/Tool.cs
  30. 1 1
      PixiEditorDotNetCore3/Models/Tools/ToolType.cs
  31. 4 4
      PixiEditorDotNetCore3/Models/Tools/Tools/BrightnessTool.cs
  32. 3 3
      PixiEditorDotNetCore3/Models/Tools/Tools/CircleTool.cs
  33. 3 3
      PixiEditorDotNetCore3/Models/Tools/Tools/EarserTool.cs
  34. 10 7
      PixiEditorDotNetCore3/Models/Tools/Tools/FloodFill.cs
  35. 3 3
      PixiEditorDotNetCore3/Models/Tools/Tools/LineTool.cs
  36. 3 3
      PixiEditorDotNetCore3/Models/Tools/Tools/PenTool.cs
  37. 4 4
      PixiEditorDotNetCore3/Models/Tools/Tools/RectangleTool.cs
  38. 3 3
      PixiEditorDotNetCore3/Models/Tools/ToolsManager.cs
  39. 1 1
      PixiEditorDotNetCore3/ViewModels/NewFileMenuViewModel.cs
  40. 36 25
      PixiEditorDotNetCore3/ViewModels/ViewModelMain.cs
  41. 1 1
      PixiEditorDotNetCore3/Views/MainDrawingPanel.xaml.cs
  42. 3 3
      PixiEditorDotNetCore3/Views/MainWindow.xaml

+ 1 - 1
PixiEditorDotNetCore3/Models/Colors/ExColor.cs

@@ -1,6 +1,6 @@
 using System.Windows.Media;
 using System.Windows.Media;
 
 
-namespace PixiEditorDotNetCore3.Models.Colors
+namespace PixiEditor.Models.Colors
 {
 {
     public static class ExColor
     public static class ExColor
     {
     {

+ 50 - 3
PixiEditorDotNetCore3/Models/Controllers/BitmapOperationsUtility.cs

@@ -1,13 +1,16 @@
 using PixiEditor.Helpers;
 using PixiEditor.Helpers;
 using PixiEditor.Models.Controllers;
 using PixiEditor.Models.Controllers;
-using PixiEditorDotNetCore3.Models.Layers;
-using PixiEditorDotNetCore3.Models.Position;
-using PixiEditorDotNetCore3.Models.Tools;
+using PixiEditor.Models.Enums;
+using PixiEditor.Models.Layers;
+using PixiEditor.Models.Position;
+using PixiEditor.Models.Tools;
 using System;
 using System;
 using System.Collections.ObjectModel;
 using System.Collections.ObjectModel;
 using System.Diagnostics;
 using System.Diagnostics;
+using System.Linq;
 using System.Windows.Input;
 using System.Windows.Input;
 using System.Windows.Media;
 using System.Windows.Media;
+using System.Windows.Media.Imaging;
 
 
 namespace PixiEditor.Models.Controllers
 namespace PixiEditor.Models.Controllers
 {
 {
@@ -42,6 +45,7 @@ namespace PixiEditor.Models.Controllers
         public int ToolSize { get; set; }
         public int ToolSize { get; set; }
 
 
         public event EventHandler<BitmapChangedEventArgs> BitmapChanged;
         public event EventHandler<BitmapChangedEventArgs> BitmapChanged;
+        public event EventHandler<LayersChangedEventArgs> LayersChanged;
 
 
         public BitmapOperationsUtility()
         public BitmapOperationsUtility()
         {
         {
@@ -70,12 +74,43 @@ namespace PixiEditor.Models.Controllers
             {
             {
                 ActiveLayerIndex = 0;
                 ActiveLayerIndex = 0;
             }
             }
+            LayersChanged?.Invoke(this, new LayersChangedEventArgs(0, LayerAction.Add));
         }
         }
 
 
         public void SetActiveLayer(int index)
         public void SetActiveLayer(int index)
         {
         {
             ActiveLayerIndex = index;
             ActiveLayerIndex = index;
+            LayersChanged?.Invoke(this, new LayersChangedEventArgs(index, LayerAction.SetActive));
         }
         }
+
+        public WriteableBitmap GetCombinedBitmaps()
+        {
+            Layer[] visibleLayers = Layers.Where(x => x.IsVisible).ToArray();
+            visibleLayers.Reverse();
+            int width = visibleLayers[0].Width;
+            int height = visibleLayers[0].Height;
+            WriteableBitmap finalBitmap = BitmapFactory.New(width, height);
+            finalBitmap.Lock();
+            finalBitmap = WriteLayersToBitmap(finalBitmap, visibleLayers);
+            finalBitmap.Unlock();
+            return finalBitmap;
+        }
+
+        private WriteableBitmap WriteLayersToBitmap(WriteableBitmap targetBitmap, Layer[] layers)
+        {
+            for (int i = 0; i < layers.Length; i++)
+            {
+                Coordinates[] nonTransparentCords = layers[i].GetNonTransprarentPixels();
+                for (int j = 0; j < nonTransparentCords.Length; j++)
+                {
+                    int x = nonTransparentCords[j].X;
+                    int y = nonTransparentCords[j].Y;
+                    targetBitmap.SetPixel(x, y, layers[i].LayerBitmap.GetPixel(x,y));
+                }
+            }
+            return targetBitmap;
+        }
+
     }
     }
 }
 }
 
 
@@ -90,3 +125,15 @@ public class BitmapChangedEventArgs : EventArgs
         ChangedLayerIndex = changedLayerIndex;
         ChangedLayerIndex = changedLayerIndex;
     }
     }
 }
 }
+
+public class LayersChangedEventArgs : EventArgs
+{
+    public int LayerAffected { get; set; }
+    public LayerAction LayerChangeType { get; set; }
+
+    public LayersChangedEventArgs(int layerAffected, LayerAction layerChangeType)
+    {
+        LayerAffected = layerAffected;
+        LayerChangeType = layerChangeType;
+    }
+}

+ 2 - 1
PixiEditorDotNetCore3/Models/Controllers/MouseMovementController.cs

@@ -1,4 +1,4 @@
-using PixiEditorDotNetCore3.Models.Position;
+using PixiEditor.Models.Position;
 using System;
 using System;
 using System.Collections.Generic;
 using System.Collections.Generic;
 using System.Text;
 using System.Text;
@@ -16,6 +16,7 @@ namespace PixiEditor.Models.Controllers
         {
         {
             if (IsRecordingChanges == false)
             if (IsRecordingChanges == false)
             {
             {
+                LastMouseMoveCoordinates.Clear();
                 IsRecordingChanges = true;
                 IsRecordingChanges = true;
             }
             }
         }
         }

+ 1 - 1
PixiEditorDotNetCore3/Models/Controllers/UndoManager.cs

@@ -1,4 +1,4 @@
-using PixiEditorDotNetCore3.Models.DataHolders;
+using PixiEditor.Models.DataHolders;
 using System.Collections.Generic;
 using System.Collections.Generic;
 using System.Diagnostics;
 using System.Diagnostics;
 using System.Linq;
 using System.Linq;

+ 1 - 1
PixiEditorDotNetCore3/Models/DataHolders/Change.cs

@@ -5,7 +5,7 @@ using System.Runtime.Serialization;
 using System.Text;
 using System.Text;
 using System.Threading.Tasks;
 using System.Threading.Tasks;
 
 
-namespace PixiEditorDotNetCore3.Models.DataHolders
+namespace PixiEditor.Models.DataHolders
 {
 {
     [Serializable]
     [Serializable]
     public class Change
     public class Change

+ 4 - 4
PixiEditorDotNetCore3/Models/DataHolders/StackEx.cs

@@ -4,7 +4,7 @@ using System.Linq;
 using System.Text;
 using System.Text;
 using System.Threading.Tasks;
 using System.Threading.Tasks;
 
 
-namespace PixiEditorDotNetCore3.Models.DataHolders
+namespace PixiEditor.Models.DataHolders
 {
 {
     public class StackEx<T>
     public class StackEx<T>
     {
     {
@@ -25,9 +25,9 @@ namespace PixiEditorDotNetCore3.Models.DataHolders
             items.Clear();
             items.Clear();
         }
         }
 
 
-        /// <summary>
-        /// Returns top object without deleting it.
-        /// </summary>
+        /// <summary>
+        /// Returns top object without deleting it.
+        /// </summary>
         /// <returns>Returns n - 1 item from stack.</returns>
         /// <returns>Returns n - 1 item from stack.</returns>
         public T Peek()
         public T Peek()
         {
         {

+ 1 - 1
PixiEditorDotNetCore3/Models/DataHolders/Tuple.cs

@@ -2,7 +2,7 @@
 using System.Collections.Generic;
 using System.Collections.Generic;
 using System.Text;
 using System.Text;
 
 
-namespace PixiEditorDotNetCore3.Models.DataHolders
+namespace PixiEditor.Models.DataHolders
 {
 {
     public class Tuple<T1, T2, T3> : IEquatable<object>
     public class Tuple<T1, T2, T3> : IEquatable<object>
     {
     {

+ 1 - 1
PixiEditorDotNetCore3/Models/Dialogs/CustomDialog.cs

@@ -7,7 +7,7 @@ using System.Text;
 using System.Threading.Tasks;
 using System.Threading.Tasks;
 using System.Windows;
 using System.Windows;
 
 
-namespace PixiEditorDotNetCore3.Models.Dialogs
+namespace PixiEditor.Models.Dialogs
 {
 {
     public abstract class CustomDialog : NotifyableObject
     public abstract class CustomDialog : NotifyableObject
     {
     {

+ 1 - 1
PixiEditorDotNetCore3/Models/Dialogs/ExportFileDialog.cs

@@ -7,7 +7,7 @@ using System.Text;
 using System.Threading.Tasks;
 using System.Threading.Tasks;
 using System.Windows;
 using System.Windows;
 
 
-namespace PixiEditorDotNetCore3.Models.Dialogs
+namespace PixiEditor.Models.Dialogs
 {
 {
     public class ExportFileDialog : CustomDialog
     public class ExportFileDialog : CustomDialog
     {
     {

+ 1 - 1
PixiEditorDotNetCore3/Models/Dialogs/ImportFileDialog.cs

@@ -6,7 +6,7 @@ using System.Text;
 using System.Threading.Tasks;
 using System.Threading.Tasks;
 using System.Windows;
 using System.Windows;
 
 
-namespace PixiEditorDotNetCore3.Models.Dialogs
+namespace PixiEditor.Models.Dialogs
 {
 {
     class ImportFileDialog : CustomDialog
     class ImportFileDialog : CustomDialog
     {
     {

+ 1 - 1
PixiEditorDotNetCore3/Models/Dialogs/NewFileDialog.cs

@@ -7,7 +7,7 @@ using System.Text;
 using System.Threading.Tasks;
 using System.Threading.Tasks;
 using System.Windows;
 using System.Windows;
 
 
-namespace PixiEditorDotNetCore3.Models.Dialogs
+namespace PixiEditor.Models.Dialogs
 {
 {
     public class NewFileDialog : CustomDialog
     public class NewFileDialog : CustomDialog
     {
     {

+ 1 - 1
PixiEditorDotNetCore3/Models/Enums/FileType.cs

@@ -4,7 +4,7 @@ using System.Linq;
 using System.Text;
 using System.Text;
 using System.Threading.Tasks;
 using System.Threading.Tasks;
 
 
-namespace PixiEditorDotNetCore3.Models.Enums
+namespace PixiEditor.Models.Enums
 {
 {
     public enum FileType
     public enum FileType
     {
     {

+ 2 - 2
PixiEditorDotNetCore3/Models/Enums/MouseAction.cs → PixiEditorDotNetCore3/Models/Enums/LayerAction.cs

@@ -4,8 +4,8 @@ using System.Text;
 
 
 namespace PixiEditor.Models.Enums
 namespace PixiEditor.Models.Enums
 {
 {
-    public enum MouseAction
+    public enum LayerAction
     {
     {
-        Move, MouseDown, MouseUp
+        Add, Remove, Move, SetActive
     }
     }
 }
 }

+ 3 - 3
PixiEditorDotNetCore3/Models/IO/Exporter.cs

@@ -10,10 +10,10 @@ using System.Windows.Controls;
 using System.Windows.Media;
 using System.Windows.Media;
 using System.Windows.Media.Imaging;
 using System.Windows.Media.Imaging;
 using Microsoft.Win32;
 using Microsoft.Win32;
-using PixiEditorDotNetCore3.Models.Dialogs;
-using PixiEditorDotNetCore3.Models.Enums;
+using PixiEditor.Models.Dialogs;
+using PixiEditor.Models.Enums;
 
 
-namespace PixiEditorDotNetCore3.Models.IO
+namespace PixiEditor.Models.IO
 {
 {
     public class Exporter
     public class Exporter
     {
     {

+ 1 - 1
PixiEditorDotNetCore3/Models/IO/Importer.cs

@@ -7,7 +7,7 @@ using System.Threading.Tasks;
 using System.Windows.Media.Imaging;
 using System.Windows.Media.Imaging;
 using System.Windows.Media;
 using System.Windows.Media;
 
 
-namespace PixiEditorDotNetCore3.Models.IO
+namespace PixiEditor.Models.IO
 {
 {
     public class Importer : NotifyableObject
     public class Importer : NotifyableObject
     {
     {

+ 1 - 1
PixiEditorDotNetCore3/Models/IO/PixiFilesManager.cs

@@ -5,7 +5,7 @@ using System.IO;
 using System.Text;
 using System.Text;
 using Newtonsoft.Json;
 using Newtonsoft.Json;
 
 
-namespace PixiEditorDotNetCore3.Models.IO
+namespace PixiEditor.Models.IO
 {
 {
     public static class PixiFilesManager
     public static class PixiFilesManager
     {
     {

+ 1 - 1
PixiEditorDotNetCore3/Models/Images/BitmapConverter.cs

@@ -8,7 +8,7 @@ using System.Threading.Tasks;
 using System.Windows.Media;
 using System.Windows.Media;
 using System.Windows.Media.Imaging;
 using System.Windows.Media.Imaging;
 
 
-namespace PixiEditorDotNetCore3.Models.Images
+namespace PixiEditor.Models.Images
 {
 {
     public static class BitmapConverter
     public static class BitmapConverter
     {
     {

+ 1 - 1
PixiEditorDotNetCore3/Models/Images/ImageGenerator.cs

@@ -6,7 +6,7 @@ using System.Threading.Tasks;
 using System.Windows.Controls;
 using System.Windows.Controls;
 using System.Windows.Media;
 using System.Windows.Media;
 
 
-namespace PixiEditorDotNetCore3.Models.Images
+namespace PixiEditor.Models.Images
 {
 {
     public static class ImageGenerator
     public static class ImageGenerator
     {
     {

+ 1 - 1
PixiEditorDotNetCore3/Models/Layers/BasicLayer.cs

@@ -6,7 +6,7 @@ using System.Threading.Tasks;
 using System.Windows.Controls;
 using System.Windows.Controls;
 using PixiEditor.Helpers;
 using PixiEditor.Helpers;
 
 
-namespace PixiEditorDotNetCore3.Models.Layers
+namespace PixiEditor.Models.Layers
 {
 {
     [Serializable]
     [Serializable]
     public class BasicLayer : NotifyableObject
     public class BasicLayer : NotifyableObject

+ 20 - 8
PixiEditorDotNetCore3/Models/Layers/Layer.cs

@@ -1,13 +1,10 @@
-using PixiEditorDotNetCore3.Models.Tools;
+using PixiEditor.Models.Position;
+using PixiEditor.Models.Tools;
 using System;
 using System;
-using System.ComponentModel;
-using System.Runtime.InteropServices;
-using System.Threading.Tasks;
-using System.Windows;
-using System.Windows.Media;
+using System.Collections.Generic;
 using System.Windows.Media.Imaging;
 using System.Windows.Media.Imaging;
 
 
-namespace PixiEditorDotNetCore3.Models.Layers
+namespace PixiEditor.Models.Layers
 {
 {
     public class Layer : BasicLayer
     public class Layer : BasicLayer
     {
     {
@@ -25,7 +22,7 @@ namespace PixiEditorDotNetCore3.Models.Layers
             }
             }
         }
         }
 
 
-        public Layer(string name,int width, int height)
+        public Layer(string name, int width, int height)
         {
         {
             Name = name;
             Name = name;
             Layer layer = LayerGenerator.Generate(width, height);
             Layer layer = LayerGenerator.Generate(width, height);
@@ -55,6 +52,21 @@ namespace PixiEditorDotNetCore3.Models.Layers
             LayerBitmap.Unlock();
             LayerBitmap.Unlock();
         }
         }
 
 
+        public Coordinates[] GetNonTransprarentPixels()
+        {
+            List<Coordinates> coordinates = new List<Coordinates>();
+            for (int y = 0; y < Height; y++)
+            {
+                for (int x = 0; x < Width; x++)
+                {
+                    if (LayerBitmap.GetPixeli(x, y) != 0)
+                    {
+                        coordinates.Add(new Coordinates(x, y));
+                    }
+                }
+            }
+            return coordinates.ToArray();
+        }
 
 
         public byte[] ConvertBitmapToBytes()
         public byte[] ConvertBitmapToBytes()
         {            
         {            

+ 2 - 2
PixiEditorDotNetCore3/Models/Layers/LayerGenerator.cs

@@ -1,4 +1,4 @@
-using PixiEditorDotNetCore3.Models.Tools;
+using PixiEditor.Models.Tools;
 using System;
 using System;
 using System.Collections.Generic;
 using System.Collections.Generic;
 using System.ComponentModel;
 using System.ComponentModel;
@@ -10,7 +10,7 @@ using System.Windows.Controls;
 using System.Windows.Media;
 using System.Windows.Media;
 using System.Windows.Media.Imaging;
 using System.Windows.Media.Imaging;
 
 
-namespace PixiEditorDotNetCore3.Models.Layers
+namespace PixiEditor.Models.Layers
 {
 {
     public static class LayerGenerator
     public static class LayerGenerator
     {
     {

+ 1 - 1
PixiEditorDotNetCore3/Models/Layers/LightLayer.cs

@@ -8,7 +8,7 @@ using Newtonsoft.Json;
 using Newtonsoft.Json.Linq;
 using Newtonsoft.Json.Linq;
 using PixiEditor.Helpers;
 using PixiEditor.Helpers;
 
 
-namespace PixiEditorDotNetCore3.Models.Layers
+namespace PixiEditor.Models.Layers
 {
 {
     [Serializable]
     [Serializable]
     public class LightLayer : BasicLayer
     public class LightLayer : BasicLayer

+ 27 - 27
PixiEditorDotNetCore3/Models/Position/Coordinates.cs

@@ -1,31 +1,31 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace PixiEditorDotNetCore3.Models.Position
-{
-    public struct Coordinates
-    {
-        public int X { get; set; }
-
-        public int Y { get; set; }
-
-        public Coordinates(int x, int y)
-        {
-            X = x;
-            Y = y;
-        }
-
-        public override string ToString() => $"x: {X}, y: {Y}";
-
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace PixiEditor.Models.Position
+{
+    public struct Coordinates
+    {
+        public int X { get; set; }
+
+        public int Y { get; set; }
+
+        public Coordinates(int x, int y)
+        {
+            X = x;
+            Y = y;
+        }
+
+        public override string ToString() => $"x: {X}, y: {Y}";
+
         public static bool operator ==(Coordinates c1, Coordinates c2)
         public static bool operator ==(Coordinates c1, Coordinates c2)
         {
         {
             if (c1 == null || c2 == null) return false;
             if (c1 == null || c2 == null) return false;
             return c2.X == c1.X && c2.Y == c1.Y;
             return c2.X == c1.X && c2.Y == c1.Y;
-        }
-
+        }
+
         public static bool operator !=(Coordinates c1, Coordinates c2)
         public static bool operator !=(Coordinates c1, Coordinates c2)
         {
         {
             return !(c1 == c2);
             return !(c1 == c2);
@@ -49,6 +49,6 @@ namespace PixiEditorDotNetCore3.Models.Position
                 hash = (hash * HashingMultiplier) ^ (!ReferenceEquals(null, Y) ? Y.GetHashCode() : 0);            
                 hash = (hash * HashingMultiplier) ^ (!ReferenceEquals(null, Y) ? Y.GetHashCode() : 0);            
                 return hash;
                 return hash;
             }
             }
-        }
-    }
-}
+        }
+    }
+}

+ 1 - 1
PixiEditorDotNetCore3/Models/Position/CoordinatesCalculator.cs

@@ -2,7 +2,7 @@
 using System.Collections.Generic;
 using System.Collections.Generic;
 using System.Text;
 using System.Text;
 
 
-namespace PixiEditorDotNetCore3.Models.Position
+namespace PixiEditor.Models.Position
 {
 {
     public static class CoordinatesCalculator
     public static class CoordinatesCalculator
     {
     {

+ 1 - 1
PixiEditorDotNetCore3/Models/Position/DoubleCords.cs

@@ -4,7 +4,7 @@ using System.Linq;
 using System.Text;
 using System.Text;
 using System.Threading.Tasks;
 using System.Threading.Tasks;
 
 
-namespace PixiEditorDotNetCore3.Models.Position
+namespace PixiEditor.Models.Position
 {
 {
     public class DoubleCords
     public class DoubleCords
     {
     {

+ 2 - 2
PixiEditorDotNetCore3/Models/Position/MousePositionConverter.cs

@@ -1,7 +1,7 @@
-using PixiEditorDotNetCore3.Models.Layers;
+using PixiEditor.Models.Layers;
 using System.Windows;
 using System.Windows;
 
 
-namespace PixiEditorDotNetCore3.Models.Position
+namespace PixiEditor.Models.Position
 {
 {
     public static class MousePositionConverter
     public static class MousePositionConverter
     {
     {

+ 10 - 10
PixiEditorDotNetCore3/Models/Tools/BitmapPixelChanges.cs

@@ -1,10 +1,10 @@
-using PixiEditorDotNetCore3.Models.Position;
+using PixiEditor.Models.Position;
 using System;
 using System;
 using System.Collections.Generic;
 using System.Collections.Generic;
 using System.Text;
 using System.Text;
 using System.Windows.Media;
 using System.Windows.Media;
 
 
-namespace PixiEditorDotNetCore3.Models.Tools
+namespace PixiEditor.Models.Tools
 {
 {
     public struct BitmapPixelChanges
     public struct BitmapPixelChanges
     {
     {
@@ -15,14 +15,14 @@ namespace PixiEditorDotNetCore3.Models.Tools
             ChangedPixels = changedPixels;
             ChangedPixels = changedPixels;
         }
         }
 
 
-        public static BitmapPixelChanges FromSingleColoredArray(Coordinates[] coordinates, Color color)
-        {
-            Dictionary<Coordinates, Color> dict = new Dictionary<Coordinates, Color>();
-            for (int i = 0; i < coordinates.Length; i++)
-            {
-                dict.Add(coordinates[i], color);
-            }
-            return new BitmapPixelChanges(dict);
+        public static BitmapPixelChanges FromSingleColoredArray(Coordinates[] coordinates, Color color)
+        {
+            Dictionary<Coordinates, Color> dict = new Dictionary<Coordinates, Color>();
+            for (int i = 0; i < coordinates.Length; i++)
+            {
+                dict.Add(coordinates[i], color);
+            }
+            return new BitmapPixelChanges(dict);
         }
         }
     }
     }
 }
 }

+ 3 - 3
PixiEditorDotNetCore3/Models/Tools/ShapeTool.cs

@@ -1,11 +1,11 @@
-using PixiEditorDotNetCore3.Models.Layers;
-using PixiEditorDotNetCore3.Models.Position;
+using PixiEditor.Models.Layers;
+using PixiEditor.Models.Position;
 using System;
 using System;
 using System.Collections.Generic;
 using System.Collections.Generic;
 using System.Text;
 using System.Text;
 using System.Windows.Media;
 using System.Windows.Media;
 
 
-namespace PixiEditorDotNetCore3.Models.Tools
+namespace PixiEditor.Models.Tools
 {
 {
     public abstract class ShapeTool : Tool
     public abstract class ShapeTool : Tool
     {
     {

+ 3 - 3
PixiEditorDotNetCore3/Models/Tools/Tool.cs

@@ -1,11 +1,11 @@
-using PixiEditorDotNetCore3.Models.Layers;
-using PixiEditorDotNetCore3.Models.Position;
+using PixiEditor.Models.Layers;
+using PixiEditor.Models.Position;
 using System;
 using System;
 using System.Collections.Generic;
 using System.Collections.Generic;
 using System.Text;
 using System.Text;
 using System.Windows.Media;
 using System.Windows.Media;
 
 
-namespace PixiEditorDotNetCore3.Models.Tools
+namespace PixiEditor.Models.Tools
 {
 {
     public abstract class Tool
     public abstract class Tool
     {
     {

+ 1 - 1
PixiEditorDotNetCore3/Models/Tools/ToolType.cs

@@ -4,7 +4,7 @@ using System.Linq;
 using System.Text;
 using System.Text;
 using System.Threading.Tasks;
 using System.Threading.Tasks;
 
 
-namespace PixiEditorDotNetCore3.Models.Tools
+namespace PixiEditor.Models.Tools
 {
 {
     public enum ToolType
     public enum ToolType
     {
     {

+ 4 - 4
PixiEditorDotNetCore3/Models/Tools/Tools/BrightnessTool.cs

@@ -1,11 +1,11 @@
-using PixiEditorDotNetCore3.Models.Colors;
-using PixiEditorDotNetCore3.Models.Layers;
-using PixiEditorDotNetCore3.Models.Position;
+using PixiEditor.Models.Colors;
+using PixiEditor.Models.Layers;
+using PixiEditor.Models.Position;
 using System.Windows.Input;
 using System.Windows.Input;
 using System.Windows.Media;
 using System.Windows.Media;
 using System.Windows.Media.Imaging;
 using System.Windows.Media.Imaging;
 
 
-namespace PixiEditorDotNetCore3.Models.Tools.Tools
+namespace PixiEditor.Models.Tools.Tools
 {
 {
     public class BrightnessTool : Tool
     public class BrightnessTool : Tool
     {
     {

+ 3 - 3
PixiEditorDotNetCore3/Models/Tools/Tools/CircleTool.cs

@@ -1,9 +1,9 @@
-using PixiEditorDotNetCore3.Models.Layers;
-using PixiEditorDotNetCore3.Models.Position;
+using PixiEditor.Models.Layers;
+using PixiEditor.Models.Position;
 using System.Windows.Media;
 using System.Windows.Media;
 using System.Windows.Media.Imaging;
 using System.Windows.Media.Imaging;
 
 
-namespace PixiEditorDotNetCore3.Models.Tools.Tools
+namespace PixiEditor.Models.Tools.Tools
 {
 {
     public class CircleTool : ShapeTool
     public class CircleTool : ShapeTool
     {
     {

+ 3 - 3
PixiEditorDotNetCore3/Models/Tools/Tools/EarserTool.cs

@@ -1,11 +1,11 @@
-using PixiEditorDotNetCore3.Models.Layers;
-using PixiEditorDotNetCore3.Models.Position;
+using PixiEditor.Models.Layers;
+using PixiEditor.Models.Position;
 using System;
 using System;
 using System.Collections.Generic;
 using System.Collections.Generic;
 using System.Text;
 using System.Text;
 using System.Windows.Media;
 using System.Windows.Media;
 
 
-namespace PixiEditorDotNetCore3.Models.Tools.Tools
+namespace PixiEditor.Models.Tools.Tools
 {
 {
     public class EarserTool : Tool
     public class EarserTool : Tool
     {
     {

+ 10 - 7
PixiEditorDotNetCore3/Models/Tools/Tools/FloodFill.cs

@@ -1,11 +1,11 @@
-using PixiEditorDotNetCore3.Models.Layers;
-using PixiEditorDotNetCore3.Models.Position;
+using PixiEditor.Models.Layers;
+using PixiEditor.Models.Position;
 using System;
 using System;
 using System.Collections.Generic;
 using System.Collections.Generic;
 using System.Windows.Media;
 using System.Windows.Media;
 using System.Windows.Media.Imaging;
 using System.Windows.Media.Imaging;
 
 
-namespace PixiEditorDotNetCore3.Models.Tools.Tools
+namespace PixiEditor.Models.Tools.Tools
 {
 {
     public class FloodFill : Tool
     public class FloodFill : Tool
     {
     {
@@ -25,28 +25,31 @@ namespace PixiEditorDotNetCore3.Models.Tools.Tools
         {
         {
             List<Coordinates> changedCoords = new List<Coordinates>();
             List<Coordinates> changedCoords = new List<Coordinates>();
 
 
-            Color colorToReplace = layer.LayerBitmap.GetPixel(startingCoords.X, startingCoords.Y);
+            WriteableBitmap bitmap = layer.LayerBitmap.Clone();
+            Color colorToReplace = bitmap.GetPixel(startingCoords.X, startingCoords.Y);
 
 
             var stack = new Stack<Tuple<int, int>>();
             var stack = new Stack<Tuple<int, int>>();
             stack.Push(Tuple.Create(startingCoords.X, startingCoords.Y));
             stack.Push(Tuple.Create(startingCoords.X, startingCoords.Y));
 
 
+            bitmap.Lock();
             while (stack.Count > 0)
             while (stack.Count > 0)
             {
             {
                 var point = stack.Pop();
                 var point = stack.Pop();
                 if (point.Item1 < 0 || point.Item1 > layer.Height - 1) continue;
                 if (point.Item1 < 0 || point.Item1 > layer.Height - 1) continue;
                 if (point.Item2 < 0 || point.Item2 > layer.Width - 1) continue;
                 if (point.Item2 < 0 || point.Item2 > layer.Width - 1) continue;
-                if (layer.LayerBitmap.GetPixel(point.Item1, point.Item2) == newColor) continue;
+                if (bitmap.GetPixel(point.Item1, point.Item2) == newColor) continue;
 
 
-                if (layer.LayerBitmap.GetPixel(point.Item1, point.Item2) == colorToReplace)
+                if (bitmap.GetPixel(point.Item1, point.Item2) == colorToReplace)
                 {
                 {
                     changedCoords.Add(new Coordinates(point.Item1, point.Item2));
                     changedCoords.Add(new Coordinates(point.Item1, point.Item2));
-                    layer.LayerBitmap.SetPixel(point.Item1, point.Item2, newColor);
+                    bitmap.SetPixel(point.Item1, point.Item2, newColor);
                     stack.Push(Tuple.Create(point.Item1, point.Item2 - 1));
                     stack.Push(Tuple.Create(point.Item1, point.Item2 - 1));
                     stack.Push(Tuple.Create(point.Item1 + 1, point.Item2));
                     stack.Push(Tuple.Create(point.Item1 + 1, point.Item2));
                     stack.Push(Tuple.Create(point.Item1, point.Item2 + 1));
                     stack.Push(Tuple.Create(point.Item1, point.Item2 + 1));
                     stack.Push(Tuple.Create(point.Item1 - 1, point.Item2));
                     stack.Push(Tuple.Create(point.Item1 - 1, point.Item2));
                 }
                 }
             }
             }
+            bitmap.Unlock();
             return BitmapPixelChanges.FromSingleColoredArray(changedCoords.ToArray(), newColor);
             return BitmapPixelChanges.FromSingleColoredArray(changedCoords.ToArray(), newColor);
         }
         }
     }
     }

+ 3 - 3
PixiEditorDotNetCore3/Models/Tools/Tools/LineTool.cs

@@ -1,9 +1,9 @@
-using PixiEditorDotNetCore3.Models.Layers;
-using PixiEditorDotNetCore3.Models.Position;
+using PixiEditor.Models.Layers;
+using PixiEditor.Models.Position;
 using System.Windows.Media;
 using System.Windows.Media;
 using System.Windows.Media.Imaging;
 using System.Windows.Media.Imaging;
 
 
-namespace PixiEditorDotNetCore3.Models.Tools.Tools
+namespace PixiEditor.Models.Tools.Tools
 {
 {
     public class LineTool : ShapeTool
     public class LineTool : ShapeTool
     {
     {

+ 3 - 3
PixiEditorDotNetCore3/Models/Tools/Tools/PenTool.cs

@@ -1,11 +1,11 @@
-using PixiEditorDotNetCore3.Models.Layers;
-using PixiEditorDotNetCore3.Models.Position;
+using PixiEditor.Models.Layers;
+using PixiEditor.Models.Position;
 using System;
 using System;
 using System.Collections.Generic;
 using System.Collections.Generic;
 using System.Text;
 using System.Text;
 using System.Windows.Media;
 using System.Windows.Media;
 
 
-namespace PixiEditorDotNetCore3.Models.Tools.Tools
+namespace PixiEditor.Models.Tools.Tools
 {
 {
     public class PenTool : Tool
     public class PenTool : Tool
     {
     {

+ 4 - 4
PixiEditorDotNetCore3/Models/Tools/Tools/RectangleTool.cs

@@ -1,9 +1,9 @@
-using PixiEditorDotNetCore3.Models.Layers;
-using PixiEditorDotNetCore3.Models.Position;
+using PixiEditor.Models.Layers;
+using PixiEditor.Models.Position;
 using System.Windows.Media;
 using System.Windows.Media;
 using System.Windows.Media.Imaging;
 using System.Windows.Media.Imaging;
 
 
-namespace PixiEditorDotNetCore3.Models.Tools.Tools
+namespace PixiEditor.Models.Tools.Tools
 {
 {
     public class RectangleTool : ShapeTool
     public class RectangleTool : ShapeTool
     {
     {
@@ -11,7 +11,7 @@ namespace PixiEditorDotNetCore3.Models.Tools.Tools
 
 
         public override BitmapPixelChanges Use(Layer layer, Coordinates[] coordinates, Color color, int toolSize)
         public override BitmapPixelChanges Use(Layer layer, Coordinates[] coordinates, Color color, int toolSize)
         {
         {
-            CreateRectangle(layer,coordinates[0] ,color,toolSize);
+            CreateRectangle(layer,coordinates[0], color, toolSize);
             return new BitmapPixelChanges();
             return new BitmapPixelChanges();
         }
         }
 
 

+ 3 - 3
PixiEditorDotNetCore3/Models/Tools/ToolsManager.cs

@@ -9,10 +9,10 @@ using PixiEditor.ViewModels;
 using System.Timers;
 using System.Timers;
 using System.Windows.Threading;
 using System.Windows.Threading;
 using System.Threading;
 using System.Threading;
-using PixiEditorDotNetCore3.Models.Layers;
-using PixiEditorDotNetCore3.Models.Position;
+using PixiEditor.Models.Layers;
+using PixiEditor.Models.Position;
 
 
-namespace PixiEditorDotNetCore3.Models.Tools
+namespace PixiEditor.Models.Tools
 {
 {
     public class ToolsManager
     public class ToolsManager
     {
     {

+ 1 - 1
PixiEditorDotNetCore3/ViewModels/NewFileMenuViewModel.cs

@@ -1,5 +1,5 @@
 using PixiEditor.Helpers;
 using PixiEditor.Helpers;
-using PixiEditorDotNetCore3.Models;
+using PixiEditor.Models;
 using System;
 using System;
 using System.Collections.Generic;
 using System.Collections.Generic;
 using System.Diagnostics;
 using System.Diagnostics;

+ 36 - 25
PixiEditorDotNetCore3/ViewModels/ViewModelMain.cs

@@ -1,6 +1,6 @@
 using PixiEditor.Helpers;
 using PixiEditor.Helpers;
-using PixiEditorDotNetCore3.Models.Enums;
-using PixiEditorDotNetCore3.Models.Tools;
+using PixiEditor.Models.Enums;
+using PixiEditor.Models.Tools;
 using System;
 using System;
 using System.Collections.Generic;
 using System.Collections.Generic;
 using System.Collections.ObjectModel;
 using System.Collections.ObjectModel;
@@ -11,13 +11,13 @@ using System.Windows.Controls;
 using System.Windows.Input;
 using System.Windows.Input;
 using System.Windows.Media;
 using System.Windows.Media;
 using System.Windows.Media.Imaging;
 using System.Windows.Media.Imaging;
-using PixiTools = PixiEditorDotNetCore3.Models.Tools.Tools;
+using PixiTools = PixiEditor.Models.Tools.Tools;
 using PixiEditor.Models.Controllers;
 using PixiEditor.Models.Controllers;
-using PixiEditorDotNetCore3.Models.Dialogs;
-using PixiEditorDotNetCore3.Models.Images;
-using PixiEditorDotNetCore3.Models.IO;
-using PixiEditorDotNetCore3.Models.Layers;
-using PixiEditorDotNetCore3.Models.Position;
+using PixiEditor.Models.Dialogs;
+using PixiEditor.Models.Images;
+using PixiEditor.Models.IO;
+using PixiEditor.Models.Layers;
+using PixiEditor.Models.Position;
 using PixiEditor.Models.Enums;
 using PixiEditor.Models.Enums;
 
 
 namespace PixiEditor.ViewModels
 namespace PixiEditor.ViewModels
@@ -27,7 +27,8 @@ namespace PixiEditor.ViewModels
 
 
         public RelayCommand SelectToolCommand { get; set; } //Command that handles tool switching 
         public RelayCommand SelectToolCommand { get; set; } //Command that handles tool switching 
         public RelayCommand GenerateDrawAreaCommand { get; set; } //Command that generates draw area
         public RelayCommand GenerateDrawAreaCommand { get; set; } //Command that generates draw area
-        public RelayCommand MouseMoveOrClickCommand { get; set; } //Command that is used to draw
+        public RelayCommand MouseMoveCommand { get; set; } //Command that is used to draw
+        public RelayCommand MouseDownCommand { get; set; }
         public RelayCommand SaveFileCommand { get; set; } //Command that is used to save file
         public RelayCommand SaveFileCommand { get; set; } //Command that is used to save file
         public RelayCommand UndoCommand { get; set; }
         public RelayCommand UndoCommand { get; set; }
         public RelayCommand RedoCommand { get; set; }
         public RelayCommand RedoCommand { get; set; }
@@ -131,9 +132,11 @@ namespace PixiEditor.ViewModels
             PixiFilesManager.InitializeTempDirectories();
             PixiFilesManager.InitializeTempDirectories();
             BitmapUtility = new BitmapOperationsUtility();
             BitmapUtility = new BitmapOperationsUtility();
             BitmapUtility.BitmapChanged += BitmapUtility_BitmapChanged;
             BitmapUtility.BitmapChanged += BitmapUtility_BitmapChanged;
+            BitmapUtility.LayersChanged += BitmapUtility_LayersChanged;
             SelectToolCommand = new RelayCommand(RecognizeTool);
             SelectToolCommand = new RelayCommand(RecognizeTool);
             GenerateDrawAreaCommand = new RelayCommand(GenerateDrawArea);
             GenerateDrawAreaCommand = new RelayCommand(GenerateDrawArea);
-            MouseMoveOrClickCommand = new RelayCommand(MouseMoveOrClick);
+            MouseMoveCommand = new RelayCommand(MouseMove);
+            MouseDownCommand = new RelayCommand(MouseDown);
             SaveFileCommand = new RelayCommand(SaveFile, CanSave);
             SaveFileCommand = new RelayCommand(SaveFile, CanSave);
             UndoCommand = new RelayCommand(Undo, CanUndo);
             UndoCommand = new RelayCommand(Undo, CanUndo);
             RedoCommand = new RelayCommand(Redo, CanRedo);
             RedoCommand = new RelayCommand(Redo, CanRedo);
@@ -150,9 +153,9 @@ namespace PixiEditor.ViewModels
             ToolSize = 1;
             ToolSize = 1;
         }
         }
 
 
-        public void SetActiveLayer(object parameter)
+        private void BitmapUtility_LayersChanged(object sender, LayersChangedEventArgs e)
         {
         {
-            BitmapUtility.SetActiveLayer((int)parameter);
+            RefreshImage();
         }
         }
 
 
         private void BitmapUtility_BitmapChanged(object sender, BitmapChangedEventArgs e)
         private void BitmapUtility_BitmapChanged(object sender, BitmapChangedEventArgs e)
@@ -160,6 +163,12 @@ namespace PixiEditor.ViewModels
             RefreshImage();
             RefreshImage();
         }
         }
 
 
+        public void SetActiveLayer(object parameter)
+        {
+            BitmapUtility.SetActiveLayer((int)parameter);
+            ActiveImage.Source = BitmapUtility.GetCombinedBitmaps();
+        }
+
         #region Undo/Redo
         #region Undo/Redo
         /// <summary>
         /// <summary>
         /// Undo last action
         /// Undo last action
@@ -221,31 +230,30 @@ namespace PixiEditor.ViewModels
             UndoManager.StopRecording();
             UndoManager.StopRecording();
             BitmapUtility.MouseController.StopRecordingMouseMovementChanges();
             BitmapUtility.MouseController.StopRecordingMouseMovementChanges();
             primaryToolSet.StopExectuingTool();
             primaryToolSet.StopExectuingTool();
+        }
+
+        private void MouseDown(object parameter)
+        {
+            if (!BitmapUtility.MouseController.IsRecordingChanges)
+            {
+                BitmapUtility.MouseController.StartRecordingMouseMovementChanges();
+                BitmapUtility.MouseController.RecordMouseMovementChanges(MousePositionConverter.CurrentCoordinates);
+            }
         }
         }
 
 
         /// <summary>
         /// <summary>
         /// Method connected with command, it executes tool "activity"
         /// Method connected with command, it executes tool "activity"
         /// </summary>
         /// </summary>
         /// <param name="parameter"></param>
         /// <param name="parameter"></param>
-        private void MouseMoveOrClick(object parameter)
+        private void MouseMove(object parameter)
         {
         {
             Coordinates cords = new Coordinates((int)MouseXOnCanvas, (int)MouseYOnCanvas);
             Coordinates cords = new Coordinates((int)MouseXOnCanvas, (int)MouseYOnCanvas);
             MousePositionConverter.CurrentCoordinates = cords;
             MousePositionConverter.CurrentCoordinates = cords;
 
 
-            if ((Models.Enums.MouseAction)parameter == Models.Enums.MouseAction.MouseDown)
-            {
-                if (!BitmapUtility.MouseController.IsRecordingChanges)
-                {
-                    BitmapUtility.MouseController.StartRecordingMouseMovementChanges();
-                }
-            }
-            if((Models.Enums.MouseAction)parameter == Models.Enums.MouseAction.Move)
-            {
                 if (BitmapUtility.MouseController.IsRecordingChanges)
                 if (BitmapUtility.MouseController.IsRecordingChanges)
                 {
                 {
                     BitmapUtility.MouseController.RecordMouseMovementChanges(cords);
                     BitmapUtility.MouseController.RecordMouseMovementChanges(cords);
                 }
                 }
-            }
         }
         }
 
 
 
 
@@ -330,12 +338,15 @@ namespace PixiEditor.ViewModels
 
 
         public void RefreshImage()
         public void RefreshImage()
         {
         {
-            ActiveImage.Source = BitmapUtility.ActiveLayer.LayerBitmap;
+            if (ActiveImage != null)
+            {
+                ActiveImage.Source = BitmapUtility.ActiveLayer.LayerBitmap;
+            }
         }
         }
 
 
         public void NewLayer(object parameter)
         public void NewLayer(object parameter)
         {
         {
-            BitmapUtility.AddNewLayer("New Layer", BitmapUtility.Layers[0].Width, BitmapUtility.Layers[0].Height);
+            BitmapUtility.AddNewLayer("New Layer", BitmapUtility.Layers[0].Width, BitmapUtility.Layers[0].Height);         
         }
         }
 
 
         public bool CanCreateNewLayer(object parameter)
         public bool CanCreateNewLayer(object parameter)

+ 1 - 1
PixiEditorDotNetCore3/Views/MainDrawingPanel.xaml.cs

@@ -1,4 +1,4 @@
-using PixiEditorDotNetCore3.Models;
+using PixiEditor.Models;
 using System;
 using System;
 using System.Collections.Generic;
 using System.Collections.Generic;
 using System.Diagnostics;
 using System.Diagnostics;

+ 3 - 3
PixiEditorDotNetCore3/Views/MainWindow.xaml

@@ -115,13 +115,13 @@
                         <Canvas Width="{Binding BitmapUtility.ActiveLayer.Width}" Height="{Binding BitmapUtility.ActiveLayer.Height}" VerticalAlignment="Center" HorizontalAlignment="Center">
                         <Canvas Width="{Binding BitmapUtility.ActiveLayer.Width}" Height="{Binding BitmapUtility.ActiveLayer.Height}" VerticalAlignment="Center" HorizontalAlignment="Center">
                             <i:Interaction.Triggers>
                             <i:Interaction.Triggers>
                                 <i:EventTrigger EventName="MouseMove">
                                 <i:EventTrigger EventName="MouseMove">
-                                    <i:InvokeCommandAction Command="{Binding MouseMoveOrClickCommand}" CommandParameter="{x:Static enums:MouseAction.Move}"/>
+                                    <i:InvokeCommandAction Command="{Binding MouseMoveCommand}"/>
                                 </i:EventTrigger>
                                 </i:EventTrigger>
                                 <i:EventTrigger EventName="MouseDown">
                                 <i:EventTrigger EventName="MouseDown">
-                                    <i:InvokeCommandAction Command="{Binding MouseMoveOrClickCommand}" CommandParameter="{x:Static enums:MouseAction.MouseDown}"/>
+                                    <i:InvokeCommandAction Command="{Binding MouseDownCommand}"/>
                                 </i:EventTrigger>
                                 </i:EventTrigger>
                                 <i:EventTrigger EventName="MouseUp">
                                 <i:EventTrigger EventName="MouseUp">
-                                    <i:InvokeCommandAction Command="{Binding MouseUpCommand}" CommandParameter="{x:Static enums:MouseAction.MouseUp}"/>
+                                    <i:InvokeCommandAction Command="{Binding MouseUpCommand}"/>
                                 </i:EventTrigger>
                                 </i:EventTrigger>
                             </i:Interaction.Triggers>
                             </i:Interaction.Triggers>
                             <i:Interaction.Behaviors>
                             <i:Interaction.Behaviors>