Browse Source

Added Clip canvas

flabbet 5 years ago
parent
commit
c0cf2ae761
92 changed files with 464 additions and 604 deletions
  1. 0 2
      PixiEditor/Exceptions/LengthMismatchException.cs
  2. 0 4
      PixiEditor/Helpers/Behaviours/AllowableCharactersTextBoxBehavior.cs
  3. 4 9
      PixiEditor/Helpers/Behaviours/HintTextBehavior.cs
  4. 4 7
      PixiEditor/Helpers/Behaviours/MouseBehaviour.cs
  5. 2 7
      PixiEditor/Helpers/Behaviours/TextBoxFocusBehavior.cs
  6. 3 3
      PixiEditor/Helpers/Converters/BoolToColorConverter.cs
  7. 0 2
      PixiEditor/Helpers/Converters/BoolToIntConverter.cs
  8. 3 5
      PixiEditor/Helpers/Converters/OppositeVisibilityConverter.cs
  9. 0 3
      PixiEditor/Helpers/Converters/ToolSizeToIntConverter.cs
  10. 0 4
      PixiEditor/Helpers/NotifyableObject.cs
  11. 0 4
      PixiEditor/Helpers/RelayCommand.cs
  12. 0 1
      PixiEditor/Helpers/UI/ReversedOrderStackPanel.cs
  13. 1 1
      PixiEditor/Models/Colors/ExColor.cs
  14. 40 44
      PixiEditor/Models/Controllers/BitmapManager.cs
  15. 20 24
      PixiEditor/Models/Controllers/BitmapOperationsUtility.cs
  16. 2 7
      PixiEditor/Models/Controllers/ClipboardController.cs
  17. 0 2
      PixiEditor/Models/Controllers/MouseMovementController.cs
  18. 3 3
      PixiEditor/Models/Controllers/PixelChangesController.cs
  19. 2 4
      PixiEditor/Models/Controllers/ReadonlyToolUtility.cs
  20. 1 1
      PixiEditor/Models/Controllers/Shortcuts/Shortcut.cs
  21. 3 4
      PixiEditor/Models/Controllers/Shortcuts/ShortcutController.cs
  22. 1 3
      PixiEditor/Models/Controllers/UndoManager.cs
  23. 0 5
      PixiEditor/Models/DataHolders/Change.cs
  24. 111 0
      PixiEditor/Models/DataHolders/Document.cs
  25. 0 3
      PixiEditor/Models/DataHolders/LayerChanges.cs
  26. 0 2
      PixiEditor/Models/DataHolders/Selection.cs
  27. 1 5
      PixiEditor/Models/DataHolders/StackEx.cs
  28. 0 2
      PixiEditor/Models/DataHolders/Tuple.cs
  29. 0 7
      PixiEditor/Models/Dialogs/CustomDialog.cs
  30. 0 6
      PixiEditor/Models/Dialogs/ExportFileDialog.cs
  31. 0 6
      PixiEditor/Models/Dialogs/ImportFileDialog.cs
  32. 0 6
      PixiEditor/Models/Dialogs/NewFileDialog.cs
  33. 1 7
      PixiEditor/Models/Enums/FileType.cs
  34. 1 5
      PixiEditor/Models/Enums/LayerAction.cs
  35. 4 12
      PixiEditor/Models/IO/Exporter.cs
  36. 0 5
      PixiEditor/Models/IO/Importer.cs
  37. 2 4
      PixiEditor/Models/IO/PixiFilesManager.cs
  38. 4 5
      PixiEditor/Models/ImageManipulation/Morphology.cs
  39. 0 3
      PixiEditor/Models/ImageManipulation/Transform.cs
  40. 2 10
      PixiEditor/Models/Images/BitmapConverter.cs
  41. 1 6
      PixiEditor/Models/Images/ImageGenerator.cs
  42. 2 7
      PixiEditor/Models/Layers/BasicLayer.cs
  43. 3 3
      PixiEditor/Models/Layers/Layer.cs
  44. 1 11
      PixiEditor/Models/Layers/LayerGenerator.cs
  45. 2 8
      PixiEditor/Models/Layers/LightLayer.cs
  46. 2 5
      PixiEditor/Models/Position/Coordinates.cs
  47. 100 2
      PixiEditor/Models/Position/CoordinatesCalculator.cs
  48. 1 7
      PixiEditor/Models/Position/DoubleCords.cs
  49. 2 2
      PixiEditor/Models/Position/MousePositionConverter.cs
  50. 0 3
      PixiEditor/Models/Tools/BitmapOperationTool.cs
  51. 2 4
      PixiEditor/Models/Tools/BitmapPixelChanges.cs
  52. 1 5
      PixiEditor/Models/Tools/ReadonlyTool.cs
  53. 4 6
      PixiEditor/Models/Tools/ShapeTool.cs
  54. 3 6
      PixiEditor/Models/Tools/Tool.cs
  55. 2 8
      PixiEditor/Models/Tools/ToolSettings/Settings/FloatSetting.cs
  56. 4 5
      PixiEditor/Models/Tools/ToolSettings/Settings/Setting.cs
  57. 0 3
      PixiEditor/Models/Tools/ToolSettings/Settings/SizeSetting.cs
  58. 1 4
      PixiEditor/Models/Tools/ToolSettings/Toolbars/BasicShapeToolbar.cs
  59. 0 5
      PixiEditor/Models/Tools/ToolSettings/Toolbars/BasicToolbar.cs
  60. 0 3
      PixiEditor/Models/Tools/ToolSettings/Toolbars/BrightnessToolToolbar.cs
  61. 1 5
      PixiEditor/Models/Tools/ToolSettings/Toolbars/EmptyToolbar.cs
  62. 2 3
      PixiEditor/Models/Tools/ToolSettings/Toolbars/Toolbar.cs
  63. 1 7
      PixiEditor/Models/Tools/ToolType.cs
  64. 7 7
      PixiEditor/Models/Tools/Tools/BrightnessTool.cs
  65. 0 3
      PixiEditor/Models/Tools/Tools/CircleTool.cs
  66. 1 5
      PixiEditor/Models/Tools/Tools/ColorPickerTool.cs
  67. 0 3
      PixiEditor/Models/Tools/Tools/EarserTool.cs
  68. 7 10
      PixiEditor/Models/Tools/Tools/LineTool.cs
  69. 2 4
      PixiEditor/Models/Tools/Tools/MoveTool.cs
  70. 2 2
      PixiEditor/Models/Tools/Tools/RectangleTool.cs
  71. 2 5
      PixiEditor/Models/Tools/Tools/SelectTool.cs
  72. 0 2
      PixiEditor/Properties/AssemblyInfo.cs
  73. 0 6
      PixiEditor/ViewModels/FeedbackDialogViewModel.cs
  74. 0 4
      PixiEditor/ViewModels/ImportFilePopupViewModel.cs
  75. 0 5
      PixiEditor/ViewModels/MenuButtonViewModel.cs
  76. 0 8
      PixiEditor/ViewModels/NewFileMenuViewModel.cs
  77. 2 11
      PixiEditor/ViewModels/SaveFilePopupViewModel.cs
  78. 2 6
      PixiEditor/ViewModels/ViewModelBase.cs
  79. 56 40
      PixiEditor/ViewModels/ViewModelMain.cs
  80. 7 18
      PixiEditor/Views/EditableTextBlock.xaml.cs
  81. 0 12
      PixiEditor/Views/ImportFilePopup.xaml.cs
  82. 2 2
      PixiEditor/Views/MainDrawingPanel.xaml.cs
  83. 7 4
      PixiEditor/Views/MainWindow.xaml
  84. 6 24
      PixiEditor/Views/MainWindow.xaml.cs
  85. 0 11
      PixiEditor/Views/MenuButton.xaml.cs
  86. 1 15
      PixiEditor/Views/NewFilePopup.xaml.cs
  87. 1 9
      PixiEditor/Views/NumerInput.xaml.cs
  88. 0 12
      PixiEditor/Views/SaveFilePopup.xaml.cs
  89. 0 3
      PixiEditorTests/ModelsTests/ControllersTests/UndoManagerTests.cs
  90. 5 7
      PixiEditorTests/WorkspaceTests/ColorsTests/ExtendedColorTests.cs
  91. 4 7
      PixiEditorTests/WorkspaceTests/ImageGeneratorTests.cs
  92. 0 4
      PixiEditorTests/WorkspaceTests/ToolsTests/CoordinatesCalculatorTests.cs

+ 0 - 2
PixiEditor/Exceptions/LengthMismatchException.cs

@@ -1,6 +1,4 @@
 using System;
-using System.Collections.Generic;
-using System.Text;
 
 namespace PixiEditor.Exceptions
 {

+ 0 - 4
PixiEditor/Helpers/Behaviours/AllowableCharactersTextBoxBehavior.cs

@@ -1,9 +1,5 @@
 using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
 using System.Text.RegularExpressions;
-using System.Threading.Tasks;
 using System.Windows;
 using System.Windows.Controls;
 using System.Windows.Input;

+ 4 - 9
PixiEditor/Helpers/Behaviours/HintTextBehavior.cs

@@ -1,9 +1,4 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using System.Windows;
+using System.Windows;
 using System.Windows.Controls;
 using System.Windows.Interactivity;
 using System.Windows.Media;
@@ -38,7 +33,7 @@ namespace PixiEditor.Helpers.Behaviours
 
         private void AssociatedObject_LostFocus(object sender, RoutedEventArgs e)
         {
-            if(string.IsNullOrEmpty(AssociatedObject.Text) == true)
+            if (string.IsNullOrEmpty(AssociatedObject.Text) == true)
             {
                 SetHint(true);
             }
@@ -46,7 +41,7 @@ namespace PixiEditor.Helpers.Behaviours
 
         private void AssociatedObject_GotFocus(object sender, RoutedEventArgs e)
         {
-            if(AssociatedObject.Text == Hint)
+            if (AssociatedObject.Text == Hint)
             {
                 SetHint(false);
             }
@@ -69,7 +64,7 @@ namespace PixiEditor.Helpers.Behaviours
         protected override void OnDetaching()
         {
             base.OnDetaching();
-            AssociatedObject.LostFocus -= AssociatedObject_LostFocus;          
+            AssociatedObject.LostFocus -= AssociatedObject_LostFocus;
             AssociatedObject.GotFocus -= AssociatedObject_GotFocus;
         }
     }

+ 4 - 7
PixiEditor/Helpers/Behaviours/MouseBehaviour.cs

@@ -1,11 +1,8 @@
-using PixiEditor.Views;
-using System.Diagnostics;
-using System.Windows;
-using System.Windows.Controls;
+using System.Windows;
 using System.Windows.Input;
-using Xceed.Wpf.Toolkit.Zoombox;
 
-namespace PixiEditor.Helpers.Behaviours {
+namespace PixiEditor.Helpers.Behaviours
+{
 
     public class MouseBehaviour : System.Windows.Interactivity.Behavior<FrameworkElement>
     {
@@ -48,7 +45,7 @@ namespace PixiEditor.Helpers.Behaviours {
 
         private void AssociatedObjectOnMouseMove(object sender, MouseEventArgs mouseEventArgs)
         {
-            if(RelativeTo == null)
+            if (RelativeTo == null)
             {
                 RelativeTo = AssociatedObject;
             }

+ 2 - 7
PixiEditor/Helpers/Behaviours/TextBoxFocusBehavior.cs

@@ -1,9 +1,4 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Text.RegularExpressions;
-using System.Threading.Tasks;
+using System.Text.RegularExpressions;
 using System.Windows;
 using System.Windows.Controls;
 using System.Windows.Input;
@@ -86,7 +81,7 @@ namespace PixiEditor.Helpers.Behaviours
 
         private void AssociatedObject_LostKeyboardFocus(object sender, System.Windows.Input.KeyboardFocusChangedEventArgs e)
         {
-            ConvertValue();            
+            ConvertValue();
         }
 
         /// <summary>

+ 3 - 3
PixiEditor/Helpers/Converters/BoolToColorConverter.cs

@@ -8,7 +8,7 @@ namespace PixiEditor.Helpers.Converters
     {
         public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
         {
-            if(value.ToString() == "Transparent")
+            if (value.ToString() == "Transparent")
             {
                 return false;
             }
@@ -17,9 +17,9 @@ namespace PixiEditor.Helpers.Converters
 
         public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
         {
-            if(value is bool)
+            if (value is bool)
             {
-                if((bool)value == false)
+                if ((bool)value == false)
                 {
                     return "Transparent";
                 }

+ 0 - 2
PixiEditor/Helpers/Converters/BoolToIntConverter.cs

@@ -1,7 +1,5 @@
 using System;
-using System.Collections.Generic;
 using System.Globalization;
-using System.Text;
 using System.Windows.Data;
 
 namespace PixiEditor.Helpers.Converters

+ 3 - 5
PixiEditor/Helpers/Converters/OppositeVisibilityConverter.cs

@@ -1,7 +1,5 @@
 using System;
-using System.Collections.Generic;
 using System.Globalization;
-using System.Text;
 using System.Windows;
 using System.Windows.Data;
 
@@ -11,7 +9,7 @@ namespace PixiEditor.Helpers.Converters
     {
         public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
         {
-            if(value.ToString().ToLower() == "visible")
+            if (value.ToString().ToLower() == "visible")
             {
                 return Visibility.Hidden;
             }
@@ -20,9 +18,9 @@ namespace PixiEditor.Helpers.Converters
 
         public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
         {
-            if(value is Visibility)
+            if (value is Visibility)
             {
-                if((Visibility)value == Visibility.Visible)
+                if ((Visibility)value == Visibility.Visible)
                 {
                     return "Hidden";
                 }

+ 0 - 3
PixiEditor/Helpers/Converters/ToolSizeToIntConverter.cs

@@ -1,10 +1,7 @@
 using System;
-using System.Collections.Generic;
 using System.Globalization;
 using System.Linq;
-using System.Text;
 using System.Text.RegularExpressions;
-using System.Threading.Tasks;
 using System.Windows.Data;
 
 namespace PixiEditor.Helpers

+ 0 - 4
PixiEditor/Helpers/NotifyableObject.cs

@@ -1,9 +1,5 @@
 using System;
-using System.Collections.Generic;
 using System.ComponentModel;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
 
 namespace PixiEditor.Helpers
 {

+ 0 - 4
PixiEditor/Helpers/RelayCommand.cs

@@ -1,8 +1,4 @@
 using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
 using System.Windows.Input;
 
 namespace PixiEditor.Helpers

+ 0 - 1
PixiEditor/Helpers/UI/ReversedOrderStackPanel.cs

@@ -1,5 +1,4 @@
 using System;
-using System.Collections.Generic;
 using System.Linq;
 using System.Windows;
 using System.Windows.Controls;

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

@@ -35,7 +35,7 @@ namespace PixiEditor.Models.Colors
         /// <param name="b">Blue value</param>
         /// <param name="g">Green value</param>
         /// <returns>Tuple with 3 values in order: h, s, l0</returns>
-        public static Tuple<int,float,float> RgbToHsl(int r, int g, int b)
+        public static Tuple<int, float, float> RgbToHsl(int r, int g, int b)
         {
             int h;
             float s, l;

+ 40 - 44
PixiEditor/Models/Controllers/BitmapManager.cs

@@ -1,13 +1,11 @@
 using PixiEditor.Helpers;
+using PixiEditor.Models.DataHolders;
 using PixiEditor.Models.Enums;
 using PixiEditor.Models.Layers;
 using PixiEditor.Models.Position;
 using PixiEditor.Models.Tools;
 using System;
-using System.Collections.Generic;
-using System.Collections.ObjectModel;
 using System.Linq;
-using System.Text;
 using System.Windows.Input;
 using System.Windows.Media;
 using System.Windows.Media.Imaging;
@@ -28,25 +26,6 @@ namespace PixiEditor.Models.Controllers
             }
         }
 
-        private ObservableCollection<Layer> _layers = new ObservableCollection<Layer>();
-
-        public ObservableCollection<Layer> Layers
-        {
-            get => _layers;
-            set { if (_layers != value) { _layers = value; } }
-        }
-        private int _activeLayerIndex;
-        public int ActiveLayerIndex
-        {
-            get => _activeLayerIndex;
-            set
-            {
-                _activeLayerIndex = value;
-                RaisePropertyChanged("ActiveLayerIndex");
-                RaisePropertyChanged("ActiveLayer");
-            }
-        }
-
         private Layer _previewLayer;
 
         public Layer PreviewLayer
@@ -59,8 +38,9 @@ namespace PixiEditor.Models.Controllers
             }
         }
 
+        public Layer ActiveLayer => ActiveDocument.ActiveLayer;
 
-        public Layer ActiveLayer => Layers.Count > 0 ? Layers[ActiveLayerIndex] : null;
+        public int ActiveLayerIndex => ActiveDocument.ActiveLayerIndex;
 
         public Color PrimaryColor { get; set; }
 
@@ -71,6 +51,17 @@ namespace PixiEditor.Models.Controllers
         public BitmapOperationsUtility BitmapOperations { get; set; }
         public ReadonlyToolUtility ReadonlyToolUtility { get; set; }
 
+        private Document _activeDocument = null;
+        public Document ActiveDocument
+        {
+            get => _activeDocument;
+            set
+            {
+                _activeDocument = value;
+                RaisePropertyChanged("ActiveDocument");
+            }
+        }
+
         public void SetActiveTool(Tool tool)
         {
             if (PreviewLayer != null)
@@ -97,45 +88,45 @@ namespace PixiEditor.Models.Controllers
 
         public void SetActiveLayer(int index)
         {
-            if (ActiveLayerIndex <= Layers.Count - 1)
+            if (ActiveDocument.ActiveLayerIndex <= ActiveDocument.Layers.Count - 1)
             {
-                ActiveLayer.IsActive = false;
+                ActiveDocument.ActiveLayer.IsActive = false;
             }
-            ActiveLayerIndex = index;
-            ActiveLayer.IsActive = true;
+            ActiveDocument.ActiveLayerIndex = index;
+            ActiveDocument.ActiveLayer.IsActive = true;
             LayersChanged?.Invoke(this, new LayersChangedEventArgs(index, LayerAction.SetActive));
         }
 
         public void AddNewLayer(string name, int width, int height, bool setAsActive = true)
         {
-            Layers.Add(new Layer(name, width, height));
+            ActiveDocument.Layers.Add(new Layer(name, width, height));
             if (setAsActive)
             {
-                SetActiveLayer(Layers.Count - 1);
+                SetActiveLayer(ActiveDocument.Layers.Count - 1);
             }
             LayersChanged?.Invoke(this, new LayersChangedEventArgs(0, LayerAction.Add));
         }
 
         public void RemoveLayer(int layerIndex)
         {
-            if (Layers.Count <= 1) return;
+            if (ActiveDocument.Layers.Count <= 1) return;
 
-            bool wasActive = Layers[layerIndex].IsActive;
-            Layers.RemoveAt(layerIndex);
+            bool wasActive = ActiveDocument.Layers[layerIndex].IsActive;
+            ActiveDocument.Layers.RemoveAt(layerIndex);
             if (wasActive)
             {
                 SetActiveLayer(0);
             }
-            else if (ActiveLayerIndex > Layers.Count - 1)
+            else if (ActiveDocument.ActiveLayerIndex > ActiveDocument.Layers.Count - 1)
             {
-                SetActiveLayer(Layers.Count - 1);
+                SetActiveLayer(ActiveDocument.Layers.Count - 1);
             }
         }
 
         private void Controller_MousePositionChanged(object sender, MouseMovementEventArgs e)
         {
-            if (Mouse.LeftButton == MouseButtonState.Pressed)
-            {               
+            if (Mouse.LeftButton == MouseButtonState.Pressed && ActiveDocument != null)
+            {
                 if (IsOperationTool(SelectedTool))
                 {
                     BitmapOperations.ExecuteTool(e.NewPosition,
@@ -145,8 +136,8 @@ namespace PixiEditor.Models.Controllers
                 {
                     ReadonlyToolUtility.ExecuteTool(MouseController.LastMouseMoveCoordinates.ToArray(), (ReadonlyTool)SelectedTool);
                 }
-            }            
-            else if(Mouse.LeftButton == MouseButtonState.Released)
+            }
+            else if (Mouse.LeftButton == MouseButtonState.Released)
             {
                 HighlightPixels(e.NewPosition);
             }
@@ -170,15 +161,20 @@ namespace PixiEditor.Models.Controllers
 
         public void GeneratePreviewLayer()
         {
-            if (PreviewLayer == null)
+            if ((PreviewLayer == null && ActiveDocument != null) || PreviewLayerSizeMismatch())
             {
-                PreviewLayer = new Layer("_previewLayer", Layers[0].Width, Layers[0].Height);
+                PreviewLayer = new Layer("_previewLayer", ActiveDocument.Width, ActiveDocument.Height);
             }
         }
 
+        private bool PreviewLayerSizeMismatch()
+        {
+            return PreviewLayer.Width != ActiveDocument.Width || PreviewLayer.Height != ActiveDocument.Height;
+        }
+
         private void HighlightPixels(Coordinates newPosition)
         {
-            if (Layers.Count == 0 || SelectedTool.HideHighlight) return;
+            if (ActiveDocument == null || ActiveDocument.Layers.Count == 0 || SelectedTool.HideHighlight) return;
             GeneratePreviewLayer();
             PreviewLayer.Clear();
             Coordinates[] highlightArea = CoordinatesCalculator.RectangleToCoordinates(
@@ -188,15 +184,15 @@ namespace PixiEditor.Models.Controllers
 
         public WriteableBitmap GetCombinedLayersBitmap()
         {
-            WriteableBitmap finalBitmap = Layers[0].LayerBitmap.Clone();
+            WriteableBitmap finalBitmap = ActiveDocument.Layers[0].LayerBitmap.Clone();
             finalBitmap.Lock();
-            for (int i = 1; i < Layers.Count; i++)
+            for (int i = 1; i < ActiveDocument.Layers.Count; i++)
             {
                 for (int y = 0; y < finalBitmap.Height; y++)
                 {
                     for (int x = 0; x < finalBitmap.Width; x++)
                     {
-                        Color color = Layers[i].LayerBitmap.GetPixel(x, y);
+                        Color color = ActiveDocument.Layers[i].LayerBitmap.GetPixel(x, y);
                         if (color.A != 0 || color.R != 0 || color.B != 0 || color.G != 0)
                         {
                             finalBitmap.SetPixel(x, y, color);

+ 20 - 24
PixiEditor/Models/Controllers/BitmapOperationsUtility.cs

@@ -1,11 +1,7 @@
-using PixiEditor.Helpers;
-using PixiEditor.Models.Enums;
-using PixiEditor.Models.Layers;
-using PixiEditor.Models.Position;
+using PixiEditor.Models.Position;
 using PixiEditor.Models.Tools;
 using System;
 using System.Collections.Generic;
-using System.Collections.ObjectModel;
 using System.Linq;
 using System.Windows.Input;
 using System.Windows.Media;
@@ -30,9 +26,9 @@ namespace PixiEditor.Models.Controllers
 
         public void ExecuteTool(Coordinates newPos, List<Coordinates> mouseMove, BitmapOperationTool tool)
         {
-            if (tool != null && tool.ToolType != ToolType.None)
+            if (Manager.ActiveDocument != null && tool != null && tool.ToolType != ToolType.None)
             {
-                if (Manager.Layers.Count == 0 || mouseMove.Count == 0) return;
+                if (Manager.ActiveDocument.Layers.Count == 0 || mouseMove.Count == 0) return;
                 mouseMove.Reverse();
                 UseTool(mouseMove, tool, Manager.PrimaryColor);
 
@@ -48,7 +44,7 @@ namespace PixiEditor.Models.Controllers
             Manager.PreviewLayer.Clear();
         }
 
-      
+
 
         private void UseTool(List<Coordinates> mouseMoveCords, BitmapOperationTool tool, Color color)
         {
@@ -56,17 +52,17 @@ namespace PixiEditor.Models.Controllers
             {
                 mouseMoveCords = GetSquareCoordiantes(mouseMoveCords);
             };
-                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));
-                }
-                else
-                {
-                    UseToolOnPreviewLayer(mouseMoveCords);
-                }           
+            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));
+            }
+            else
+            {
+                UseToolOnPreviewLayer(mouseMoveCords);
+            }
         }
 
         private bool MouseCordsNotInLine(List<Coordinates> cords)
@@ -83,11 +79,11 @@ namespace PixiEditor.Models.Controllers
         {
             int xLength = mouseMoveCords[0].Y - mouseMoveCords[^1].Y;
             int yLength = mouseMoveCords[0].Y - mouseMoveCords[^1].Y;
-            if(mouseMoveCords[^1].Y > mouseMoveCords[0].Y)
+            if (mouseMoveCords[^1].Y > mouseMoveCords[0].Y)
             {
                 xLength *= -1;
             }
-            if(mouseMoveCords[^1].X > mouseMoveCords[0].X)
+            if (mouseMoveCords[^1].X > mouseMoveCords[0].X)
             {
                 xLength *= -1;
             }
@@ -101,7 +97,7 @@ namespace PixiEditor.Models.Controllers
             Manager.ActiveLayer.LayerBitmap.Lock();
             for (int i = 0; i < coordinates.Length; i++)
             {
-                if (coordinates[i].X < 0 || coordinates[i].X > Manager.Layers[0].Width - 1 || coordinates[i].Y < 0 || coordinates[i].Y > Manager.Layers[0].Height - 1) 
+                if (coordinates[i].X < 0 || coordinates[i].X > Manager.ActiveDocument.Width - 1 || coordinates[i].Y < 0 || coordinates[i].Y > Manager.ActiveDocument.Height - 1)
                     continue;
                 values.Add(coordinates[i], Manager.ActiveLayer.LayerBitmap.GetPixel(coordinates[i].X, coordinates[i].Y));
             }
@@ -116,11 +112,11 @@ namespace PixiEditor.Models.Controllers
             {
                 Manager.GeneratePreviewLayer();
                 Manager.PreviewLayer.Clear();
-                changedPixels = ((BitmapOperationTool)Manager.SelectedTool).Use(Manager.ActiveLayer, mouseMove.ToArray(), Manager.PrimaryColor);
+                changedPixels = ((BitmapOperationTool)Manager.SelectedTool).Use(Manager.ActiveDocument.ActiveLayer, mouseMove.ToArray(), Manager.PrimaryColor);
                 Manager.PreviewLayer.ApplyPixels(changedPixels);
                 _lastChangedPixels = changedPixels;
             }
-        }      
+        }
     }
 }
 

+ 2 - 7
PixiEditor/Models/Controllers/ClipboardController.cs

@@ -1,12 +1,7 @@
-using PixiEditor.Models.Layers;
-using PixiEditor.Models.Position;
+using PixiEditor.Models.Position;
 using System;
-using System.Collections.Generic;
-using System.Drawing;
-using System.Drawing.Imaging;
 using System.IO;
 using System.Linq;
-using System.Text;
 using System.Windows;
 using System.Windows.Media.Imaging;
 
@@ -40,7 +35,7 @@ namespace PixiEditor.Models.Controllers
             int height = selection.Max(x => x.Y) - offsetY + 1;
             return bitmap.Crop(offsetX, offsetY, width, height);
         }
-        
+
         public WriteableBitmap GetFromClipboard()
         {
             throw new NotImplementedException();

+ 0 - 2
PixiEditor/Models/Controllers/MouseMovementController.cs

@@ -1,8 +1,6 @@
 using PixiEditor.Models.Position;
 using System;
 using System.Collections.Generic;
-using System.Text;
-using System.Windows.Media;
 
 namespace PixiEditor.Models.Controllers
 {

+ 3 - 3
PixiEditor/Models/Controllers/PixelChangesController.cs

@@ -15,7 +15,7 @@ namespace PixiEditor.Models.Controllers
 
         public void AddChanges(LayerChanges changes, LayerChanges oldValues)
         {
-            if(LastChanges == null)
+            if (LastChanges == null)
             {
                 LastChanges = changes;
                 LastOldValues = oldValues;
@@ -51,10 +51,10 @@ namespace PixiEditor.Models.Controllers
         {
             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);
-            
+
             var tmp = new LayerChanges(new BitmapPixelChanges(pixelChanges), LastChanges.LayerIndex);
             var oldValuesTmp = new LayerChanges(new BitmapPixelChanges(oldValues), LastOldValues.LayerIndex);
-            
+
             Tuple<LayerChanges, LayerChanges> outputChanges = new Tuple<LayerChanges, LayerChanges>(tmp, oldValuesTmp);
             LastChanges = null;
             LastOldValues = null;

+ 2 - 4
PixiEditor/Models/Controllers/ReadonlyToolUtility.cs

@@ -1,7 +1,5 @@
-using PixiEditor.Models.Layers;
-using PixiEditor.Models.Position;
+using PixiEditor.Models.Position;
 using PixiEditor.Models.Tools;
-using System.Collections.Generic;
 
 namespace PixiEditor.Models.Controllers
 {
@@ -15,7 +13,7 @@ namespace PixiEditor.Models.Controllers
         }
 
         public void ExecuteTool(Coordinates[] mouseMove, ReadonlyTool tool)
-        {            
+        {
             tool.Use(mouseMove);
         }
 

+ 1 - 1
PixiEditor/Models/Controllers/Shortcuts/Shortcut.cs

@@ -19,7 +19,7 @@ namespace PixiEditor.Models.Controllers
 
         public void Execute()
         {
-            if(Command.CanExecute(CommandParameter))
+            if (Command.CanExecute(CommandParameter))
             {
                 Command.Execute(CommandParameter);
             }

+ 3 - 4
PixiEditor/Models/Controllers/Shortcuts/ShortcutController.cs

@@ -1,5 +1,4 @@
-using System;
-using System.Collections.Generic;
+using System.Collections.Generic;
 using System.Linq;
 using System.Windows.Input;
 
@@ -9,12 +8,12 @@ namespace PixiEditor.Models.Controllers
     {
         public static bool BlockShortcutExecution { get; set; }
 
-        public List<Shortcut> Shortcuts { get; set; }       
+        public List<Shortcut> Shortcuts { get; set; }
 
         public ShortcutController()
         {
             Shortcuts = new List<Shortcut>();
-            
+
         }
 
         public void KeyPressed(Key key)

+ 1 - 3
PixiEditor/Models/Controllers/UndoManager.cs

@@ -1,7 +1,5 @@
 using PixiEditor.Models.DataHolders;
 using System.Collections.Generic;
-using System.Diagnostics;
-using System.Linq;
 using System.Reflection;
 
 namespace PixiEditor.Models.Controllers
@@ -37,7 +35,7 @@ namespace PixiEditor.Models.Controllers
         {
             MainRoot = root;
         }
-      
+
 
         public static void AddUndoChange(Change change)
         {

+ 0 - 5
PixiEditor/Models/DataHolders/Change.cs

@@ -1,9 +1,4 @@
 using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Runtime.Serialization;
-using System.Text;
-using System.Threading.Tasks;
 
 namespace PixiEditor.Models.DataHolders
 {

+ 111 - 0
PixiEditor/Models/DataHolders/Document.cs

@@ -0,0 +1,111 @@
+using PixiEditor.Helpers;
+using PixiEditor.Models.Layers;
+using PixiEditor.Models.Position;
+using System.Collections.ObjectModel;
+using System.Linq;
+using System.Windows.Media.Imaging;
+
+namespace PixiEditor.Models.DataHolders
+{
+    public class Document : NotifyableObject
+    {
+        private int _width;
+        public int Width
+        {
+            get => _width;
+            set
+            {
+                _width = value;
+                RaisePropertyChanged("Width");
+            }
+        }
+        private int _height;
+        public int Height
+        {
+            get => _height;
+            set
+            {
+                _height = value;
+                RaisePropertyChanged("Height");
+            }
+        }
+
+        private ObservableCollection<Layer> _layers = new ObservableCollection<Layer>();
+
+        public ObservableCollection<Layer> Layers
+        {
+            get => _layers;
+            set { if (_layers != value) { _layers = value; } }
+        }
+        public Layer ActiveLayer => Layers.Count > 0 ? Layers[ActiveLayerIndex] : null;
+
+        private int _activeLayerIndex;
+        public int ActiveLayerIndex
+        {
+            get => _activeLayerIndex;
+            set
+            {
+                _activeLayerIndex = value;
+                RaisePropertyChanged("ActiveLayerIndex");
+                RaisePropertyChanged("ActiveLayer");
+            }
+        }
+
+        public Document(int width, int height)
+        {
+            Width = width;
+            Height = height;
+        }
+
+        public void Crop(int x, int y, int width, int height)
+        {
+            for (int i = 0; i < Layers.Count; i++)
+            {
+                Layers[i].LayerBitmap = Layers[i].LayerBitmap.Crop(x, y, width, height);
+                Layers[i].Width = width;
+                Layers[i].Height = height;
+            }
+            Height = height;
+            Width = width;
+        }
+
+        public void ClipCanvas()
+        {
+            Coordinates[] smallestPixels = GetSmallestPixels();
+            Coordinates[] biggestPixels = GetBiggestPixels();
+
+            int smallestX = smallestPixels.Min(x => x.X);
+            int smallestY = smallestPixels.Min(x => x.Y);
+            int biggestX = biggestPixels.Max(x => x.X);
+            int biggestY = biggestPixels.Max(x => x.Y);
+
+            int width = biggestX - smallestX + 1;
+            int height = biggestY - smallestY + 1;
+            Crop(smallestX, smallestY, width, height);
+        }
+
+        private Coordinates[] GetSmallestPixels()
+        {
+            Coordinates[] smallestPixels = new Coordinates[Layers.Count];
+            for (int i = 0; i < smallestPixels.Length; i++)
+            {
+                Coordinates point = CoordinatesCalculator.FindMinEdgeNonTransparentPixel(Layers[i].LayerBitmap);
+                if(point.X >= 0 && point.Y >=0)
+                    smallestPixels[i] = point;
+            }
+            return smallestPixels;
+        }
+
+        private Coordinates[] GetBiggestPixels()
+        {
+            Coordinates[] biggestPixels = new Coordinates[Layers.Count];
+            for (int i = 0; i < biggestPixels.Length; i++)
+            {
+                Coordinates point = CoordinatesCalculator.FindMostEdgeNonTransparentPixel(Layers[i].LayerBitmap);
+                if (point.X >= 0 && point.Y >= 0)
+                    biggestPixels[i] = point;
+            }
+            return biggestPixels;
+        }
+    }
+}

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

@@ -1,7 +1,4 @@
 using PixiEditor.Models.Tools;
-using System;
-using System.Collections.Generic;
-using System.Text;
 
 namespace PixiEditor.Models.DataHolders
 {

+ 0 - 2
PixiEditor/Models/DataHolders/Selection.cs

@@ -1,8 +1,6 @@
 using PixiEditor.Models.Position;
 using System;
-using System.Collections.Generic;
 using System.Linq;
-using System.Text;
 using System.Windows;
 
 namespace PixiEditor.Models.DataHolders

+ 1 - 5
PixiEditor/Models/DataHolders/StackEx.cs

@@ -1,8 +1,4 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
+using System.Collections.Generic;
 
 namespace PixiEditor.Models.DataHolders
 {

+ 0 - 2
PixiEditor/Models/DataHolders/Tuple.cs

@@ -1,6 +1,4 @@
 using System;
-using System.Collections.Generic;
-using System.Text;
 
 namespace PixiEditor.Models.DataHolders
 {

+ 0 - 7
PixiEditor/Models/Dialogs/CustomDialog.cs

@@ -1,11 +1,4 @@
 using PixiEditor.Helpers;
-using System;
-using System.Collections.Generic;
-using System.ComponentModel;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using System.Windows;
 
 namespace PixiEditor.Models.Dialogs
 {

+ 0 - 6
PixiEditor/Models/Dialogs/ExportFileDialog.cs

@@ -1,10 +1,4 @@
 using PixiEditor.Views;
-using System;
-using System.Collections.Generic;
-using System.ComponentModel;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
 using System.Windows;
 
 namespace PixiEditor.Models.Dialogs

+ 0 - 6
PixiEditor/Models/Dialogs/ImportFileDialog.cs

@@ -1,10 +1,4 @@
 using PixiEditor.Views;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using System.Windows;
 
 namespace PixiEditor.Models.Dialogs
 {

+ 0 - 6
PixiEditor/Models/Dialogs/NewFileDialog.cs

@@ -1,10 +1,4 @@
 using PixiEditor.Views;
-using System;
-using System.Collections.Generic;
-using System.ComponentModel;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
 using System.Windows;
 
 namespace PixiEditor.Models.Dialogs

+ 1 - 7
PixiEditor/Models/Enums/FileType.cs

@@ -1,10 +1,4 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace PixiEditor.Models.Enums
+namespace PixiEditor.Models.Enums
 {
     public enum FileType
     {

+ 1 - 5
PixiEditor/Models/Enums/LayerAction.cs

@@ -1,8 +1,4 @@
-using System;
-using System.Collections.Generic;
-using System.Text;
-
-namespace PixiEditor.Models.Enums
+namespace PixiEditor.Models.Enums
 {
     public enum LayerAction
     {

+ 4 - 12
PixiEditor/Models/IO/Exporter.cs

@@ -1,17 +1,9 @@
-using System;
-using System.Collections.Generic;
-using System.Diagnostics;
+using PixiEditor.Models.Dialogs;
+using PixiEditor.Models.Enums;
+using System;
 using System.IO;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
 using System.Windows;
-using System.Windows.Controls;
-using System.Windows.Media;
 using System.Windows.Media.Imaging;
-using Microsoft.Win32;
-using PixiEditor.Models.Dialogs;
-using PixiEditor.Models.Enums;
 
 namespace PixiEditor.Models.IO
 {
@@ -71,7 +63,7 @@ namespace PixiEditor.Models.IO
             try
             {
                 bitmap = bitmap.Resize(exportWidth, exportHeight, WriteableBitmapExtensions.Interpolation.NearestNeighbor);
-                using(FileStream stream = new FileStream(savePath, FileMode.Create))
+                using (FileStream stream = new FileStream(savePath, FileMode.Create))
                 {
                     PngBitmapEncoder encoder = new PngBitmapEncoder();
                     encoder.Frames.Add(BitmapFrame.Create(bitmap));

+ 0 - 5
PixiEditor/Models/IO/Importer.cs

@@ -1,11 +1,6 @@
 using PixiEditor.Helpers;
 using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
 using System.Windows.Media.Imaging;
-using System.Windows.Media;
 
 namespace PixiEditor.Models.IO
 {

+ 2 - 4
PixiEditor/Models/IO/PixiFilesManager.cs

@@ -1,9 +1,7 @@
-using System;
-using System.Collections.Generic;
+using Newtonsoft.Json;
+using System;
 using System.Diagnostics;
 using System.IO;
-using System.Text;
-using Newtonsoft.Json;
 
 namespace PixiEditor.Models.IO
 {

+ 4 - 5
PixiEditor/Models/ImageManipulation/Morphology.cs

@@ -1,7 +1,6 @@
 using PixiEditor.Models.Position;
 using System;
 using System.Collections.Generic;
-using System.Diagnostics;
 using System.Linq;
 
 namespace PixiEditor.Models.ImageManipulation
@@ -60,7 +59,7 @@ namespace PixiEditor.Models.ImageManipulation
             {
                 for (int x = 0; x < width; x++)
                 {
-                    if(byteArray[x,y] == 1)
+                    if (byteArray[x, y] == 1)
                     {
                         output.Add(new Coordinates(x + offset.X, y + offset.Y));
                     }
@@ -83,7 +82,7 @@ namespace PixiEditor.Models.ImageManipulation
                 for (int x = 0; x < dimensions.Item1 + margin; x++)
                 {
                     Coordinates cords = new Coordinates(x + minX, y + minY);
-                    array[x + margin,y + margin] = points.Contains(cords) ? (byte)1 : (byte)0;
+                    array[x + margin, y + margin] = points.Contains(cords) ? (byte)1 : (byte)0;
                 }
             }
 
@@ -101,8 +100,8 @@ namespace PixiEditor.Models.ImageManipulation
 
         private static Tuple<int, int> GetDimensionsForPoints(Coordinates[] points)
         {
-            int width = points.Max(x=> x.X) - points.Min(x => x.X);
-            int height = points.Max(x=> x.Y) - points.Min(x => x.Y);
+            int width = points.Max(x => x.X) - points.Min(x => x.X);
+            int height = points.Max(x => x.Y) - points.Min(x => x.Y);
             return new Tuple<int, int>(width + 1, height + 1);
         }
     }

+ 0 - 3
PixiEditor/Models/ImageManipulation/Transform.cs

@@ -1,7 +1,4 @@
 using PixiEditor.Models.Position;
-using System;
-using System.Collections.Generic;
-using System.Text;
 
 namespace PixiEditor.Models.ImageManipulation
 {

+ 2 - 10
PixiEditor/Models/Images/BitmapConverter.cs

@@ -1,12 +1,4 @@
-using System;
-using System.Collections.Generic;
-using System.Drawing;
-using System.IO;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using System.Windows.Media;
-using System.Windows.Media.Imaging;
+using System.Windows.Media.Imaging;
 
 namespace PixiEditor.Models.Images
 {
@@ -17,6 +9,6 @@ namespace PixiEditor.Models.Images
             WriteableBitmap bitmap = BitmapFactory.New(currentBitmapWidth, currentBitmapHeight);
             bitmap.FromByteArray(byteArray);
             return bitmap;
-        }      
+        }
     }
 }

+ 1 - 6
PixiEditor/Models/Images/ImageGenerator.cs

@@ -1,9 +1,4 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using System.Windows.Controls;
+using System.Windows.Controls;
 using System.Windows.Media;
 
 namespace PixiEditor.Models.Images

+ 2 - 7
PixiEditor/Models/Layers/BasicLayer.cs

@@ -1,10 +1,5 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using System.Windows.Controls;
-using PixiEditor.Helpers;
+using PixiEditor.Helpers;
+using System;
 
 namespace PixiEditor.Models.Layers
 {

+ 3 - 3
PixiEditor/Models/Layers/Layer.cs

@@ -12,8 +12,8 @@ namespace PixiEditor.Models.Layers
         public string Name
         {
             get { return _name; }
-            set 
-            { 
+            set
+            {
                 _name = value;
                 RaisePropertyChanged("Name");
             }
@@ -108,7 +108,7 @@ namespace PixiEditor.Models.Layers
         }
 
         public byte[] ConvertBitmapToBytes()
-        {            
+        {
             LayerBitmap.Lock();
             byte[] byteArray = LayerBitmap.ToByteArray();
             LayerBitmap.Unlock();

+ 1 - 11
PixiEditor/Models/Layers/LayerGenerator.cs

@@ -1,14 +1,4 @@
-using PixiEditor.Models.Tools;
-using System;
-using System.Collections.Generic;
-using System.ComponentModel;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using System.Windows;
-using System.Windows.Controls;
-using System.Windows.Media;
-using System.Windows.Media.Imaging;
+using System.Windows.Media.Imaging;
 
 namespace PixiEditor.Models.Layers
 {

+ 2 - 8
PixiEditor/Models/Layers/LightLayer.cs

@@ -1,12 +1,6 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using System.Windows.Controls;
-using Newtonsoft.Json;
+using Newtonsoft.Json;
 using Newtonsoft.Json.Linq;
-using PixiEditor.Helpers;
+using System;
 
 namespace PixiEditor.Models.Layers
 {

+ 2 - 5
PixiEditor/Models/Position/Coordinates.cs

@@ -1,8 +1,5 @@
 using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
+using System.Diagnostics.CodeAnalysis;
 
 namespace PixiEditor.Models.Position
 {
@@ -46,7 +43,7 @@ namespace PixiEditor.Models.Position
 
                 int hash = HashingBase;
                 hash = (hash * HashingMultiplier) ^ (!ReferenceEquals(null, X) ? X.GetHashCode() : 0);
-                hash = (hash * HashingMultiplier) ^ (!ReferenceEquals(null, Y) ? Y.GetHashCode() : 0);            
+                hash = (hash * HashingMultiplier) ^ (!ReferenceEquals(null, Y) ? Y.GetHashCode() : 0);
                 return hash;
             }
         }

+ 100 - 2
PixiEditor/Models/Position/CoordinatesCalculator.cs

@@ -1,7 +1,9 @@
 using System;
 using System.Collections.Generic;
-using System.Text;
-
+using System.Drawing;
+using System.Security.Cryptography.X509Certificates;
+using System.Windows.Media.Imaging;
+
 namespace PixiEditor.Models.Position
 {
     public static class CoordinatesCalculator
@@ -58,5 +60,101 @@ namespace PixiEditor.Models.Position
         {
             return RectangleToCoordinates(coordinates.Coords1.X, coordinates.Coords1.Y, coordinates.Coords2.X, coordinates.Coords2.Y);
         }
+
+        /// <summary>
+        /// Returns first pixel coordinates in bitmap that is most top left on canvas
+        /// </summary>
+        /// <param name="bitmap"></param>
+        /// <returns></returns>
+        public static Coordinates FindMinEdgeNonTransparentPixel(WriteableBitmap bitmap)
+        {
+            return new Coordinates(FindMinXNonTransparent(bitmap), FindMinYNonTransparent(bitmap));
+        }
+
+        /// <summary>
+        /// Returns last pixel coordinates that is most bottom right
+        /// </summary>
+        /// <param name="bitmap"></param>
+        /// <returns></returns>
+        public static Coordinates FindMostEdgeNonTransparentPixel(WriteableBitmap bitmap)
+        {
+            return new Coordinates(FindMaxXNonTransparent(bitmap), FindMaxYNonTransparent(bitmap));
+        }
+
+        public static int FindMinYNonTransparent(WriteableBitmap bitmap)
+        {
+            System.Windows.Media.Color transparent = System.Windows.Media.Color.FromArgb(0, 0, 0, 0);
+            bitmap.Lock();
+            for (int y = 0; y < bitmap.Height; y++)
+            {
+                for (int x = 0; x < bitmap.Width; x++)
+                {
+                    if (bitmap.GetPixel(x, y) != transparent)
+                    {
+                        bitmap.Unlock();
+                        return y;
+                    }
+                }
+            }
+            bitmap.Unlock();
+            return -1;
+        }
+
+        public static int FindMinXNonTransparent(WriteableBitmap bitmap)
+        {
+            System.Windows.Media.Color transparent = System.Windows.Media.Color.FromArgb(0, 0, 0, 0);
+            bitmap.Lock();
+            for (int x = 0; x < bitmap.Width; x++)
+            {
+                for (int y = 0; y < bitmap.Height; y++)
+                {
+                    if (bitmap.GetPixel(x, y) != transparent)
+                    {
+                        bitmap.Unlock();
+                        return x;
+                    }
+                }
+            }
+            bitmap.Unlock();
+            return -1;
+        }
+
+        public static int FindMaxYNonTransparent(WriteableBitmap bitmap)
+        {
+            System.Windows.Media.Color transparent = System.Windows.Media.Color.FromArgb(0, 0, 0, 0);
+            bitmap.Lock();
+            for (int y = (int)bitmap.Height - 1; y >= 0; y--)
+            {
+                for (int x = (int)bitmap.Width - 1; x >= 0; x--)
+                {
+                    if (bitmap.GetPixel(x, y) != transparent)
+                    {
+                        bitmap.Unlock();
+                        return y;
+                    }
+                }
+            }
+            bitmap.Unlock();
+            return -1;
+        }
+
+        public static int FindMaxXNonTransparent(WriteableBitmap bitmap)
+        {
+            System.Windows.Media.Color transparent = System.Windows.Media.Color.FromArgb(0, 0, 0, 0);
+            bitmap.Lock();
+            for (int x = (int)bitmap.Width - 1; x >= 0; x--)
+            {
+                for (int y = (int)bitmap.Height - 1; y >= 0; y--)
+                {
+                    if (bitmap.GetPixel(x, y) != transparent)
+                    {
+                        bitmap.Unlock();
+                        return x;
+                    }
+                }
+            }
+            bitmap.Unlock();
+            return -1;
+        }
     }
 }

+ 1 - 7
PixiEditor/Models/Position/DoubleCords.cs

@@ -1,10 +1,4 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace PixiEditor.Models.Position
+namespace PixiEditor.Models.Position
 {
     public struct DoubleCords
     {

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

@@ -16,8 +16,8 @@ namespace PixiEditor.Models.Position
         }
 
         [DllImport("user32.dll")]
-        private static extern bool GetCursorPos(out System.Drawing.Point point);
-        
+        private static extern bool GetCursorPos(out System.Drawing.Point point);
+
         public static System.Drawing.Point GetCursorPosition()
         {
             System.Drawing.Point point;

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

@@ -1,8 +1,5 @@
 using PixiEditor.Models.Layers;
 using PixiEditor.Models.Position;
-using System;
-using System.Collections.Generic;
-using System.Text;
 using System.Windows.Media;
 
 namespace PixiEditor.Models.Tools

+ 2 - 4
PixiEditor/Models/Tools/BitmapPixelChanges.cs

@@ -1,9 +1,7 @@
 using PixiEditor.Exceptions;
 using PixiEditor.Models.Position;
-using System;
 using System.Collections.Generic;
 using System.Linq;
-using System.Text;
 using System.Windows.Media;
 
 namespace PixiEditor.Models.Tools
@@ -11,7 +9,7 @@ namespace PixiEditor.Models.Tools
     public struct BitmapPixelChanges
     {
         public static BitmapPixelChanges Empty = new BitmapPixelChanges(new Dictionary<Coordinates, Color>());
-        public Dictionary<Coordinates, Color> ChangedPixels { get; set; } 
+        public Dictionary<Coordinates, Color> ChangedPixels { get; set; }
 
         public BitmapPixelChanges(Dictionary<Coordinates, Color> changedPixels)
         {
@@ -43,7 +41,7 @@ namespace PixiEditor.Models.Tools
         {
             var coordinateArray = coordinates.ToArray();
             var colorArray = color.ToArray();
-            if(coordinateArray.Length != colorArray.Length)
+            if (coordinateArray.Length != colorArray.Length)
             {
                 throw new ArrayLengthMismatchException();
             }

+ 1 - 5
PixiEditor/Models/Tools/ReadonlyTool.cs

@@ -1,8 +1,4 @@
-using PixiEditor.Models.Layers;
-using PixiEditor.Models.Position;
-using System;
-using System.Collections.Generic;
-using System.Text;
+using PixiEditor.Models.Position;
 
 namespace PixiEditor.Models.Tools
 {

+ 4 - 6
PixiEditor/Models/Tools/ShapeTool.cs

@@ -1,8 +1,6 @@
 using PixiEditor.Models.Layers;
 using PixiEditor.Models.Position;
-using PixiEditor.Models.Tools.Tools;
 using PixiEditor.Models.Tools.ToolSettings;
-using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Windows.Input;
@@ -31,9 +29,9 @@ namespace PixiEditor.Models.Tools
                 output.AddRange(CoordinatesCalculator.RectangleToCoordinates(CoordinatesCalculator.CalculateThicknessCenter(shape[i], thickness)));
             }
             return output.Distinct().ToArray();
-        }
-     
-
+        }
+
+
         protected DoubleCords CalculateCoordinatesForShapeRotation(Coordinates startingCords, Coordinates secondCoordinates)
         {
             Coordinates currentCoordinates = secondCoordinates;
@@ -50,7 +48,7 @@ namespace PixiEditor.Models.Tools
             {
                 return new DoubleCords(new Coordinates(startingCords.X, currentCoordinates.Y), new Coordinates(currentCoordinates.X, startingCords.Y));
             }
-            else if(startingCords.X > currentCoordinates.X && startingCords.Y <= currentCoordinates.Y)
+            else if (startingCords.X > currentCoordinates.X && startingCords.Y <= currentCoordinates.Y)
             {
                 return new DoubleCords(new Coordinates(currentCoordinates.X, startingCords.Y), new Coordinates(startingCords.X, currentCoordinates.Y));
             }

+ 3 - 6
PixiEditor/Models/Tools/Tool.cs

@@ -1,14 +1,11 @@
 using PixiEditor.Helpers;
-using PixiEditor.Models.Layers;
-using PixiEditor.Models.Position;
 using PixiEditor.Models.Tools.ToolSettings;
 using System.Windows.Input;
-using System.Windows.Media;
 
 namespace PixiEditor.Models.Tools
 {
     public abstract class Tool : NotifyableObject
-    {        
+    {
         public abstract ToolType ToolType { get; }
         public string ImagePath => $"/Images/{ToolType}Image.png";
         public bool HideHighlight { get; set; } = false;
@@ -18,8 +15,8 @@ namespace PixiEditor.Models.Tools
         public bool IsActive
         {
             get { return _isActive; }
-            set 
-            { 
+            set
+            {
                 _isActive = value;
                 RaisePropertyChanged("IsActive");
             }

+ 2 - 8
PixiEditor/Models/Tools/ToolSettings/Settings/FloatSetting.cs

@@ -1,10 +1,4 @@
 using PixiEditor.Views;
-using System;
-using System.Collections.Generic;
-using System.Text;
-using System.Text.RegularExpressions;
-using System.Windows;
-using System.Windows.Controls;
 using System.Windows.Data;
 
 namespace PixiEditor.Models.Tools.ToolSettings.Settings
@@ -14,7 +8,7 @@ namespace PixiEditor.Models.Tools.ToolSettings.Settings
         public float Min { get; set; }
         public float Max { get; set; }
 
-        public FloatSetting(string name, float initialValue, string label = "", 
+        public FloatSetting(string name, float initialValue, string label = "",
             float min = float.NegativeInfinity, float max = float.PositiveInfinity) : base(name)
         {
             Label = label;
@@ -31,7 +25,7 @@ namespace PixiEditor.Models.Tools.ToolSettings.Settings
                 Width = 40,
                 Height = 20,
                 Min = Min,
-                Max = Max,                
+                Max = Max,
 
             };
             Binding binding = new Binding("Value")

+ 4 - 5
PixiEditor/Models/Tools/ToolSettings/Settings/Setting.cs

@@ -1,7 +1,4 @@
 using PixiEditor.Helpers;
-using System;
-using System.Collections.Generic;
-using System.Text;
 using System.Windows.Controls;
 
 namespace PixiEditor.Models.Tools.ToolSettings
@@ -12,7 +9,9 @@ namespace PixiEditor.Models.Tools.ToolSettings
         public string Label { get; set; }
         public bool HasLabel => !string.IsNullOrEmpty(Label);
         private object value;
-        public object Value { get => value;
+        public object Value
+        {
+            get => value;
             set
             {
                 this.value = value;
@@ -25,5 +24,5 @@ namespace PixiEditor.Models.Tools.ToolSettings
         {
             Name = name;
         }
-	}
+    }
 }

+ 0 - 3
PixiEditor/Models/Tools/ToolSettings/Settings/SizeSetting.cs

@@ -1,8 +1,5 @@
 using PixiEditor.Helpers;
 using PixiEditor.Helpers.Behaviours;
-using System;
-using System.Collections.Generic;
-using System.Text;
 using System.Windows;
 using System.Windows.Controls;
 using System.Windows.Data;

+ 1 - 4
PixiEditor/Models/Tools/ToolSettings/Toolbars/BasicShapeToolbar.cs

@@ -1,7 +1,4 @@
 using PixiEditor.Models.Tools.ToolSettings.Settings;
-using System;
-using System.Collections.Generic;
-using System.Text;
 
 namespace PixiEditor.Models.Tools.ToolSettings
 {
@@ -10,7 +7,7 @@ namespace PixiEditor.Models.Tools.ToolSettings
         public BasicShapeToolbar()
         {
             Settings.Add(new BoolSetting("Fill", "Fill shape: "));
-            Settings.Add(new ColorSetting("FillColor", "Fill color"));            
+            Settings.Add(new ColorSetting("FillColor", "Fill color"));
         }
     }
 }

+ 0 - 5
PixiEditor/Models/Tools/ToolSettings/Toolbars/BasicToolbar.cs

@@ -1,9 +1,4 @@
 using PixiEditor.Models.Tools.ToolSettings.Settings;
-using System;
-using System.Collections.Generic;
-using System.Collections.ObjectModel;
-using System.Text;
-using System.Windows.Controls;
 
 namespace PixiEditor.Models.Tools.ToolSettings
 {

+ 0 - 3
PixiEditor/Models/Tools/ToolSettings/Toolbars/BrightnessToolToolbar.cs

@@ -1,7 +1,4 @@
 using PixiEditor.Models.Tools.ToolSettings.Settings;
-using System;
-using System.Collections.Generic;
-using System.Text;
 
 namespace PixiEditor.Models.Tools.ToolSettings.Toolbars
 {

+ 1 - 5
PixiEditor/Models/Tools/ToolSettings/Toolbars/EmptyToolbar.cs

@@ -1,8 +1,4 @@
-using System;
-using System.Collections.Generic;
-using System.Text;
-
-namespace PixiEditor.Models.Tools.ToolSettings
+namespace PixiEditor.Models.Tools.ToolSettings
 {
     public class EmptyToolbar : Toolbar
     {

+ 2 - 3
PixiEditor/Models/Tools/ToolSettings/Toolbars/Toolbar.cs

@@ -1,7 +1,6 @@
 using System.Collections.Generic;
 using System.Collections.ObjectModel;
 using System.Linq;
-using System.Windows.Controls;
 
 namespace PixiEditor.Models.Tools.ToolSettings
 {
@@ -22,7 +21,7 @@ namespace PixiEditor.Models.Tools.ToolSettings
         {
             for (int i = 0; i < Settings.Count; i++)
             {
-                if(_sharedSettings.Any(x=> x.Name == Settings[i].Name))
+                if (_sharedSettings.Any(x => x.Name == Settings[i].Name))
                 {
                     _sharedSettings.First(x => x.Name == Settings[i].Name).Value = Settings[i].Value;
                 }
@@ -39,7 +38,7 @@ namespace PixiEditor.Models.Tools.ToolSettings
         {
             for (int i = 0; i < _sharedSettings.Count; i++)
             {
-                if(Settings.Any(x=> x.Name == _sharedSettings[i].Name))
+                if (Settings.Any(x => x.Name == _sharedSettings[i].Name))
                 {
                     Settings.First(x => x.Name == _sharedSettings[i].Name).Value = _sharedSettings[i].Value;
                 }

+ 1 - 7
PixiEditor/Models/Tools/ToolType.cs

@@ -1,10 +1,4 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace PixiEditor.Models.Tools
+namespace PixiEditor.Models.Tools
 {
     public enum ToolType
     {

+ 7 - 7
PixiEditor/Models/Tools/Tools/BrightnessTool.cs

@@ -13,8 +13,8 @@ namespace PixiEditor.Models.Tools.Tools
     public class BrightnessTool : BitmapOperationTool
     {
         public override ToolType ToolType => ToolType.Brightness;
-        private const float CorrectionFactor = 5f; //Initial correction factor
-        
+        private const float CorrectionFactor = 5f; //Initial correction factor
+
         public BrightnessTool()
         {
             Tooltip = "Makes pixel brighter or darker pixel (U)";
@@ -25,13 +25,13 @@ namespace PixiEditor.Models.Tools.Tools
         {
             int toolSize = (int)Toolbar.GetSetting("ToolSize").Value;
             float correctionFactor = (float)Toolbar.GetSetting("CorrectionFactor").Value;
-            if(Keyboard.IsKeyDown(Key.LeftCtrl))
+            if (Keyboard.IsKeyDown(Key.LeftCtrl))
             {
                 return ChangeBrightness(layer, coordinates[0], toolSize, -correctionFactor);
-            }
-                return ChangeBrightness(layer, coordinates[0], toolSize, correctionFactor);
-        }       
-
+            }
+            return ChangeBrightness(layer, coordinates[0], toolSize, correctionFactor);
+        }
+
         private BitmapPixelChanges ChangeBrightness(Layer layer, Coordinates coordinates, int toolSize, float correctionFactor)
         {
             DoubleCords centeredCoords = CoordinatesCalculator.CalculateThicknessCenter(coordinates, toolSize);

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

@@ -1,12 +1,9 @@
 using PixiEditor.Helpers.Extensions;
-using PixiEditor.Models.ImageManipulation;
 using PixiEditor.Models.Layers;
 using PixiEditor.Models.Position;
-using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Windows.Media;
-using System.Windows.Media.Imaging;
 
 namespace PixiEditor.Models.Tools.Tools
 {

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

@@ -1,9 +1,5 @@
-using PixiEditor.Models.Layers;
-using PixiEditor.Models.Position;
+using PixiEditor.Models.Position;
 using PixiEditor.ViewModels;
-using System;
-using System.Collections.Generic;
-using System.Text;
 using System.Windows.Media;
 
 namespace PixiEditor.Models.Tools.Tools

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

@@ -1,9 +1,6 @@
 using PixiEditor.Models.Layers;
 using PixiEditor.Models.Position;
 using PixiEditor.Models.Tools.ToolSettings;
-using System;
-using System.Collections.Generic;
-using System.Text;
 using System.Windows.Media;
 
 namespace PixiEditor.Models.Tools.Tools

+ 7 - 10
PixiEditor/Models/Tools/Tools/LineTool.cs

@@ -1,15 +1,12 @@
-using PixiEditor.Models.ImageManipulation;
-using PixiEditor.Models.Layers;
+using PixiEditor.Models.Layers;
 using PixiEditor.Models.Position;
 using PixiEditor.Models.Tools.ToolSettings;
-using System;
 using System.Collections.Generic;
-using System.Linq;
 using System.Windows.Media;
 
 namespace PixiEditor.Models.Tools.Tools
 {
-	public class LineTool : ShapeTool
+    public class LineTool : ShapeTool
     {
 
         public override ToolType ToolType => ToolType.Line;
@@ -29,7 +26,7 @@ namespace PixiEditor.Models.Tools.Tools
         {
             Coordinates startingCoordinates = coordinates[^1];
             Coordinates latestCoordinates = coordinates[0];
-            if(thickness == 1)
+            if (thickness == 1)
             {
                 return BresenhamLine(startingCoordinates.X, startingCoordinates.Y, latestCoordinates.X, latestCoordinates.Y);
             }
@@ -123,7 +120,7 @@ namespace PixiEditor.Models.Tools.Tools
 
         private int[,] GetMaskForThickness(int thickness)
         {
-            if(thickness == 2)
+            if (thickness == 2)
             {
                 return new int[,] {
                 {0,0,0 },
@@ -131,7 +128,7 @@ namespace PixiEditor.Models.Tools.Tools
                 {0,1,1 }
                 };
             }
-            int[,] mask = new int[thickness,thickness];
+            int[,] mask = new int[thickness, thickness];
 
             for (int i = 0; i < thickness; i++)
             {
@@ -141,6 +138,6 @@ namespace PixiEditor.Models.Tools.Tools
                 }
             }
             return mask;
-        }    
-	}
+        }
+    }
 }

+ 2 - 4
PixiEditor/Models/Tools/Tools/MoveTool.cs

@@ -1,9 +1,7 @@
-using PixiEditor.Helpers.Extensions;
-using PixiEditor.Models.DataHolders;
+using PixiEditor.Models.DataHolders;
 using PixiEditor.Models.Layers;
 using PixiEditor.Models.Position;
 using PixiEditor.ViewModels;
-using System;
 using System.Linq;
 using System.Windows.Input;
 using System.Windows.Media;
@@ -81,7 +79,7 @@ namespace PixiEditor.Models.Tools.Tools
         private Coordinates[] TranslateSelection(Coordinates end, out Coordinates[] previousSelection)
         {
             Coordinates translation = ImageManipulation.Transform.GetTranslation(_lastMouseMove, end);
-            previousSelection = _currentSelection.ToArray();            
+            previousSelection = _currentSelection.ToArray();
             return ImageManipulation.Transform.Translate(previousSelection, translation);
         }
 

+ 2 - 2
PixiEditor/Models/Tools/Tools/RectangleTool.cs

@@ -36,7 +36,7 @@ namespace PixiEditor.Models.Tools.Tools
         {
             DoubleCords fixedCoordinates = CalculateCoordinatesForShapeRotation(coordinates[^1], coordinates[0]);
             List<Coordinates> output = new List<Coordinates>();
-            Coordinates[] rectangle =  CalculateRectanglePoints(fixedCoordinates);
+            Coordinates[] rectangle = CalculateRectanglePoints(fixedCoordinates);
             output.AddRange(rectangle);
 
             for (int i = 1; i < (int)Math.Floor(thickness / 2f) + 1; i++)
@@ -73,7 +73,7 @@ namespace PixiEditor.Models.Tools.Tools
             {
                 finalCoordinates.Add(new Coordinates(coordinates.Coords1.X, i));
                 finalCoordinates.Add(new Coordinates(coordinates.Coords2.X, i));
-            }            
+            }
             return finalCoordinates.ToArray();
         }
 

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

@@ -1,11 +1,8 @@
 using PixiEditor.Models.Layers;
 using PixiEditor.Models.Position;
 using PixiEditor.ViewModels;
-using System;
 using System.Collections.Generic;
 using System.Linq;
-using System.Text;
-using System.Windows.Media;
 
 namespace PixiEditor.Models.Tools.Tools
 {
@@ -39,7 +36,7 @@ namespace PixiEditor.Models.Tools.Tools
         public Coordinates[] GetAllSelection()
         {
 
-            return GetAllSelection(ViewModelMain.Current.BitmapManager.Layers[0]);
+            return GetAllSelection(ViewModelMain.Current.BitmapManager.ActiveDocument.Layers[0]);
         }
 
         /// <summary>
@@ -49,7 +46,7 @@ namespace PixiEditor.Models.Tools.Tools
         /// <returns>Coordinates array of pixels</returns>
         public Coordinates[] GetAllSelection(Layer layer)
         {
-            return GetRectangleSelectionForPoints(new Coordinates(0,0), new Coordinates(layer.Width - 1, layer.Height - 1));
+            return GetRectangleSelectionForPoints(new Coordinates(0, 0), new Coordinates(layer.Width, layer.Height));
         }
     }
 }

+ 0 - 2
PixiEditor/Properties/AssemblyInfo.cs

@@ -1,6 +1,4 @@
 using System.Reflection;
-using System.Resources;
-using System.Runtime.CompilerServices;
 using System.Runtime.InteropServices;
 using System.Windows;
 

+ 0 - 6
PixiEditor/ViewModels/FeedbackDialogViewModel.cs

@@ -1,10 +1,4 @@
 using PixiEditor.Helpers;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Net.Mail;
-using System.Text;
-using System.Threading.Tasks;
 using System.Windows;
 
 namespace PixiEditor.ViewModels

+ 0 - 4
PixiEditor/ViewModels/ImportFilePopupViewModel.cs

@@ -1,10 +1,6 @@
 using Microsoft.Win32;
 using PixiEditor.Helpers;
 using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
 using System.Windows;
 using System.Windows.Media.Imaging;
 

+ 0 - 5
PixiEditor/ViewModels/MenuButtonViewModel.cs

@@ -1,9 +1,4 @@
 using PixiEditor.Helpers;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
 using System.Windows;
 
 namespace PixiEditor.ViewModels

+ 0 - 8
PixiEditor/ViewModels/NewFileMenuViewModel.cs

@@ -1,13 +1,5 @@
 using PixiEditor.Helpers;
-using PixiEditor.Models;
-using System;
-using System.Collections.Generic;
-using System.Diagnostics;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
 using System.Windows;
-using System.Windows.Input;
 
 namespace PixiEditor.ViewModels
 {

+ 2 - 11
PixiEditor/ViewModels/SaveFilePopupViewModel.cs

@@ -1,19 +1,10 @@
 using Microsoft.Win32;
 using PixiEditor.Helpers;
-using PixiEditor.Views;
-using System;
-using System.Collections.Generic;
-using System.Diagnostics;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
 using System.Windows;
-using System.Windows.Input;
-using System.Windows.Media;
 
 namespace PixiEditor.ViewModels
 {
-     class SaveFilePopupViewModel : ViewModelBase
+    class SaveFilePopupViewModel : ViewModelBase
     {
         public RelayCommand CloseButtonCommand { get; set; }
         public RelayCommand DragMoveCommand { get; set; }
@@ -68,7 +59,7 @@ namespace PixiEditor.ViewModels
                 DefaultExt = "PNG Image (.png)|*.png",
                 Filter = "PNG Image (.png)|*.png"
             };
-            if(path.ShowDialog() == true)
+            if (path.ShowDialog() == true)
             {
                 if (string.IsNullOrEmpty(path.FileName) == false)
                 {

+ 2 - 6
PixiEditor/ViewModels/ViewModelBase.cs

@@ -1,15 +1,11 @@
-using System;
-using System.Collections.Generic;
-using System.ComponentModel;
+using System.ComponentModel;
 using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
 using System.Windows;
 using System.Windows.Input;
 
 namespace PixiEditor.ViewModels
 {
-     class ViewModelBase : INotifyPropertyChanged
+    class ViewModelBase : INotifyPropertyChanged
     {
         public event PropertyChangedEventHandler PropertyChanged = delegate { };
 

+ 56 - 40
PixiEditor/ViewModels/ViewModelMain.cs

@@ -1,20 +1,20 @@
 using PixiEditor.Helpers;
+using PixiEditor.Models.Controllers;
+using PixiEditor.Models.DataHolders;
+using PixiEditor.Models.Dialogs;
 using PixiEditor.Models.Enums;
+using PixiEditor.Models.IO;
+using PixiEditor.Models.Position;
 using PixiEditor.Models.Tools;
+using PixiEditor.Models.Tools.Tools;
 using System;
 using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.Linq;
 using System.Windows;
 using System.Windows.Input;
 using System.Windows.Media;
 using System.Windows.Media.Imaging;
-using PixiEditor.Models.Controllers;
-using PixiEditor.Models.Dialogs;
-using PixiEditor.Models.IO;
-using PixiEditor.Models.Position;
-using PixiEditor.Models.DataHolders;
-using System.Linq;
-using System.Collections.ObjectModel;
-using PixiEditor.Models.Tools.Tools;
 
 namespace PixiEditor.ViewModels
 {
@@ -43,6 +43,7 @@ namespace PixiEditor.ViewModels
         public RelayCommand DeselectCommand { get; set; }
         public RelayCommand SelectAllCommand { get; set; }
         public RelayCommand CopyCommand { get; set; }
+        public RelayCommand ClipCanvasCommand { get; set; }
 
 
         private double _mouseXonCanvas;
@@ -91,15 +92,17 @@ namespace PixiEditor.ViewModels
         public ToolType SelectedTool
         {
             get { return _selectedTool; }
-            set 
-            { 
-                if (_selectedTool != value) 
-                { 
-                    _selectedTool = value; 
-                    SetActiveTool(value); 
-                    RaisePropertyChanged("SelectedTool"); } }
-        }        
-
+            set
+            {
+                if (_selectedTool != value)
+                {
+                    _selectedTool = value;
+                    SetActiveTool(value);
+                    RaisePropertyChanged("SelectedTool");
+                }
+            }
+        }
+
         public ObservableCollection<Tool> ToolSet { get; set; }
 
         private LayerChanges _undoChanges;
@@ -107,10 +110,10 @@ namespace PixiEditor.ViewModels
         public LayerChanges UndoChanges
         {
             get { return _undoChanges; }
-            set 
-            { 
+            set
+            {
                 _undoChanges = value;
-                BitmapManager.Layers[value.LayerIndex].ApplyPixels(value.PixelChanges);
+                BitmapManager.ActiveDocument.Layers[value.LayerIndex].ApplyPixels(value.PixelChanges);
             }
         }
 
@@ -119,7 +122,8 @@ namespace PixiEditor.ViewModels
         public Cursor ToolCursor
         {
             get { return _toolCursor; }
-            set {
+            set
+            {
                 _toolCursor = value;
                 RaisePropertyChanged("ToolCursor");
             }
@@ -150,7 +154,7 @@ namespace PixiEditor.ViewModels
             BitmapManager.BitmapOperations.BitmapChanged += BitmapUtility_BitmapChanged;
             BitmapManager.MouseController.StoppedRecordingChanges += MouseController_StoppedRecordingChanges;
             ChangesController = new PixelChangesController();
-            SelectToolCommand = new RelayCommand(SetTool);
+            SelectToolCommand = new RelayCommand(SetTool, DocumentIsNotNull);
             GenerateDrawAreaCommand = new RelayCommand(GenerateDrawArea);
             MouseMoveCommand = new RelayCommand(MouseMove);
             MouseDownCommand = new RelayCommand(MouseDown);
@@ -171,11 +175,12 @@ namespace PixiEditor.ViewModels
             DeselectCommand = new RelayCommand(Deselect, SelectionIsNotEmpty);
             SelectAllCommand = new RelayCommand(SelectAll, CanSelectAll);
             CopyCommand = new RelayCommand(Copy, SelectionIsNotEmpty);
+            ClipCanvasCommand = new RelayCommand(ClipCanvas, DocumentIsNotNull);
             ToolSet = new ObservableCollection<Tool> {new MoveTool(), new PenTool(), new SelectTool(), new FloodFill(), new LineTool(),
             new CircleTool(), new RectangleTool(), new EarserTool(), new ColorPickerTool(), new BrightnessTool()};
             ShortcutController = new ShortcutController
             {
-                Shortcuts = new List<Shortcut> { 
+                Shortcuts = new List<Shortcut> {
                     new Shortcut(Key.B, SelectToolCommand, ToolType.Pen),
                     new Shortcut(Key.X, SwapColorsCommand),
                     new Shortcut(Key.O, OpenFileCommand, modifier: ModifierKeys.Control),
@@ -203,6 +208,12 @@ namespace PixiEditor.ViewModels
             Current = this;
         }
 
+        public void ClipCanvas(object parameter)
+        {
+            if(BitmapManager.ActiveDocument != null)
+                BitmapManager.ActiveDocument.ClipCanvas();
+        }
+
         private void Copy(object parameter)
         {
             ClipboardController.CopyToClipboard(BitmapManager.ActiveLayer.LayerBitmap, ActiveSelection.SelectedPoints);
@@ -216,7 +227,12 @@ namespace PixiEditor.ViewModels
 
         private bool CanSelectAll(object property)
         {
-            return BitmapManager.Layers.Count > 0;
+            return BitmapManager.ActiveDocument != null && BitmapManager.ActiveDocument.Layers.Count > 0;
+        }
+
+        private bool DocumentIsNotNull(object property)
+        {
+            return BitmapManager.ActiveDocument != null;
         }
 
         public void Deselect(object parameter)
@@ -236,7 +252,7 @@ namespace PixiEditor.ViewModels
 
         public void RenameLayer(object parameter)
         {
-            BitmapManager.Layers[(int)parameter].IsRenaming = true;
+            BitmapManager.ActiveDocument.Layers[(int)parameter].IsRenaming = true;
         }
 
         public void KeyDown(object parameter)
@@ -256,7 +272,7 @@ namespace PixiEditor.ViewModels
 
         private void BitmapUtility_BitmapChanged(object sender, BitmapChangedEventArgs e)
         {
-            ChangesController.AddChanges(new LayerChanges(e.PixelsChanged, e.ChangedLayerIndex), 
+            ChangesController.AddChanges(new LayerChanges(e.PixelsChanged, e.ChangedLayerIndex),
                 new LayerChanges(e.OldPixelsValues, e.ChangedLayerIndex));
         }
 
@@ -270,8 +286,8 @@ namespace PixiEditor.ViewModels
         public void MoveLayerToFront(object parameter)
         {
             int oldIndex = (int)parameter;
-            BitmapManager.Layers.Move(oldIndex, oldIndex + 1);
-            if(BitmapManager.ActiveLayerIndex == oldIndex)
+            BitmapManager.ActiveDocument.Layers.Move(oldIndex, oldIndex + 1);
+            if (BitmapManager.ActiveDocument.ActiveLayerIndex == oldIndex)
             {
                 BitmapManager.SetActiveLayer(oldIndex + 1);
             }
@@ -280,8 +296,8 @@ namespace PixiEditor.ViewModels
         public void MoveLayerToBack(object parameter)
         {
             int oldIndex = (int)parameter;
-            BitmapManager.Layers.Move(oldIndex, oldIndex - 1);
-            if (BitmapManager.ActiveLayerIndex == oldIndex)
+            BitmapManager.ActiveDocument.Layers.Move(oldIndex, oldIndex - 1);
+            if (BitmapManager.ActiveDocument.ActiveLayerIndex == oldIndex)
             {
                 BitmapManager.SetActiveLayer(oldIndex - 1);
             }
@@ -289,7 +305,7 @@ namespace PixiEditor.ViewModels
 
         public bool CanMoveToFront(object property)
         {
-            return BitmapManager.Layers.Count - 1 > (int)property;
+            return BitmapManager.ActiveDocument.Layers.Count - 1 > (int)property;
         }
 
         public bool CanMoveToBack(object property)
@@ -309,7 +325,7 @@ namespace PixiEditor.ViewModels
 
         public bool CanDeleteLayer(object property)
         {
-            return BitmapManager.Layers.Count > 1;
+            return BitmapManager.ActiveDocument.Layers.Count > 1;
         }
 
         #region Undo/Redo
@@ -353,7 +369,7 @@ namespace PixiEditor.ViewModels
         {
             Tool foundTool = ToolSet.First(x => x.ToolType == tool);
             Tool activeTool = ToolSet.FirstOrDefault(x => x.IsActive);
-            if(activeTool != null)
+            if (activeTool != null)
             {
                 activeTool.IsActive = false;
             }
@@ -386,8 +402,8 @@ namespace PixiEditor.ViewModels
 
         private void MouseDown(object parameter)
         {
-            if (BitmapManager.Layers.Count == 0) return;
-            if(Mouse.LeftButton == MouseButtonState.Pressed)
+            if (BitmapManager.ActiveDocument.Layers.Count == 0) return;
+            if (Mouse.LeftButton == MouseButtonState.Pressed)
             {
                 if (!BitmapManager.MouseController.IsRecordingChanges)
                 {
@@ -452,7 +468,7 @@ namespace PixiEditor.ViewModels
         /// <returns></returns>
         private bool CanSave(object property)
         {
-            return BitmapManager.ActiveLayer != null;
+            return BitmapManager.ActiveDocument != null;
         }
         #endregion
 
@@ -466,13 +482,13 @@ namespace PixiEditor.ViewModels
             if (dialog.ShowDialog())
             {
                 NewDocument(dialog.FileWidth, dialog.FileHeight);
-                BitmapManager.ActiveLayer.LayerBitmap = Importer.ImportImage(dialog.FilePath, dialog.FileWidth, dialog.FileHeight);
+                BitmapManager.ActiveDocument.ActiveLayer.LayerBitmap = Importer.ImportImage(dialog.FilePath, dialog.FileWidth, dialog.FileHeight);
             }
         }
 
         private void NewDocument(int width, int height)
         {
-            BitmapManager.Layers.Clear();
+            BitmapManager.ActiveDocument = new Document(width, height);
             BitmapManager.AddNewLayer("Base Layer", width, height, true);
             BitmapManager.PreviewLayer = null;
         }
@@ -488,12 +504,12 @@ namespace PixiEditor.ViewModels
 
         public void NewLayer(object parameter)
         {
-            BitmapManager.AddNewLayer($"New Layer {BitmapManager.Layers.Count}", BitmapManager.Layers[0].Width, BitmapManager.Layers[0].Height);         
+            BitmapManager.AddNewLayer($"New Layer {BitmapManager.ActiveDocument.Layers.Count}", BitmapManager.ActiveDocument.Width, BitmapManager.ActiveDocument.Height);
         }
 
         public bool CanCreateNewLayer(object parameter)
         {
-                return BitmapManager.Layers.Count > 0;
+            return BitmapManager.ActiveDocument != null && BitmapManager.ActiveDocument.Layers.Count > 0;
         }
     }
 }

+ 7 - 18
PixiEditor/Views/EditableTextBlock.xaml.cs

@@ -1,18 +1,7 @@
-using PixiEditor.Helpers;
-using PixiEditor.Models.Controllers;
-using System;
-using System.Collections.Generic;
-using System.Text;
-using System.Threading.Tasks;
+using PixiEditor.Models.Controllers;
 using System.Windows;
 using System.Windows.Controls;
-using System.Windows.Data;
-using System.Windows.Documents;
 using System.Windows.Input;
-using System.Windows.Media;
-using System.Windows.Media.Imaging;
-using System.Windows.Navigation;
-using System.Windows.Shapes;
 
 namespace PixiEditor.Views
 {
@@ -37,11 +26,11 @@ namespace PixiEditor.Views
         public static readonly DependencyProperty TextBlockVisibilityProperty =
             DependencyProperty.Register("TextBlockVisibility", typeof(Visibility), typeof(EditableTextBlock), new PropertyMetadata(Visibility.Visible));
 
-      
+
 
         // Using a DependencyProperty as the backing store for Text.  This enables animation, styling, binding, etc...
         public static readonly DependencyProperty TextProperty =
-            DependencyProperty.Register("Text", typeof(string), typeof(EditableTextBlock), new PropertyMetadata(default(string)));       
+            DependencyProperty.Register("Text", typeof(string), typeof(EditableTextBlock), new PropertyMetadata(default(string)));
 
 
 
@@ -49,7 +38,7 @@ namespace PixiEditor.Views
         public bool IsEditing
         {
             get { return (bool)GetValue(EnableEditingProperty); }
-            set { SetValue(EnableEditingProperty, value);}
+            set { SetValue(EnableEditingProperty, value); }
         }
 
         // Using a DependencyProperty as the backing store for EnableEditing.  This enables animation, styling, binding, etc...
@@ -58,11 +47,11 @@ namespace PixiEditor.Views
 
         private static void OnIsEditingChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
         {
-            if((bool)e.NewValue == true)
+            if ((bool)e.NewValue == true)
             {
                 EditableTextBlock tb = (EditableTextBlock)d;
                 tb.EnableEditing();
-                
+
             }
         }
 
@@ -98,7 +87,7 @@ namespace PixiEditor.Views
 
         private void TextBox_KeyDown(object sender, KeyEventArgs e)
         {
-            if(e.Key == Key.Enter)
+            if (e.Key == Key.Enter)
             {
                 DisableEditing();
             }

+ 0 - 12
PixiEditor/Views/ImportFilePopup.xaml.cs

@@ -1,17 +1,5 @@
 using PixiEditor.ViewModels;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
 using System.Windows;
-using System.Windows.Controls;
-using System.Windows.Data;
-using System.Windows.Documents;
-using System.Windows.Input;
-using System.Windows.Media;
-using System.Windows.Media.Imaging;
-using System.Windows.Shapes;
 
 namespace PixiEditor.Views
 {

+ 2 - 2
PixiEditor/Views/MainDrawingPanel.xaml.cs

@@ -19,7 +19,7 @@ namespace PixiEditor.Views
         public double MouseX
         {
             get { return (double)GetValue(MouseXProperty); }
-            set { SetValue(MouseXProperty, value);}
+            set { SetValue(MouseXProperty, value); }
         }
 
         // Using a DependencyProperty as the backing store for MouseX.  This enables animation, styling, binding, etc...
@@ -76,7 +76,7 @@ namespace PixiEditor.Views
 
         private void Zoombox_Loaded(object sender, RoutedEventArgs e)
         {
-            if(CenterOnStart == true)
+            if (CenterOnStart == true)
             {
                 ((Zoombox)sender).CenterContent();
             }

+ 7 - 4
PixiEditor/Views/MainWindow.xaml

@@ -77,6 +77,9 @@
                     <MenuItem Header="_Select All" Command="{Binding SelectAllCommand}" InputGestureText="Ctrl+A"/>
                     <MenuItem Header="_Deselect" Command="{Binding DeselectCommand}" InputGestureText="Ctrl+D"/>
                 </MenuItem>
+                <MenuItem Header="_Document">
+                    <MenuItem Header="Clip canvas" Command="{Binding ClipCanvasCommand}"/>
+                </MenuItem>
             </Menu>
             <StackPanel DockPanel.Dock="Right" VerticalAlignment="Top" Orientation="Horizontal" HorizontalAlignment="Right" WindowChrome.IsHitTestVisibleInChrome="True">
                 <Button Style="{StaticResource MinimizeButtonStyle}" WindowChrome.IsHitTestVisibleInChrome="True" ToolTip="Minimize"
@@ -121,15 +124,15 @@
                         <behaviors:MouseBehaviour RelativeTo="{Binding ElementName=DrawingPanel, Path=Item}" MouseX="{Binding MouseXOnCanvas, Mode=OneWayToSource}" MouseY="{Binding MouseYOnCanvas, Mode=OneWayToSource}"/>
                     </i:Interaction.Behaviors>
                     <vws:MainDrawingPanel.Item>
-                        <Canvas Width="{Binding BitmapManager.ActiveLayer.Width}" Height="{Binding BitmapManager.ActiveLayer.Height}" VerticalAlignment="Center" HorizontalAlignment="Center">
+                        <Canvas Width="{Binding BitmapManager.ActiveDocument.Width}" Height="{Binding BitmapManager.ActiveDocument.Height}" VerticalAlignment="Center" HorizontalAlignment="Center">
                             <i:Interaction.Triggers>
                                 <i:EventTrigger EventName="MouseDown">
                                     <i:InvokeCommandAction Command="{Binding MouseDownCommand}"/>
                                 </i:EventTrigger>
                             </i:Interaction.Triggers>
-                            <Image Source="/Images/transparentbg.png" Height="{Binding BitmapManager.ActiveLayer.Height}" Width="{Binding BitmapManager.ActiveLayer.Width}" Opacity="0.9" Stretch="UniformToFill"/>
+                            <Image Source="/Images/transparentbg.png" Height="{Binding BitmapManager.ActiveDocument.Height}" Width="{Binding BitmapManager.ActiveDocument.Width}" Opacity="0.9" Stretch="UniformToFill"/>
                             <Image Source="{Binding BitmapManager.PreviewLayer.LayerBitmap}" Panel.ZIndex="2" RenderOptions.BitmapScalingMode="NearestNeighbor" Stretch="Uniform" Width="{Binding BitmapManager.PreviewLayer.Width}" Height="{Binding BitmapManager.PreviewLayer.Height}"/>
-                            <ItemsControl ItemsSource="{Binding BitmapManager.Layers}">
+                            <ItemsControl ItemsSource="{Binding BitmapManager.ActiveDocument.Layers}">
                                 <ItemsControl.ItemsPanel>
                                     <ItemsPanelTemplate>
                                         <Grid/>
@@ -202,7 +205,7 @@
                             <xcad:LayoutAnchorable ContentId="layers" Title="Layers" CanHide="False" CanClose="False" CanAutoHide="False" CanDockAsTabbedDocument="False" CanFloat="True">
                                 <StackPanel  Orientation="Vertical">
                                     <Button Command="{Binding NewLayerCommand}" Height="30" Content="New Layer" HorizontalAlignment="Stretch" Margin="5" Style="{StaticResource DarkRoundButton}"/>
-                                    <ItemsControl ItemsSource="{Binding BitmapManager.Layers}" x:Name="layersItemsControl" AlternationCount="9999">
+                                    <ItemsControl ItemsSource="{Binding BitmapManager.ActiveDocument.Layers}" x:Name="layersItemsControl" AlternationCount="9999">
                                         <ItemsControl.ItemsPanel>
                                             <ItemsPanelTemplate>
                                                 <ui:ReversedOrderStackPanel Orientation="Vertical"/>

+ 6 - 24
PixiEditor/Views/MainWindow.xaml.cs

@@ -1,24 +1,6 @@
-using PixiEditor.Models.Controllers;
-using PixiEditor.Models.Layers;
-using PixiEditor.ViewModels;
-using PixiEditor.Views;
-using System;
-using System.Collections.Generic;
-using System.Collections.ObjectModel;
-using System.Linq;
-using System.Text;
-using System.Threading;
-using System.Threading.Tasks;
+using System;
 using System.Windows;
-using System.Windows.Controls;
-using System.Windows.Data;
-using System.Windows.Documents;
 using System.Windows.Input;
-using System.Windows.Media;
-using System.Windows.Media.Imaging;
-using System.Windows.Navigation;
-using System.Windows.Shapes;
-using Xceed.Wpf.Toolkit.Core.Input;
 
 namespace PixiEditor
 {
@@ -38,31 +20,31 @@ namespace PixiEditor
             e.CanExecute = true;
         }
 
-        
+
         private void CommandBinding_Executed_Minimize(object sender, ExecutedRoutedEventArgs e)
         {
             SystemCommands.MinimizeWindow(this);
         }
 
-       
+
         private void CommandBinding_Executed_Maximize(object sender, ExecutedRoutedEventArgs e)
         {
             SystemCommands.MaximizeWindow(this);
         }
 
-        
+
         private void CommandBinding_Executed_Restore(object sender, ExecutedRoutedEventArgs e)
         {
             SystemCommands.RestoreWindow(this);
         }
 
-        
+
         private void CommandBinding_Executed_Close(object sender, ExecutedRoutedEventArgs e)
         {
             SystemCommands.CloseWindow(this);
         }
 
-        
+
         private void MainWindowStateChangeRaised(object sender, EventArgs e)
         {
             if (WindowState == WindowState.Maximized)

+ 0 - 11
PixiEditor/Views/MenuButton.xaml.cs

@@ -1,18 +1,7 @@
 using PixiEditor.ViewModels;
 using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
 using System.Windows;
 using System.Windows.Controls;
-using System.Windows.Data;
-using System.Windows.Documents;
-using System.Windows.Input;
-using System.Windows.Media;
-using System.Windows.Media.Imaging;
-using System.Windows.Navigation;
-using System.Windows.Shapes;
 
 namespace PixiEditor.Views
 {

+ 1 - 15
PixiEditor/Views/NewFilePopup.xaml.cs

@@ -1,18 +1,4 @@
-using PixiEditor.ViewModels;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using System.Windows;
-using System.Windows.Controls;
-using System.Windows.Data;
-using System.Windows.Documents;
-using System.Windows.Input;
-using System.Windows.Media;
-using System.Windows.Media.Imaging;
-using System.Windows.Navigation;
-using System.Windows.Shapes;
+using System.Windows;
 
 namespace PixiEditor.Views
 {

+ 1 - 9
PixiEditor/Views/NumerInput.xaml.cs

@@ -1,16 +1,8 @@
 using System;
-using System.Collections.Generic;
-using System.Text;
 using System.Text.RegularExpressions;
 using System.Windows;
 using System.Windows.Controls;
-using System.Windows.Data;
-using System.Windows.Documents;
 using System.Windows.Input;
-using System.Windows.Media;
-using System.Windows.Media.Imaging;
-using System.Windows.Navigation;
-using System.Windows.Shapes;
 
 namespace PixiEditor.Views
 {
@@ -28,7 +20,7 @@ namespace PixiEditor.Views
 
         // Using a DependencyProperty as the backing store for Value.  This enables animation, styling, binding, etc...
         public static readonly DependencyProperty ValueProperty =
-            DependencyProperty.Register("Value", typeof(float), typeof(NumberInput), 
+            DependencyProperty.Register("Value", typeof(float), typeof(NumberInput),
                 new PropertyMetadata(0f, new PropertyChangedCallback(OnValueChanged)));
 
         private static void OnValueChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)

+ 0 - 12
PixiEditor/Views/SaveFilePopup.xaml.cs

@@ -1,17 +1,5 @@
 using PixiEditor.ViewModels;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
 using System.Windows;
-using System.Windows.Controls;
-using System.Windows.Data;
-using System.Windows.Documents;
-using System.Windows.Input;
-using System.Windows.Media;
-using System.Windows.Media.Imaging;
-using System.Windows.Shapes;
 
 namespace PixiEditor.Views
 {

+ 0 - 3
PixiEditorTests/ModelsTests/ControllersTests/UndoManagerTests.cs

@@ -1,9 +1,6 @@
 using NUnit.Framework;
 using PixiEditor.Models.Controllers;
 using PixiEditor.Models.DataHolders;
-using System;
-using System.Collections.Generic;
-using System.Text;
 
 namespace PixiEditorTests.ModelsTests.ControllersTests
 {

+ 5 - 7
PixiEditorTests/WorkspaceTests/ColorsTests/ExtendedColorTests.cs

@@ -1,8 +1,6 @@
 using NUnit.Framework;
 using PixiEditor.Models.Colors;
 using System;
-using System.Collections.Generic;
-using System.Text;
 using System.Windows.Media;
 
 namespace PixiEditorTests.WorkspaceTests.ColorsTests
@@ -28,11 +26,11 @@ namespace PixiEditorTests.WorkspaceTests.ColorsTests
 
 
         //Acceptable margin of error is 1
-        [TestCase(0,0,0,0,0,0)]
-        [TestCase(255,255,255,0,0,100)]
-        [TestCase(182,55,55,0,53.6f,46.5f)]
-        [TestCase(20,47,255,233,100,53.9f)]
-        [TestCase(137, 43,226, 271,75.9f,52.7f)]
+        [TestCase(0, 0, 0, 0, 0, 0)]
+        [TestCase(255, 255, 255, 0, 0, 100)]
+        [TestCase(182, 55, 55, 0, 53.6f, 46.5f)]
+        [TestCase(20, 47, 255, 233, 100, 53.9f)]
+        [TestCase(137, 43, 226, 271, 75.9f, 52.7f)]
         public void RgbToHslTest(int r, int g, int b, int h, float s, float l)
         {
             Tuple<int, float, float> hsl = ExColor.RgbToHsl(r, g, b);

+ 4 - 7
PixiEditorTests/WorkspaceTests/ImageGeneratorTests.cs

@@ -1,8 +1,5 @@
 using NUnit.Framework;
 using PixiEditor.Models.Images;
-using System;
-using System.Collections.Generic;
-using System.Text;
 using System.Windows.Controls;
 using System.Windows.Media;
 
@@ -11,13 +8,13 @@ namespace PixiEditorTests.ToolsTests
     [TestFixture, Apartment(System.Threading.ApartmentState.STA)]
     public class ImageGeneratorTests
     {
-        [TestCase(16,16)]
-        [TestCase(1024,12)]
-        [TestCase(50000,50000)]
+        [TestCase(16, 16)]
+        [TestCase(1024, 12)]
+        [TestCase(50000, 50000)]
         public void ImageIsPixelArtReady(int width, int height)
         {
             Image img = ImageGenerator.GenerateForPixelArts(width, height);
-            
+
             Assert.IsTrue(img.Stretch == Stretch.Uniform && RenderOptions.GetBitmapScalingMode(img) == BitmapScalingMode.NearestNeighbor
                 && RenderOptions.GetEdgeMode(img) == EdgeMode.Aliased && img.Width == width && img.Height == height);
         }

+ 0 - 4
PixiEditorTests/WorkspaceTests/ToolsTests/CoordinatesCalculatorTests.cs

@@ -1,9 +1,5 @@
 using NUnit.Framework;
 using PixiEditor.Models.Position;
-using PixiEditor.Models.Tools.Tools;
-using System;
-using System.Collections.Generic;
-using System.Text;
 
 namespace PixiEditorTests.WorkspaceTests.ToolsTests
 {