Browse Source

Used Cleanup feature in Visual studio IDE. For now there are only 326 warnings

ArtemK123 4 years ago
parent
commit
c2aa5c7cc7
100 changed files with 2072 additions and 1408 deletions
  1. 9 9
      PixiEditor.UpdateInstaller/AssemblyInfo.cs
  2. 1 1
      PixiEditor.UpdateInstaller/Extensions.cs
  3. 2 2
      PixiEditor.UpdateInstaller/MainWindow.xaml.cs
  4. 2 2
      PixiEditor.UpdateInstaller/ViewModelMain.cs
  5. 5 5
      PixiEditor.UpdateModule/UpdateChecker.cs
  6. 5 5
      PixiEditor.UpdateModule/UpdateDownloader.cs
  7. 7 7
      PixiEditor.UpdateModule/UpdateInstaller.cs
  8. 4 2
      PixiEditor/Exceptions/LengthMismatchException.cs
  9. 105 93
      PixiEditor/Helpers/Behaviours/AllowableCharactersTextBoxBehavior.cs
  10. 71 63
      PixiEditor/Helpers/Behaviours/HintTextBehavior.cs
  11. 62 57
      PixiEditor/Helpers/Behaviours/MouseBehaviour.cs
  12. 25 15
      PixiEditor/Helpers/Behaviours/TextBoxFocusBehavior.cs
  13. 5 0
      PixiEditor/Helpers/Converters/BoolToColorConverter.cs
  14. 5 0
      PixiEditor/Helpers/Converters/BoolToIntConverter.cs
  15. 2 2
      PixiEditor/Helpers/Converters/DoubleToIntConverter.cs
  16. 2 2
      PixiEditor/Helpers/Converters/FloatNormalizeConverter.cs
  17. 9 2
      PixiEditor/Helpers/Converters/OppositeVisibilityConverter.cs
  18. 11 3
      PixiEditor/Helpers/Converters/ToolSizeToIntConverter.cs
  19. 11 4
      PixiEditor/Helpers/Extensions/DictionaryHelper.cs
  20. 12 7
      PixiEditor/Helpers/GlobalMouseHook.cs
  21. 5 3
      PixiEditor/Helpers/RelayCommand.cs
  22. 7 5
      PixiEditor/Helpers/UI/ReversedOrderStackPanel.cs
  23. 1 1
      PixiEditor/Helpers/Validators/SizeValidationRule.cs
  24. 66 46
      PixiEditor/Models/Colors/ExColor.cs
  25. 60 26
      PixiEditor/Models/Controllers/BitmapManager.cs
  26. 47 25
      PixiEditor/Models/Controllers/BitmapOperationsUtility.cs
  27. 39 26
      PixiEditor/Models/Controllers/ClipboardController.cs
  28. 7 0
      PixiEditor/Models/Controllers/MouseMovementController.cs
  29. 30 13
      PixiEditor/Models/Controllers/PixelChangesController.cs
  30. 7 1
      PixiEditor/Models/Controllers/Shortcuts/Shortcut.cs
  31. 10 3
      PixiEditor/Models/Controllers/Shortcuts/ShortcutController.cs
  32. 32 19
      PixiEditor/Models/Controllers/UndoManager.cs
  33. 32 11
      PixiEditor/Models/DataHolders/BitmapPixelChanges.cs
  34. 2 0
      PixiEditor/Models/DataHolders/Change.cs
  35. 113 80
      PixiEditor/Models/DataHolders/Document.cs
  36. 1 0
      PixiEditor/Models/DataHolders/LayerChange.cs
  37. 1 1
      PixiEditor/Models/DataHolders/Selection.cs
  38. 8 5
      PixiEditor/Models/DataHolders/SerializableDocument.cs
  39. 6 2
      PixiEditor/Models/Dialogs/ConfirmationDialog.cs
  40. 5 6
      PixiEditor/Models/Dialogs/ExportFileDialog.cs
  41. 6 5
      PixiEditor/Models/Dialogs/ImportFileDialog.cs
  42. 1 1
      PixiEditor/Models/Dialogs/NewFileDialog.cs
  43. 5 4
      PixiEditor/Models/Dialogs/ResizeDocumentDialog.cs
  44. 3 3
      PixiEditor/Models/IO/BinarySerialization.cs
  45. 11 9
      PixiEditor/Models/IO/Exporter.cs
  46. 8 5
      PixiEditor/Models/IO/Importer.cs
  47. 28 19
      PixiEditor/Models/ImageManipulation/BitmapUtils.cs
  48. 63 44
      PixiEditor/Models/ImageManipulation/Morphology.cs
  49. 8 5
      PixiEditor/Models/ImageManipulation/Transform.cs
  50. 128 76
      PixiEditor/Models/Layers/Layer.cs
  51. 18 6
      PixiEditor/Models/Layers/SerializableLayer.cs
  52. 4 1
      PixiEditor/Models/Position/Coordinates.cs
  53. 55 31
      PixiEditor/Models/Position/CoordinatesCalculator.cs
  54. 1 0
      PixiEditor/Models/Position/DoubleCords.cs
  55. 1 2
      PixiEditor/Models/Position/MousePositionConverter.cs
  56. 4 2
      PixiEditor/Models/Tools/BitmapOperationTool.cs
  57. 28 14
      PixiEditor/Models/Tools/ShapeTool.cs
  58. 5 0
      PixiEditor/Models/Tools/Tool.cs
  59. 6 4
      PixiEditor/Models/Tools/ToolSettings/Settings/BoolSetting.cs
  60. 4 3
      PixiEditor/Models/Tools/ToolSettings/Settings/ColorSetting.cs
  61. 8 8
      PixiEditor/Models/Tools/ToolSettings/Settings/DropdownSetting.cs
  62. 5 3
      PixiEditor/Models/Tools/ToolSettings/Settings/FloatSetting.cs
  63. 10 6
      PixiEditor/Models/Tools/ToolSettings/Settings/SizeSetting.cs
  64. 1 1
      PixiEditor/Models/Tools/ToolSettings/Toolbars/SelectToolToolbar.cs
  65. 21 12
      PixiEditor/Models/Tools/ToolSettings/Toolbars/Toolbar.cs
  66. 25 16
      PixiEditor/Models/Tools/Tools/BrightnessTool.cs
  67. 59 45
      PixiEditor/Models/Tools/Tools/CircleTool.cs
  68. 2 2
      PixiEditor/Models/Tools/Tools/ColorPickerTool.cs
  69. 4 4
      PixiEditor/Models/Tools/Tools/EraserTool.cs
  70. 23 12
      PixiEditor/Models/Tools/Tools/FloodFill.cs
  71. 30 18
      PixiEditor/Models/Tools/Tools/LineTool.cs
  72. 210 178
      PixiEditor/Models/Tools/Tools/MoveTool.cs
  73. 3 3
      PixiEditor/Models/Tools/Tools/PenTool.cs
  74. 37 25
      PixiEditor/Models/Tools/Tools/RectangleTool.cs
  75. 13 9
      PixiEditor/Models/Tools/Tools/SelectTool.cs
  76. 11 7
      PixiEditor/Models/Tools/Tools/ZoomTool.cs
  77. 4 1
      PixiEditor/NotifyableObject.cs
  78. 17 19
      PixiEditor/Properties/AssemblyInfo.cs
  79. 3 3
      PixiEditor/ViewModels/FeedbackDialogViewModel.cs
  80. 11 12
      PixiEditor/ViewModels/ImportFilePopupViewModel.cs
  81. 2 2
      PixiEditor/ViewModels/MenuButtonViewModel.cs
  82. 5 3
      PixiEditor/ViewModels/NewFileMenuViewModel.cs
  83. 8 7
      PixiEditor/ViewModels/SaveFilePopupViewModel.cs
  84. 10 4
      PixiEditor/ViewModels/ViewModelBase.cs
  85. 185 72
      PixiEditor/ViewModels/ViewModelMain.cs
  86. 13 8
      PixiEditor/Views/AnchorPointPicker.xaml.cs
  87. 5 5
      PixiEditor/Views/ConfirmationPopup.xaml.cs
  88. 13 11
      PixiEditor/Views/EditableTextBlock.xaml.cs
  89. 3 6
      PixiEditor/Views/ImportFilePopup.xaml.cs
  90. 10 12
      PixiEditor/Views/LayerItem.xaml.cs
  91. 47 34
      PixiEditor/Views/MainDrawingPanel.xaml.cs
  92. 4 8
      PixiEditor/Views/MainWindow.xaml.cs
  93. 2 3
      PixiEditor/Views/MenuButton.xaml.cs
  94. 4 6
      PixiEditor/Views/NewFilePopup.xaml.cs
  95. 8 10
      PixiEditor/Views/NumberInput.xaml.cs
  96. 7 11
      PixiEditor/Views/ResizeCanvasPopup.xaml.cs
  97. 5 8
      PixiEditor/Views/ResizeDocumentPopup.xaml.cs
  98. 9 7
      PixiEditor/Views/Rotatebox.xaml.cs
  99. 5 8
      PixiEditor/Views/SaveFilePopup.xaml.cs
  100. 9 11
      PixiEditor/Views/SizeInput.xaml.cs

+ 9 - 9
PixiEditor.UpdateInstaller/AssemblyInfo.cs

@@ -2,13 +2,13 @@ using System.Windows;
 
 [assembly: ThemeInfo(
     ResourceDictionaryLocation.None,
-    ResourceDictionaryLocation.SourceAssembly)
-
-    // ResourceDictionaryLocation.None - where theme specific resource dictionaries are located
-    // (used if a resource is not found in the page,
-    // or application resource dictionaries)
-
-    // ResourceDictionaryLocation.SourceAssembly - where the generic resource dictionary is located
-    // (used if a resource is not found in the page,
-    // app, or any theme specific resource dictionaries)
+    ResourceDictionaryLocation.SourceAssembly)
+
+// ResourceDictionaryLocation.None - where theme specific resource dictionaries are located
+// (used if a resource is not found in the page,
+// or application resource dictionaries)
+
+// ResourceDictionaryLocation.SourceAssembly - where the generic resource dictionary is located
+// (used if a resource is not found in the page,
+// app, or any theme specific resource dictionaries)
 ]

+ 1 - 1
PixiEditor.UpdateInstaller/Extensions.cs

@@ -13,7 +13,7 @@ namespace PixiEditor.UpdateInstaller
         {
             if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
             {
-                var sb = new StringBuilder(MaxPath);
+                StringBuilder sb = new StringBuilder(MaxPath);
                 GetModuleFileName(IntPtr.Zero, sb, MaxPath);
                 return sb.ToString();
             }

+ 2 - 2
PixiEditor.UpdateInstaller/MainWindow.xaml.cs

@@ -19,7 +19,7 @@ namespace PixiEditor.UpdateInstaller
 
         private async void Window_Loaded(object sender, RoutedEventArgs e)
         {
-            var vmm = (ViewModelMain)DataContext;
+            ViewModelMain vmm = (ViewModelMain)DataContext;
             await Task.Run(() =>
             {
                 try
@@ -33,7 +33,7 @@ namespace PixiEditor.UpdateInstaller
                 }
                 finally
                 {
-                    var pixiEditorExecutablePath = Directory.GetFiles(vmm.UpdateDirectory, "PixiEditor.exe")[0];
+                    string pixiEditorExecutablePath = Directory.GetFiles(vmm.UpdateDirectory, "PixiEditor.exe")[0];
                     Process.Start(pixiEditorExecutablePath);
                 }
             });

+ 2 - 2
PixiEditor.UpdateInstaller/ViewModelMain.cs

@@ -12,7 +12,7 @@ namespace PixiEditor.UpdateInstaller
         {
             Current = this;
 
-            var updateDirectory = Path.GetDirectoryName(Extensions.GetExecutablePath());
+            string updateDirectory = Path.GetDirectoryName(Extensions.GetExecutablePath());
 
 #if DEBUG
             updateDirectory = Environment.GetCommandLineArgs()[1];
@@ -38,7 +38,7 @@ namespace PixiEditor.UpdateInstaller
 
         public void InstallUpdate()
         {
-            var files = Directory.GetFiles(UpdateDirectory, "update-*.zip");
+            string[] files = Directory.GetFiles(UpdateDirectory, "update-*.zip");
 
             if (files.Length > 0)
             {

+ 5 - 5
PixiEditor.UpdateModule/UpdateChecker.cs

@@ -27,12 +27,12 @@ namespace PixiEditor.UpdateModule
         /// <returns></returns>
         public static bool VersionBigger(string originalVer, string newVer)
         {
-            if (!ParseVersionString(originalVer, out var ver1))
+            if (!ParseVersionString(originalVer, out float ver1))
             {
                 return false;
             }
 
-            if (ParseVersionString(newVer, out var ver2))
+            if (ParseVersionString(newVer, out float ver2))
             {
                 return ver2 > ver1;
             }
@@ -53,13 +53,13 @@ namespace PixiEditor.UpdateModule
 
         private static async Task<ReleaseInfo> GetLatestReleaseInfo_Async()
         {
-            using (var client = new HttpClient())
+            using (HttpClient client = new HttpClient())
             {
                 client.DefaultRequestHeaders.Add("User-Agent", "PixiEditor");
-                var response = await client.GetAsync(ReleaseApiUrl);
+                HttpResponseMessage response = await client.GetAsync(ReleaseApiUrl);
                 if (response.StatusCode == HttpStatusCode.OK)
                 {
-                    var content = await response.Content.ReadAsStringAsync();
+                    string content = await response.Content.ReadAsStringAsync();
                     return JsonSerializer.Deserialize<ReleaseInfo>(content);
                 }
             }

+ 5 - 5
PixiEditor.UpdateModule/UpdateDownloader.cs

@@ -13,16 +13,16 @@ namespace PixiEditor.UpdateModule
 
         public static async Task DownloadReleaseZip(ReleaseInfo release)
         {
-            var matchingAsset = GetMatchingAsset(release);
+            Asset matchingAsset = GetMatchingAsset(release);
 
-            using (var client = new HttpClient())
+            using (HttpClient client = new HttpClient())
             {
                 client.DefaultRequestHeaders.Add("User-Agent", "PixiEditor");
                 client.DefaultRequestHeaders.Add("Accept", "application/octet-stream");
-                var response = await client.GetAsync(matchingAsset.Url);
+                HttpResponseMessage response = await client.GetAsync(matchingAsset.Url);
                 if (response.StatusCode == HttpStatusCode.OK)
                 {
-                    var bytes = await response.Content.ReadAsByteArrayAsync();
+                    byte[] bytes = await response.Content.ReadAsByteArrayAsync();
                     File.WriteAllBytes(Path.Join(DownloadLocation, $"update-{release.TagName}.zip"), bytes);
                 }
             }
@@ -30,7 +30,7 @@ namespace PixiEditor.UpdateModule
 
         private static Asset GetMatchingAsset(ReleaseInfo release)
         {
-            var arch = IntPtr.Size == 8 ? "x64" : "x86";
+            string arch = IntPtr.Size == 8 ? "x64" : "x86";
             return release.Assets.First(x => x.ContentType == "application/x-zip-compressed"
                                              && x.Name.Contains(arch));
         }

+ 7 - 7
PixiEditor.UpdateModule/UpdateInstaller.cs

@@ -31,7 +31,7 @@ namespace PixiEditor.UpdateModule
 
         public void Install()
         {
-            var processes = Process.GetProcessesByName("PixiEditor");
+            Process[] processes = Process.GetProcessesByName("PixiEditor");
             if (processes.Length > 0)
             {
                 processes[0].WaitForExit();
@@ -39,8 +39,8 @@ namespace PixiEditor.UpdateModule
 
             ZipFile.ExtractToDirectory(ArchiveFileName, TargetDirectoryName, true);
             Progress = 25; // 25% for unzip
-            var dirWithFiles = Directory.GetDirectories(TargetDirectoryName)[0];
-            var files = Directory.GetFiles(dirWithFiles);
+            string dirWithFiles = Directory.GetDirectories(TargetDirectoryName)[0];
+            string[] files = Directory.GetFiles(dirWithFiles);
             CopyFilesToDestination(files);
             DeleteArchive();
             Progress = 100;
@@ -53,11 +53,11 @@ namespace PixiEditor.UpdateModule
 
         private void CopyFilesToDestination(string[] files)
         {
-            var fileCopiedVal = 74f / files.Length; // 74% is reserved for copying
-            var destinationDir = Path.GetDirectoryName(ArchiveFileName);
-            foreach (var file in files)
+            float fileCopiedVal = 74f / files.Length; // 74% is reserved for copying
+            string destinationDir = Path.GetDirectoryName(ArchiveFileName);
+            foreach (string file in files)
             {
-                var targetFileName = Path.GetFileName(file);
+                string targetFileName = Path.GetFileName(file);
                 File.Copy(file, Path.Join(destinationDir, targetFileName), true);
                 Progress += fileCopiedVal;
             }

+ 4 - 2
PixiEditor/Exceptions/LengthMismatchException.cs

@@ -6,11 +6,13 @@ namespace PixiEditor.Exceptions
     {
         public const string DefaultMessage = "First array length doesn't match second array length";
 
-        public ArrayLengthMismatchException() : base(DefaultMessage)
+        public ArrayLengthMismatchException()
+            : base(DefaultMessage)
         {
         }
 
-        public ArrayLengthMismatchException(string message) : base(message)
+        public ArrayLengthMismatchException(string message)
+            : base(message)
         {
         }
     }

+ 105 - 93
PixiEditor/Helpers/Behaviours/AllowableCharactersTextBoxBehavior.cs

@@ -1,94 +1,106 @@
-using System;
-using System.Text.RegularExpressions;
-using System.Windows;
-using System.Windows.Controls;
-using System.Windows.Input;
-using System.Windows.Interactivity;
-
-namespace PixiEditor.Helpers.Behaviours
-{
-    public class AllowableCharactersTextBoxBehavior : Behavior<TextBox>
-    {
-        public static readonly DependencyProperty RegularExpressionProperty =
-            DependencyProperty.Register("RegularExpression", typeof(string), typeof(AllowableCharactersTextBoxBehavior),
-                new FrameworkPropertyMetadata(".*"));
-
-        public static readonly DependencyProperty MaxLengthProperty =
-            DependencyProperty.Register("MaxLength", typeof(int), typeof(AllowableCharactersTextBoxBehavior),
-                new FrameworkPropertyMetadata(int.MinValue));
-
-        public string RegularExpression
-        {
-            get => (string) GetValue(RegularExpressionProperty);
-            set => SetValue(RegularExpressionProperty, value);
-        }
-
-        public int MaxLength
-        {
-            get => (int) GetValue(MaxLengthProperty);
-            set => SetValue(MaxLengthProperty, value);
-        }
-
-        protected override void OnAttached()
-        {
-            base.OnAttached();
-            AssociatedObject.PreviewTextInput += OnPreviewTextInput;
-            DataObject.AddPastingHandler(AssociatedObject, OnPaste);
-        }
-
-        private void OnPaste(object sender, DataObjectPastingEventArgs e)
-        {
-            if (e.DataObject.GetDataPresent(DataFormats.Text))
-            {
-                var text = Convert.ToString(e.DataObject.GetData(DataFormats.Text));
-
-                if (!IsValid(text, true)) e.CancelCommand();
-            }
-            else
-            {
-                e.CancelCommand();
-            }
-        }
-
-        private void OnPreviewTextInput(object sender, TextCompositionEventArgs e)
-        {
-            e.Handled = !IsValid(e.Text, false);
-        }
-
-        protected override void OnDetaching()
-        {
-            base.OnDetaching();
-            AssociatedObject.PreviewTextInput -= OnPreviewTextInput;
-            DataObject.RemovePastingHandler(AssociatedObject, OnPaste);
-        }
-
-        private bool IsValid(string newText, bool paste)
-        {
-            return !ExceedsMaxLength(newText, paste) && Regex.IsMatch(newText, RegularExpression);
-        }
-
-        private bool ExceedsMaxLength(string newText, bool paste)
-        {
-            if (MaxLength == 0) return false;
-
-            return LengthOfModifiedText(newText, paste) > MaxLength;
-        }
-
-        private int LengthOfModifiedText(string newText, bool paste)
-        {
-            var countOfSelectedChars = AssociatedObject.SelectedText.Length;
-            var caretIndex = AssociatedObject.CaretIndex;
-            var text = AssociatedObject.Text;
-
-            if (countOfSelectedChars > 0 || paste)
-            {
-                text = text.Remove(caretIndex, countOfSelectedChars);
-                return text.Length + newText.Length;
-            }
-
-            var insert = Keyboard.IsKeyToggled(Key.Insert);
-
-            return insert && caretIndex < text.Length ? text.Length : text.Length + newText.Length;
-        }
-    }
+using System;
+using System.Text.RegularExpressions;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Input;
+using System.Windows.Interactivity;
+
+namespace PixiEditor.Helpers.Behaviours
+{
+    public class AllowableCharactersTextBoxBehavior : Behavior<TextBox>
+    {
+        public static readonly DependencyProperty RegularExpressionProperty =
+            DependencyProperty.Register(
+                "RegularExpression",
+                typeof(string),
+                typeof(AllowableCharactersTextBoxBehavior),
+                new FrameworkPropertyMetadata(".*"));
+
+        public static readonly DependencyProperty MaxLengthProperty =
+            DependencyProperty.Register(
+                "MaxLength",
+                typeof(int),
+                typeof(AllowableCharactersTextBoxBehavior),
+                new FrameworkPropertyMetadata(int.MinValue));
+
+        public string RegularExpression
+        {
+            get => (string)GetValue(RegularExpressionProperty);
+            set => SetValue(RegularExpressionProperty, value);
+        }
+
+        public int MaxLength
+        {
+            get => (int)GetValue(MaxLengthProperty);
+            set => SetValue(MaxLengthProperty, value);
+        }
+
+        protected override void OnAttached()
+        {
+            base.OnAttached();
+            AssociatedObject.PreviewTextInput += OnPreviewTextInput;
+            DataObject.AddPastingHandler(AssociatedObject, OnPaste);
+        }
+
+        private void OnPaste(object sender, DataObjectPastingEventArgs e)
+        {
+            if (e.DataObject.GetDataPresent(DataFormats.Text))
+            {
+                string text = Convert.ToString(e.DataObject.GetData(DataFormats.Text));
+
+                if (!IsValid(text, true))
+                {
+                    e.CancelCommand();
+                }
+            }
+            else
+            {
+                e.CancelCommand();
+            }
+        }
+
+        private void OnPreviewTextInput(object sender, TextCompositionEventArgs e)
+        {
+            e.Handled = !IsValid(e.Text, false);
+        }
+
+        protected override void OnDetaching()
+        {
+            base.OnDetaching();
+            AssociatedObject.PreviewTextInput -= OnPreviewTextInput;
+            DataObject.RemovePastingHandler(AssociatedObject, OnPaste);
+        }
+
+        private bool IsValid(string newText, bool paste)
+        {
+            return !ExceedsMaxLength(newText, paste) && Regex.IsMatch(newText, RegularExpression);
+        }
+
+        private bool ExceedsMaxLength(string newText, bool paste)
+        {
+            if (MaxLength == 0)
+            {
+                return false;
+            }
+
+            return LengthOfModifiedText(newText, paste) > MaxLength;
+        }
+
+        private int LengthOfModifiedText(string newText, bool paste)
+        {
+            int countOfSelectedChars = AssociatedObject.SelectedText.Length;
+            int caretIndex = AssociatedObject.CaretIndex;
+            string text = AssociatedObject.Text;
+
+            if (countOfSelectedChars > 0 || paste)
+            {
+                text = text.Remove(caretIndex, countOfSelectedChars);
+                return text.Length + newText.Length;
+            }
+
+            bool insert = Keyboard.IsKeyToggled(Key.Insert);
+
+            return insert && caretIndex < text.Length ? text.Length : text.Length + newText.Length;
+        }
+    }
 }

+ 71 - 63
PixiEditor/Helpers/Behaviours/HintTextBehavior.cs

@@ -1,64 +1,72 @@
-using System.Windows;
-using System.Windows.Controls;
-using System.Windows.Interactivity;
-using System.Windows.Media;
-
-namespace PixiEditor.Helpers.Behaviours
-{
-    internal class HintTextBehavior : Behavior<TextBox>
-    {
-        // Using a DependencyProperty as the backing store for Hint.  This enables animation, styling, binding, etc...
-        public static readonly DependencyProperty HintProperty =
-            DependencyProperty.Register("Hint", typeof(string), typeof(HintTextBehavior),
-                new PropertyMetadata(string.Empty));
-
-        private Brush textColor;
-
-        public string Hint
-        {
-            get => (string) GetValue(HintProperty);
-            set => SetValue(HintProperty, value);
-        }
-
-
-        protected override void OnAttached()
-        {
-            base.OnAttached();
-            AssociatedObject.GotFocus += AssociatedObject_GotFocus;
-            AssociatedObject.LostFocus += AssociatedObject_LostFocus;
-            textColor = AssociatedObject.Foreground;
-            SetHint(true);
-        }
-
-        private void AssociatedObject_LostFocus(object sender, RoutedEventArgs e)
-        {
-            if (string.IsNullOrEmpty(AssociatedObject.Text)) SetHint(true);
-        }
-
-        private void AssociatedObject_GotFocus(object sender, RoutedEventArgs e)
-        {
-            if (AssociatedObject.Text == Hint) SetHint(false);
-        }
-
-        private void SetHint(bool active)
-        {
-            if (active)
-            {
-                AssociatedObject.Foreground = (SolidColorBrush) new BrushConverter().ConvertFromString("#7B7B7B");
-                AssociatedObject.Text = Hint;
-            }
-            else
-            {
-                AssociatedObject.Text = string.Empty;
-                AssociatedObject.Foreground = textColor;
-            }
-        }
-
-        protected override void OnDetaching()
-        {
-            base.OnDetaching();
-            AssociatedObject.LostFocus -= AssociatedObject_LostFocus;
-            AssociatedObject.GotFocus -= AssociatedObject_GotFocus;
-        }
-    }
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Interactivity;
+using System.Windows.Media;
+
+namespace PixiEditor.Helpers.Behaviours
+{
+    internal class HintTextBehavior : Behavior<TextBox>
+    {
+        // Using a DependencyProperty as the backing store for Hint.  This enables animation, styling, binding, etc...
+        public static readonly DependencyProperty HintProperty =
+            DependencyProperty.Register(
+                "Hint",
+                typeof(string),
+                typeof(HintTextBehavior),
+                new PropertyMetadata(string.Empty));
+
+        private Brush textColor;
+
+        public string Hint
+        {
+            get => (string)GetValue(HintProperty);
+            set => SetValue(HintProperty, value);
+        }
+
+        protected override void OnAttached()
+        {
+            base.OnAttached();
+            AssociatedObject.GotFocus += AssociatedObject_GotFocus;
+            AssociatedObject.LostFocus += AssociatedObject_LostFocus;
+            textColor = AssociatedObject.Foreground;
+            SetHint(true);
+        }
+
+        private void AssociatedObject_LostFocus(object sender, RoutedEventArgs e)
+        {
+            if (string.IsNullOrEmpty(AssociatedObject.Text))
+            {
+                SetHint(true);
+            }
+        }
+
+        private void AssociatedObject_GotFocus(object sender, RoutedEventArgs e)
+        {
+            if (AssociatedObject.Text == Hint)
+            {
+                SetHint(false);
+            }
+        }
+
+        private void SetHint(bool active)
+        {
+            if (active)
+            {
+                AssociatedObject.Foreground = (SolidColorBrush)new BrushConverter().ConvertFromString("#7B7B7B");
+                AssociatedObject.Text = Hint;
+            }
+            else
+            {
+                AssociatedObject.Text = string.Empty;
+                AssociatedObject.Foreground = textColor;
+            }
+        }
+
+        protected override void OnDetaching()
+        {
+            base.OnDetaching();
+            AssociatedObject.LostFocus -= AssociatedObject_LostFocus;
+            AssociatedObject.GotFocus -= AssociatedObject_GotFocus;
+        }
+    }
 }

+ 62 - 57
PixiEditor/Helpers/Behaviours/MouseBehaviour.cs

@@ -1,58 +1,63 @@
-using System.Windows;
-using System.Windows.Input;
-using System.Windows.Interactivity;
-
-namespace PixiEditor.Helpers.Behaviours
-{
-    public class MouseBehaviour : Behavior<FrameworkElement>
-    {
-        public static readonly DependencyProperty MouseYProperty = DependencyProperty.Register(
-            "MouseY", typeof(double), typeof(MouseBehaviour), new PropertyMetadata(default(double)));
-
-        public static readonly DependencyProperty MouseXProperty = DependencyProperty.Register(
-            "MouseX", typeof(double), typeof(MouseBehaviour), new PropertyMetadata(default(double)));
-
-        // Using a DependencyProperty as the backing store for RelativeTo.  This enables animation, styling, binding, etc...
-        public static readonly DependencyProperty RelativeToProperty =
-            DependencyProperty.Register("RelativeTo", typeof(FrameworkElement), typeof(MouseBehaviour),
-                new PropertyMetadata(default(FrameworkElement)));
-
-        public double MouseY
-        {
-            get => (double) GetValue(MouseYProperty);
-            set => SetValue(MouseYProperty, value);
-        }
-
-        public double MouseX
-        {
-            get => (double) GetValue(MouseXProperty);
-            set => SetValue(MouseXProperty, value);
-        }
-
-
-        public FrameworkElement RelativeTo
-        {
-            get => (FrameworkElement) GetValue(RelativeToProperty);
-            set => SetValue(RelativeToProperty, value);
-        }
-
-
-        protected override void OnAttached()
-        {
-            AssociatedObject.MouseMove += AssociatedObjectOnMouseMove;
-        }
-
-        private void AssociatedObjectOnMouseMove(object sender, MouseEventArgs mouseEventArgs)
-        {
-            if (RelativeTo == null) RelativeTo = AssociatedObject;
-            var pos = mouseEventArgs.GetPosition(RelativeTo);
-            MouseX = pos.X;
-            MouseY = pos.Y;
-        }
-
-        protected override void OnDetaching()
-        {
-            AssociatedObject.MouseMove -= AssociatedObjectOnMouseMove;
-        }
-    }
+using System.Windows;
+using System.Windows.Input;
+using System.Windows.Interactivity;
+
+namespace PixiEditor.Helpers.Behaviours
+{
+    public class MouseBehaviour : Behavior<FrameworkElement>
+    {
+        public static readonly DependencyProperty MouseYProperty = DependencyProperty.Register(
+            "MouseY", typeof(double), typeof(MouseBehaviour), new PropertyMetadata(default(double)));
+
+        public static readonly DependencyProperty MouseXProperty = DependencyProperty.Register(
+            "MouseX", typeof(double), typeof(MouseBehaviour), new PropertyMetadata(default(double)));
+
+        // Using a DependencyProperty as the backing store for RelativeTo.  This enables animation, styling, binding, etc...
+        public static readonly DependencyProperty RelativeToProperty =
+            DependencyProperty.Register(
+                "RelativeTo",
+                typeof(FrameworkElement),
+                typeof(MouseBehaviour),
+                new PropertyMetadata(default(FrameworkElement)));
+
+        public double MouseY
+        {
+            get => (double)GetValue(MouseYProperty);
+            set => SetValue(MouseYProperty, value);
+        }
+
+        public double MouseX
+        {
+            get => (double)GetValue(MouseXProperty);
+            set => SetValue(MouseXProperty, value);
+        }
+
+        public FrameworkElement RelativeTo
+        {
+            get => (FrameworkElement)GetValue(RelativeToProperty);
+            set => SetValue(RelativeToProperty, value);
+        }
+
+        protected override void OnAttached()
+        {
+            AssociatedObject.MouseMove += AssociatedObjectOnMouseMove;
+        }
+
+        protected override void OnDetaching()
+        {
+            AssociatedObject.MouseMove -= AssociatedObjectOnMouseMove;
+        }
+
+        private void AssociatedObjectOnMouseMove(object sender, MouseEventArgs mouseEventArgs)
+        {
+            if (RelativeTo == null)
+            {
+                RelativeTo = AssociatedObject;
+            }
+
+            Point pos = mouseEventArgs.GetPosition(RelativeTo);
+            MouseX = pos.X;
+            MouseY = pos.Y;
+        }
+    }
 }

+ 25 - 15
PixiEditor/Helpers/Behaviours/TextBoxFocusBehavior.cs

@@ -12,22 +12,24 @@ namespace PixiEditor.Helpers.Behaviours
         public static readonly DependencyProperty FillSizeProperty =
             DependencyProperty.Register("FillSize", typeof(bool), typeof(TextBoxFocusBehavior),
                 new PropertyMetadata(false));
-
-
-        private string oldText; //Value of textbox before editing
-        private bool valueConverted; //This bool is used to avoid double convertion if enter is hitted
+
+        private string oldText; // Value of textbox before editing
+        private bool valueConverted; // This bool is used to avoid double convertion if enter is hitted
 
         public bool FillSize
         {
-            get => (bool) GetValue(FillSizeProperty);
+            get => (bool)GetValue(FillSizeProperty);
             set => SetValue(FillSizeProperty, value);
         }
 
-        //Converts number to proper format if enter is clicked and moves focus to next object
+        // Converts number to proper format if enter is clicked and moves focus to next object
         private void AssociatedObject_KeyUp(object sender, KeyEventArgs e)
         {
-            if (e.Key != Key.Enter) return;
-
+            if (e.Key != Key.Enter)
+            {
+                return;
+            }
+
             ConvertValue();
             AssociatedObject.MoveFocus(new TraversalRequest(FocusNavigationDirection.Down));
         }
@@ -59,7 +61,7 @@ namespace PixiEditor.Helpers.Behaviours
             if (FillSize)
             {
                 valueConverted = false;
-                oldText = AssociatedObject.Text; //Sets old value when keyboard is focused on object
+                oldText = AssociatedObject.Text; // Sets old value when keyboard is focused on object
             }
         }
 
@@ -88,12 +90,20 @@ namespace PixiEditor.Helpers.Behaviours
         /// </summary>
         private void ConvertValue()
         {
-            if (valueConverted || FillSize == false) return;
-
-            if (int.TryParse(Regex.Replace(AssociatedObject.Text, "\\p{L}", ""), out var result) && result > 0)
-                AssociatedObject.Text = $"{AssociatedObject.Text} px";
-            else //If text in textbox isn't number, set it to old value
-                AssociatedObject.Text = oldText;
+            if (valueConverted || FillSize == false)
+            {
+                return;
+            }
+
+            if (int.TryParse(Regex.Replace(AssociatedObject.Text, "\\p{L}", ""), out int result) && result > 0)
+            {
+                AssociatedObject.Text = $"{AssociatedObject.Text} px";
+            }
+            else // If text in textbox isn't number, set it to old value
+            {
+                AssociatedObject.Text = oldText;
+            }
+
             valueConverted = true;
         }
     }

+ 5 - 0
PixiEditor/Helpers/Converters/BoolToColorConverter.cs

@@ -14,8 +14,13 @@ namespace PixiEditor.Helpers.Converters
         public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
         {
             if (value is bool boolean)
+            {
                 if (boolean == false)
+                {
                     return "Transparent";
+                }
+            }
+
             return "#638DCA";
         }
     }

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

@@ -14,8 +14,13 @@ namespace PixiEditor.Helpers.Converters
         public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
         {
             if (value is bool boolean)
+            {
                 if (boolean == false)
+                {
                     return 0;
+                }
+            }
+
             return 1;
         }
     }

+ 2 - 2
PixiEditor/Helpers/Converters/DoubleToIntConverter.cs

@@ -10,8 +10,8 @@ namespace PixiEditor.Helpers.Converters
         {
             if (value is double || value is float)
             {
-                var val = (double) value;
-                return (int) val;
+                double val = (double)value;
+                return (int)val;
             }
 
             return value;

+ 2 - 2
PixiEditor/Helpers/Converters/FloatNormalizeConverter.cs

@@ -8,12 +8,12 @@ namespace PixiEditor.Helpers.Converters
     {
         public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
         {
-            return (float) value * 100;
+            return (float)value * 100;
         }
 
         public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
         {
-            return (float) value / 100;
+            return (float)value / 100;
         }
     }
 }

+ 9 - 2
PixiEditor/Helpers/Converters/OppositeVisibilityConverter.cs

@@ -9,7 +9,11 @@ namespace PixiEditor.Helpers.Converters
     {
         public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
         {
-            if (value.ToString().ToLower() == "visible") return Visibility.Hidden;
+            if (value.ToString().ToLower() == "visible")
+            {
+                return Visibility.Hidden;
+            }
+
             return Visibility.Visible;
         }
 
@@ -17,8 +21,11 @@ namespace PixiEditor.Helpers.Converters
         {
             if (value is Visibility)
             {
-                if ((Visibility) value == Visibility.Visible)
+                if ((Visibility)value == Visibility.Visible)
+                {
                     return "Hidden";
+                }
+
                 return "Visible";
             }
 

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

@@ -16,10 +16,18 @@ namespace PixiEditor.Helpers
 
         public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
         {
-            if (string.IsNullOrWhiteSpace(value as string)) return null;
-            var slicedString = value.ToString().Split(' ').First();
+            if (string.IsNullOrWhiteSpace(value as string))
+            {
+                return null;
+            }
+
+            string slicedString = value.ToString().Split(' ').First();
             slicedString = Regex.Replace(slicedString, "\\p{L}", "");
-            if (slicedString == "") return null;
+            if (slicedString == "")
+            {
+                return null;
+            }
+
             return int.Parse(slicedString);
         }
     }

+ 11 - 4
PixiEditor/Helpers/Extensions/DictionaryHelper.cs

@@ -7,15 +7,22 @@ namespace PixiEditor.Helpers.Extensions
         public static void AddRangeOverride<TKey, TValue>(this IDictionary<TKey, TValue> dict,
             IDictionary<TKey, TValue> dictToAdd)
         {
-            foreach (var item in dictToAdd) dict[item.Key] = item.Value;
+            foreach (KeyValuePair<TKey, TValue> item in dictToAdd)
+            {
+                dict[item.Key] = item.Value;
+            }
         }
 
         public static void AddRangeNewOnly<TKey, TValue>(this IDictionary<TKey, TValue> dict,
             IDictionary<TKey, TValue> dictToAdd)
         {
-            foreach (var item in dictToAdd)
-                if (!dict.ContainsKey(item.Key))
-                    dict.Add(item.Key, item.Value);
+            foreach (KeyValuePair<TKey, TValue> item in dictToAdd)
+            {
+                if (!dict.ContainsKey(item.Key))
+                {
+                    dict.Add(item.Key, item.Value);
+                }
+            }
         }
     }
 }

+ 12 - 7
PixiEditor/Helpers/GlobalMouseHook.cs

@@ -25,6 +25,7 @@ namespace PixiEditor.Helpers
                 Subscribe();
                 MouseUp += value;
             }
+
             remove
             {
                 MouseUp -= value;
@@ -41,12 +42,12 @@ namespace PixiEditor.Helpers
         {
             if (mouseHookHandle != 0)
             {
-                var result = UnhookWindowsHookEx(mouseHookHandle);
+                int result = UnhookWindowsHookEx(mouseHookHandle);
                 mouseHookHandle = 0;
                 mouseDelegate = null;
                 if (result == 0)
                 {
-                    var errorCode = Marshal.GetLastWin32Error();
+                    int errorCode = Marshal.GetLastWin32Error();
                     throw new Win32Exception(errorCode);
                 }
             }
@@ -64,7 +65,7 @@ namespace PixiEditor.Helpers
                     0);
                 if (mouseHookHandle == 0)
                 {
-                    var errorCode = Marshal.GetLastWin32Error();
+                    int errorCode = Marshal.GetLastWin32Error();
                     throw new Win32Exception(errorCode);
                 }
             }
@@ -74,10 +75,14 @@ namespace PixiEditor.Helpers
         {
             if (nCode >= 0)
             {
-                var mouseHookStruct = (Msllhookstruct) Marshal.PtrToStructure(lParam, typeof(Msllhookstruct));
-                if (wParam == WmLbuttonup)
-                    if (MouseUp != null)
-                        MouseUp.Invoke(null, new System.Windows.Point(mouseHookStruct.pt.x, mouseHookStruct.pt.y));
+                Msllhookstruct mouseHookStruct = (Msllhookstruct)Marshal.PtrToStructure(lParam, typeof(Msllhookstruct));
+                if (wParam == WmLbuttonup)
+                {
+                    if (MouseUp != null)
+                    {
+                        MouseUp.Invoke(null, new System.Windows.Point(mouseHookStruct.pt.x, mouseHookStruct.pt.y));
+                    }
+                }
             }
 
             return CallNextHookEx(mouseHookHandle, nCode, wParam, lParam);

+ 5 - 3
PixiEditor/Helpers/RelayCommand.cs

@@ -21,9 +21,11 @@ namespace PixiEditor.Helpers
 
         public RelayCommand(Action<object> execute, Predicate<object> canExecute)
         {
-            if (execute == null)
-                throw new ArgumentNullException("execute");
-
+            if (execute == null)
+            {
+                throw new ArgumentNullException("execute");
+            }
+
             this.execute = execute;
             this.canExecute = canExecute;
         }

+ 7 - 5
PixiEditor/Helpers/UI/ReversedOrderStackPanel.cs

@@ -9,15 +9,17 @@ namespace PixiEditor.Helpers.UI
     {
         protected override Size ArrangeOverride(Size arrangeSize)
         {
-            var fHorizontal = Orientation == Orientation.Horizontal;
-            var rcChild = new Rect(arrangeSize);
-            var previousChildSize = 0.0;
+            bool fHorizontal = Orientation == Orientation.Horizontal;
+            Rect rcChild = new Rect(arrangeSize);
+            double previousChildSize = 0.0;
 
-            var children = InternalChildren.Cast<UIElement>().Reverse();
-            foreach (var child in children)
+            System.Collections.Generic.IEnumerable<UIElement> children = InternalChildren.Cast<UIElement>().Reverse();
+            foreach (UIElement child in children)
             {
                 if (child == null)
+                {
                     continue;
+                }
 
                 if (fHorizontal)
                 {

+ 1 - 1
PixiEditor/Helpers/Validators/SizeValidationRule.cs

@@ -7,7 +7,7 @@ namespace PixiEditor.Helpers.Validators
     {
         public override ValidationResult Validate(object value, CultureInfo cultureInfo)
         {
-            return new ValidationResult(int.Parse(((string) value).Split(' ')[0]) > 0, null); //Size is greater than 0
+            return new ValidationResult(int.Parse(((string)value).Split(' ')[0]) > 0, null); // Size is greater than 0
         }
     }
 }

+ 66 - 46
PixiEditor/Models/Colors/ExColor.cs

@@ -18,18 +18,17 @@ namespace PixiEditor.Models.Colors
         /// </returns>
         public static Color ChangeColorBrightness(Color color, float correctionFactor)
         {
-            var hsl = RgbToHsl(color.R, color.G, color.B);
-            var h = hsl.Item1;
-            var s = hsl.Item2;
-            var l = hsl.Item3;
+            Tuple<int, float, float> hsl = RgbToHsl(color.R, color.G, color.B);
+            int h = hsl.Item1;
+            float s = hsl.Item2;
+            float l = hsl.Item3;
 
             l = Math.Clamp(l + correctionFactor, 0, 100);
-            var rgb = HslToRgb(h, s, l);
+            Color rgb = HslToRgb(h, s, l);
 
             return Color.FromArgb(color.A, rgb.R, rgb.G, rgb.B);
         }
-
-
+
         /// <summary>
         ///     Converts RGB to HSL
         /// </summary>
@@ -41,13 +40,13 @@ namespace PixiEditor.Models.Colors
         {
             int h;
             float s, l;
-            var dR = r / 255.0f;
-            var dG = g / 255.0f;
-            var dB = b / 255.0f;
+            float dR = r / 255.0f;
+            float dG = g / 255.0f;
+            float dB = b / 255.0f;
 
-            var min = Math.Min(Math.Min(dR, dG), dB);
-            var max = Math.Max(Math.Max(dR, dG), dB);
-            var delta = max - min;
+            float min = Math.Min(Math.Min(dR, dG), dB);
+            float max = Math.Max(Math.Max(dR, dG), dB);
+            float delta = max - min;
 
             l = (max + min) / 2;
 
@@ -62,19 +61,30 @@ namespace PixiEditor.Models.Colors
 
                 float hue;
 
-                if (dR == max)
-                    hue = (dG - dB) / 6 / delta;
-                else if (dG == max)
-                    hue = 1.0f / 3 + (dB - dR) / 6 / delta;
-                else
-                    hue = 2.0f / 3 + (dR - dG) / 6 / delta;
-
-                if (hue < 0)
-                    hue += 1;
-                if (hue > 1)
-                    hue -= 1;
-
-                h = (int) (hue * 360);
+                if (dR == max)
+                {
+                    hue = (dG - dB) / 6 / delta;
+                }
+                else if (dG == max)
+                {
+                    hue = 1.0f / 3 + (dB - dR) / 6 / delta;
+                }
+                else
+                {
+                    hue = 2.0f / 3 + (dR - dG) / 6 / delta;
+                }
+
+                if (hue < 0)
+                {
+                    hue += 1;
+                }
+
+                if (hue > 1)
+                {
+                    hue -= 1;
+                }
+
+                h = (int)(hue * 360);
             }
 
             return new Tuple<int, float, float>(h, s * 100, l * 100);
@@ -97,19 +107,19 @@ namespace PixiEditor.Models.Colors
 
             if (s == 0)
             {
-                r = g = b = (byte) (l * 255);
+                r = g = b = (byte)(l * 255);
             }
             else
             {
                 float v1, v2;
-                var hue = (float) h / 360;
+                float hue = (float)h / 360;
 
                 v2 = l < 0.5 ? l * (1 + s) : l + s - l * s;
                 v1 = 2 * l - v2;
 
-                r = (byte) (255 * HueToRgb(v1, v2, hue + 1.0f / 3));
-                g = (byte) (255 * HueToRgb(v1, v2, hue));
-                b = (byte) (255 * HueToRgb(v1, v2, hue - 1.0f / 3));
+                r = (byte)(255 * HueToRgb(v1, v2, hue + 1.0f / 3));
+                g = (byte)(255 * HueToRgb(v1, v2, hue));
+                b = (byte)(255 * HueToRgb(v1, v2, hue - 1.0f / 3));
             }
 
             return Color.FromRgb(r, g, b);
@@ -117,21 +127,31 @@ namespace PixiEditor.Models.Colors
 
         private static float HueToRgb(float v1, float v2, float hue)
         {
-            if (hue < 0)
-                hue += 1;
-
-            if (hue > 1)
-                hue -= 1;
-
-            if (6 * hue < 1)
-                return v1 + (v2 - v1) * 6 * hue;
-
-            if (2 * hue < 1)
-                return v2;
-
-            if (3 * hue < 2)
-                return v1 + (v2 - v1) * (2.0f / 3 - hue) * 6;
-
+            if (hue < 0)
+            {
+                hue += 1;
+            }
+
+            if (hue > 1)
+            {
+                hue -= 1;
+            }
+
+            if (6 * hue < 1)
+            {
+                return v1 + (v2 - v1) * 6 * hue;
+            }
+
+            if (2 * hue < 1)
+            {
+                return v2;
+            }
+
+            if (3 * hue < 2)
+            {
+                return v1 + (v2 - v1) * (2.0f / 3 - hue) * 6;
+            }
+
             return v1;
         }
     }

+ 60 - 26
PixiEditor/Models/Controllers/BitmapManager.cs

@@ -75,6 +75,7 @@ namespace PixiEditor.Models.Controllers
         }
 
         public BitmapOperationsUtility BitmapOperations { get; set; }
+
         public ReadonlyToolUtility ReadonlyToolUtility { get; set; }
 
         public Document ActiveDocument
@@ -89,6 +90,7 @@ namespace PixiEditor.Models.Controllers
         }
 
         public event EventHandler<LayersChangedEventArgs> LayersChanged;
+
         public event EventHandler<DocumentChangedEventArgs> DocumentChanged;
 
         public void SetActiveTool(Tool tool)
@@ -101,8 +103,11 @@ namespace PixiEditor.Models.Controllers
 
         public void SetActiveLayer(int index)
         {
-            if (ActiveDocument.ActiveLayerIndex <= ActiveDocument.Layers.Count - 1)
-                ActiveDocument.ActiveLayer.IsActive = false;
+            if (ActiveDocument.ActiveLayerIndex <= ActiveDocument.Layers.Count - 1)
+            {
+                ActiveDocument.ActiveLayer.IsActive = false;
+            }
+
             ActiveDocument.ActiveLayerIndex = index;
             ActiveDocument.ActiveLayer.IsActive = true;
             LayersChanged?.Invoke(this, new LayersChangedEventArgs(index, LayerAction.SetActive));
@@ -126,40 +131,60 @@ namespace PixiEditor.Models.Controllers
                 MaxHeight = ActiveDocument.Height,
                 MaxWidth = ActiveDocument.Width
             });
-            if (setAsActive) SetActiveLayer(ActiveDocument.Layers.Count - 1);
+            if (setAsActive)
+            {
+                SetActiveLayer(ActiveDocument.Layers.Count - 1);
+            }
+
             LayersChanged?.Invoke(this, new LayersChangedEventArgs(0, LayerAction.Add));
         }
 
         public void RemoveLayer(int layerIndex)
         {
-            if (ActiveDocument.Layers.Count == 0) return;
-
-            var wasActive = ActiveDocument.Layers[layerIndex].IsActive;
+            if (ActiveDocument.Layers.Count == 0)
+            {
+                return;
+            }
+
+            bool wasActive = ActiveDocument.Layers[layerIndex].IsActive;
             ActiveDocument.Layers.RemoveAt(layerIndex);
-            if (wasActive)
-                SetActiveLayer(0);
-            else if (ActiveDocument.ActiveLayerIndex > ActiveDocument.Layers.Count - 1)
-                SetActiveLayer(ActiveDocument.Layers.Count - 1);
+            if (wasActive)
+            {
+                SetActiveLayer(0);
+            }
+            else if (ActiveDocument.ActiveLayerIndex > ActiveDocument.Layers.Count - 1)
+            {
+                SetActiveLayer(ActiveDocument.Layers.Count - 1);
+            }
         }
 
         private void Controller_MousePositionChanged(object sender, MouseMovementEventArgs e)
         {
-            SelectedTool.OnMouseMove(new MouseEventArgs(Mouse.PrimaryDevice, (int) DateTimeOffset.UtcNow.ToUnixTimeSeconds()));
-            if (Mouse.LeftButton == MouseButtonState.Pressed && !IsDraggingViewport() && ActiveDocument != null)
-                ExecuteTool(e.NewPosition, MouseController.ClickedOnCanvas);
-            else if (Mouse.LeftButton == MouseButtonState.Released) HighlightPixels(e.NewPosition);
+            SelectedTool.OnMouseMove(new MouseEventArgs(Mouse.PrimaryDevice, (int)DateTimeOffset.UtcNow.ToUnixTimeSeconds()));
+            if (Mouse.LeftButton == MouseButtonState.Pressed && !IsDraggingViewport() && ActiveDocument != null)
+            {
+                ExecuteTool(e.NewPosition, MouseController.ClickedOnCanvas);
+            }
+            else if (Mouse.LeftButton == MouseButtonState.Released)
+            {
+                HighlightPixels(e.NewPosition);
+            }
         }
 
         public void ExecuteTool(Coordinates newPosition, bool clickedOnCanvas)
         {
             if (SelectedTool.CanStartOutsideCanvas || clickedOnCanvas)
             {
-                if (IsOperationTool(SelectedTool))
+                if (IsOperationTool(SelectedTool))
+                {
                     BitmapOperations.ExecuteTool(newPosition,
-                        MouseController.LastMouseMoveCoordinates.ToList(), (BitmapOperationTool) SelectedTool);
-                else
+                        MouseController.LastMouseMoveCoordinates.ToList(), (BitmapOperationTool)SelectedTool);
+                }
+                else
+                {
                     ReadonlyToolUtility.ExecuteTool(MouseController.LastMouseMoveCoordinates.ToArray(),
-                        (ReadonlyTool) SelectedTool);
+                        (ReadonlyTool)SelectedTool);
+                }
             }
         }
 
@@ -170,31 +195,39 @@ namespace PixiEditor.Models.Controllers
 
         private void MouseController_StartedRecordingChanges(object sender, EventArgs e)
         {
-            SelectedTool.OnMouseDown(new MouseEventArgs(Mouse.PrimaryDevice, (int) DateTimeOffset.UtcNow.ToUnixTimeSeconds()));
+            SelectedTool.OnMouseDown(new MouseEventArgs(Mouse.PrimaryDevice, (int)DateTimeOffset.UtcNow.ToUnixTimeSeconds()));
             PreviewLayer = null;
         }
 
         private void MouseController_StoppedRecordingChanges(object sender, EventArgs e)
         {
-            SelectedTool.OnMouseUp(new MouseEventArgs(Mouse.PrimaryDevice, (int) DateTimeOffset.UtcNow.ToUnixTimeSeconds()));
-            if (IsOperationTool(SelectedTool) && ((BitmapOperationTool) SelectedTool).RequiresPreviewLayer)
-                BitmapOperations.StopAction();
+            SelectedTool.OnMouseUp(new MouseEventArgs(Mouse.PrimaryDevice, (int)DateTimeOffset.UtcNow.ToUnixTimeSeconds()));
+            if (IsOperationTool(SelectedTool) && ((BitmapOperationTool)SelectedTool).RequiresPreviewLayer)
+            {
+                BitmapOperations.StopAction();
+            }
         }
 
         public void GeneratePreviewLayer()
         {
-            if (ActiveDocument != null)
+            if (ActiveDocument != null)
+            {
                 PreviewLayer = new Layer("_previewLayer")
                 {
                     MaxWidth = ActiveDocument.Width,
                     MaxHeight = ActiveDocument.Height
-                };
+                };
+            }
         }
 
         private void HighlightPixels(Coordinates newPosition)
         {
-            if (ActiveDocument == null || ActiveDocument.Layers.Count == 0 || SelectedTool.HideHighlight) return;
-            var highlightArea = CoordinatesCalculator.RectangleToCoordinates(
+            if (ActiveDocument == null || ActiveDocument.Layers.Count == 0 || SelectedTool.HideHighlight)
+            {
+                return;
+            }
+
+            Coordinates[] highlightArea = CoordinatesCalculator.RectangleToCoordinates(
                 CoordinatesCalculator.CalculateThicknessCenter(newPosition, ToolSize));
             if (CanChangeHighlightOffset(highlightArea))
             {
@@ -259,6 +292,7 @@ namespace PixiEditor.Models.Controllers
         }
 
         public int LayerAffected { get; set; }
+
         public LayerAction LayerChangeType { get; set; }
     }
 }

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

@@ -29,11 +29,11 @@ namespace PixiEditor.Models.Controllers
 
         public void DeletePixels(Layer[] layers, Coordinates[] pixels)
         {
-            var changes = BitmapPixelChanges.FromSingleColoredArray(pixels, Color.FromArgb(0, 0, 0, 0));
-            var oldValues = BitmapUtils.GetPixelsForSelection(layers, pixels);
-            var old = new LayerChange[layers.Length];
-            var newChange = new LayerChange[layers.Length];
-            for (var i = 0; i < layers.Length; i++)
+            BitmapPixelChanges changes = BitmapPixelChanges.FromSingleColoredArray(pixels, Color.FromArgb(0, 0, 0, 0));
+            Dictionary<Layer, Color[]> oldValues = BitmapUtils.GetPixelsForSelection(layers, pixels);
+            LayerChange[] old = new LayerChange[layers.Length];
+            LayerChange[] newChange = new LayerChange[layers.Length];
+            for (int i = 0; i < layers.Length; i++)
             {
                 old[i] = new LayerChange(
                     BitmapPixelChanges.FromArrays(pixels, oldValues[layers[i]]), i);
@@ -54,7 +54,11 @@ namespace PixiEditor.Models.Controllers
         {
             if (Manager.ActiveDocument != null && tool != null && tool.ToolType != ToolType.None)
             {
-                if (Manager.ActiveDocument.Layers.Count == 0 || mouseMove.Count == 0) return;
+                if (Manager.ActiveDocument.Layers.Count == 0 || mouseMove.Count == 0)
+                {
+                    return;
+                }
+
                 mouseMove.Reverse();
                 UseTool(mouseMove, tool, Manager.PrimaryColor);
 
@@ -67,12 +71,16 @@ namespace PixiEditor.Models.Controllers
         /// </summary>
         public void StopAction()
         {
-            if (lastModifiedLayers == null) return;
-            for (var i = 0; i < lastModifiedLayers.Length; i++)
+            if (lastModifiedLayers == null)
+            {
+                return;
+            }
+
+            for (int i = 0; i < lastModifiedLayers.Length; i++)
             {
-                var layer = Manager.ActiveDocument.Layers[lastModifiedLayers[i].LayerIndex];
+                Layer layer = Manager.ActiveDocument.Layers[lastModifiedLayers[i].LayerIndex];
 
-                var oldValues = ApplyToLayer(layer, lastModifiedLayers[i]).PixelChanges;
+                BitmapPixelChanges oldValues = ApplyToLayer(layer, lastModifiedLayers[i]).PixelChanges;
 
                 BitmapChanged?.Invoke(this, new BitmapChangedEventArgs(lastModifiedLayers[i].PixelChanges,
                     oldValues, lastModifiedLayers[i].LayerIndex));
@@ -80,18 +88,20 @@ namespace PixiEditor.Models.Controllers
             }
         }
 
-
         private void UseTool(List<Coordinates> mouseMoveCords, BitmapOperationTool tool, Color color)
         {
             if (Keyboard.IsKeyDown(Key.LeftShift) && !MouseCordsNotInLine(mouseMoveCords))
+            {
                 mouseMoveCords = GetSquareCoordiantes(mouseMoveCords);
+            }
+
             if (!tool.RequiresPreviewLayer)
             {
-                var modifiedLayers = tool.Use(Manager.ActiveLayer, mouseMoveCords.ToArray(), color);
-                var oldPixelsValues = new LayerChange[modifiedLayers.Length];
-                for (var i = 0; i < modifiedLayers.Length; i++)
+                LayerChange[] modifiedLayers = tool.Use(Manager.ActiveLayer, mouseMoveCords.ToArray(), color);
+                LayerChange[] oldPixelsValues = new LayerChange[modifiedLayers.Length];
+                for (int i = 0; i < modifiedLayers.Length; i++)
                 {
-                    var layer = Manager.ActiveDocument.Layers[modifiedLayers[i].LayerIndex];
+                    Layer layer = Manager.ActiveDocument.Layers[modifiedLayers[i].LayerIndex];
                     oldPixelsValues[i] = ApplyToLayer(layer, modifiedLayers[i]);
 
                     BitmapChanged?.Invoke(this, new BitmapChangedEventArgs(modifiedLayers[i].PixelChanges,
@@ -108,7 +118,7 @@ namespace PixiEditor.Models.Controllers
         {
             layer.DynamicResize(change.PixelChanges);
 
-            var oldPixelsValues = new LayerChange(
+            LayerChange oldPixelsValues = new LayerChange(
                 GetOldPixelsValues(change.PixelChanges.ChangedPixels.Keys.ToArray()),
                 change.LayerIndex);
 
@@ -128,23 +138,33 @@ namespace PixiEditor.Models.Controllers
         /// <returns></returns>
         private List<Coordinates> GetSquareCoordiantes(List<Coordinates> mouseMoveCords)
         {
-            var xLength = mouseMoveCords[0].Y - mouseMoveCords[^1].Y;
-            var yLength = mouseMoveCords[0].Y - mouseMoveCords[^1].Y;
-            if (mouseMoveCords[^1].Y > mouseMoveCords[0].Y) xLength *= -1;
-            if (mouseMoveCords[^1].X > mouseMoveCords[0].X) xLength *= -1;
+            int xLength = mouseMoveCords[0].Y - mouseMoveCords[^1].Y;
+            int yLength = mouseMoveCords[0].Y - mouseMoveCords[^1].Y;
+            if (mouseMoveCords[^1].Y > mouseMoveCords[0].Y)
+            {
+                xLength *= -1;
+            }
+
+            if (mouseMoveCords[^1].X > mouseMoveCords[0].X)
+            {
+                xLength *= -1;
+            }
+
             mouseMoveCords[0] = new Coordinates(mouseMoveCords[^1].X + xLength, mouseMoveCords[^1].Y + yLength);
             return mouseMoveCords;
         }
 
         private BitmapPixelChanges GetOldPixelsValues(Coordinates[] coordinates)
         {
-            var values = new Dictionary<Coordinates, Color>();
+            Dictionary<Coordinates, Color> values = new Dictionary<Coordinates, Color>();
             using (Manager.ActiveLayer.LayerBitmap.GetBitmapContext(ReadWriteMode.ReadOnly))
             {
-                var relativeCoords = Manager.ActiveLayer.ConvertToRelativeCoordinates(coordinates);
-                for (var i = 0; i < coordinates.Length; i++)
+                Coordinates[] relativeCoords = Manager.ActiveLayer.ConvertToRelativeCoordinates(coordinates);
+                for (int i = 0; i < coordinates.Length; i++)
+                {
                     values.Add(coordinates[i],
                         Manager.ActiveLayer.GetPixel(relativeCoords[i].X, relativeCoords[i].Y));
+                }
             }
 
             return new BitmapPixelChanges(values);
@@ -156,9 +176,9 @@ namespace PixiEditor.Models.Controllers
             if (mouseMove.Count > 0 && mouseMove[0] != lastMousePos)
             {
                 Manager.GeneratePreviewLayer();
-                modifiedLayers = ((BitmapOperationTool) Manager.SelectedTool).Use(Manager.ActiveDocument.ActiveLayer,
+                modifiedLayers = ((BitmapOperationTool)Manager.SelectedTool).Use(Manager.ActiveDocument.ActiveLayer,
                     mouseMove.ToArray(), Manager.PrimaryColor);
-                var changes = modifiedLayers.Select(x => x.PixelChanges).ToArray();
+                BitmapPixelChanges[] changes = modifiedLayers.Select(x => x.PixelChanges).ToArray();
                 Manager.PreviewLayer.SetPixels(BitmapPixelChanges.CombineOverride(changes));
                 lastModifiedLayers = modifiedLayers;
             }
@@ -177,6 +197,8 @@ public class BitmapChangedEventArgs : EventArgs
     }
 
     public BitmapPixelChanges PixelsChanged { get; set; }
+
     public BitmapPixelChanges OldPixelsValues { get; set; }
+
     public int ChangedLayerIndex { get; set; }
 }

+ 39 - 26
PixiEditor/Models/Controllers/ClipboardController.cs

@@ -21,19 +21,19 @@ namespace PixiEditor.Models.Controllers
         public static void CopyToClipboard(Layer[] layers, Coordinates[] selection, int originalImageWidth, int originalImageHeight)
         {
             Clipboard.Clear();
-            var combinedBitmaps = BitmapUtils.CombineLayers(layers, originalImageWidth, originalImageHeight);
-            using (var pngStream = new MemoryStream())
+            WriteableBitmap combinedBitmaps = BitmapUtils.CombineLayers(layers, originalImageWidth, originalImageHeight);
+            using (MemoryStream pngStream = new MemoryStream())
             {
-                var data = new DataObject();
-                var croppedBmp = BitmapSelectionToBmpSource(combinedBitmaps, selection);
-                data.SetData(DataFormats.Bitmap, croppedBmp, true); //Bitmap, no transparency support
+                DataObject data = new DataObject();
+                BitmapSource croppedBmp = BitmapSelectionToBmpSource(combinedBitmaps, selection);
+                data.SetData(DataFormats.Bitmap, croppedBmp, true); // Bitmap, no transparency support
 
-                var encoder = new PngBitmapEncoder();
+                PngBitmapEncoder encoder = new PngBitmapEncoder();
                 encoder.Frames.Add(BitmapFrame.Create(croppedBmp));
                 encoder.Save(pngStream);
-                data.SetData("PNG", pngStream, false); //PNG, supports transparency
+                data.SetData("PNG", pngStream, false); // PNG, supports transparency
 
-                Clipboard.SetImage(croppedBmp); //DIB format
+                Clipboard.SetImage(croppedBmp); // DIB format
                 Clipboard.SetDataObject(data, true);
             }
         }
@@ -43,8 +43,11 @@ namespace PixiEditor.Models.Controllers
         /// </summary>
         public static void PasteFromClipboard()
         {
-            var image = GetImageFromClipboard();
-            if (image != null) AddImageToLayers(image);
+            WriteableBitmap image = GetImageFromClipboard();
+            if (image != null)
+            {
+                AddImageToLayers(image);
+            }
         }
 
         /// <summary>
@@ -53,30 +56,40 @@ namespace PixiEditor.Models.Controllers
         /// <returns>WriteableBitmap</returns>
         public static WriteableBitmap GetImageFromClipboard()
         {
-            var dao = (DataObject) Clipboard.GetDataObject();
+            DataObject dao = (DataObject)Clipboard.GetDataObject();
             WriteableBitmap finalImage = null;
-            if (dao.GetDataPresent("PNG"))
-                using (var pngStream = dao.GetData("PNG") as MemoryStream)
+            if (dao.GetDataPresent("PNG"))
+            {
+                using (MemoryStream pngStream = dao.GetData("PNG") as MemoryStream)
                 {
                     if (pngStream != null)
                     {
-                        var decoder = new PngBitmapDecoder(pngStream, BitmapCreateOptions.IgnoreImageCache,
+                        PngBitmapDecoder decoder = new PngBitmapDecoder(pngStream, BitmapCreateOptions.IgnoreImageCache,
                             BitmapCacheOption.OnLoad);
                         finalImage = new WriteableBitmap(decoder.Frames[0].Clone());
                     }
-                }
-            else if (dao.GetDataPresent(DataFormats.Dib))
-                finalImage = new WriteableBitmap(Clipboard.GetImage()!);
-            else if (dao.GetDataPresent(DataFormats.Bitmap))
-                finalImage = new WriteableBitmap((dao.GetData(DataFormats.Bitmap) as BitmapSource)!);
-
+                }
+            }
+            else if (dao.GetDataPresent(DataFormats.Dib))
+            {
+                finalImage = new WriteableBitmap(Clipboard.GetImage()!);
+            }
+            else if (dao.GetDataPresent(DataFormats.Bitmap))
+            {
+                finalImage = new WriteableBitmap((dao.GetData(DataFormats.Bitmap) as BitmapSource)!);
+            }
+
             return finalImage;
         }
 
         public static bool IsImageInClipboard()
         {
-            var dao = (DataObject) Clipboard.GetDataObject();
-            if (dao == null) return false;
+            DataObject dao = (DataObject)Clipboard.GetDataObject();
+            if (dao == null)
+            {
+                return false;
+            }
+
             return dao.GetDataPresent("PNG") || dao.GetDataPresent(DataFormats.Dib) ||
                    dao.GetDataPresent(DataFormats.Bitmap);
         }
@@ -88,10 +101,10 @@ namespace PixiEditor.Models.Controllers
 
         public static BitmapSource BitmapSelectionToBmpSource(WriteableBitmap bitmap, Coordinates[] selection)
         {
-            var offsetX = selection.Min(x => x.X);
-            var offsetY = selection.Min(x => x.Y);
-            var width = selection.Max(x => x.X) - offsetX + 1;
-            var height = selection.Max(x => x.Y) - offsetY + 1;
+            int offsetX = selection.Min(x => x.X);
+            int offsetY = selection.Min(x => x.Y);
+            int width = selection.Max(x => x.X) - offsetX + 1;
+            int height = selection.Max(x => x.Y) - offsetY + 1;
             return bitmap.Crop(offsetX, offsetY, width, height);
         }
     }

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

@@ -7,10 +7,15 @@ namespace PixiEditor.Models.Controllers
     public class MouseMovementController
     {
         public List<Coordinates> LastMouseMoveCoordinates { get; } = new List<Coordinates>();
+
         public bool IsRecordingChanges { get; private set; }
+
         public bool ClickedOnCanvas { get; set; }
+
         public event EventHandler StartedRecordingChanges;
+
         public event EventHandler<MouseMovementEventArgs> MousePositionChanged;
+
         public event EventHandler StoppedRecordingChanges;
 
         public void StartRecordingMouseMovementChanges(bool clickedOnCanvas)
@@ -27,11 +32,13 @@ namespace PixiEditor.Models.Controllers
         public void RecordMouseMovementChange(Coordinates mouseCoordinates)
         {
             if (IsRecordingChanges)
+            {
                 if (LastMouseMoveCoordinates.Count == 0 || mouseCoordinates != LastMouseMoveCoordinates[^1])
                 {
                     LastMouseMoveCoordinates.Add(mouseCoordinates);
                     MousePositionChanged?.Invoke(this, new MouseMovementEventArgs(mouseCoordinates));
                 }
+            }
         }
 
         /// <summary>

+ 30 - 13
PixiEditor/Models/Controllers/PixelChangesController.cs

@@ -8,6 +8,7 @@ namespace PixiEditor.Models.Controllers
     public class PixelChangesController
     {
         private Dictionary<int, LayerChange> LastChanges { get; set; }
+
         private Dictionary<int, LayerChange> LastOldValues { get; set; }
 
         /// <summary>
@@ -21,8 +22,8 @@ namespace PixiEditor.Models.Controllers
             {
                 if (LastChanges == null)
                 {
-                    LastChanges = new Dictionary<int, LayerChange> {{changes.LayerIndex, changes}};
-                    LastOldValues = new Dictionary<int, LayerChange> {{oldValues.LayerIndex, oldValues}};
+                    LastChanges = new Dictionary<int, LayerChange> { { changes.LayerIndex, changes } };
+                    LastOldValues = new Dictionary<int, LayerChange> { { oldValues.LayerIndex, oldValues } };
                 }
                 else if (LastChanges.ContainsKey(changes.LayerIndex))
                 {
@@ -43,17 +44,29 @@ namespace PixiEditor.Models.Controllers
 
         private void AddToExistingLayerChange(LayerChange layerChange, LayerChange oldValues)
         {
-            foreach (var change in layerChange.PixelChanges.ChangedPixels)
+            foreach (KeyValuePair<Position.Coordinates, System.Windows.Media.Color> change in layerChange.PixelChanges.ChangedPixels)
+            {
                 if (LastChanges[layerChange.LayerIndex].PixelChanges.ChangedPixels.ContainsKey(change.Key))
+                {
                     continue;
+                }
                 else
+                {
                     LastChanges[layerChange.LayerIndex].PixelChanges.ChangedPixels.Add(change.Key, change.Value);
+                }
+            }
 
-            foreach (var change in oldValues.PixelChanges.ChangedPixels)
+            foreach (KeyValuePair<Position.Coordinates, System.Windows.Media.Color> change in oldValues.PixelChanges.ChangedPixels)
+            {
                 if (LastOldValues[layerChange.LayerIndex].PixelChanges.ChangedPixels.ContainsKey(change.Key))
+                {
                     continue;
+                }
                 else
+                {
                     LastOldValues[layerChange.LayerIndex].PixelChanges.ChangedPixels.Add(change.Key, change.Value);
+                }
+            }
         }
 
         /// <summary>
@@ -62,19 +75,23 @@ namespace PixiEditor.Models.Controllers
         /// <returns>Tuple array with new changes and old values</returns>
         public Tuple<LayerChange, LayerChange>[] PopChanges()
         {
-            //Maybe replace Tuple with custom data type
-            if (LastChanges == null) return null;
-            var result = new Tuple<LayerChange, LayerChange>[LastChanges.Count];
-            var i = 0;
-            foreach (var change in LastChanges)
+            // Maybe replace Tuple with custom data type
+            if (LastChanges == null)
+            {
+                return null;
+            }
+
+            Tuple<LayerChange, LayerChange>[] result = new Tuple<LayerChange, LayerChange>[LastChanges.Count];
+            int i = 0;
+            foreach (KeyValuePair<int, LayerChange> change in LastChanges)
             {
-                var pixelChanges =
+                Dictionary<Position.Coordinates, System.Windows.Media.Color> pixelChanges =
                     change.Value.PixelChanges.ChangedPixels.ToDictionary(entry => entry.Key, entry => entry.Value);
-                var oldValues = LastOldValues[change.Key].PixelChanges.ChangedPixels
+                Dictionary<Position.Coordinates, System.Windows.Media.Color> oldValues = LastOldValues[change.Key].PixelChanges.ChangedPixels
                     .ToDictionary(entry => entry.Key, entry => entry.Value);
 
-                var tmp = new LayerChange(new BitmapPixelChanges(pixelChanges), change.Key);
-                var oldValuesTmp = new LayerChange(new BitmapPixelChanges(oldValues), change.Key);
+                LayerChange tmp = new LayerChange(new BitmapPixelChanges(pixelChanges), change.Key);
+                LayerChange oldValuesTmp = new LayerChange(new BitmapPixelChanges(oldValues), change.Key);
 
                 result[i] = new Tuple<LayerChange, LayerChange>(tmp, oldValuesTmp);
                 i++;

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

@@ -14,13 +14,19 @@ namespace PixiEditor.Models.Controllers.Shortcuts
         }
 
         public Key ShortcutKey { get; set; }
+
         public ModifierKeys Modifier { get; set; }
+
         public ICommand Command { get; set; }
+
         public object CommandParameter { get; set; }
 
         public void Execute()
         {
-            if (Command.CanExecute(CommandParameter)) Command.Execute(CommandParameter);
+            if (Command.CanExecute(CommandParameter))
+            {
+                Command.Execute(CommandParameter);
+            }
         }
     }
 }

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

@@ -14,22 +14,29 @@ namespace PixiEditor.Models.Controllers.Shortcuts
         public static bool BlockShortcutExecution { get; set; }
 
         public List<Shortcut> Shortcuts { get; set; }
+
         public Shortcut LastShortcut { get; private set; }
 
         public void KeyPressed(Key key, ModifierKeys modifiers)
         {
             if (!BlockShortcutExecution)
             {
-                var shortcuts = Shortcuts.FindAll(x => x.ShortcutKey == key).ToArray();
-                if (shortcuts.Length < 1) return;
+                Shortcut[] shortcuts = Shortcuts.FindAll(x => x.ShortcutKey == key).ToArray();
+                if (shortcuts.Length < 1)
+                {
+                    return;
+                }
+
                 shortcuts = shortcuts.OrderByDescending(x => x.Modifier).ToArray();
-                for (var i = 0; i < shortcuts.Length; i++)
+                for (int i = 0; i < shortcuts.Length; i++)
+                {
                     if (modifiers.HasFlag(shortcuts[i].Modifier))
                     {
                         shortcuts[i].Execute();
                         LastShortcut = shortcuts[i];
                         break;
                     }
+                }
             }
         }
     }

+ 32 - 19
PixiEditor/Models/Controllers/UndoManager.cs

@@ -7,7 +7,9 @@ namespace PixiEditor.Models.Controllers
     public static class UndoManager
     {
         private static bool lastChangeWasUndo;
+
         public static Stack<Change> UndoStack { get; set; } = new Stack<Change>();
+
         public static Stack<Change> RedoStack { get; set; } = new Stack<Change>();
 
         public static bool CanUndo => UndoStack.Count > 0;
@@ -31,9 +33,11 @@ namespace PixiEditor.Models.Controllers
         /// <param name="change"></param>
         public static void AddUndoChange(Change change)
         {
-            if (lastChangeWasUndo == false && RedoStack.Count > 0
-            ) //Clears RedoStack if las move wasn't redo or undo and if redo stack is greater than 0
-                RedoStack.Clear();
+            if (lastChangeWasUndo == false && RedoStack.Count > 0) // Clears RedoStack if las move wasn't redo or undo and if redo stack is greater than 0
+            {
+                RedoStack.Clear();
+            }
+
             lastChangeWasUndo = false;
             change.Root ??= MainRoot;
             UndoStack.Push(change);
@@ -45,11 +49,16 @@ namespace PixiEditor.Models.Controllers
         public static void Undo()
         {
             lastChangeWasUndo = true;
-            var change = UndoStack.Pop();
-            if (change.ReverseProcess == null)
-                SetPropertyValue(change.Root, change.Property, change.OldValue);
-            else
-                change.ReverseProcess(change.ReverseProcessArguments);
+            Change change = UndoStack.Pop();
+            if (change.ReverseProcess == null)
+            {
+                SetPropertyValue(change.Root, change.Property, change.OldValue);
+            }
+            else
+            {
+                change.ReverseProcess(change.ReverseProcessArguments);
+            }
+
             RedoStack.Push(change);
         }
 
@@ -59,25 +68,29 @@ namespace PixiEditor.Models.Controllers
         public static void Redo()
         {
             lastChangeWasUndo = true;
-            var change = RedoStack.Pop();
-            if (change.Process == null)
-                SetPropertyValue(change.Root, change.Property, change.NewValue);
-            else
-                change.Process(change.ProcessArguments);
+            Change change = RedoStack.Pop();
+            if (change.Process == null)
+            {
+                SetPropertyValue(change.Root, change.Property, change.NewValue);
+            }
+            else
+            {
+                change.Process(change.ProcessArguments);
+            }
+
             UndoStack.Push(change);
         }
-
-
+
         private static void SetPropertyValue(object target, string propName, object value)
         {
-            var bits = propName.Split('.');
-            for (var i = 0; i < bits.Length - 1; i++)
+            string[] bits = propName.Split('.');
+            for (int i = 0; i < bits.Length - 1; i++)
             {
-                var propertyToGet = target.GetType().GetProperty(bits[i]);
+                System.Reflection.PropertyInfo propertyToGet = target.GetType().GetProperty(bits[i]);
                 target = propertyToGet.GetValue(target, null);
             }
 
-            var propertyToSet = target.GetType().GetProperty(bits.Last());
+            System.Reflection.PropertyInfo propertyToSet = target.GetType().GetProperty(bits.Last());
             propertyToSet.SetValue(target, value, null);
         }
     }

+ 32 - 11
PixiEditor/Models/DataHolders/BitmapPixelChanges.cs

@@ -13,6 +13,7 @@ namespace PixiEditor.Models.DataHolders
         public bool WasBuiltAsSingleColored { get; private set; }
 
         public static BitmapPixelChanges Empty => new BitmapPixelChanges(new Dictionary<Coordinates, Color>());
+
         public Dictionary<Coordinates, Color> ChangedPixels { get; set; }
 
         public BitmapPixelChanges(Dictionary<Coordinates, Color> changedPixels)
@@ -29,9 +30,13 @@ namespace PixiEditor.Models.DataHolders
         /// <returns>Single-colored BitmapPixelChanges</returns>
         public static BitmapPixelChanges FromSingleColoredArray(IEnumerable<Coordinates> coordinates, Color color)
         {
-            var dict = new Dictionary<Coordinates, Color>();
-            foreach (var coordinate in coordinates) dict.Add(coordinate, color);
-            return new BitmapPixelChanges(dict) {WasBuiltAsSingleColored = true};
+            Dictionary<Coordinates, Color> dict = new Dictionary<Coordinates, Color>();
+            foreach (Coordinates coordinate in coordinates)
+            {
+                dict.Add(coordinate, color);
+            }
+
+            return new BitmapPixelChanges(dict) { WasBuiltAsSingleColored = true };
         }
 
         /// <summary>
@@ -41,10 +46,18 @@ namespace PixiEditor.Models.DataHolders
         /// <returns>Combined BitmapPixelChanges</returns>
         public static BitmapPixelChanges CombineOverride(BitmapPixelChanges[] changes)
         {
-            if (changes == null || changes.Length == 0) throw new ArgumentException();
-            var output = Empty;
+            if (changes == null || changes.Length == 0)
+            {
+                throw new ArgumentException();
+            }
+
+            BitmapPixelChanges output = Empty;
 
-            for (var i = 0; i < changes.Length; i++) output.ChangedPixels.AddRangeOverride(changes[i].ChangedPixels);
+            for (int i = 0; i < changes.Length; i++)
+            {
+                output.ChangedPixels.AddRangeOverride(changes[i].ChangedPixels);
+            }
+
             return output;
         }
 
@@ -56,11 +69,19 @@ namespace PixiEditor.Models.DataHolders
         /// <returns></returns>
         public static BitmapPixelChanges FromArrays(IEnumerable<Coordinates> coordinates, IEnumerable<Color> color)
         {
-            var coordinateArray = coordinates.ToArray();
-            var colorArray = color.ToArray();
-            if (coordinateArray.Length != colorArray.Length) throw new ArrayLengthMismatchException();
-            var dict = new Dictionary<Coordinates, Color>();
-            for (var i = 0; i < coordinateArray.Length; i++) dict.Add(coordinateArray[i], colorArray[i]);
+            Coordinates[] coordinateArray = coordinates.ToArray();
+            Color[] colorArray = color.ToArray();
+            if (coordinateArray.Length != colorArray.Length)
+            {
+                throw new ArrayLengthMismatchException();
+            }
+
+            Dictionary<Coordinates, Color> dict = new Dictionary<Coordinates, Color>();
+            for (int i = 0; i < coordinateArray.Length; i++)
+            {
+                dict.Add(coordinateArray[i], colorArray[i]);
+            }
+
             return new BitmapPixelChanges(dict);
         }
     }

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

@@ -73,7 +73,9 @@ namespace PixiEditor.Models.DataHolders
         public string Property { get; set; }
 
         public Action<object[]> ReverseProcess { get; set; }
+
         public Action<object[]> Process { get; set; }
+
         public object Root { get; set; }
     }
 }

+ 113 - 80
PixiEditor/Models/DataHolders/Document.cs

@@ -73,18 +73,18 @@ namespace PixiEditor.Models.DataHolders
         /// </param>
         public void ResizeCanvas(int width, int height, AnchorPoint anchor)
         {
-            var oldWidth = Width;
-            var oldHeight = Height;
+            int oldWidth = Width;
+            int oldHeight = Height;
 
-            var offsetX = GetOffsetXForAnchor(Width, width, anchor);
-            var offsetY = GetOffsetYForAnchor(Height, height, anchor);
+            int offsetX = GetOffsetXForAnchor(Width, width, anchor);
+            int offsetY = GetOffsetYForAnchor(Height, height, anchor);
 
-            var oldOffsets = Layers.Select(x => x.Offset).ToArray();
-            var newOffsets = Layers.Select(x => new Thickness(offsetX + x.OffsetX, offsetY + x.OffsetY, 0, 0))
+            Thickness[] oldOffsets = Layers.Select(x => x.Offset).ToArray();
+            Thickness[] newOffsets = Layers.Select(x => new Thickness(offsetX + x.OffsetX, offsetY + x.OffsetY, 0, 0))
                 .ToArray();
 
-            object[] processArgs = {newOffsets, width, height};
-            object[] reverseProcessArgs = {oldOffsets, Width, Height};
+            object[] processArgs = { newOffsets, width, height };
+            object[] reverseProcessArgs = { oldOffsets, Width, Height };
 
             ResizeCanvas(newOffsets, width, height);
             UndoManager.AddUndoChange(new Change(ResizeCanvasProcess,
@@ -94,17 +94,31 @@ namespace PixiEditor.Models.DataHolders
 
         private int GetOffsetXForAnchor(int srcWidth, int destWidth, AnchorPoint anchor)
         {
-            if (anchor.HasFlag(AnchorPoint.Center))
-                return Math.Abs(destWidth / 2 - srcWidth / 2);
-            if (anchor.HasFlag(AnchorPoint.Right)) return Math.Abs(destWidth - srcWidth);
+            if (anchor.HasFlag(AnchorPoint.Center))
+            {
+                return Math.Abs(destWidth / 2 - srcWidth / 2);
+            }
+
+            if (anchor.HasFlag(AnchorPoint.Right))
+            {
+                return Math.Abs(destWidth - srcWidth);
+            }
+
             return 0;
         }
 
         private int GetOffsetYForAnchor(int srcHeight, int destHeight, AnchorPoint anchor)
         {
-            if (anchor.HasFlag(AnchorPoint.Middle))
-                return Math.Abs(destHeight / 2 - srcHeight / 2);
-            if (anchor.HasFlag(AnchorPoint.Bottom)) return Math.Abs(destHeight - srcHeight);
+            if (anchor.HasFlag(AnchorPoint.Middle))
+            {
+                return Math.Abs(destHeight / 2 - srcHeight / 2);
+            }
+
+            if (anchor.HasFlag(AnchorPoint.Bottom))
+            {
+                return Math.Abs(destHeight - srcHeight);
+            }
+
             return 0;
         }
 
@@ -115,8 +129,8 @@ namespace PixiEditor.Models.DataHolders
         /// <param name="newHeight">New document height</param>
         public void Resize(int newWidth, int newHeight)
         {
-            object[] reverseArgs = {Width, Height};
-            object[] args = {newWidth, newHeight};
+            object[] reverseArgs = { Width, Height };
+            object[] args = { newWidth, newHeight };
             ResizeDocument(args);
             UndoManager.AddUndoChange(new Change(ResizeDocument, reverseArgs,
                 ResizeDocument, args, "Resize document"));
@@ -124,18 +138,18 @@ namespace PixiEditor.Models.DataHolders
 
         private void ResizeDocument(object[] arguments)
         {
-            var oldWidth = Width;
-            var oldHeight = Height;
+            int oldWidth = Width;
+            int oldHeight = Height;
 
-            var newWidth = (int) arguments[0];
-            var newHeight = (int) arguments[1];
+            int newWidth = (int)arguments[0];
+            int newHeight = (int)arguments[1];
 
-            for (var i = 0; i < Layers.Count; i++)
+            for (int i = 0; i < Layers.Count; i++)
             {
-                var widthRatio = (float) newWidth / Width;
-                var heightRatio = (float) newHeight / Height;
-                var layerWidth = (int) (Layers[i].Width * widthRatio);
-                var layerHeight = (int) (Layers[i].Height * heightRatio);
+                float widthRatio = (float)newWidth / Width;
+                float heightRatio = (float)newHeight / Height;
+                int layerWidth = (int)(Layers[i].Width * widthRatio);
+                int layerHeight = (int)(Layers[i].Height * heightRatio);
 
                 Layers[i].Resize(layerWidth, layerHeight, newWidth, newHeight);
                 Layers[i].Offset = new Thickness(Layers[i].OffsetX * widthRatio, Layers[i].OffsetY * heightRatio, 0, 0);
@@ -149,12 +163,12 @@ namespace PixiEditor.Models.DataHolders
 
         private void ResizeCanvasProcess(object[] arguments)
         {
-            var oldWidth = Width;
-            var oldHeight = Height;
+            int oldWidth = Width;
+            int oldHeight = Height;
 
-            var offset = (Thickness[]) arguments[0];
-            var width = (int) arguments[1];
-            var height = (int) arguments[2];
+            Thickness[] offset = (Thickness[])arguments[0];
+            int width = (int)arguments[1];
+            int height = (int)arguments[2];
             ResizeCanvas(offset, width, height);
             DocumentSizeChanged?.Invoke(this, new DocumentSizeChangedEventArgs(oldWidth, oldHeight, width, height));
         }
@@ -167,7 +181,7 @@ namespace PixiEditor.Models.DataHolders
         /// <param name="newHeight">New canvas height.</param>
         private void ResizeCanvas(Thickness[] offset, int newWidth, int newHeight)
         {
-            for (var i = 0; i < Layers.Count; i++)
+            for (int i = 0; i < Layers.Count; i++)
             {
                 Layers[i].Offset = offset[i];
                 Layers[i].MaxWidth = newWidth;
@@ -183,29 +197,31 @@ namespace PixiEditor.Models.DataHolders
         /// </summary>
         public void ClipCanvas()
         {
-            var points = GetEdgePoints();
-            var smallestX = points.Coords1.X;
-            var smallestY = points.Coords1.Y;
-            var biggestX = points.Coords2.X;
-            var biggestY = points.Coords2.Y;
-
-            if (smallestX == 0 && smallestY == 0 && biggestX == 0 && biggestY == 0)
-                return;
-
-            var width = biggestX - smallestX;
-            var height = biggestY - smallestY;
-            var moveVector = new Coordinates(-smallestX, -smallestY);
-
-            var oldOffsets = Layers.Select(x => x.Offset).ToArray();
-            var oldWidth = Width;
-            var oldHeight = Height;
+            DoubleCords points = GetEdgePoints();
+            int smallestX = points.Coords1.X;
+            int smallestY = points.Coords1.Y;
+            int biggestX = points.Coords2.X;
+            int biggestY = points.Coords2.Y;
+
+            if (smallestX == 0 && smallestY == 0 && biggestX == 0 && biggestY == 0)
+            {
+                return;
+            }
+
+            int width = biggestX - smallestX;
+            int height = biggestY - smallestY;
+            Coordinates moveVector = new Coordinates(-smallestX, -smallestY);
+
+            Thickness[] oldOffsets = Layers.Select(x => x.Offset).ToArray();
+            int oldWidth = Width;
+            int oldHeight = Height;
 
             MoveOffsets(moveVector);
             Width = width;
             Height = height;
 
-            object[] reverseArguments = {oldOffsets, oldWidth, oldHeight};
-            object[] processArguments = {Layers.Select(x => x.Offset).ToArray(), width, height};
+            object[] reverseArguments = { oldOffsets, oldWidth, oldHeight };
+            object[] processArguments = { Layers.Select(x => x.Offset).ToArray(), width, height };
 
             UndoManager.AddUndoChange(new Change(ResizeCanvasProcess, reverseArguments,
                 ResizeCanvasProcess, processArguments, "Clip canvas"));
@@ -213,22 +229,34 @@ namespace PixiEditor.Models.DataHolders
 
         private DoubleCords GetEdgePoints()
         {
-            var firstLayer = Layers[0];
-            var smallestX = firstLayer.OffsetX;
-            var smallestY = firstLayer.OffsetY;
-            var biggestX = smallestX + firstLayer.Width;
-            var biggestY = smallestY + firstLayer.Height;
+            Layer firstLayer = Layers[0];
+            int smallestX = firstLayer.OffsetX;
+            int smallestY = firstLayer.OffsetY;
+            int biggestX = smallestX + firstLayer.Width;
+            int biggestY = smallestY + firstLayer.Height;
 
-            for (var i = 0; i < Layers.Count; i++)
+            for (int i = 0; i < Layers.Count; i++)
             {
                 Layers[i].ClipCanvas();
-                if (Layers[i].OffsetX < smallestX)
-                    smallestX = Layers[i].OffsetX;
-                if (Layers[i].OffsetX + Layers[i].Width > biggestX) biggestX = Layers[i].OffsetX + Layers[i].Width;
-
-                if (Layers[i].OffsetY < smallestY)
-                    smallestY = Layers[i].OffsetY;
-                if (Layers[i].OffsetY + Layers[i].Height > biggestY) biggestY = Layers[i].OffsetY + Layers[i].Height;
+                if (Layers[i].OffsetX < smallestX)
+                {
+                    smallestX = Layers[i].OffsetX;
+                }
+
+                if (Layers[i].OffsetX + Layers[i].Width > biggestX)
+                {
+                    biggestX = Layers[i].OffsetX + Layers[i].Width;
+                }
+
+                if (Layers[i].OffsetY < smallestY)
+                {
+                    smallestY = Layers[i].OffsetY;
+                }
+
+                if (Layers[i].OffsetY + Layers[i].Height > biggestY)
+                {
+                    biggestY = Layers[i].OffsetY + Layers[i].Height;
+                }
             }
 
             return new DoubleCords(new Coordinates(smallestX, smallestY),
@@ -241,39 +269,41 @@ namespace PixiEditor.Models.DataHolders
         /// <param name="moveVector"></param>
         private void MoveOffsets(Coordinates moveVector)
         {
-            for (var i = 0; i < Layers.Count; i++)
+            for (int i = 0; i < Layers.Count; i++)
             {
-                var offset = Layers[i].Offset;
+                Thickness offset = Layers[i].Offset;
                 Layers[i].Offset = new Thickness(offset.Left + moveVector.X, offset.Top + moveVector.Y, 0, 0);
             }
         }
 
         private void MoveOffsetsProcess(object[] arguments)
         {
-            var vector = (Coordinates) arguments[0];
+            Coordinates vector = (Coordinates)arguments[0];
             MoveOffsets(vector);
         }
 
         public void CenterContent()
         {
-            var points = GetEdgePoints();
-
-            var smallestX = points.Coords1.X;
-            var smallestY = points.Coords1.Y;
-            var biggestX = points.Coords2.X;
-            var biggestY = points.Coords2.Y;
-
-            if (smallestX == 0 && smallestY == 0 && biggestX == 0 && biggestY == 0)
-                return;
-
-            var contentCenter = CoordinatesCalculator.GetCenterPoint(points.Coords1, points.Coords2);
-            var documentCenter = CoordinatesCalculator.GetCenterPoint(new Coordinates(0, 0),
+            DoubleCords points = GetEdgePoints();
+
+            int smallestX = points.Coords1.X;
+            int smallestY = points.Coords1.Y;
+            int biggestX = points.Coords2.X;
+            int biggestY = points.Coords2.Y;
+
+            if (smallestX == 0 && smallestY == 0 && biggestX == 0 && biggestY == 0)
+            {
+                return;
+            }
+
+            Coordinates contentCenter = CoordinatesCalculator.GetCenterPoint(points.Coords1, points.Coords2);
+            Coordinates documentCenter = CoordinatesCalculator.GetCenterPoint(new Coordinates(0, 0),
                 new Coordinates(Width, Height));
-            var moveVector = new Coordinates(documentCenter.X - contentCenter.X, documentCenter.Y - contentCenter.Y);
+            Coordinates moveVector = new Coordinates(documentCenter.X - contentCenter.X, documentCenter.Y - contentCenter.Y);
 
             MoveOffsets(moveVector);
-            UndoManager.AddUndoChange(new Change(MoveOffsetsProcess, new object[] {new Coordinates(-moveVector.X, -moveVector.Y)}, MoveOffsetsProcess,
-                new object[] {moveVector}, "Center content"));
+            UndoManager.AddUndoChange(new Change(MoveOffsetsProcess, new object[] { new Coordinates(-moveVector.X, -moveVector.Y) }, MoveOffsetsProcess,
+                new object[] { moveVector }, "Center content"));
         }
     }
 
@@ -288,8 +318,11 @@ namespace PixiEditor.Models.DataHolders
         }
 
         public int OldWidth { get; set; }
+
         public int OldHeight { get; set; }
+
         public int NewWidth { get; set; }
+
         public int NewHeight { get; set; }
     }
 }

+ 1 - 0
PixiEditor/Models/DataHolders/LayerChange.cs

@@ -18,6 +18,7 @@ namespace PixiEditor.Models.DataHolders
         }
 
         public BitmapPixelChanges PixelChanges { get; set; }
+
         public int LayerIndex { get; set; }
     }
 }

+ 1 - 1
PixiEditor/Models/DataHolders/Selection.cs

@@ -35,7 +35,7 @@ namespace PixiEditor.Models.DataHolders
 
         public void SetSelection(IEnumerable<Coordinates> selection, SelectionType mode)
         {
-            var selectionColor = selectionBlue;
+            Color selectionColor = selectionBlue;
             switch (mode)
             {
                 case SelectionType.New:

+ 8 - 5
PixiEditor/Models/DataHolders/SerializableDocument.cs

@@ -20,13 +20,16 @@ namespace PixiEditor.Models.DataHolders
         }
 
         public int Width { get; set; }
+
         public int Height { get; set; }
+
         public SerializableLayer[] Layers { get; set; }
+
         public Tuple<byte, byte, byte, byte>[] Swatches { get; set; }
 
         public Document ToDocument()
         {
-            var document = new Document(Width, Height)
+            Document document = new Document(Width, Height)
             {
                 Layers = ToLayers(),
                 Swatches = new ObservableCollection<Color>(Swatches.Select(x =>
@@ -37,11 +40,11 @@ namespace PixiEditor.Models.DataHolders
 
         public ObservableCollection<Layer> ToLayers()
         {
-            var layers = new ObservableCollection<Layer>();
-            for (var i = 0; i < Layers.Length; i++)
+            ObservableCollection<Layer> layers = new ObservableCollection<Layer>();
+            for (int i = 0; i < Layers.Length; i++)
             {
-                var serLayer = Layers[i];
-                var layer =
+                SerializableLayer serLayer = Layers[i];
+                Layer layer =
                     new Layer(serLayer.Name, BitmapUtils.BytesToWriteableBitmap(serLayer.Width, serLayer.Height, serLayer.BitmapBytes))
                     {
                         IsVisible = serLayer.IsVisible,

+ 6 - 2
PixiEditor/Models/Dialogs/ConfirmationDialog.cs

@@ -7,11 +7,15 @@ namespace PixiEditor.Models.Dialogs
     {
         public static ConfirmationType Show(string message)
         {
-            var popup = new ConfirmationPopup
+            ConfirmationPopup popup = new ConfirmationPopup
             {
                 Body = message
             };
-            if ((bool) popup.ShowDialog()) return popup.Result ? ConfirmationType.Yes : ConfirmationType.No;
+            if ((bool)popup.ShowDialog())
+            {
+                return popup.Result ? ConfirmationType.Yes : ConfirmationType.No;
+            }
+
             return ConfirmationType.Canceled;
         }
     }

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

@@ -6,16 +6,15 @@ namespace PixiEditor.Models.Dialogs
     public class ExportFileDialog : CustomDialog
     {
         private int fileHeight;
-
-
+
         private string filePath;
 
         private int fileWidth;
 
         public ExportFileDialog(Size fileDimensions)
         {
-            FileHeight = (int) fileDimensions.Height;
-            FileWidth = (int) fileDimensions.Width;
+            FileHeight = (int)fileDimensions.Height;
+            FileWidth = (int)fileDimensions.Width;
         }
 
         public int FileWidth
@@ -59,7 +58,7 @@ namespace PixiEditor.Models.Dialogs
 
         public override bool ShowDialog()
         {
-            var popup = new SaveFilePopup
+            SaveFilePopup popup = new SaveFilePopup
             {
                 SaveWidth = FileWidth,
                 SaveHeight = FileHeight
@@ -72,7 +71,7 @@ namespace PixiEditor.Models.Dialogs
                 FilePath = popup.SavePath;
             }
 
-            return (bool) popup.DialogResult;
+            return (bool)popup.DialogResult;
         }
     }
 }

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

@@ -5,8 +5,7 @@ namespace PixiEditor.Models.Dialogs
     internal class ImportFileDialog : CustomDialog
     {
         private int fileHeight;
-
-
+
         private string filePath;
         private int fileWidth;
 
@@ -51,8 +50,10 @@ namespace PixiEditor.Models.Dialogs
 
         public override bool ShowDialog()
         {
-            var popup = new ImportFilePopup();
-            popup.FilePath = FilePath;
+            ImportFilePopup popup = new ImportFilePopup
+            {
+                FilePath = FilePath
+            };
             popup.ShowDialog();
             if (popup.DialogResult == true)
             {
@@ -61,7 +62,7 @@ namespace PixiEditor.Models.Dialogs
                 FilePath = popup.FilePath;
             }
 
-            return (bool) popup.DialogResult;
+            return (bool)popup.DialogResult;
         }
     }
 }

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

@@ -41,7 +41,7 @@ namespace PixiEditor.Models.Dialogs
             popup.ShowDialog();
             Height = (popup as NewFilePopup).FileHeight;
             Width = (popup as NewFilePopup).FileWidth;
-            return (bool) popup.DialogResult;
+            return (bool)popup.DialogResult;
         }
     }
 }

+ 5 - 4
PixiEditor/Models/Dialogs/ResizeDocumentDialog.cs

@@ -16,6 +16,7 @@ namespace PixiEditor.Models.Dialogs
         }
 
         public bool OpenResizeCanvas { get; set; }
+
         public AnchorPoint ResizeAnchor { get; set; }
 
         public int Width
@@ -51,7 +52,7 @@ namespace PixiEditor.Models.Dialogs
 
         private bool ShowResizeDocumentCanvas()
         {
-            var popup = new ResizeDocumentPopup
+            ResizeDocumentPopup popup = new ResizeDocumentPopup
             {
                 NewHeight = Height,
                 NewWidth = Width
@@ -64,12 +65,12 @@ namespace PixiEditor.Models.Dialogs
                 Height = popup.NewHeight;
             }
 
-            return (bool) popup.DialogResult;
+            return (bool)popup.DialogResult;
         }
 
         private bool ShowResizeCanvasDialog()
         {
-            var popup = new ResizeCanvasPopup
+            ResizeCanvasPopup popup = new ResizeCanvasPopup
             {
                 NewHeight = Height,
                 NewWidth = Width
@@ -83,7 +84,7 @@ namespace PixiEditor.Models.Dialogs
                 ResizeAnchor = popup.SelectedAnchorPoint;
             }
 
-            return (bool) popup.DialogResult;
+            return (bool)popup.DialogResult;
         }
     }
 }

+ 3 - 3
PixiEditor/Models/IO/BinarySerialization.cs

@@ -9,7 +9,7 @@ namespace PixiEditor.Models.IO
         {
             using (Stream stream = File.Open(path, FileMode.Create))
             {
-                var binaryFormatter = new BinaryFormatter();
+                BinaryFormatter binaryFormatter = new BinaryFormatter();
                 binaryFormatter.Serialize(stream, objectToWrite);
             }
         }
@@ -18,8 +18,8 @@ namespace PixiEditor.Models.IO
         {
             using (Stream stream = File.Open(path, FileMode.Open))
             {
-                var formatter = new BinaryFormatter();
-                return (T) formatter.Deserialize(stream);
+                BinaryFormatter formatter = new BinaryFormatter();
+                return (T)formatter.Deserialize(stream);
             }
         }
     }

+ 11 - 9
PixiEditor/Models/IO/Exporter.cs

@@ -21,12 +21,12 @@ namespace PixiEditor.Models.IO
         /// <param name="updateWorkspacePath">Should editor remember dialog path for further saves</param>
         public static bool SaveAsEditableFileWithDialog(Document document, bool updateWorkspacePath = false)
         {
-            var dialog = new SaveFileDialog
+            SaveFileDialog dialog = new SaveFileDialog
             {
                 Filter = "PixiEditor Files | *.pixi",
                 DefaultExt = "pixi"
             };
-            if ((bool) dialog.ShowDialog())
+            if ((bool)dialog.ShowDialog())
             {
                 SaveAsEditableFile(document, dialog.FileName, updateWorkspacePath);
                 return true;
@@ -39,8 +39,10 @@ namespace PixiEditor.Models.IO
         {
             BinarySerialization.WriteToBinaryFile(path, new SerializableDocument(document));
 
-            if (updateWorkspacePath)
-                SaveDocumentPath = path;
+            if (updateWorkspacePath)
+            {
+                SaveDocumentPath = path;
+            }
         }
 
         /// <summary>
@@ -50,11 +52,11 @@ namespace PixiEditor.Models.IO
         /// <param name="fileDimensions">Size of file</param>
         public static void Export(WriteableBitmap bitmap, Size fileDimensions)
         {
-            var info = new ExportFileDialog(fileDimensions);
-            //If OK on dialog has been clicked
+            ExportFileDialog info = new ExportFileDialog(fileDimensions);
+            // If OK on dialog has been clicked
             if (info.ShowDialog())
             {
-                //If sizes are incorrect
+                // If sizes are incorrect
                 if (info.FileWidth < bitmap.Width || info.FileHeight < bitmap.Height)
                 {
                     MessageBox.Show("Incorrect height or width value", "Error", MessageBoxButton.OK,
@@ -80,9 +82,9 @@ namespace PixiEditor.Models.IO
             {
                 bitmap = bitmap.Resize(exportWidth, exportHeight,
                     WriteableBitmapExtensions.Interpolation.NearestNeighbor);
-                using (var stream = new FileStream(savePath, FileMode.Create))
+                using (FileStream stream = new FileStream(savePath, FileMode.Create))
                 {
-                    var encoder = new PngBitmapEncoder();
+                    PngBitmapEncoder encoder = new PngBitmapEncoder();
                     encoder.Frames.Add(BitmapFrame.Create(bitmap));
                     encoder.Save(stream);
                 }

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

@@ -16,9 +16,12 @@ namespace PixiEditor.Models.IO
         /// <returns></returns>
         public static WriteableBitmap ImportImage(string path, int width, int height)
         {
-            var wbmp = ImportImage(path);
-            if (wbmp.PixelWidth != width || wbmp.PixelHeight != height) return wbmp.Resize(width, height, WriteableBitmapExtensions.Interpolation.NearestNeighbor);
-
+            WriteableBitmap wbmp = ImportImage(path);
+            if (wbmp.PixelWidth != width || wbmp.PixelHeight != height)
+            {
+                return wbmp.Resize(width, height, WriteableBitmapExtensions.Interpolation.NearestNeighbor);
+            }
+
             return wbmp;
         }
 
@@ -28,8 +31,8 @@ namespace PixiEditor.Models.IO
         /// <param name="path">Path of image.</param>
         public static WriteableBitmap ImportImage(string path)
         {
-            var uri = new Uri(path);
-            var bitmap = new BitmapImage();
+            Uri uri = new Uri(path);
+            BitmapImage bitmap = new BitmapImage();
             bitmap.BeginInit();
             bitmap.UriSource = uri;
             bitmap.EndInit();

+ 28 - 19
PixiEditor/Models/ImageManipulation/BitmapUtils.cs

@@ -18,7 +18,7 @@ namespace PixiEditor.Models.ImageManipulation
         public static WriteableBitmap BytesToWriteableBitmap(int currentBitmapWidth, int currentBitmapHeight,
             byte[] byteArray)
         {
-            var bitmap = BitmapFactory.New(currentBitmapWidth, currentBitmapHeight);
+            WriteableBitmap bitmap = BitmapFactory.New(currentBitmapWidth, currentBitmapHeight);
             bitmap.FromByteArray(byteArray);
             return bitmap;
         }
@@ -32,18 +32,25 @@ namespace PixiEditor.Models.ImageManipulation
         /// <returns>WriteableBitmap of layered bitmaps</returns>
         public static WriteableBitmap CombineLayers(Layer[] layers, int width, int height)
         {
-            var finalBitmap = BitmapFactory.New(width, height);
+            WriteableBitmap finalBitmap = BitmapFactory.New(width, height);
 
             using (finalBitmap.GetBitmapContext())
             {
-                for (var i = 0; i < layers.Length; i++)
-                for (var y = 0; y < finalBitmap.Height; y++)
-                for (var x = 0; x < finalBitmap.Width; x++)
-                {
-                    var color = layers[i].GetPixelWithOffset(x, y);
-                    color = Color.FromArgb((byte) (color.A * layers[i].Opacity), color.R, color.G, color.B);
-                    if (color.A != 0 || color.R != 0 || color.B != 0 || color.G != 0) finalBitmap.SetPixel(x, y, color);
-                }
+                for (int i = 0; i < layers.Length; i++)
+                {
+                    for (int y = 0; y < finalBitmap.Height; y++)
+                    {
+                        for (int x = 0; x < finalBitmap.Width; x++)
+                        {
+                            Color color = layers[i].GetPixelWithOffset(x, y);
+                            color = Color.FromArgb((byte)(color.A * layers[i].Opacity), color.R, color.G, color.B);
+                            if (color.A != 0 || color.R != 0 || color.B != 0 || color.G != 0)
+                            {
+                                finalBitmap.SetPixel(x, y, color);
+                            }
+                        }
+                    }
+                }
             }
 
             return finalBitmap;
@@ -51,25 +58,27 @@ namespace PixiEditor.Models.ImageManipulation
 
         public static Dictionary<Layer, Color[]> GetPixelsForSelection(Layer[] layers, Coordinates[] selection)
         {
-            var result = new Dictionary<Layer, Color[]>();
+            Dictionary<Layer, Color[]> result = new Dictionary<Layer, Color[]>();
 
-            for (var i = 0; i < layers.Length; i++)
+            for (int i = 0; i < layers.Length; i++)
             {
-                var pixels = new Color[selection.Length];
+                Color[] pixels = new Color[selection.Length];
 
                 using (layers[i].LayerBitmap.GetBitmapContext())
                 {
-                    for (var j = 0; j < pixels.Length; j++)
+                    for (int j = 0; j < pixels.Length; j++)
                     {
-                        var position = layers[i].GetRelativePosition(selection[j]);
+                        Coordinates position = layers[i].GetRelativePosition(selection[j]);
                         if (position.X < 0 || position.X > layers[i].Width - 1 || position.Y < 0 ||
-                            position.Y > layers[i].Height - 1)
-                            continue;
+                            position.Y > layers[i].Height - 1)
+                        {
+                            continue;
+                        }
+
                         pixels[j] = layers[i].GetPixel(position.X, position.Y);
                     }
                 }
-
-
+
                 result[layers[i]] = pixels;
             }
 

+ 63 - 44
PixiEditor/Models/ImageManipulation/Morphology.cs

@@ -9,70 +9,89 @@ namespace PixiEditor.Models.ImageManipulation
     {
         public static IEnumerable<Coordinates> ApplyDilation(Coordinates[] points, int kernelSize, int[,] mask)
         {
-            var kernelDim = kernelSize;
+            int kernelDim = kernelSize;
 
-            //This is the offset of center pixel from border of the kernel
-            var kernelOffset = (kernelDim - 1) / 2;
-            var margin = kernelDim;
+            // This is the offset of center pixel from border of the kernel
+            int kernelOffset = (kernelDim - 1) / 2;
+            int margin = kernelDim;
 
-            var byteImg = GetByteArrayForPoints(points, margin);
-            var outputArray = byteImg.Clone() as byte[,];
-            var offset = new Coordinates(points.Min(x => x.X) - margin, points.Min(x => x.Y) - margin);
-
-            var width = byteImg.GetLength(0);
-            var height = byteImg.GetLength(1);
-            for (var y = kernelOffset; y < height - kernelOffset; y++)
-            for (var x = kernelOffset; x < width - kernelOffset; x++)
-            {
-                byte value = 0;
-
-                //Apply dilation
-                for (var ykernel = -kernelOffset; ykernel <= kernelOffset; ykernel++)
-                for (var xkernel = -kernelOffset; xkernel <= kernelOffset; xkernel++)
-                    if (mask[xkernel + kernelOffset, ykernel + kernelOffset] == 1)
-                        value = Math.Max(value, byteImg[x + xkernel, y + ykernel]);
-                    else
-                        continue;
-                //Write processed data into the second array
-                outputArray[x, y] = value;
-            }
+            byte[,] byteImg = GetByteArrayForPoints(points, margin);
+            byte[,] outputArray = byteImg.Clone() as byte[,];
+            Coordinates offset = new Coordinates(points.Min(x => x.X) - margin, points.Min(x => x.Y) - margin);
 
+            int width = byteImg.GetLength(0);
+            int height = byteImg.GetLength(1);
+            for (int y = kernelOffset; y < height - kernelOffset; y++)
+            {
+                for (int x = kernelOffset; x < width - kernelOffset; x++)
+                {
+                    byte value = 0;
+
+                    // Apply dilation
+                    for (int ykernel = -kernelOffset; ykernel <= kernelOffset; ykernel++)
+                    {
+                        for (int xkernel = -kernelOffset; xkernel <= kernelOffset; xkernel++)
+                        {
+                            if (mask[xkernel + kernelOffset, ykernel + kernelOffset] == 1)
+                            {
+                                value = Math.Max(value, byteImg[x + xkernel, y + ykernel]);
+                            }
+                            else
+                            {
+                                continue;
+                            }
+                        }
+                    }
+                    // Write processed data into the second array
+                    outputArray[x, y] = value;
+                }
+            }
+
             return ToCoordinates(outputArray, offset).Distinct();
         }
 
         private static IEnumerable<Coordinates> ToCoordinates(byte[,] byteArray, Coordinates offset)
         {
-            var output = new List<Coordinates>();
-            var width = byteArray.GetLength(0);
+            List<Coordinates> output = new List<Coordinates>();
+            int width = byteArray.GetLength(0);
 
-            for (var y = 0; y < byteArray.GetLength(1); y++)
-            for (var x = 0; x < width; x++)
-                if (byteArray[x, y] == 1)
-                    output.Add(new Coordinates(x + offset.X, y + offset.Y));
+            for (int y = 0; y < byteArray.GetLength(1); y++)
+            {
+                for (int x = 0; x < width; x++)
+                {
+                    if (byteArray[x, y] == 1)
+                    {
+                        output.Add(new Coordinates(x + offset.X, y + offset.Y));
+                    }
+                }
+            }
+
             return output;
         }
 
         private static byte[,] GetByteArrayForPoints(Coordinates[] points, int margin)
         {
-            var dimensions = GetDimensionsForPoints(points);
-            var minX = points.Min(x => x.X);
-            var minY = points.Min(x => x.Y);
-            var array = new byte[dimensions.Item1 + margin * 2, dimensions.Item2 + margin * 2];
-
-            for (var y = 0; y < dimensions.Item2 + margin; y++)
-            for (var x = 0; x < dimensions.Item1 + margin; x++)
-            {
-                var cords = new Coordinates(x + minX, y + minY);
-                array[x + margin, y + margin] = points.Contains(cords) ? (byte) 1 : (byte) 0;
-            }
+            Tuple<int, int> dimensions = GetDimensionsForPoints(points);
+            int minX = points.Min(x => x.X);
+            int minY = points.Min(x => x.Y);
+            byte[,] array = new byte[dimensions.Item1 + margin * 2, dimensions.Item2 + margin * 2];
 
+            for (int y = 0; y < dimensions.Item2 + margin; y++)
+            {
+                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;
+                }
+            }
+
             return array;
         }
 
         private static Tuple<int, int> GetDimensionsForPoints(Coordinates[] points)
         {
-            var width = points.Max(x => x.X) - points.Min(x => x.X);
-            var 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);
         }
     }

+ 8 - 5
PixiEditor/Models/ImageManipulation/Transform.cs

@@ -12,16 +12,19 @@ namespace PixiEditor.Models.ImageManipulation
         /// <returns>Translation as coordinate</returns>
         public static Coordinates GetTranslation(Coordinates from, Coordinates to)
         {
-            var translationX = to.X - from.X;
-            var translationY = to.Y - from.Y;
+            int translationX = to.X - from.X;
+            int translationY = to.Y - from.Y;
             return new Coordinates(translationX, translationY);
         }
 
         public static Coordinates[] Translate(Coordinates[] points, Coordinates vector)
         {
-            var translatedPoints = new Coordinates[points.Length];
-            for (var i = 0; i < translatedPoints.Length; i++)
-                translatedPoints[i] = new Coordinates(points[i].X + vector.X, points[i].Y + vector.Y);
+            Coordinates[] translatedPoints = new Coordinates[points.Length];
+            for (int i = 0; i < translatedPoints.Length; i++)
+            {
+                translatedPoints[i] = new Coordinates(points[i].X + vector.X, points[i].Y + vector.Y);
+            }
+
             return translatedPoints;
         }
     }

+ 128 - 76
PixiEditor/Models/Layers/Layer.cs

@@ -43,8 +43,7 @@ namespace PixiEditor.Models.Layers
             Width = width;
             Height = height;
         }
-
-
+
         public Layer(string name, WriteableBitmap layerBitmap)
         {
             Name = name;
@@ -92,8 +91,7 @@ namespace PixiEditor.Models.Layers
                 RaisePropertyChanged("IsRenaming");
             }
         }
-
-
+
         public WriteableBitmap LayerBitmap
         {
             get => layerBitmap;
@@ -114,9 +112,9 @@ namespace PixiEditor.Models.Layers
             }
         }
 
-        public int OffsetX => (int) Offset.Left;
+        public int OffsetX => (int)Offset.Left;
 
-        public int OffsetY => (int) Offset.Top;
+        public int OffsetY => (int)Offset.Top;
 
         public Thickness Offset
         {
@@ -129,6 +127,7 @@ namespace PixiEditor.Models.Layers
         }
 
         public int MaxWidth { get; set; } = int.MaxValue;
+
         public int MaxHeight { get; set; } = int.MaxValue;
 
         /// <summary>
@@ -183,7 +182,7 @@ namespace PixiEditor.Models.Layers
         /// <returns>Color of a pixel</returns>
         public Color GetPixelWithOffset(int x, int y)
         {
-            var cords = GetRelativePosition(new Coordinates(x, y));
+            Coordinates cords = GetRelativePosition(new Coordinates(x, y));
             return GetPixel(cords.X, cords.Y);
         }
 
@@ -195,8 +194,11 @@ namespace PixiEditor.Models.Layers
         /// <returns>Color of pixel, if out of bounds, returns transparent pixel.</returns>
         public Color GetPixel(int x, int y)
         {
-            if (x > Width - 1 || x < 0 || y > Height - 1 || y < 0) return Color.FromArgb(0, 0, 0, 0);
-
+            if (x > Width - 1 || x < 0 || y > Height - 1 || y < 0)
+            {
+                return Color.FromArgb(0, 0, 0, 0);
+            }
+
             return LayerBitmap.GetPixel(x, y);
         }
 
@@ -209,7 +211,7 @@ namespace PixiEditor.Models.Layers
         /// <param name="applyOffset">Converts pixels coordinates to relative to bitmap</param>
         public void SetPixel(Coordinates coordinates, Color color, bool dynamicResize = true, bool applyOffset = true)
         {
-            SetPixels(BitmapPixelChanges.FromSingleColoredArray(new[] {coordinates}, color), dynamicResize, applyOffset);
+            SetPixels(BitmapPixelChanges.FromSingleColoredArray(new[] { coordinates }, color), dynamicResize, applyOffset);
         }
 
         /// <summary>
@@ -220,18 +222,32 @@ namespace PixiEditor.Models.Layers
         /// <param name="applyOffset">Converts pixels coordinates to relative to bitmap</param>
         public void SetPixels(BitmapPixelChanges pixels, bool dynamicResize = true, bool applyOffset = true)
         {
-            if (pixels.ChangedPixels == null || pixels.ChangedPixels.Count == 0) return;
-            if (dynamicResize)
-                DynamicResize(pixels);
-            if (applyOffset)
-                pixels.ChangedPixels = GetRelativePosition(pixels.ChangedPixels);
+            if (pixels.ChangedPixels == null || pixels.ChangedPixels.Count == 0)
+            {
+                return;
+            }
+
+            if (dynamicResize)
+            {
+                DynamicResize(pixels);
+            }
+
+            if (applyOffset)
+            {
+                pixels.ChangedPixels = GetRelativePosition(pixels.ChangedPixels);
+            }
+
             LastRelativeCoordinates = pixels.ChangedPixels;
 
-            using (var ctx = LayerBitmap.GetBitmapContext())
+            using (BitmapContext ctx = LayerBitmap.GetBitmapContext())
             {
-                foreach (var coords in pixels.ChangedPixels)
+                foreach (KeyValuePair<Coordinates, Color> coords in pixels.ChangedPixels)
                 {
-                    if (OutOfBounds(coords.Key)) continue;
+                    if (OutOfBounds(coords.Key))
+                    {
+                        continue;
+                    }
+
                     ctx.WriteableBitmap.SetPixel(coords.Key.X, coords.Key.Y, coords.Value);
                 }
             }
@@ -252,9 +268,12 @@ namespace PixiEditor.Models.Layers
         /// <returns></returns>
         public Coordinates[] ConvertToRelativeCoordinates(Coordinates[] nonRelativeCords)
         {
-            var result = new Coordinates[nonRelativeCords.Length];
-            for (var i = 0; i < nonRelativeCords.Length; i++) result[i] = new Coordinates(nonRelativeCords[i].X - OffsetX, nonRelativeCords[i].Y - OffsetY);
-
+            Coordinates[] result = new Coordinates[nonRelativeCords.Length];
+            for (int i = 0; i < nonRelativeCords.Length; i++)
+            {
+                result[i] = new Coordinates(nonRelativeCords[i].X - OffsetX, nonRelativeCords[i].Y - OffsetY);
+            }
+
             return result;
         }
 
@@ -264,44 +283,71 @@ namespace PixiEditor.Models.Layers
         /// <param name="pixels"></param>
         public void DynamicResize(BitmapPixelChanges pixels)
         {
-            if (pixels.ChangedPixels.Count == 0) return;
+            if (pixels.ChangedPixels.Count == 0)
+            {
+                return;
+            }
+
             ResetOffset(pixels);
-            var borderData = ExtractBorderData(pixels);
-            var minMaxCords = borderData.Item1;
-            var newMaxX = minMaxCords.Coords2.X - OffsetX;
-            var newMaxY = minMaxCords.Coords2.Y - OffsetY;
-            var newMinX = minMaxCords.Coords1.X - OffsetX;
-            var newMinY = minMaxCords.Coords1.Y - OffsetY;
+            Tuple<DoubleCords, bool> borderData = ExtractBorderData(pixels);
+            DoubleCords minMaxCords = borderData.Item1;
+            int newMaxX = minMaxCords.Coords2.X - OffsetX;
+            int newMaxY = minMaxCords.Coords2.Y - OffsetY;
+            int newMinX = minMaxCords.Coords1.X - OffsetX;
+            int newMinY = minMaxCords.Coords1.Y - OffsetY;
 
             if (!(pixels.WasBuiltAsSingleColored && pixels.ChangedPixels.First().Value.A == 0))
             {
-                if (newMaxX + 1 > Width || newMaxY + 1 > Height) IncreaseSizeToBottom(newMaxX, newMaxY);
-                if (newMinX < 0 || newMinY < 0) IncreaseSizeToTop(newMinX, newMinY);
+                if (newMaxX + 1 > Width || newMaxY + 1 > Height)
+                {
+                    IncreaseSizeToBottom(newMaxX, newMaxY);
+                }
+
+                if (newMinX < 0 || newMinY < 0)
+                {
+                    IncreaseSizeToTop(newMinX, newMinY);
+                }
             }
 
-            if (borderData.Item2) //if clip is requested
-                clipRequested = true;
+            if (borderData.Item2) // if clip is requested
+            {
+                clipRequested = true;
+            }
         }
 
         private Tuple<DoubleCords, bool> ExtractBorderData(BitmapPixelChanges pixels)
         {
-            var firstCords = pixels.ChangedPixels.First().Key;
-            var minX = firstCords.X;
-            var minY = firstCords.Y;
-            var maxX = minX;
-            var maxY = minY;
-            var clipRequested = false;
+            Coordinates firstCords = pixels.ChangedPixels.First().Key;
+            int minX = firstCords.X;
+            int minY = firstCords.Y;
+            int maxX = minX;
+            int maxY = minY;
+            bool clipRequested = false;
 
-            foreach (var pixel in pixels.ChangedPixels)
+            foreach (KeyValuePair<Coordinates, Color> pixel in pixels.ChangedPixels)
             {
-                if (pixel.Key.X < minX) minX = pixel.Key.X;
-                else if (pixel.Key.X > maxX) maxX = pixel.Key.X;
-
-                if (pixel.Key.Y < minY) minY = pixel.Key.Y;
-                else if (pixel.Key.Y > maxY) maxY = pixel.Key.Y;
-
-                if (clipRequested == false && IsBorderPixel(pixel.Key) && pixel.Value.A == 0)
-                    clipRequested = true;
+                if (pixel.Key.X < minX)
+                {
+                    minX = pixel.Key.X;
+                }
+                else if (pixel.Key.X > maxX)
+                {
+                    maxX = pixel.Key.X;
+                }
+
+                if (pixel.Key.Y < minY)
+                {
+                    minY = pixel.Key.Y;
+                }
+                else if (pixel.Key.Y > maxY)
+                {
+                    maxY = pixel.Key.Y;
+                }
+
+                if (clipRequested == false && IsBorderPixel(pixel.Key) && pixel.Value.A == 0)
+                {
+                    clipRequested = true;
+                }
             }
 
             return new Tuple<DoubleCords, bool>(
@@ -333,24 +379,30 @@ namespace PixiEditor.Models.Layers
         /// </summary>
         public void ClipCanvas()
         {
-            var points = GetEdgePoints();
-            var smallestX = points.Coords1.X;
-            var smallestY = points.Coords1.Y;
-            var biggestX = points.Coords2.X;
-            var biggestY = points.Coords2.Y;
-
-            if (smallestX < 0 && smallestY < 0 && biggestX < 0 && biggestY < 0)
-                return;
-
-            var width = biggestX - smallestX + 1;
-            var height = biggestY - smallestY + 1;
+            DoubleCords points = GetEdgePoints();
+            int smallestX = points.Coords1.X;
+            int smallestY = points.Coords1.Y;
+            int biggestX = points.Coords2.X;
+            int biggestY = points.Coords2.Y;
+
+            if (smallestX < 0 && smallestY < 0 && biggestX < 0 && biggestY < 0)
+            {
+                return;
+            }
+
+            int width = biggestX - smallestX + 1;
+            int height = biggestY - smallestY + 1;
             ResizeCanvas(0, 0, smallestX, smallestY, width, height);
             Offset = new Thickness(OffsetX + smallestX, OffsetY + smallestY, 0, 0);
         }
 
         private void IncreaseSizeToBottom(int newMaxX, int newMaxY)
         {
-            if (MaxWidth - OffsetX < 0 || MaxHeight - OffsetY < 0) return;
+            if (MaxWidth - OffsetX < 0 || MaxHeight - OffsetY < 0)
+            {
+                return;
+            }
+
             newMaxX = Math.Clamp(Math.Max(newMaxX + 1, Width), 0, MaxWidth - OffsetX);
             newMaxY = Math.Clamp(Math.Max(newMaxY + 1, Height), 0, MaxHeight - OffsetY);
 
@@ -365,19 +417,19 @@ namespace PixiEditor.Models.Layers
             Offset = new Thickness(Math.Clamp(OffsetX + newMinX, 0, MaxWidth),
                 Math.Clamp(OffsetY + newMinY, 0, MaxHeight), 0, 0);
 
-            var newWidth = Math.Clamp(Width - newMinX, 0, MaxWidth);
-            var newHeight = Math.Clamp(Height - newMinY, 0, MaxHeight);
+            int newWidth = Math.Clamp(Width - newMinX, 0, MaxWidth);
+            int newHeight = Math.Clamp(Height - newMinY, 0, MaxHeight);
 
-            var offsetX = Math.Abs(newWidth - Width);
-            var offsetY = Math.Abs(newHeight - Height);
+            int offsetX = Math.Abs(newWidth - Width);
+            int offsetY = Math.Abs(newHeight - Height);
 
             ResizeCanvas(offsetX, offsetY, 0, 0, newWidth, newHeight);
         }
 
         private DoubleCords GetEdgePoints()
         {
-            var smallestPixel = CoordinatesCalculator.FindMinEdgeNonTransparentPixel(LayerBitmap);
-            var biggestPixel = CoordinatesCalculator.FindMostEdgeNonTransparentPixel(LayerBitmap);
+            Coordinates smallestPixel = CoordinatesCalculator.FindMinEdgeNonTransparentPixel(LayerBitmap);
+            Coordinates biggestPixel = CoordinatesCalculator.FindMostEdgeNonTransparentPixel(LayerBitmap);
 
             return new DoubleCords(smallestPixel, biggestPixel);
         }
@@ -386,8 +438,8 @@ namespace PixiEditor.Models.Layers
         {
             if (Width == 0 || Height == 0)
             {
-                var offsetX = pixels.ChangedPixels.Min(x => x.Key.X);
-                var offsetY = pixels.ChangedPixels.Min(x => x.Key.Y);
+                int offsetX = pixels.ChangedPixels.Min(x => x.Key.X);
+                int offsetY = pixels.ChangedPixels.Min(x => x.Key.Y);
                 Offset = new Thickness(offsetX, offsetY, 0, 0);
             }
         }
@@ -407,7 +459,7 @@ namespace PixiEditor.Models.Layers
         public byte[] ConvertBitmapToBytes()
         {
             LayerBitmap.Lock();
-            var byteArray = LayerBitmap.ToByteArray();
+            byte[] byteArray = LayerBitmap.ToByteArray();
             LayerBitmap.Unlock();
             return byteArray;
         }
@@ -423,18 +475,18 @@ namespace PixiEditor.Models.Layers
         /// <param name="newHeight"></param>
         private void ResizeCanvas(int offsetX, int offsetY, int offsetXSrc, int offsetYSrc, int newWidth, int newHeight)
         {
-            var iteratorHeight = Height > newHeight ? newHeight : Height;
-            var count = Width > newWidth ? newWidth : Width;
+            int iteratorHeight = Height > newHeight ? newHeight : Height;
+            int count = Width > newWidth ? newWidth : Width;
 
-            using (var srcContext = LayerBitmap.GetBitmapContext(ReadWriteMode.ReadOnly))
+            using (BitmapContext srcContext = LayerBitmap.GetBitmapContext(ReadWriteMode.ReadOnly))
             {
-                var result = BitmapFactory.New(newWidth, newHeight);
-                using (var destContext = result.GetBitmapContext())
+                WriteableBitmap result = BitmapFactory.New(newWidth, newHeight);
+                using (BitmapContext destContext = result.GetBitmapContext())
                 {
-                    for (var line = 0; line < iteratorHeight; line++)
+                    for (int line = 0; line < iteratorHeight; line++)
                     {
-                        var srcOff = ((offsetYSrc + line) * Width + offsetXSrc) * SizeOfArgb;
-                        var dstOff = ((offsetY + line) * newWidth + offsetX) * SizeOfArgb;
+                        int srcOff = ((offsetYSrc + line) * Width + offsetXSrc) * SizeOfArgb;
+                        int dstOff = ((offsetY + line) * newWidth + offsetX) * SizeOfArgb;
                         BitmapContext.BlockCopy(srcContext, srcOff, destContext, dstOff, count * SizeOfArgb);
                     }
 

+ 18 - 6
PixiEditor/Models/Layers/SerializableLayer.cs

@@ -13,29 +13,41 @@ namespace PixiEditor.Models.Layers
             Height = layer.Height;
             BitmapBytes = layer.ConvertBitmapToBytes();
             IsVisible = layer.IsVisible;
-            OffsetX = (int) layer.Offset.Left;
-            OffsetY = (int) layer.Offset.Top;
+            OffsetX = (int)layer.Offset.Left;
+            OffsetY = (int)layer.Offset.Top;
             Opacity = layer.Opacity;
             MaxWidth = layer.MaxWidth;
             MaxHeight = layer.MaxHeight;
         }
 
         public string Name { get; set; }
+
         public int Width { get; set; }
+
         public int Height { get; set; }
+
         public int MaxWidth { get; set; }
+
         public int MaxHeight { get; set; }
+
         public byte[] BitmapBytes { get; set; }
+
         public bool IsVisible { get; set; }
+
         public int OffsetX { get; set; }
+
         public int OffsetY { get; set; }
+
         public float Opacity { get; set; }
 
         public override bool Equals(object? obj)
         {
-            if (obj == null || obj.GetType() != typeof(SerializableLayer)) return false;
-
-            var layer = (SerializableLayer) obj;
+            if (obj == null || obj.GetType() != typeof(SerializableLayer))
+            {
+                return false;
+            }
+
+            SerializableLayer layer = (SerializableLayer)obj;
 
             return Equals(layer);
         }
@@ -48,7 +60,7 @@ namespace PixiEditor.Models.Layers
 
         public override int GetHashCode()
         {
-            var hashCode = new HashCode();
+            HashCode hashCode = new HashCode();
             hashCode.Add(Name);
             hashCode.Add(Width);
             hashCode.Add(Height);

+ 4 - 1
PixiEditor/Models/Position/Coordinates.cs

@@ -31,7 +31,10 @@ namespace PixiEditor.Models.Position
 
         public override bool Equals(object obj)
         {
-            if (obj is Coordinates coords) return this == coords;
+            if (obj is Coordinates coords)
+            {
+                return this == coords;
+            }
 
             return false;
         }

+ 55 - 31
PixiEditor/Models/Position/CoordinatesCalculator.cs

@@ -36,8 +36,8 @@ namespace PixiEditor.Models.Position
 
         public static Coordinates GetCenterPoint(Coordinates startingPoint, Coordinates endPoint)
         {
-            var x = (int) Math.Floor((startingPoint.X + endPoint.X) / 2f);
-            var y = (int) Math.Floor((startingPoint.Y + endPoint.Y) / 2f);
+            int x = (int)Math.Floor((startingPoint.X + endPoint.X) / 2f);
+            int y = (int)Math.Floor((startingPoint.Y + endPoint.Y) / 2f);
             return new Coordinates(x, y);
         }
 
@@ -53,10 +53,15 @@ namespace PixiEditor.Models.Position
         {
             x2++;
             y2++;
-            var coordinates = new List<Coordinates>();
-            for (var y = y1; y < y1 + (y2 - y1); y++)
-            for (var x = x1; x < x1 + (x2 - x1); x++)
-                coordinates.Add(new Coordinates(x, y));
+            List<Coordinates> coordinates = new List<Coordinates>();
+            for (int y = y1; y < y1 + (y2 - y1); y++)
+            {
+                for (int x = x1; x < x1 + (x2 - x1); x++)
+                {
+                    coordinates.Add(new Coordinates(x, y));
+                }
+            }
+
             return coordinates.ToArray();
         }
 
@@ -86,42 +91,57 @@ namespace PixiEditor.Models.Position
             return new Coordinates(FindMaxXNonTransparent(bitmap), FindMaxYNonTransparent(bitmap));
         }
 
-
         public static int FindMinYNonTransparent(WriteableBitmap bitmap)
         {
-            var transparent = Color.FromArgb(0, 0, 0, 0);
-            using var ctx = bitmap.GetBitmapContext(ReadWriteMode.ReadOnly);
-            for (var y = 0; y < ctx.Height; y++)
-            for (var x = 0; x < ctx.Width; x++)
-                if (ctx.WriteableBitmap.GetPixel(x, y) != transparent)
-                    return y;
+            Color transparent = Color.FromArgb(0, 0, 0, 0);
+            using BitmapContext ctx = bitmap.GetBitmapContext(ReadWriteMode.ReadOnly);
+            for (int y = 0; y < ctx.Height; y++)
+            {
+                for (int x = 0; x < ctx.Width; x++)
+                {
+                    if (ctx.WriteableBitmap.GetPixel(x, y) != transparent)
+                    {
+                        return y;
+                    }
+                }
+            }
 
             return -1;
         }
 
         public static int FindMinXNonTransparent(WriteableBitmap bitmap)
         {
-            var transparent = Color.FromArgb(0, 0, 0, 0);
-            using var ctx = bitmap.GetBitmapContext(ReadWriteMode.ReadOnly);
-            for (var x = 0; x < ctx.Width; x++)
-            for (var y = 0; y < ctx.Height; y++)
-                if (bitmap.GetPixel(x, y) != transparent)
-                    return x;
+            Color transparent = Color.FromArgb(0, 0, 0, 0);
+            using BitmapContext ctx = bitmap.GetBitmapContext(ReadWriteMode.ReadOnly);
+            for (int x = 0; x < ctx.Width; x++)
+            {
+                for (int y = 0; y < ctx.Height; y++)
+                {
+                    if (bitmap.GetPixel(x, y) != transparent)
+                    {
+                        return x;
+                    }
+                }
+            }
 
             return -1;
         }
 
         public static int FindMaxYNonTransparent(WriteableBitmap bitmap)
         {
-            var transparent = Color.FromArgb(0, 0, 0, 0);
+            Color transparent = Color.FromArgb(0, 0, 0, 0);
             bitmap.Lock();
-            for (var y = (int) bitmap.Height - 1; y >= 0; y--)
-            for (var x = (int) bitmap.Width - 1; x >= 0; x--)
-                if (bitmap.GetPixel(x, y) != transparent)
+            for (int y = (int)bitmap.Height - 1; y >= 0; y--)
+            {
+                for (int x = (int)bitmap.Width - 1; x >= 0; x--)
                 {
-                    bitmap.Unlock();
-                    return y;
+                    if (bitmap.GetPixel(x, y) != transparent)
+                    {
+                        bitmap.Unlock();
+                        return y;
+                    }
                 }
+            }
 
             bitmap.Unlock();
             return -1;
@@ -129,15 +149,19 @@ namespace PixiEditor.Models.Position
 
         public static int FindMaxXNonTransparent(WriteableBitmap bitmap)
         {
-            var transparent = Color.FromArgb(0, 0, 0, 0);
+            Color transparent = Color.FromArgb(0, 0, 0, 0);
             bitmap.Lock();
-            for (var x = (int) bitmap.Width - 1; x >= 0; x--)
-            for (var y = (int) bitmap.Height - 1; y >= 0; y--)
-                if (bitmap.GetPixel(x, y) != transparent)
+            for (int x = (int)bitmap.Width - 1; x >= 0; x--)
+            {
+                for (int y = (int)bitmap.Height - 1; y >= 0; y--)
                 {
-                    bitmap.Unlock();
-                    return x;
+                    if (bitmap.GetPixel(x, y) != transparent)
+                    {
+                        bitmap.Unlock();
+                        return x;
+                    }
                 }
+            }
 
             bitmap.Unlock();
             return -1;

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

@@ -3,6 +3,7 @@
     public struct DoubleCords
     {
         public Coordinates Coords1 { get; set; }
+
         public Coordinates Coords2 { get; set; }
 
         public DoubleCords(Coordinates cords1, Coordinates cords2)

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

@@ -12,8 +12,7 @@ namespace PixiEditor.Models.Position
 
         public static Point GetCursorPosition()
         {
-            Point point;
-            GetCursorPos(out point);
+            GetCursorPos(out Point point);
             return point;
         }
     }

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

@@ -8,17 +8,19 @@ namespace PixiEditor.Models.Tools
     public abstract class BitmapOperationTool : Tool
     {
         public bool RequiresPreviewLayer { get; set; }
+
         public bool UseDefaultUndoMethod { get; set; } = true;
+
         public abstract LayerChange[] Use(Layer layer, Coordinates[] mouseMove, Color color);
 
         protected LayerChange[] Only(BitmapPixelChanges changes, Layer layer)
         {
-            return new[] {new LayerChange(changes, layer)};
+            return new[] { new LayerChange(changes, layer) };
         }
 
         protected LayerChange[] Only(BitmapPixelChanges changes, int layerIndex)
         {
-            return new[] {new LayerChange(changes, layerIndex)};
+            return new[] { new LayerChange(changes, layerIndex) };
         }
     }
 }

+ 28 - 14
PixiEditor/Models/Tools/ShapeTool.cs

@@ -24,32 +24,46 @@ namespace PixiEditor.Models.Tools
 
         protected IEnumerable<Coordinates> GetThickShape(IEnumerable<Coordinates> shape, int thickness)
         {
-            var output = new List<Coordinates>();
-            foreach (var item in shape)
+            List<Coordinates> output = new List<Coordinates>();
+            foreach (Coordinates item in shape)
+            {
                 output.AddRange(
                     CoordinatesCalculator.RectangleToCoordinates(
-                        CoordinatesCalculator.CalculateThicknessCenter(item, thickness)));
+                        CoordinatesCalculator.CalculateThicknessCenter(item, thickness)));
+            }
+
             return output.Distinct();
         }
-
-
+
         protected DoubleCords CalculateCoordinatesForShapeRotation(Coordinates startingCords,
             Coordinates secondCoordinates)
         {
-            var currentCoordinates = secondCoordinates;
+            Coordinates currentCoordinates = secondCoordinates;
 
-            if (startingCords.X > currentCoordinates.X && startingCords.Y > currentCoordinates.Y)
+            if (startingCords.X > currentCoordinates.X && startingCords.Y > currentCoordinates.Y)
+            {
                 return new DoubleCords(new Coordinates(currentCoordinates.X, currentCoordinates.Y),
-                    new Coordinates(startingCords.X, startingCords.Y));
-            if (startingCords.X < currentCoordinates.X && startingCords.Y < currentCoordinates.Y)
+                    new Coordinates(startingCords.X, startingCords.Y));
+            }
+
+            if (startingCords.X < currentCoordinates.X && startingCords.Y < currentCoordinates.Y)
+            {
                 return new DoubleCords(new Coordinates(startingCords.X, startingCords.Y),
-                    new Coordinates(currentCoordinates.X, currentCoordinates.Y));
-            if (startingCords.Y > currentCoordinates.Y)
+                    new Coordinates(currentCoordinates.X, currentCoordinates.Y));
+            }
+
+            if (startingCords.Y > currentCoordinates.Y)
+            {
                 return new DoubleCords(new Coordinates(startingCords.X, currentCoordinates.Y),
-                    new Coordinates(currentCoordinates.X, startingCords.Y));
-            if (startingCords.X > currentCoordinates.X && startingCords.Y <= currentCoordinates.Y)
+                    new Coordinates(currentCoordinates.X, startingCords.Y));
+            }
+
+            if (startingCords.X > currentCoordinates.X && startingCords.Y <= currentCoordinates.Y)
+            {
                 return new DoubleCords(new Coordinates(currentCoordinates.X, startingCords.Y),
-                    new Coordinates(startingCords.X, currentCoordinates.Y));
+                    new Coordinates(startingCords.X, currentCoordinates.Y));
+            }
+
             return new DoubleCords(startingCords, secondCoordinates);
         }
     }

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

@@ -8,9 +8,13 @@ namespace PixiEditor.Models.Tools
     public abstract class Tool : NotifyableObject
     {
         private bool isActive;
+
         public abstract ToolType ToolType { get; }
+
         public string ImagePath => $"/Images/{ToolType}Image.png";
+
         public bool HideHighlight { get; set; } = false;
+
         public string Tooltip { get; set; }
 
         public bool IsActive
@@ -26,6 +30,7 @@ namespace PixiEditor.Models.Tools
         public Cursor Cursor { get; set; } = Cursors.Arrow;
 
         public Toolbar Toolbar { get; set; } = new EmptyToolbar();
+
         public bool CanStartOutsideCanvas { get; set; } = false;
 
         public virtual void OnMouseDown(MouseEventArgs e)

+ 6 - 4
PixiEditor/Models/Tools/ToolSettings/Settings/BoolSetting.cs

@@ -7,14 +7,16 @@ namespace PixiEditor.Models.Tools.ToolSettings.Settings
 {
     public class BoolSetting : Setting<bool>
     {
-        public BoolSetting(string name, string label = "") : base(name)
+        public BoolSetting(string name, string label = "")
+            : base(name)
         {
             Label = label;
             Value = false;
             SettingControl = GenerateCheckBox();
         }
 
-        public BoolSetting(string name, bool isChecked, string label = "") : base(name)
+        public BoolSetting(string name, bool isChecked, string label = "")
+            : base(name)
         {
             Label = label;
             Value = isChecked;
@@ -23,13 +25,13 @@ namespace PixiEditor.Models.Tools.ToolSettings.Settings
 
         private Control GenerateCheckBox()
         {
-            var checkBox = new CheckBox
+            CheckBox checkBox = new CheckBox
             {
                 IsChecked = Value,
                 VerticalAlignment = VerticalAlignment.Center
             };
 
-            var binding = new Binding("Value")
+            Binding binding = new Binding("Value")
             {
                 Mode = BindingMode.TwoWay
             };

+ 4 - 3
PixiEditor/Models/Tools/ToolSettings/Settings/ColorSetting.cs

@@ -6,7 +6,8 @@ namespace PixiEditor.Models.Tools.ToolSettings.Settings
 {
     public class ColorSetting : Setting<Color>
     {
-        public ColorSetting(string name, string label = "") : base(name)
+        public ColorSetting(string name, string label = "")
+            : base(name)
         {
             Label = label;
             SettingControl = GenerateColorPicker();
@@ -15,8 +16,8 @@ namespace PixiEditor.Models.Tools.ToolSettings.Settings
 
         private PortableColorPicker GenerateColorPicker()
         {
-            var picker = new PortableColorPicker();
-            var binding = new Binding("Value")
+            PortableColorPicker picker = new PortableColorPicker();
+            Binding binding = new Binding("Value")
             {
                 Mode = BindingMode.TwoWay
             };

+ 8 - 8
PixiEditor/Models/Tools/ToolSettings/Settings/DropdownSetting.cs

@@ -7,26 +7,26 @@ namespace PixiEditor.Models.Tools.ToolSettings.Settings
 {
     public class DropdownSetting : Setting<object>
     {
-        public DropdownSetting(string name, string[] values, string label) : base(name)
+        public DropdownSetting(string name, string[] values, string label)
+            : base(name)
         {
             Values = values;
             SettingControl = GenerateDropdown();
-            Value = ((ComboBox) SettingControl).Items[0];
+            Value = ((ComboBox)SettingControl).Items[0];
             Label = label;
         }
 
         public string[] Values { get; set; }
-
-
+
         private ComboBox GenerateDropdown()
         {
-            var combobox = new ComboBox
+            ComboBox combobox = new ComboBox
             {
                 VerticalAlignment = VerticalAlignment.Center
             };
             GenerateItems(combobox);
 
-            var binding = new Binding("Value")
+            Binding binding = new Binding("Value")
             {
                 Mode = BindingMode.TwoWay
             };
@@ -36,9 +36,9 @@ namespace PixiEditor.Models.Tools.ToolSettings.Settings
 
         private void GenerateItems(ComboBox comboBox)
         {
-            for (var i = 0; i < Values.Length; i++)
+            for (int i = 0; i < Values.Length; i++)
             {
-                var item = new ComboBoxItem
+                ComboBoxItem item = new ComboBoxItem
                 {
                     Content = Values[i]
                 };

+ 5 - 3
PixiEditor/Models/Tools/ToolSettings/Settings/FloatSetting.cs

@@ -6,7 +6,8 @@ namespace PixiEditor.Models.Tools.ToolSettings.Settings
     public class FloatSetting : Setting<float>
     {
         public FloatSetting(string name, float initialValue, string label = "",
-            float min = float.NegativeInfinity, float max = float.PositiveInfinity) : base(name)
+            float min = float.NegativeInfinity, float max = float.PositiveInfinity)
+            : base(name)
         {
             Label = label;
             Value = initialValue;
@@ -16,18 +17,19 @@ namespace PixiEditor.Models.Tools.ToolSettings.Settings
         }
 
         public float Min { get; set; }
+
         public float Max { get; set; }
 
         private NumberInput GenerateNumberInput()
         {
-            var numbrInput = new NumberInput
+            NumberInput numbrInput = new NumberInput
             {
                 Width = 40,
                 Height = 20,
                 Min = Min,
                 Max = Max
             };
-            var binding = new Binding("Value")
+            Binding binding = new Binding("Value")
             {
                 Mode = BindingMode.TwoWay
             };

+ 10 - 6
PixiEditor/Models/Tools/ToolSettings/Settings/SizeSetting.cs

@@ -9,7 +9,8 @@ namespace PixiEditor.Models.Tools.ToolSettings.Settings
 {
     public class SizeSetting : Setting<int>
     {
-        public SizeSetting(string name, string label = null) : base(name)
+        public SizeSetting(string name, string label = null)
+            : base(name)
         {
             Value = 1;
             SettingControl = GenerateTextBox();
@@ -18,7 +19,7 @@ namespace PixiEditor.Models.Tools.ToolSettings.Settings
 
         private TextBox GenerateTextBox()
         {
-            var tb = new TextBox
+            TextBox tb = new TextBox
             {
                 TextAlignment = TextAlignment.Center,
                 MaxLength = 4,
@@ -26,15 +27,18 @@ namespace PixiEditor.Models.Tools.ToolSettings.Settings
                 Height = 20
             };
 
-            if (Application.Current != null) tb.Style = (Style) Application.Current.TryFindResource("DarkTextBoxStyle");
-
-            var binding = new Binding("Value")
+            if (Application.Current != null)
+            {
+                tb.Style = (Style)Application.Current.TryFindResource("DarkTextBoxStyle");
+            }
+
+            Binding binding = new Binding("Value")
             {
                 Converter = new ToolSizeToIntConverter(),
                 Mode = BindingMode.TwoWay
             };
             tb.SetBinding(TextBox.TextProperty, binding);
-            var behavor = new TextBoxFocusBehavior
+            TextBoxFocusBehavior behavor = new TextBoxFocusBehavior
             {
                 FillSize = true
             };

+ 1 - 1
PixiEditor/Models/Tools/ToolSettings/Toolbars/SelectToolToolbar.cs

@@ -6,7 +6,7 @@ namespace PixiEditor.Models.Tools.ToolSettings.Toolbars
     {
         public SelectToolToolbar()
         {
-            Settings.Add(new DropdownSetting("Mode", new[] {"New", "Add", "Subtract"}, "Selection type"));
+            Settings.Add(new DropdownSetting("Mode", new[] { "New", "Add", "Subtract" }, "Selection type"));
         }
     }
 }

+ 21 - 12
PixiEditor/Models/Tools/ToolSettings/Toolbars/Toolbar.cs

@@ -9,6 +9,7 @@ namespace PixiEditor.Models.Tools.ToolSettings.Toolbars
     public abstract class Toolbar
     {
         private static readonly List<Setting> SharedSettings = new List<Setting>();
+
         public ObservableCollection<Setting> Settings { get; set; } = new ObservableCollection<Setting>();
 
         /// <summary>
@@ -29,11 +30,13 @@ namespace PixiEditor.Models.Tools.ToolSettings.Toolbars
         public T GetSetting<T>(string name)
             where T : Setting
         {
-            var setting = Settings.FirstOrDefault(currentSetting => string.Equals(currentSetting.Name, name, StringComparison.CurrentCultureIgnoreCase));
-
-            if (setting == null || !(setting is T convertedSetting))
-                return null;
+            Setting setting = Settings.FirstOrDefault(currentSetting => string.Equals(currentSetting.Name, name, StringComparison.CurrentCultureIgnoreCase));
 
+            if (setting == null || !(setting is T convertedSetting))
+            {
+                return null;
+            }
+
             return convertedSetting;
         }
 
@@ -42,8 +45,10 @@ namespace PixiEditor.Models.Tools.ToolSettings.Toolbars
         /// </summary>
         public void SaveToolbarSettings()
         {
-            foreach (var setting in Settings)
-                AddSettingToCollection(SharedSettings, setting);
+            foreach (Setting setting in Settings)
+            {
+                AddSettingToCollection(SharedSettings, setting);
+            }
         }
 
         /// <summary>
@@ -51,16 +56,20 @@ namespace PixiEditor.Models.Tools.ToolSettings.Toolbars
         /// </summary>
         public void LoadSharedSettings()
         {
-            foreach (var sharedSetting in SharedSettings)
-                AddSettingToCollection(Settings, sharedSetting);
+            foreach (Setting sharedSetting in SharedSettings)
+            {
+                AddSettingToCollection(Settings, sharedSetting);
+            }
         }
 
         private static void AddSettingToCollection(ICollection<Setting> collection, Setting setting)
         {
-            var storedSetting = collection.FirstOrDefault(currentSetting => currentSetting.Name == setting.Name);
-            if (storedSetting != null)
-                collection.Remove(storedSetting);
-
+            Setting storedSetting = collection.FirstOrDefault(currentSetting => currentSetting.Name == setting.Name);
+            if (storedSetting != null)
+            {
+                collection.Remove(storedSetting);
+            }
+
             collection.Add(setting);
         }
     }

+ 25 - 16
PixiEditor/Models/Tools/Tools/BrightnessTool.cs

@@ -15,7 +15,7 @@ namespace PixiEditor.Models.Tools.Tools
 {
     public class BrightnessTool : BitmapOperationTool
     {
-        private const float CorrectionFactor = 5f; //Initial correction factor
+        private const float CorrectionFactor = 5f; // Initial correction factor
 
         private readonly List<Coordinates> pixelsVisited = new List<Coordinates>();
 
@@ -26,6 +26,7 @@ namespace PixiEditor.Models.Tools.Tools
         }
 
         public override ToolType ToolType => ToolType.Brightness;
+
         public BrightnessMode Mode { get; set; } = BrightnessMode.Default;
 
         public override void OnMouseDown(MouseEventArgs e)
@@ -35,41 +36,49 @@ namespace PixiEditor.Models.Tools.Tools
 
         public override LayerChange[] Use(Layer layer, Coordinates[] coordinates, Color color)
         {
-            var toolSize = Toolbar.GetSetting<SizeSetting>("ToolSize").Value;
-            var correctionFactor = Toolbar.GetSetting<FloatSetting>("CorrectionFactor").Value;
+            int toolSize = Toolbar.GetSetting<SizeSetting>("ToolSize").Value;
+            float correctionFactor = Toolbar.GetSetting<FloatSetting>("CorrectionFactor").Value;
             Enum.TryParse((Toolbar.GetSetting<DropdownSetting>("Mode")?.Value as ComboBoxItem)?.Content as string, out BrightnessMode mode);
             Mode = mode;
 
-            var layersChanges = new LayerChange[1];
-            if (Keyboard.IsKeyDown(Key.LeftCtrl))
+            LayerChange[] layersChanges = new LayerChange[1];
+            if (Keyboard.IsKeyDown(Key.LeftCtrl))
+            {
                 layersChanges[0] = new LayerChange(ChangeBrightness(layer, coordinates[0], toolSize, -correctionFactor),
-                    layer);
-            else
+                    layer);
+            }
+            else
+            {
                 layersChanges[0] = new LayerChange(ChangeBrightness(layer, coordinates[0], toolSize, correctionFactor),
-                    layer);
+                    layer);
+            }
+
             return layersChanges;
         }
 
         public BitmapPixelChanges ChangeBrightness(Layer layer, Coordinates coordinates, int toolSize,
             float correctionFactor)
         {
-            var centeredCoords = CoordinatesCalculator.CalculateThicknessCenter(coordinates, toolSize);
-            var rectangleCoordinates = CoordinatesCalculator.RectangleToCoordinates(centeredCoords.Coords1.X,
+            DoubleCords centeredCoords = CoordinatesCalculator.CalculateThicknessCenter(coordinates, toolSize);
+            Coordinates[] rectangleCoordinates = CoordinatesCalculator.RectangleToCoordinates(centeredCoords.Coords1.X,
                 centeredCoords.Coords1.Y,
                 centeredCoords.Coords2.X, centeredCoords.Coords2.Y);
-            var changes = new BitmapPixelChanges(new Dictionary<Coordinates, Color>());
+            BitmapPixelChanges changes = new BitmapPixelChanges(new Dictionary<Coordinates, Color>());
 
-            for (var i = 0; i < rectangleCoordinates.Length; i++)
+            for (int i = 0; i < rectangleCoordinates.Length; i++)
             {
                 if (Mode == BrightnessMode.Default)
                 {
-                    if (pixelsVisited.Contains(rectangleCoordinates[i]))
-                        continue;
+                    if (pixelsVisited.Contains(rectangleCoordinates[i]))
+                    {
+                        continue;
+                    }
+
                     pixelsVisited.Add(rectangleCoordinates[i]);
                 }
 
-                var pixel = layer.GetPixelWithOffset(rectangleCoordinates[i].X, rectangleCoordinates[i].Y);
-                var newColor = ExColor.ChangeColorBrightness(Color.FromArgb(pixel.A, pixel.R, pixel.G, pixel.B),
+                Color pixel = layer.GetPixelWithOffset(rectangleCoordinates[i].X, rectangleCoordinates[i].Y);
+                Color newColor = ExColor.ChangeColorBrightness(Color.FromArgb(pixel.A, pixel.R, pixel.G, pixel.B),
                     correctionFactor);
                 changes.ChangedPixels.Add(new Coordinates(rectangleCoordinates[i].X, rectangleCoordinates[i].Y),
                     newColor);

+ 59 - 45
PixiEditor/Models/Tools/Tools/CircleTool.cs

@@ -21,19 +21,19 @@ namespace PixiEditor.Models.Tools.Tools
 
         public override LayerChange[] Use(Layer layer, Coordinates[] coordinates, Color color)
         {
-            var thickness = Toolbar.GetSetting<SizeSetting>("ToolSize").Value;
-            var fixedCoordinates = CalculateCoordinatesForShapeRotation(coordinates[^1], coordinates[0]);
-            var outline = CreateEllipse(fixedCoordinates.Coords1, fixedCoordinates.Coords2, thickness);
-            var pixels = BitmapPixelChanges.FromSingleColoredArray(outline, color);
+            int thickness = Toolbar.GetSetting<SizeSetting>("ToolSize").Value;
+            DoubleCords fixedCoordinates = CalculateCoordinatesForShapeRotation(coordinates[^1], coordinates[0]);
+            IEnumerable<Coordinates> outline = CreateEllipse(fixedCoordinates.Coords1, fixedCoordinates.Coords2, thickness);
+            BitmapPixelChanges pixels = BitmapPixelChanges.FromSingleColoredArray(outline, color);
             if (Toolbar.GetSetting<BoolSetting>("Fill").Value)
             {
-                var fillColor = Toolbar.GetSetting<ColorSetting>("FillColor").Value;
+                Color fillColor = Toolbar.GetSetting<ColorSetting>("FillColor").Value;
                 pixels.ChangedPixels.AddRangeNewOnly(
                     BitmapPixelChanges.FromSingleColoredArray(CalculateFillForEllipse(outline), fillColor)
                         .ChangedPixels);
             }
 
-            return new[] {new LayerChange(pixels, layer)};
+            return new[] { new LayerChange(pixels, layer) };
         }
 
         /// <summary>
@@ -47,8 +47,8 @@ namespace PixiEditor.Models.Tools.Tools
         public IEnumerable<Coordinates> CreateEllipse(Coordinates startCoordinates, Coordinates endCoordinates, int thickness,
             bool filled)
         {
-            var output = new List<Coordinates>();
-            var outline = CreateEllipse(startCoordinates, endCoordinates, thickness);
+            List<Coordinates> output = new List<Coordinates>();
+            IEnumerable<Coordinates> outline = CreateEllipse(startCoordinates, endCoordinates, thickness);
             output.AddRange(outline);
             if (filled)
             {
@@ -68,55 +68,64 @@ namespace PixiEditor.Models.Tools.Tools
         /// <returns>Coordinates for ellipse</returns>
         public IEnumerable<Coordinates> CreateEllipse(Coordinates startCoordinates, Coordinates endCoordinates, int thickness)
         {
-            var radiusX = (endCoordinates.X - startCoordinates.X) / 2.0;
-            var radiusY = (endCoordinates.Y - startCoordinates.Y) / 2.0;
-            var centerX = (startCoordinates.X + endCoordinates.X + 1) / 2.0;
-            var centerY = (startCoordinates.Y + endCoordinates.Y + 1) / 2.0;
+            double radiusX = (endCoordinates.X - startCoordinates.X) / 2.0;
+            double radiusY = (endCoordinates.Y - startCoordinates.Y) / 2.0;
+            double centerX = (startCoordinates.X + endCoordinates.X + 1) / 2.0;
+            double centerY = (startCoordinates.Y + endCoordinates.Y + 1) / 2.0;
 
-            var output = new List<Coordinates>();
-            var ellipse = MidpointEllipse(radiusX, radiusY, centerX, centerY);
+            List<Coordinates> output = new List<Coordinates>();
+            IEnumerable<Coordinates> ellipse = MidpointEllipse(radiusX, radiusY, centerX, centerY);
             if (thickness == 1)
+            {
                 output.AddRange(ellipse);
+            }
             else
+            {
                 output.AddRange(GetThickShape(ellipse, thickness));
+            }
+
             return output.Distinct();
         }
 
         public IEnumerable<Coordinates> MidpointEllipse(double halfWidth, double halfHeight, double centerX, double centerY)
         {
             if (halfWidth < 1 || halfHeight < 1)
+            {
                 return FallbackRectangle(halfWidth, halfHeight, centerX, centerY);
+            }
 
-            //ellipse formula: halfHeight^2 * x^2 + halfWidth^2 * y^2 - halfHeight^2 * halfWidth^2 = 0
+            // ellipse formula: halfHeight^2 * x^2 + halfWidth^2 * y^2 - halfHeight^2 * halfWidth^2 = 0
 
-            //Make sure we are always at the center of a pixel
-            var currentX = Math.Ceiling(centerX - 0.5) + 0.5;
-            var currentY = centerY + halfHeight;
+            // Make sure we are always at the center of a pixel
+            double currentX = Math.Ceiling(centerX - 0.5) + 0.5;
+            double currentY = centerY + halfHeight;
 
-            var outputCoordinates = new List<Coordinates>();
+            List<Coordinates> outputCoordinates = new List<Coordinates>();
 
             double currentSlope;
 
-            //from PI/2 to middle
+            // from PI/2 to middle
             do
             {
                 outputCoordinates.AddRange(GetRegionPoints(currentX, centerX, currentY, centerY));
 
-                //calculate next pixel coords
+                // calculate next pixel coords
                 currentX++;
 
                 if (Math.Pow(halfHeight, 2) * Math.Pow(currentX - centerX, 2) +
                     Math.Pow(halfWidth, 2) * Math.Pow(currentY - centerY - 0.5, 2) -
                     Math.Pow(halfWidth, 2) * Math.Pow(halfHeight, 2) >= 0)
+                {
                     currentY--;
+                }
 
-                //calculate how far we've advanced
-                var derivativeX = 2 * Math.Pow(halfHeight, 2) * (currentX - centerX);
-                var derivativeY = 2 * Math.Pow(halfWidth, 2) * (currentY - centerY);
+                // calculate how far we've advanced
+                double derivativeX = 2 * Math.Pow(halfHeight, 2) * (currentX - centerX);
+                double derivativeY = 2 * Math.Pow(halfWidth, 2) * (currentY - centerY);
                 currentSlope = -(derivativeX / derivativeY);
             } while (currentSlope > -1 && currentY - centerY > 0.5);
 
-            //from middle to 0
+            // from middle to 0
             while (currentY - centerY >= 0)
             {
                 outputCoordinates.AddRange(GetRegionPoints(currentX, centerX, currentY, centerY));
@@ -125,7 +134,9 @@ namespace PixiEditor.Models.Tools.Tools
                 if (Math.Pow(halfHeight, 2) * Math.Pow(currentX - centerX + 0.5, 2) +
                     Math.Pow(halfWidth, 2) * Math.Pow(currentY - centerY, 2) -
                     Math.Pow(halfWidth, 2) * Math.Pow(halfHeight, 2) < 0)
+                {
                     currentX++;
+                }
             }
 
             return outputCoordinates;
@@ -133,17 +144,17 @@ namespace PixiEditor.Models.Tools.Tools
 
         private Coordinates[] FallbackRectangle(double halfWidth, double halfHeight, double centerX, double centerY)
         {
-            var coordinates = new List<Coordinates>();
-            for (var x = centerX - halfWidth; x <= centerX + halfWidth; x++)
+            List<Coordinates> coordinates = new List<Coordinates>();
+            for (double x = centerX - halfWidth; x <= centerX + halfWidth; x++)
             {
-                coordinates.Add(new Coordinates((int) x, (int) (centerY - halfHeight)));
-                coordinates.Add(new Coordinates((int) x, (int) (centerY + halfHeight)));
+                coordinates.Add(new Coordinates((int)x, (int)(centerY - halfHeight)));
+                coordinates.Add(new Coordinates((int)x, (int)(centerY + halfHeight)));
             }
 
-            for (var y = centerY - halfHeight + 1; y <= centerY + halfHeight - 1; y++)
+            for (double y = centerY - halfHeight + 1; y <= centerY + halfHeight - 1; y++)
             {
-                coordinates.Add(new Coordinates((int) (centerX - halfWidth), (int) y));
-                coordinates.Add(new Coordinates((int) (centerX + halfWidth), (int) y));
+                coordinates.Add(new Coordinates((int)(centerX - halfWidth), (int)y));
+                coordinates.Add(new Coordinates((int)(centerX + halfWidth), (int)y));
             }
 
             return coordinates.ToArray();
@@ -151,15 +162,18 @@ namespace PixiEditor.Models.Tools.Tools
 
         private IEnumerable<Coordinates> CalculateFillForEllipse(IEnumerable<Coordinates> outlineCoordinates)
         {
-            var finalCoordinates = new List<Coordinates>();
-            var bottom = outlineCoordinates.Max(x => x.Y);
-            var top = outlineCoordinates.Min(x => x.Y);
-            for (var i = top + 1; i < bottom; i++)
+            List<Coordinates> finalCoordinates = new List<Coordinates>();
+            int bottom = outlineCoordinates.Max(x => x.Y);
+            int top = outlineCoordinates.Min(x => x.Y);
+            for (int i = top + 1; i < bottom; i++)
             {
-                var rowCords = outlineCoordinates.Where(x => x.Y == i);
-                var right = rowCords.Max(x => x.X);
-                var left = rowCords.Min(x => x.X);
-                for (var j = left + 1; j < right; j++) finalCoordinates.Add(new Coordinates(j, i));
+                IEnumerable<Coordinates> rowCords = outlineCoordinates.Where(x => x.Y == i);
+                int right = rowCords.Max(x => x.X);
+                int left = rowCords.Min(x => x.X);
+                for (int j = left + 1; j < right; j++)
+                {
+                    finalCoordinates.Add(new Coordinates(j, i));
+                }
             }
 
             return finalCoordinates;
@@ -167,11 +181,11 @@ namespace PixiEditor.Models.Tools.Tools
 
         private Coordinates[] GetRegionPoints(double x, double xc, double y, double yc)
         {
-            var outputCoordinates = new Coordinates[4];
-            outputCoordinates[0] = new Coordinates((int) Math.Floor(x), (int) Math.Floor(y));
-            outputCoordinates[1] = new Coordinates((int) Math.Floor(-(x - xc) + xc), (int) Math.Floor(y));
-            outputCoordinates[2] = new Coordinates((int) Math.Floor(x), (int) Math.Floor(-(y - yc) + yc));
-            outputCoordinates[3] = new Coordinates((int) Math.Floor(-(x - xc) + xc), (int) Math.Floor(-(y - yc) + yc));
+            Coordinates[] outputCoordinates = new Coordinates[4];
+            outputCoordinates[0] = new Coordinates((int)Math.Floor(x), (int)Math.Floor(y));
+            outputCoordinates[1] = new Coordinates((int)Math.Floor(-(x - xc) + xc), (int)Math.Floor(y));
+            outputCoordinates[2] = new Coordinates((int)Math.Floor(x), (int)Math.Floor(-(y - yc) + yc));
+            outputCoordinates[3] = new Coordinates((int)Math.Floor(-(x - xc) + xc), (int)Math.Floor(-(y - yc) + yc));
             return outputCoordinates;
         }
     }

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

@@ -23,9 +23,9 @@ namespace PixiEditor.Models.Tools.Tools
         public Color GetColorUnderMouse()
         {
             System.Drawing.Color color;
-            using (var bitmap = new Bitmap(1, 1))
+            using (Bitmap bitmap = new Bitmap(1, 1))
             {
-                using (var graphics = Graphics.FromImage(bitmap))
+                using (Graphics graphics = Graphics.FromImage(bitmap))
                 {
                     graphics.CopyFromScreen(MousePositionConverter.GetCursorPosition(), new Point(0, 0),
                         new Size(1, 1));

+ 4 - 4
PixiEditor/Models/Tools/Tools/EraserTool.cs

@@ -24,10 +24,10 @@ namespace PixiEditor.Models.Tools.Tools
 
         public LayerChange[] Erase(Layer layer, Coordinates[] coordinates, int toolSize)
         {
-            var startingCords = coordinates.Length > 1 ? coordinates[1] : coordinates[0];
-            var pen = new PenTool();
-            var pixels = pen.Draw(startingCords, coordinates[0], System.Windows.Media.Colors.Transparent, toolSize);
-            return new[] {new LayerChange(pixels, layer)};
+            Coordinates startingCords = coordinates.Length > 1 ? coordinates[1] : coordinates[0];
+            PenTool pen = new PenTool();
+            BitmapPixelChanges pixels = pen.Draw(startingCords, coordinates[0], System.Windows.Media.Colors.Transparent, toolSize);
+            return new[] { new LayerChange(pixels, layer) };
         }
     }
 }

+ 23 - 12
PixiEditor/Models/Tools/Tools/FloodFill.cs

@@ -24,28 +24,39 @@ namespace PixiEditor.Models.Tools.Tools
 
         public BitmapPixelChanges ForestFire(Layer layer, Coordinates startingCoords, Color newColor)
         {
-            var changedCoords = new List<Coordinates>();
+            List<Coordinates> changedCoords = new List<Coordinates>();
 
-            var clone = layer.Clone();
-            var width = ViewModelMain.Current.BitmapManager.ActiveDocument.Width;
-            var height = ViewModelMain.Current.BitmapManager.ActiveDocument.Height;
+            Layer clone = layer.Clone();
+            int width = ViewModelMain.Current.BitmapManager.ActiveDocument.Width;
+            int height = ViewModelMain.Current.BitmapManager.ActiveDocument.Height;
 
-            var colorToReplace = layer.GetPixelWithOffset(startingCoords.X, startingCoords.Y);
+            Color colorToReplace = layer.GetPixelWithOffset(startingCoords.X, startingCoords.Y);
 
-            var stack = new Stack<Coordinates>();
+            Stack<Coordinates> stack = new Stack<Coordinates>();
             stack.Push(new Coordinates(startingCoords.X, startingCoords.Y));
 
             using (clone.LayerBitmap.GetBitmapContext(ReadWriteMode.ReadWrite))
             {
                 while (stack.Count > 0)
                 {
-                    var cords = stack.Pop();
-                    var relativeCords = clone.GetRelativePosition(cords);
-
-                    if (cords.X < 0 || cords.X > width - 1) continue;
-                    if (cords.Y < 0 || cords.Y > height - 1) continue;
-                    if (clone.GetPixel(relativeCords.X, relativeCords.Y) == newColor) continue;
+                    Coordinates cords = stack.Pop();
+                    Coordinates relativeCords = clone.GetRelativePosition(cords);
 
+                    if (cords.X < 0 || cords.X > width - 1)
+                    {
+                        continue;
+                    }
+
+                    if (cords.Y < 0 || cords.Y > height - 1)
+                    {
+                        continue;
+                    }
+
+                    if (clone.GetPixel(relativeCords.X, relativeCords.Y) == newColor)
+                    {
+                        continue;
+                    }
+
                     if (clone.GetPixel(relativeCords.X, relativeCords.Y) == colorToReplace)
                     {
                         changedCoords.Add(new Coordinates(cords.X, cords.Y));

+ 30 - 18
PixiEditor/Models/Tools/Tools/LineTool.cs

@@ -22,7 +22,7 @@ namespace PixiEditor.Models.Tools.Tools
 
         public override LayerChange[] Use(Layer layer, Coordinates[] coordinates, Color color)
         {
-            var pixels =
+            BitmapPixelChanges pixels =
                 BitmapPixelChanges.FromSingleColoredArray(
                     CreateLine(coordinates,
                         Toolbar.GetSetting<SizeSetting>("ToolSize").Value, CapType.Square, CapType.Square), color);
@@ -31,36 +31,45 @@ namespace PixiEditor.Models.Tools.Tools
 
         public IEnumerable<Coordinates> CreateLine(Coordinates start, Coordinates end, int thickness)
         {
-            return CreateLine(new[] {end, start}, thickness, CapType.Square, CapType.Square);
+            return CreateLine(new[] { end, start }, thickness, CapType.Square, CapType.Square);
         }
 
         public IEnumerable<Coordinates> CreateLine(Coordinates start, Coordinates end, int thickness, CapType startCap,
             CapType endCap)
         {
-            return CreateLine(new[] {end, start}, thickness, startCap, endCap);
+            return CreateLine(new[] { end, start }, thickness, startCap, endCap);
         }
 
         private IEnumerable<Coordinates> CreateLine(Coordinates[] coordinates, int thickness, CapType startCap, CapType endCap)
         {
-            var startingCoordinates = coordinates[^1];
-            var latestCoordinates = coordinates[0];
+            Coordinates startingCoordinates = coordinates[^1];
+            Coordinates latestCoordinates = coordinates[0];
             if (thickness == 1)
+            {
                 return BresenhamLine(startingCoordinates.X, startingCoordinates.Y, latestCoordinates.X,
                     latestCoordinates.Y);
+            }
+
             return GetLinePoints(startingCoordinates, latestCoordinates, thickness, startCap, endCap);
         }
 
         private IEnumerable<Coordinates> GetLinePoints(Coordinates start, Coordinates end, int thickness, CapType startCap, CapType endCap)
         {
-            var startingCap = GetCapCoordinates(startCap, start, thickness);
-            if (start == end) return startingCap;
+            IEnumerable<Coordinates> startingCap = GetCapCoordinates(startCap, start, thickness);
+            if (start == end)
+            {
+                return startingCap;
+            }
 
-            var line = BresenhamLine(start.X, start.Y, end.X, end.Y);
+            IEnumerable<Coordinates> line = BresenhamLine(start.X, start.Y, end.X, end.Y);
 
-            var output = new List<Coordinates>(startingCap);
+            List<Coordinates> output = new List<Coordinates>(startingCap);
 
             output.AddRange(GetCapCoordinates(endCap, end, thickness));
-            if (line.Count() > 2) output.AddRange(GetThickShape(line.Except(new[] {start, end}).ToArray(), thickness));
+            if (line.Count() > 2)
+            {
+                output.AddRange(GetThickShape(line.Except(new[] { start, end }).ToArray(), thickness));
+            }
 
             return output.Distinct();
         }
@@ -70,11 +79,11 @@ namespace PixiEditor.Models.Tools.Tools
             switch (cap)
             {
                 case CapType.Round:
-                {
-                    return GetRoundCap(position, thickness); // Round cap is not working very well, circle tool must be improved
-                }
+                    {
+                        return GetRoundCap(position, thickness); // Round cap is not working very well, circle tool must be improved
+                    }
                 default:
-                    return GetThickShape(new[] {position}, thickness);
+                    return GetThickShape(new[] { position }, thickness);
             }
         }
 
@@ -86,16 +95,19 @@ namespace PixiEditor.Models.Tools.Tools
         /// <returns></returns>
         private IEnumerable<Coordinates> GetRoundCap(Coordinates position, int thickness)
         {
-            var circle = new CircleTool();
-            var rectangleCords = CoordinatesCalculator.RectangleToCoordinates(
+            CircleTool circle = new CircleTool();
+            Coordinates[] rectangleCords = CoordinatesCalculator.RectangleToCoordinates(
                 CoordinatesCalculator.CalculateThicknessCenter(position, thickness));
             return circle.CreateEllipse(rectangleCords[0], rectangleCords[^1], 1, true);
         }
 
         private IEnumerable<Coordinates> BresenhamLine(int x1, int y1, int x2, int y2)
         {
-            var coordinates = new List<Coordinates>();
-            if (x1 == x2 && y1 == y2) return new[] {new Coordinates(x1, y1)};
+            List<Coordinates> coordinates = new List<Coordinates>();
+            if (x1 == x2 && y1 == y2)
+            {
+                return new[] { new Coordinates(x1, y1) };
+            }
 
             int d, dx, dy, ai, bi, xi, yi;
             int x = x1, y = y1;

+ 210 - 178
PixiEditor/Models/Tools/Tools/MoveTool.cs

@@ -1,179 +1,211 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Windows;
-using System.Windows.Input;
-using System.Windows.Media;
-using PixiEditor.Helpers.Extensions;
-using PixiEditor.Models.Controllers;
-using PixiEditor.Models.DataHolders;
-using PixiEditor.Models.Enums;
-using PixiEditor.Models.ImageManipulation;
-using PixiEditor.Models.Layers;
-using PixiEditor.Models.Position;
-using PixiEditor.ViewModels;
-using Transform = PixiEditor.Models.ImageManipulation.Transform;
-
-namespace PixiEditor.Models.Tools.Tools
-{
-    public class MoveTool : BitmapOperationTool
-    {
-        private Layer[] affectedLayers;
-        private Dictionary<Layer, bool> clearedPixels = new Dictionary<Layer, bool>();
-        private Coordinates[] currentSelection;
-        private Coordinates lastMouseMove;
-        private Coordinates lastStartMousePos;
-        private Dictionary<Layer, Thickness> startingOffsets;
-        private Dictionary<Layer, Color[]> startPixelColors;
-        private Coordinates[] startSelection;
-        private bool updateViewModelSelection = true;
-
-        public MoveTool()
-        {
-            Tooltip = "Moves selected pixels (V). Hold Ctrl to move all layers";
-            Cursor = Cursors.Arrow;
-            HideHighlight = true;
-            RequiresPreviewLayer = true;
-            UseDefaultUndoMethod = true;
-        }
-
-        public bool MoveAll { get; set; } = false;
-
-        public override ToolType ToolType => ToolType.Move;
-
-        public override void AfterAddedUndo()
-        {
-            if (currentSelection != null && currentSelection.Length != 0)
-                //Inject to default undo system change custom changes made by this tool
-                foreach (var item in startPixelColors)
-                {
-                    var beforeMovePixels = BitmapPixelChanges.FromArrays(startSelection, item.Value);
-                    var changes = UndoManager.UndoStack.Peek();
-                    var layerIndex = ViewModelMain.Current.BitmapManager.ActiveDocument.Layers.IndexOf(item.Key);
-
-                    ((LayerChange[]) changes.OldValue).First(x => x.LayerIndex == layerIndex).PixelChanges.ChangedPixels
-                        .AddRangeOverride(beforeMovePixels.ChangedPixels);
-
-                    ((LayerChange[]) changes.NewValue).First(x => x.LayerIndex == layerIndex).PixelChanges.ChangedPixels
-                        .AddRangeNewOnly(BitmapPixelChanges
-                            .FromSingleColoredArray(startSelection, System.Windows.Media.Colors.Transparent)
-                            .ChangedPixels);
-                }
-        }
-
-        public override void OnMouseUp(MouseEventArgs e) //This adds undo if there is no selection, reason why this isn't in AfterUndoAdded,
-        {
-            //is because it doesn't fire if no pixel changes were made.
-            if (currentSelection != null && currentSelection.Length == 0)
-                UndoManager.AddUndoChange(new Change(ApplyOffsets, new object[] {startingOffsets},
-                    ApplyOffsets, new object[] {GetOffsets(affectedLayers)}, "Move layers"));
-        }
-
-        private void ApplyOffsets(object[] parameters)
-        {
-            var offsets = (Dictionary<Layer, Thickness>) parameters[0];
-            foreach (var offset in offsets) offset.Key.Offset = offset.Value;
-        }
-
-        public override LayerChange[] Use(Layer layer, Coordinates[] mouseMove, Color color)
-        {
-            var start = mouseMove[^1];
-            if (lastStartMousePos != start) //I am aware that this could be moved to OnMouseDown, but it is executed before Use, so I didn't want to complicate for now
-            {
-                ResetSelectionValues(start);
-                if (ViewModelMain.Current.ActiveSelection != null && ViewModelMain.Current.ActiveSelection.SelectedPoints.Count > 0) //Move offset if no selection
-                    currentSelection = ViewModelMain.Current.ActiveSelection.SelectedPoints.ToArray();
-                else
-                    currentSelection = Array.Empty<Coordinates>();
-
-                if (Keyboard.IsKeyDown(Key.LeftCtrl) || MoveAll)
-                    affectedLayers = ViewModelMain.Current.BitmapManager.ActiveDocument.Layers.Where(x => x.IsVisible)
-                        .ToArray();
-                else
-                    affectedLayers = new[] {layer};
-
-                startSelection = currentSelection;
-                startPixelColors = BitmapUtils.GetPixelsForSelection(affectedLayers, startSelection);
-                startingOffsets = GetOffsets(affectedLayers);
-            }
-
-            var result = new LayerChange[affectedLayers.Length];
-            var end = mouseMove[0];
-            for (var i = 0; i < affectedLayers.Length; i++)
-                if (currentSelection.Length > 0)
-                {
-                    var changes = MoveSelection(affectedLayers[i], mouseMove);
-                    changes = RemoveTransparentPixels(changes);
-
-                    result[i] = new LayerChange(changes, affectedLayers[i]);
-                }
-                else
-                {
-                    var vector = Transform.GetTranslation(lastMouseMove, end);
-                    affectedLayers[i].Offset = new Thickness(affectedLayers[i].OffsetX + vector.X, affectedLayers[i].OffsetY + vector.Y, 0, 0);
-                    result[i] = new LayerChange(BitmapPixelChanges.Empty, affectedLayers[i]);
-                }
-
-            lastMouseMove = end;
-
-            return result;
-        }
-
-        private Dictionary<Layer, Thickness> GetOffsets(Layer[] layers)
-        {
-            var dict = new Dictionary<Layer, Thickness>();
-            for (var i = 0; i < layers.Length; i++) dict.Add(layers[i], layers[i].Offset);
-
-            return dict;
-        }
-
-        private BitmapPixelChanges RemoveTransparentPixels(BitmapPixelChanges pixels)
-        {
-            foreach (var item in pixels.ChangedPixels.Where(x => x.Value.A == 0).ToList())
-                pixels.ChangedPixels.Remove(item.Key);
-            return pixels;
-        }
-
-        public BitmapPixelChanges MoveSelection(Layer layer, Coordinates[] mouseMove)
-        {
-            var end = mouseMove[0];
-
-            currentSelection = TranslateSelection(end, out var previousSelection);
-            if (updateViewModelSelection)
-                ViewModelMain.Current.ActiveSelection.SetSelection(currentSelection, SelectionType.New);
-            ClearSelectedPixels(layer, previousSelection);
-
-
-            lastMouseMove = end;
-            return BitmapPixelChanges.FromArrays(currentSelection, startPixelColors[layer]);
-        }
-
-        private void ResetSelectionValues(Coordinates start)
-        {
-            lastStartMousePos = start;
-            lastMouseMove = start;
-            clearedPixels = new Dictionary<Layer, bool>();
-            updateViewModelSelection = true;
-            startPixelColors = null;
-            startSelection = null;
-        }
-
-        private Coordinates[] TranslateSelection(Coordinates end, out Coordinates[] previousSelection)
-        {
-            var translation = Transform.GetTranslation(lastMouseMove, end);
-            previousSelection = currentSelection.ToArray();
-            return Transform.Translate(previousSelection, translation);
-        }
-
-        private void ClearSelectedPixels(Layer layer, Coordinates[] selection)
-        {
-            if (!clearedPixels.ContainsKey(layer) || clearedPixels[layer] == false)
-            {
-                ViewModelMain.Current.BitmapManager.ActiveDocument.Layers.First(x => x == layer)
-                    .SetPixels(BitmapPixelChanges.FromSingleColoredArray(selection, System.Windows.Media.Colors.Transparent));
-
-                clearedPixels[layer] = true;
-            }
-        }
-    }
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Windows;
+using System.Windows.Input;
+using System.Windows.Media;
+using PixiEditor.Helpers.Extensions;
+using PixiEditor.Models.Controllers;
+using PixiEditor.Models.DataHolders;
+using PixiEditor.Models.Enums;
+using PixiEditor.Models.ImageManipulation;
+using PixiEditor.Models.Layers;
+using PixiEditor.Models.Position;
+using PixiEditor.ViewModels;
+using Transform = PixiEditor.Models.ImageManipulation.Transform;
+
+namespace PixiEditor.Models.Tools.Tools
+{
+    public class MoveTool : BitmapOperationTool
+    {
+        private Layer[] affectedLayers;
+        private Dictionary<Layer, bool> clearedPixels = new Dictionary<Layer, bool>();
+        private Coordinates[] currentSelection;
+        private Coordinates lastMouseMove;
+        private Coordinates lastStartMousePos;
+        private Dictionary<Layer, Thickness> startingOffsets;
+        private Dictionary<Layer, Color[]> startPixelColors;
+        private Coordinates[] startSelection;
+        private bool updateViewModelSelection = true;
+
+        public MoveTool()
+        {
+            Tooltip = "Moves selected pixels (V). Hold Ctrl to move all layers";
+            Cursor = Cursors.Arrow;
+            HideHighlight = true;
+            RequiresPreviewLayer = true;
+            UseDefaultUndoMethod = true;
+        }
+
+        public bool MoveAll { get; set; } = false;
+
+        public override ToolType ToolType => ToolType.Move;
+
+        public override void AfterAddedUndo()
+        {
+            if (currentSelection != null && currentSelection.Length != 0)
+            {
+                // Inject to default undo system change custom changes made by this tool
+                foreach (KeyValuePair<Layer, Color[]> item in startPixelColors)
+                {
+                    BitmapPixelChanges beforeMovePixels = BitmapPixelChanges.FromArrays(startSelection, item.Value);
+                    Change changes = UndoManager.UndoStack.Peek();
+                    int layerIndex = ViewModelMain.Current.BitmapManager.ActiveDocument.Layers.IndexOf(item.Key);
+
+                    ((LayerChange[])changes.OldValue).First(x => x.LayerIndex == layerIndex).PixelChanges.ChangedPixels
+                        .AddRangeOverride(beforeMovePixels.ChangedPixels);
+
+                    ((LayerChange[])changes.NewValue).First(x => x.LayerIndex == layerIndex).PixelChanges.ChangedPixels
+                        .AddRangeNewOnly(BitmapPixelChanges
+                            .FromSingleColoredArray(startSelection, System.Windows.Media.Colors.Transparent)
+                            .ChangedPixels);
+                }
+            }
+        }
+
+        public override void OnMouseUp(MouseEventArgs e) // This adds undo if there is no selection, reason why this isn't in AfterUndoAdded,
+        {
+            // is because it doesn't fire if no pixel changes were made.
+            if (currentSelection != null && currentSelection.Length == 0)
+            {
+                UndoManager.AddUndoChange(new Change(
+                    ApplyOffsets,
+                    new object[] { startingOffsets },
+                    ApplyOffsets,
+                    new object[] { GetOffsets(affectedLayers) },
+                    "Move layers"));
+            }
+        }
+
+        public override LayerChange[] Use(Layer layer, Coordinates[] mouseMove, Color color)
+        {
+            Coordinates start = mouseMove[^1];
+
+            // I am aware that this could be moved to OnMouseDown, but it is executed before Use, so I didn't want to complicate for now
+            if (lastStartMousePos != start)
+            {
+                ResetSelectionValues(start);
+
+                // Move offset if no selection
+                if (ViewModelMain.Current.ActiveSelection != null && ViewModelMain.Current.ActiveSelection.SelectedPoints.Count > 0)
+                {
+                    currentSelection = ViewModelMain.Current.ActiveSelection.SelectedPoints.ToArray();
+                }
+                else
+                {
+                    currentSelection = Array.Empty<Coordinates>();
+                }
+
+                if (Keyboard.IsKeyDown(Key.LeftCtrl) || MoveAll)
+                {
+                    affectedLayers = ViewModelMain.Current.BitmapManager.ActiveDocument.Layers.Where(x => x.IsVisible)
+                        .ToArray();
+                }
+                else
+                {
+                    affectedLayers = new[] { layer };
+                }
+
+                startSelection = currentSelection;
+                startPixelColors = BitmapUtils.GetPixelsForSelection(affectedLayers, startSelection);
+                startingOffsets = GetOffsets(affectedLayers);
+            }
+
+            LayerChange[] result = new LayerChange[affectedLayers.Length];
+            Coordinates end = mouseMove[0];
+            for (int i = 0; i < affectedLayers.Length; i++)
+            {
+                if (currentSelection.Length > 0)
+                {
+                    BitmapPixelChanges changes = MoveSelection(affectedLayers[i], mouseMove);
+                    changes = RemoveTransparentPixels(changes);
+
+                    result[i] = new LayerChange(changes, affectedLayers[i]);
+                }
+                else
+                {
+                    Coordinates vector = Transform.GetTranslation(lastMouseMove, end);
+                    affectedLayers[i].Offset = new Thickness(affectedLayers[i].OffsetX + vector.X, affectedLayers[i].OffsetY + vector.Y, 0, 0);
+                    result[i] = new LayerChange(BitmapPixelChanges.Empty, affectedLayers[i]);
+                }
+            }
+
+            lastMouseMove = end;
+
+            return result;
+        }
+
+        private void ApplyOffsets(object[] parameters)
+        {
+            Dictionary<Layer, Thickness> offsets = (Dictionary<Layer, Thickness>)parameters[0];
+            foreach (KeyValuePair<Layer, Thickness> offset in offsets)
+            {
+                offset.Key.Offset = offset.Value;
+            }
+        }
+
+        private Dictionary<Layer, Thickness> GetOffsets(Layer[] layers)
+        {
+            Dictionary<Layer, Thickness> dict = new Dictionary<Layer, Thickness>();
+            for (int i = 0; i < layers.Length; i++)
+            {
+                dict.Add(layers[i], layers[i].Offset);
+            }
+
+            return dict;
+        }
+
+        private BitmapPixelChanges RemoveTransparentPixels(BitmapPixelChanges pixels)
+        {
+            foreach (KeyValuePair<Coordinates, Color> item in pixels.ChangedPixels.Where(x => x.Value.A == 0).ToList())
+            {
+                pixels.ChangedPixels.Remove(item.Key);
+            }
+
+            return pixels;
+        }
+
+        public BitmapPixelChanges MoveSelection(Layer layer, Coordinates[] mouseMove)
+        {
+            Coordinates end = mouseMove[0];
+
+            currentSelection = TranslateSelection(end, out Coordinates[] previousSelection);
+            if (updateViewModelSelection)
+            {
+                ViewModelMain.Current.ActiveSelection.SetSelection(currentSelection, SelectionType.New);
+            }
+
+            ClearSelectedPixels(layer, previousSelection);
+
+            lastMouseMove = end;
+            return BitmapPixelChanges.FromArrays(currentSelection, startPixelColors[layer]);
+        }
+
+        private void ResetSelectionValues(Coordinates start)
+        {
+            lastStartMousePos = start;
+            lastMouseMove = start;
+            clearedPixels = new Dictionary<Layer, bool>();
+            updateViewModelSelection = true;
+            startPixelColors = null;
+            startSelection = null;
+        }
+
+        private Coordinates[] TranslateSelection(Coordinates end, out Coordinates[] previousSelection)
+        {
+            Coordinates translation = Transform.GetTranslation(lastMouseMove, end);
+            previousSelection = currentSelection.ToArray();
+            return Transform.Translate(previousSelection, translation);
+        }
+        private void ClearSelectedPixels(Layer layer, Coordinates[] selection)
+        {
+            if (!clearedPixels.ContainsKey(layer) || clearedPixels[layer] == false)
+            {
+                ViewModelMain.Current.BitmapManager.ActiveDocument.Layers.First(x => x == layer)
+                    .SetPixels(BitmapPixelChanges.FromSingleColoredArray(selection, System.Windows.Media.Colors.Transparent));
+
+                clearedPixels[layer] = true;
+            }
+        }
+    }
 }

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

@@ -24,14 +24,14 @@ namespace PixiEditor.Models.Tools.Tools
 
         public override LayerChange[] Use(Layer layer, Coordinates[] coordinates, Color color)
         {
-            var startingCords = coordinates.Length > 1 ? coordinates[1] : coordinates[0];
-            var pixels = Draw(startingCords, coordinates[0], color, toolSizeSetting.Value);
+            Coordinates startingCords = coordinates.Length > 1 ? coordinates[1] : coordinates[0];
+            BitmapPixelChanges pixels = Draw(startingCords, coordinates[0], color, toolSizeSetting.Value);
             return Only(pixels, layer);
         }
 
         public BitmapPixelChanges Draw(Coordinates startingCoords, Coordinates latestCords, Color color, int toolSize)
         {
-            var line = new LineTool();
+            LineTool line = new LineTool();
             return BitmapPixelChanges.FromSingleColoredArray(
                 line.CreateLine(startingCoords, latestCords, toolSize), color);
         }

+ 37 - 25
PixiEditor/Models/Tools/Tools/RectangleTool.cs

@@ -18,60 +18,66 @@ namespace PixiEditor.Models.Tools.Tools
         }
 
         public override ToolType ToolType => ToolType.Rectangle;
+
         public bool Filled { get; set; } = false;
 
         public override LayerChange[] Use(Layer layer, Coordinates[] coordinates, Color color)
         {
-            var thickness = Toolbar.GetSetting<SizeSetting>("ToolSize").Value;
-            var pixels =
+            int thickness = Toolbar.GetSetting<SizeSetting>("ToolSize").Value;
+            BitmapPixelChanges pixels =
                 BitmapPixelChanges.FromSingleColoredArray(CreateRectangle(coordinates, thickness), color);
             if (Toolbar.GetSetting<BoolSetting>("Fill").Value)
             {
-                var fillColor = Toolbar.GetSetting<ColorSetting>("FillColor").Value;
+                Color fillColor = Toolbar.GetSetting<ColorSetting>("FillColor").Value;
                 pixels.ChangedPixels.AddRangeOverride(
                     BitmapPixelChanges.FromSingleColoredArray
                             (CalculateFillForRectangle(coordinates[^1], coordinates[0], thickness), fillColor)
                         .ChangedPixels);
             }
 
-            return new[] {new LayerChange(pixels, layer)};
+            return new[] { new LayerChange(pixels, layer) };
         }
 
         public IEnumerable<Coordinates> CreateRectangle(Coordinates[] coordinates, int thickness)
         {
-            var fixedCoordinates = CalculateCoordinatesForShapeRotation(coordinates[^1], coordinates[0]);
-            var output = new List<Coordinates>();
-            var rectangle = CalculateRectanglePoints(fixedCoordinates);
+            DoubleCords fixedCoordinates = CalculateCoordinatesForShapeRotation(coordinates[^1], coordinates[0]);
+            List<Coordinates> output = new List<Coordinates>();
+            IEnumerable<Coordinates> rectangle = CalculateRectanglePoints(fixedCoordinates);
             output.AddRange(rectangle);
 
-            for (var i = 1; i < (int) Math.Floor(thickness / 2f) + 1; i++)
+            for (int i = 1; i < (int)Math.Floor(thickness / 2f) + 1; i++)
+            {
                 output.AddRange(CalculateRectanglePoints(new DoubleCords(
                     new Coordinates(fixedCoordinates.Coords1.X - i, fixedCoordinates.Coords1.Y - i),
                     new Coordinates(fixedCoordinates.Coords2.X + i, fixedCoordinates.Coords2.Y + i))));
-            for (var i = 1; i < (int) Math.Ceiling(thickness / 2f); i++)
+            }
+
+            for (int i = 1; i < (int)Math.Ceiling(thickness / 2f); i++)
+            {
                 output.AddRange(CalculateRectanglePoints(new DoubleCords(
                     new Coordinates(fixedCoordinates.Coords1.X + i, fixedCoordinates.Coords1.Y + i),
                     new Coordinates(fixedCoordinates.Coords2.X - i, fixedCoordinates.Coords2.Y - i))));
+            }
 
             return output.Distinct();
         }
 
         public IEnumerable<Coordinates> CreateRectangle(Coordinates start, Coordinates end, int thickness)
         {
-            return CreateRectangle(new[] {end, start}, thickness);
+            return CreateRectangle(new[] { end, start }, thickness);
         }
 
         private IEnumerable<Coordinates> CalculateRectanglePoints(DoubleCords coordinates)
         {
-            var finalCoordinates = new List<Coordinates>();
+            List<Coordinates> finalCoordinates = new List<Coordinates>();
 
-            for (var i = coordinates.Coords1.X; i < coordinates.Coords2.X + 1; i++)
+            for (int i = coordinates.Coords1.X; i < coordinates.Coords2.X + 1; i++)
             {
                 finalCoordinates.Add(new Coordinates(i, coordinates.Coords1.Y));
                 finalCoordinates.Add(new Coordinates(i, coordinates.Coords2.Y));
             }
 
-            for (var i = coordinates.Coords1.Y + 1; i <= coordinates.Coords2.Y - 1; i++)
+            for (int i = coordinates.Coords1.Y + 1; i <= coordinates.Coords2.Y - 1; i++)
             {
                 finalCoordinates.Add(new Coordinates(coordinates.Coords1.X, i));
                 finalCoordinates.Add(new Coordinates(coordinates.Coords2.X, i));
@@ -82,26 +88,32 @@ namespace PixiEditor.Models.Tools.Tools
 
         public IEnumerable<Coordinates> CalculateFillForRectangle(Coordinates start, Coordinates end, int thickness)
         {
-            var offset = (int) Math.Ceiling(thickness / 2f);
-            var fixedCords = CalculateCoordinatesForShapeRotation(start, end);
+            int offset = (int)Math.Ceiling(thickness / 2f);
+            DoubleCords fixedCords = CalculateCoordinatesForShapeRotation(start, end);
 
-            var innerCords = new DoubleCords
+            DoubleCords innerCords = new DoubleCords
             {
                 Coords1 = new Coordinates(fixedCords.Coords1.X + offset, fixedCords.Coords1.Y + offset),
                 Coords2 = new Coordinates(fixedCords.Coords2.X - (offset - 1), fixedCords.Coords2.Y - (offset - 1))
             };
 
-            var height = innerCords.Coords2.Y - innerCords.Coords1.Y;
-            var width = innerCords.Coords2.X - innerCords.Coords1.X;
+            int height = innerCords.Coords2.Y - innerCords.Coords1.Y;
+            int width = innerCords.Coords2.X - innerCords.Coords1.X;
+
+            if (height < 1 || width < 1)
+            {
+                return Array.Empty<Coordinates>();
+            }
 
-            if (height < 1 || width < 1) return Array.Empty<Coordinates>();
-            var filledCoordinates = new Coordinates[width * height];
-            var i = 0;
-            for (var y = 0; y < height; y++)
-            for (var x = 0; x < width; x++)
+            Coordinates[] filledCoordinates = new Coordinates[width * height];
+            int i = 0;
+            for (int y = 0; y < height; y++)
             {
-                filledCoordinates[i] = new Coordinates(innerCords.Coords1.X + x, innerCords.Coords1.Y + y);
-                i++;
+                for (int x = 0; x < width; x++)
+                {
+                    filledCoordinates[i] = new Coordinates(innerCords.Coords1.X + x, innerCords.Coords1.Y + y);
+                    i++;
+                }
             }
 
             return filledCoordinates.Distinct();

+ 13 - 9
PixiEditor/Models/Tools/Tools/SelectTool.cs

@@ -32,16 +32,20 @@ namespace PixiEditor.Models.Tools.Tools
 
             oldSelection = null;
             if (ViewModelMain.Current.ActiveSelection != null &&
-                ViewModelMain.Current.ActiveSelection.SelectedPoints != null)
-                oldSelection = ViewModelMain.Current.ActiveSelection;
+                ViewModelMain.Current.ActiveSelection.SelectedPoints != null)
+            {
+                oldSelection = ViewModelMain.Current.ActiveSelection;
+            }
         }
 
         public override void OnMouseUp(MouseEventArgs e)
         {
-            if (ViewModelMain.Current.ActiveSelection.SelectedPoints.Count() <= 1)
-                // If we have not selected multiple points, clear the selection
-                ViewModelMain.Current.ActiveSelection.Clear();
-
+            if (ViewModelMain.Current.ActiveSelection.SelectedPoints.Count() <= 1)
+            {
+                // If we have not selected multiple points, clear the selection
+                ViewModelMain.Current.ActiveSelection.Clear();
+            }
+
             UndoManager.AddUndoChange(new Change("ActiveSelection", oldSelection,
                 ViewModelMain.Current.ActiveSelection, "Select pixels"));
         }
@@ -53,14 +57,14 @@ namespace PixiEditor.Models.Tools.Tools
 
         private void Select(Coordinates[] pixels)
         {
-            var selection = GetRectangleSelectionForPoints(pixels[^1], pixels[0]);
+            IEnumerable<Coordinates> selection = GetRectangleSelectionForPoints(pixels[^1], pixels[0]);
             ViewModelMain.Current.ActiveSelection.SetSelection(selection, SelectionType);
         }
 
         public IEnumerable<Coordinates> GetRectangleSelectionForPoints(Coordinates start, Coordinates end)
         {
-            var rectangleTool = new RectangleTool();
-            var selection = rectangleTool.CreateRectangle(start, end, 1).ToList();
+            RectangleTool rectangleTool = new RectangleTool();
+            List<Coordinates> selection = rectangleTool.CreateRectangle(start, end, 1).ToList();
             selection.AddRange(rectangleTool.CalculateFillForRectangle(start, end, 1));
             return selection;
         }

+ 11 - 7
PixiEditor/Models/Tools/Tools/ZoomTool.cs

@@ -26,7 +26,7 @@ namespace PixiEditor.Models.Tools.Tools
         public override void OnMouseDown(MouseEventArgs e)
         {
             startingX = MousePositionConverter.GetCursorPosition().X;
-            ViewModelMain.Current.ZoomPercentage = 100; //This resest the value, so callback in MainDrawingPanel can fire again later
+            ViewModelMain.Current.ZoomPercentage = 100; // This resest the value, so callback in MainDrawingPanel can fire again later
         }
 
         public override void OnMouseMove(MouseEventArgs e)
@@ -35,8 +35,8 @@ namespace PixiEditor.Models.Tools.Tools
             {
                 double xPos = MousePositionConverter.GetCursorPosition().X;
 
-                var rawPercentDifference = (xPos - startingX) / pixelsPerZoomMultiplier; //negative - zoom out, positive - zoom in, linear
-                var finalPercentDifference = Math.Pow(2, rawPercentDifference) * 100.0; //less than 100 - zoom out, greater than 100 - zoom in
+                double rawPercentDifference = (xPos - startingX) / pixelsPerZoomMultiplier; // negative - zoom out, positive - zoom in, linear
+                double finalPercentDifference = Math.Pow(2, rawPercentDifference) * 100.0; // less than 100 - zoom out, greater than 100 - zoom in
                 Zoom(finalPercentDifference);
             }
         }
@@ -46,10 +46,14 @@ namespace PixiEditor.Models.Tools.Tools
             if (e.LeftButton == MouseButtonState.Released && e.RightButton == MouseButtonState.Released &&
                 startingX == MousePositionConverter.GetCursorPosition().X)
             {
-                if (Keyboard.Modifiers.HasFlag(ModifierKeys.Alt))
-                    Zoom(85);
-                else
-                    Zoom(115);
+                if (Keyboard.Modifiers.HasFlag(ModifierKeys.Alt))
+                {
+                    Zoom(85);
+                }
+                else
+                {
+                    Zoom(115);
+                }
             }
         }
 

+ 4 - 1
PixiEditor/NotifyableObject.cs

@@ -10,7 +10,10 @@ namespace PixiEditor.Helpers
 
         protected void RaisePropertyChanged(string property)
         {
-            if (property != null) PropertyChanged(this, new PropertyChangedEventArgs(property));
+            if (property != null)
+            {
+                PropertyChanged(this, new PropertyChangedEventArgs(property));
+            }
         }
     }
 }

+ 17 - 19
PixiEditor/Properties/AssemblyInfo.cs

@@ -19,26 +19,24 @@ using System.Windows;
 // COM, set the ComVisible attribute to true on that type.
 [assembly: ComVisible(false)]
 
-//In order to begin building localizable applications, set
-//<UICulture>CultureYouAreCodingWith</UICulture> in your .csproj file
-//inside a <PropertyGroup>.  For example, if you are using US english
-//in your source files, set the <UICulture> to en-US.  Then uncomment
-//the NeutralResourceLanguage attribute below.  Update the "en-US" in
-//the line below to match the UICulture setting in the project file.
-
-//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
-
-
+// In order to begin building localizable applications, set
+// <UICulture>CultureYouAreCodingWith</UICulture> in your .csproj file
+// inside a <PropertyGroup>.  For example, if you are using US english
+// in your source files, set the <UICulture> to en-US.  Then uncomment
+// the NeutralResourceLanguage attribute below.  Update the "en-US" in
+// the line below to match the UICulture setting in the project file.
+
+// [assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
+
 [assembly: ThemeInfo(
-    ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
-    //(used if a resource is not found in the page,
-    // or application resource dictionaries)
-    ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
-    //(used if a resource is not found in the page,
-    // app, or any theme specific resource dictionaries)
-)]
-
-
+    ResourceDictionaryLocation.None, // where theme specific resource dictionaries are located
+                                     // (used if a resource is not found in the page,
+                                     // or application resource dictionaries)
+    ResourceDictionaryLocation.SourceAssembly) // where the generic resource dictionary is located
+                                               // (used if a resource is not found in the page,
+                                               // app, or any theme specific resource dictionaries)
+]
+
 // Version information for an assembly consists of the following four values:
 //
 //      Major Version

+ 3 - 3
PixiEditor/ViewModels/FeedbackDialogViewModel.cs

@@ -6,8 +6,7 @@ namespace PixiEditor.ViewModels
     internal class FeedbackDialogViewModel : ViewModelBase
     {
         private string emailBody;
-
-
+
         private string mailFrom;
 
         public FeedbackDialogViewModel()
@@ -17,6 +16,7 @@ namespace PixiEditor.ViewModels
         }
 
         public RelayCommand CloseButtonCommand { get; set; }
+
         public RelayCommand SendButtonCommand { get; set; }
 
         public string MailFrom
@@ -47,7 +47,7 @@ namespace PixiEditor.ViewModels
 
         private void CloseWindow(object parameter)
         {
-            ((Window) parameter).DialogResult = false;
+            ((Window)parameter).DialogResult = false;
             CloseButton(parameter);
         }
 

+ 11 - 12
PixiEditor/ViewModels/ImportFilePopupViewModel.cs

@@ -10,17 +10,13 @@ namespace PixiEditor.ViewModels
     internal class ImportFilePopupViewModel : ViewModelBase
     {
         private string filePath;
-
-
+
         private int importHeight = 16;
-
-
+
         private int importWidth = 16;
-
-
+
         private string pathButtonBorder = "#f08080";
-
-
+
         private bool pathIsCorrect;
 
         public ImportFilePopupViewModel()
@@ -32,8 +28,11 @@ namespace PixiEditor.ViewModels
         }
 
         public RelayCommand CloseButtonCommand { get; set; }
+
         public RelayCommand DragMoveCommand { get; set; }
+
         public RelayCommand ChoosePathCommand { get; set; }
+
         public RelayCommand OkCommand { get; set; }
 
         public string PathButtonBorder
@@ -108,7 +107,7 @@ namespace PixiEditor.ViewModels
         /// <param name="parameter"></param>
         private void ChoosePath(object parameter)
         {
-            var path = new OpenFileDialog
+            OpenFileDialog path = new OpenFileDialog
             {
                 Title = "Import path",
                 CheckPathExists = true,
@@ -135,7 +134,7 @@ namespace PixiEditor.ViewModels
                 PathButtonBorder = "#b8f080";
                 PathIsCorrect = true;
                 filePath = path;
-                var bitmap = new BitmapImage(new Uri(path));
+                BitmapImage bitmap = new BitmapImage(new Uri(path));
                 ImportHeight = bitmap.PixelHeight;
                 ImportWidth = bitmap.PixelWidth;
             }
@@ -143,7 +142,7 @@ namespace PixiEditor.ViewModels
 
         private void CloseWindow(object parameter)
         {
-            ((Window) parameter).DialogResult = false;
+            ((Window)parameter).DialogResult = false;
             CloseButton(parameter);
         }
 
@@ -154,7 +153,7 @@ namespace PixiEditor.ViewModels
 
         private void OkButton(object parameter)
         {
-            ((Window) parameter).DialogResult = true;
+            ((Window)parameter).DialogResult = true;
             CloseButton(parameter);
         }
 

+ 2 - 2
PixiEditor/ViewModels/MenuButtonViewModel.cs

@@ -6,8 +6,7 @@ namespace PixiEditor.ViewModels
     internal class MenuButtonViewModel : ViewModelBase
     {
         private Visibility listViewVisibility;
-
-
+
         public MenuButtonViewModel()
         {
             OpenListViewCommand = new RelayCommand(OpenListView);
@@ -16,6 +15,7 @@ namespace PixiEditor.ViewModels
         }
 
         public RelayCommand OpenListViewCommand { get; set; }
+
         public RelayCommand CloseListViewCommand { get; set; }
 
         public Visibility ListViewVisibility

+ 5 - 3
PixiEditor/ViewModels/NewFileMenuViewModel.cs

@@ -13,18 +13,20 @@ namespace PixiEditor.ViewModels
         }
 
         public RelayCommand OkCommand { get; set; }
+
         public RelayCommand CloseCommand { get; set; }
+
         public RelayCommand DragMoveCommand { get; set; }
 
         private void OkButton(object parameter)
         {
-            ((Window) parameter).DialogResult = true;
-            ((Window) parameter).Close();
+            ((Window)parameter).DialogResult = true;
+            ((Window)parameter).Close();
         }
 
         private void CloseWindow(object parameter)
         {
-            ((Window) parameter).DialogResult = false;
+            ((Window)parameter).DialogResult = false;
             CloseButton(parameter);
         }
 

+ 8 - 7
PixiEditor/ViewModels/SaveFilePopupViewModel.cs

@@ -7,11 +7,9 @@ namespace PixiEditor.ViewModels
     internal class SaveFilePopupViewModel : ViewModelBase
     {
         private string filePath;
-
-
+
         private string pathButtonBorder = "#f08080";
-
-
+
         private bool pathIsCorrect;
 
         public SaveFilePopupViewModel()
@@ -23,8 +21,11 @@ namespace PixiEditor.ViewModels
         }
 
         public RelayCommand CloseButtonCommand { get; set; }
+
         public RelayCommand DragMoveCommand { get; set; }
+
         public RelayCommand ChoosePathCommand { get; set; }
+
         public RelayCommand OkCommand { get; set; }
 
         public string PathButtonBorder
@@ -72,7 +73,7 @@ namespace PixiEditor.ViewModels
         /// <param name="parameter"></param>
         private void ChoosePath(object parameter)
         {
-            var path = new SaveFileDialog
+            SaveFileDialog path = new SaveFileDialog
             {
                 Title = "Export path",
                 CheckPathExists = true,
@@ -97,7 +98,7 @@ namespace PixiEditor.ViewModels
 
         private void CloseWindow(object parameter)
         {
-            ((Window) parameter).DialogResult = false;
+            ((Window)parameter).DialogResult = false;
             CloseButton(parameter);
         }
 
@@ -108,7 +109,7 @@ namespace PixiEditor.ViewModels
 
         private void OkButton(object parameter)
         {
-            ((Window) parameter).DialogResult = true;
+            ((Window)parameter).DialogResult = true;
             CloseButton(parameter);
         }
 

+ 10 - 4
PixiEditor/ViewModels/ViewModelBase.cs

@@ -11,18 +11,24 @@ namespace PixiEditor.ViewModels
 
         protected void RaisePropertyChanged(string property)
         {
-            if (property != null) PropertyChanged(this, new PropertyChangedEventArgs(property));
+            if (property != null)
+            {
+                PropertyChanged(this, new PropertyChangedEventArgs(property));
+            }
         }
 
         protected void CloseButton(object parameter)
         {
-            ((Window) parameter).Close();
+            ((Window)parameter).Close();
         }
 
         protected void DragMove(object parameter)
         {
-            var popup = Application.Current.Windows.OfType<Window>().SingleOrDefault(x => x.IsActive);
-            if (Mouse.LeftButton == MouseButtonState.Pressed) popup.DragMove();
+            Window popup = Application.Current.Windows.OfType<Window>().SingleOrDefault(x => x.IsActive);
+            if (Mouse.LeftButton == MouseButtonState.Pressed)
+            {
+                popup.DragMove();
+            }
         }
     }
 }

+ 185 - 72
PixiEditor/ViewModels/ViewModelMain.cs

@@ -31,7 +31,6 @@ namespace PixiEditor.ViewModels
         private const string ConfirmationDialogMessage = "Document was modified. Do you want to save changes?";
         private Tool lastActionTool;
 
-
         private double mouseXonCanvas;
 
         private double mouseYonCanvas;
@@ -111,7 +110,7 @@ namespace PixiEditor.ViewModels
             {
                 Shortcuts = new List<Shortcut>
                 {
-                    //Tools
+                    // Tools
                     new Shortcut(Key.B, SelectToolCommand, ToolType.Pen),
                     new Shortcut(Key.E, SelectToolCommand, ToolType.Eraser),
                     new Shortcut(Key.O, SelectToolCommand, ToolType.ColorPicker),
@@ -127,7 +126,7 @@ namespace PixiEditor.ViewModels
                     new Shortcut(Key.OemMinus, ZoomCommand, 85),
                     new Shortcut(Key.OemOpenBrackets, ChangeToolSizeCommand, -1),
                     new Shortcut(Key.OemCloseBrackets, ChangeToolSizeCommand, 1),
-                    //Editor
+                    // Editor
                     new Shortcut(Key.X, SwapColorsCommand),
                     new Shortcut(Key.Y, RedoCommand, modifier: ModifierKeys.Control),
                     new Shortcut(Key.Z, UndoCommand, modifier: ModifierKeys.Control),
@@ -141,7 +140,7 @@ namespace PixiEditor.ViewModels
                     new Shortcut(Key.I, OpenResizePopupCommand, modifier: ModifierKeys.Control | ModifierKeys.Shift),
                     new Shortcut(Key.C, OpenResizePopupCommand, "canvas", ModifierKeys.Control | ModifierKeys.Shift),
                     new Shortcut(Key.F11, SystemCommands.MaximizeWindowCommand),
-                    //File
+                    // File
                     new Shortcut(Key.O, OpenFileCommand, modifier: ModifierKeys.Control),
                     new Shortcut(Key.S, ExportFileCommand,
                         modifier: ModifierKeys.Control | ModifierKeys.Shift | ModifierKeys.Alt),
@@ -161,42 +160,77 @@ namespace PixiEditor.ViewModels
         public Action CloseAction { get; set; }
 
         public static ViewModelMain Current { get; set; }
-        public RelayCommand SelectToolCommand { get; set; } //Command that handles tool switching
-        public RelayCommand OpenNewFilePopupCommand { get; set; } //Command that generates draw area
-        public RelayCommand MouseMoveCommand { get; set; } //Command that is used to draw
+
+        public RelayCommand SelectToolCommand { get; set; } // Command that handles tool switching
+
+        public RelayCommand OpenNewFilePopupCommand { get; set; } // Command that generates draw area
+
+        public RelayCommand MouseMoveCommand { get; set; } // Command that is used to draw
+
         public RelayCommand MouseDownCommand { get; set; }
+
         public RelayCommand KeyDownCommand { get; set; }
+
         public RelayCommand KeyUpCommand { get; set; }
-        public RelayCommand ExportFileCommand { get; set; } //Command that is used to save file
+
+        public RelayCommand ExportFileCommand { get; set; } // Command that is used to save file
+
         public RelayCommand UndoCommand { get; set; }
+
         public RelayCommand RedoCommand { get; set; }
 
         public RelayCommand OpenFileCommand { get; set; }
+
         public RelayCommand SetActiveLayerCommand { get; set; }
+
         public RelayCommand NewLayerCommand { get; set; }
+
         public RelayCommand DeleteLayerCommand { get; set; }
+
         public RelayCommand RenameLayerCommand { get; set; }
+
         public RelayCommand MoveToBackCommand { get; set; }
+
         public RelayCommand MoveToFrontCommand { get; set; }
+
         public RelayCommand SwapColorsCommand { get; set; }
+
         public RelayCommand DeselectCommand { get; set; }
+
         public RelayCommand SelectAllCommand { get; set; }
+
         public RelayCommand CopyCommand { get; set; }
+
         public RelayCommand DuplicateCommand { get; set; }
+
         public RelayCommand CutCommand { get; set; }
+
         public RelayCommand PasteCommand { get; set; }
+
         public RelayCommand ClipCanvasCommand { get; set; }
+
         public RelayCommand DeletePixelsCommand { get; set; }
+
         public RelayCommand OpenResizePopupCommand { get; set; }
+
         public RelayCommand SelectColorCommand { get; set; }
+
         public RelayCommand RemoveSwatchCommand { get; set; }
+
         public RelayCommand SaveDocumentCommand { get; set; }
+
         public RelayCommand OnStartupCommand { get; set; }
+
         public RelayCommand CloseWindowCommand { get; set; }
+
         public RelayCommand CenterContentCommand { get; set; }
+
         public RelayCommand OpenHyperlinkCommand { get; set; }
+
         public RelayCommand ZoomCommand { get; set; }
+
         public RelayCommand ChangeToolSizeCommand { get; set; }
+
         public RelayCommand RestartApplicationCommand { get; set; }
 
         public double MouseXOnCanvas // Mouse X coordinate relative to canvas
@@ -229,7 +263,6 @@ namespace PixiEditor.ViewModels
             }
         }
 
-
         public bool RecenterZoombox
         {
             get => recenterZoombox;
@@ -240,7 +273,7 @@ namespace PixiEditor.ViewModels
             }
         }
 
-        public Color PrimaryColor //Primary color, hooked with left mouse button
+        public Color PrimaryColor // Primary color, hooked with left mouse button
         {
             get => primaryColor;
             set
@@ -269,14 +302,16 @@ namespace PixiEditor.ViewModels
 
         public ObservableCollection<Tool> ToolSet { get; set; }
 
-        public LayerChange[] UndoChanges //This acts like UndoManager process, but it was implemented before process system, so it can be transformed into it
+        public LayerChange[] UndoChanges // This acts like UndoManager process, but it was implemented before process system, so it can be transformed into it
         {
             get => undoChanges;
             set
             {
                 undoChanges = value;
-                for (var i = 0; i < value.Length; i++)
+                for (int i = 0; i < value.Length; i++)
+                {
                     BitmapManager.ActiveDocument.Layers[value[i].LayerIndex].SetPixels(value[i].PixelChanges);
+                }
             }
         }
 
@@ -311,6 +346,7 @@ namespace PixiEditor.ViewModels
         }
 
         public BitmapManager BitmapManager { get; set; }
+
         public PixelChangesController ChangesController { get; set; }
 
         public ShortcutController ShortcutController { get; set; }
@@ -337,13 +373,13 @@ namespace PixiEditor.ViewModels
         {
             return await Task.Run(async () =>
             {
-                var updateAvailable = await UpdateChecker.CheckUpdateAvailable();
-                var updateFileDoesNotExists = !File.Exists($"update-{UpdateChecker.LatestReleaseInfo.TagName}.zip");
+                bool updateAvailable = await UpdateChecker.CheckUpdateAvailable();
+                bool updateFileDoesNotExists = !File.Exists($"update-{UpdateChecker.LatestReleaseInfo.TagName}.zip");
                 if (updateAvailable && updateFileDoesNotExists)
                 {
                     VersionText = "Downloading update...";
                     await UpdateDownloader.DownloadReleaseZip(UpdateChecker.LatestReleaseInfo);
-                    VersionText = "to install update"; //Button shows "Restart" before this text
+                    VersionText = "to install update"; // Button shows "Restart" before this text
                     UpdateReadyToInstall = true;
                     return true;
                 }
@@ -354,31 +390,38 @@ namespace PixiEditor.ViewModels
 
         private void InitUpdateChecker()
         {
-            var assembly = Assembly.GetExecutingAssembly();
-            var info = FileVersionInfo.GetVersionInfo(assembly.Location);
+            Assembly assembly = Assembly.GetExecutingAssembly();
+            FileVersionInfo info = FileVersionInfo.GetVersionInfo(assembly.Location);
             UpdateChecker = new UpdateChecker(info.FileVersion);
             VersionText = $"Version {info.FileVersion}";
         }
 
         private void ZoomViewport(object parameter)
         {
-            double zoom = (int) parameter;
+            double zoom = (int)parameter;
             ZoomPercentage = zoom;
             ZoomPercentage = 100;
         }
 
         private void ChangeToolSize(object parameter)
         {
-            var increment = (int) parameter;
-            var newSize = BitmapManager.ToolSize + increment;
-            if (newSize > 0) BitmapManager.ToolSize = newSize;
+            int increment = (int)parameter;
+            int newSize = BitmapManager.ToolSize + increment;
+            if (newSize > 0)
+            {
+                BitmapManager.ToolSize = newSize;
+            }
         }
 
         private void OpenHyperlink(object parameter)
         {
-            if (parameter == null) return;
-            var url = (string) parameter;
-            var processInfo = new ProcessStartInfo
+            if (parameter == null)
+            {
+                return;
+            }
+
+            string url = (string)parameter;
+            ProcessStartInfo processInfo = new ProcessStartInfo
             {
                 FileName = url,
                 UseShellExecute = true
@@ -393,27 +436,39 @@ namespace PixiEditor.ViewModels
 
         private void CloseWindow(object property)
         {
-            if (!(property is CancelEventArgs)) throw new ArgumentException();
-
-            ((CancelEventArgs) property).Cancel = true;
+            if (!(property is CancelEventArgs))
+            {
+                throw new ArgumentException();
+            } ((CancelEventArgs)property).Cancel = true;
 
-            var result = ConfirmationType.No;
+            ConfirmationType result = ConfirmationType.No;
             if (unsavedDocumentModified)
             {
                 result = ConfirmationDialog.Show(ConfirmationDialogMessage);
-                if (result == ConfirmationType.Yes) SaveDocument(null);
+                if (result == ConfirmationType.Yes)
+                {
+                    SaveDocument(null);
+                }
             }
 
-            if (result != ConfirmationType.Canceled) ((CancelEventArgs) property).Cancel = false;
+            if (result != ConfirmationType.Canceled)
+            {
+                ((CancelEventArgs)property).Cancel = false;
+            }
         }
 
         private async void OnStartup(object parameter)
         {
-            var lastArg = Environment.GetCommandLineArgs().Last();
+            string lastArg = Environment.GetCommandLineArgs().Last();
             if (Importer.IsSupportedFile(lastArg) && File.Exists(lastArg))
+            {
                 Open(lastArg);
+            }
             else
+            {
                 OpenNewFilePopup(null);
+            }
+
             await CheckForUpdate();
         }
 
@@ -424,15 +479,18 @@ namespace PixiEditor.ViewModels
 
         private void Open(object property)
         {
-            var dialog = new OpenFileDialog
+            OpenFileDialog dialog = new OpenFileDialog
             {
                 Filter = "All Files|*.*|PixiEditor Files | *.pixi|PNG Files|*.png",
                 DefaultExt = "pixi"
             };
-            if ((bool) dialog.ShowDialog())
+            if ((bool)dialog.ShowDialog())
             {
                 if (Importer.IsSupportedFile(dialog.FileName))
+                {
                     Open(dialog.FileName);
+                }
+
                 RecenterZoombox = !RecenterZoombox;
             }
         }
@@ -441,17 +499,26 @@ namespace PixiEditor.ViewModels
         {
             if (unsavedDocumentModified)
             {
-                var result = ConfirmationDialog.Show(ConfirmationDialogMessage);
+                ConfirmationType result = ConfirmationDialog.Show(ConfirmationDialogMessage);
                 if (result == ConfirmationType.Yes)
+                {
                     SaveDocument(null);
-                else if (result == ConfirmationType.Canceled) return;
+                }
+                else if (result == ConfirmationType.Canceled)
+                {
+                    return;
+                }
             }
 
             ResetProgramStateValues();
             if (path.EndsWith(".pixi"))
+            {
                 OpenDocument(path);
+            }
             else
+            {
                 OpenFile(path);
+            }
         }
 
         private void OpenDocument(string path)
@@ -463,10 +530,10 @@ namespace PixiEditor.ViewModels
 
         private void SaveDocument(object parameter)
         {
-            var paramIsAsNew = parameter != null && parameter.ToString()?.ToLower() == "asnew";
+            bool paramIsAsNew = parameter != null && parameter.ToString()?.ToLower() == "asnew";
             if (paramIsAsNew || Exporter.SaveDocumentPath == null)
             {
-                var saved = Exporter.SaveAsEditableFileWithDialog(BitmapManager.ActiveDocument, !paramIsAsNew);
+                bool saved = Exporter.SaveAsEditableFileWithDialog(BitmapManager.ActiveDocument, !paramIsAsNew);
                 unsavedDocumentModified = unsavedDocumentModified && !saved;
             }
             else
@@ -478,10 +545,16 @@ namespace PixiEditor.ViewModels
 
         private void RemoveSwatch(object parameter)
         {
-            if (!(parameter is Color)) throw new ArgumentException();
-            var color = (Color) parameter;
+            if (!(parameter is Color))
+            {
+                throw new ArgumentException();
+            }
+
+            Color color = (Color)parameter;
             if (BitmapManager.ActiveDocument.Swatches.Contains(color))
+            {
                 BitmapManager.ActiveDocument.Swatches.Remove(color);
+            }
         }
 
         private void SelectColor(object parameter)
@@ -499,26 +572,34 @@ namespace PixiEditor.ViewModels
         public void AddSwatch(Color color)
         {
             if (!BitmapManager.ActiveDocument.Swatches.Contains(color))
+            {
                 BitmapManager.ActiveDocument.Swatches.Add(color);
+            }
         }
 
         private void OpenResizePopup(object parameter)
         {
-            var isCanvasDialog = (string) parameter == "canvas";
-            var dialog = new ResizeDocumentDialog(BitmapManager.ActiveDocument.Width,
-                BitmapManager.ActiveDocument.Height, isCanvasDialog);
+            bool isCanvasDialog = (string)parameter == "canvas";
+            ResizeDocumentDialog dialog = new ResizeDocumentDialog(
+                BitmapManager.ActiveDocument.Width,
+                BitmapManager.ActiveDocument.Height,
+                isCanvasDialog);
             if (dialog.ShowDialog())
             {
                 if (isCanvasDialog)
+                {
                     BitmapManager.ActiveDocument.ResizeCanvas(dialog.Width, dialog.Height, dialog.ResizeAnchor);
+                }
                 else
+                {
                     BitmapManager.ActiveDocument.Resize(dialog.Width, dialog.Height);
+                }
             }
         }
 
         private void DeletePixels(object parameter)
         {
-            BitmapManager.BitmapOperations.DeletePixels(new[] {BitmapManager.ActiveLayer},
+            BitmapManager.BitmapOperations.DeletePixels(new[] { BitmapManager.ActiveLayer },
                 ActiveSelection.SelectedPoints.ToArray());
         }
 
@@ -559,7 +640,7 @@ namespace PixiEditor.ViewModels
 
         public void SelectAll(object parameter)
         {
-            var select = new SelectTool();
+            SelectTool select = new SelectTool();
             ActiveSelection.SetSelection(select.GetAllSelection(), SelectionType.New);
         }
 
@@ -585,17 +666,17 @@ namespace PixiEditor.ViewModels
 
         public void SetTool(object parameter)
         {
-            SetActiveTool((ToolType) parameter);
+            SetActiveTool((ToolType)parameter);
         }
 
         public void RenameLayer(object parameter)
         {
-            BitmapManager.ActiveDocument.Layers[(int) parameter].IsRenaming = true;
+            BitmapManager.ActiveDocument.Layers[(int)parameter].IsRenaming = true;
         }
 
         private void KeyUp(object parameter)
         {
-            var args = (KeyEventArgs) parameter;
+            KeyEventArgs args = (KeyEventArgs)parameter;
             if (restoreToolOnKeyUp && ShortcutController.LastShortcut != null && ShortcutController.LastShortcut.ShortcutKey == args.Key)
             {
                 restoreToolOnKeyUp = false;
@@ -606,7 +687,7 @@ namespace PixiEditor.ViewModels
 
         public void KeyDown(object parameter)
         {
-            var args = (KeyEventArgs) parameter;
+            KeyEventArgs args = (KeyEventArgs)parameter;
             if (args.IsRepeat && !restoreToolOnKeyUp && ShortcutController.LastShortcut != null && ShortcutController.LastShortcut.Command == SelectToolCommand)
             {
                 restoreToolOnKeyUp = true;
@@ -624,13 +705,13 @@ namespace PixiEditor.ViewModels
         public void TriggerNewUndoChange(Tool toolUsed)
         {
             if (BitmapManager.IsOperationTool(toolUsed)
-                && ((BitmapOperationTool) toolUsed).UseDefaultUndoMethod)
+                && ((BitmapOperationTool)toolUsed).UseDefaultUndoMethod)
             {
-                var changes = ChangesController.PopChanges();
+                Tuple<LayerChange, LayerChange>[] changes = ChangesController.PopChanges();
                 if (changes != null && changes.Length > 0)
                 {
-                    var newValues = changes.Select(x => x.Item1).ToArray();
-                    var oldValues = changes.Select(x => x.Item2).ToArray();
+                    LayerChange[] newValues = changes.Select(x => x.Item1).ToArray();
+                    LayerChange[] oldValues = changes.Select(x => x.Item2).ToArray();
                     UndoManager.AddUndoChange(new Change("UndoChanges", oldValues, newValues));
                     toolUsed.AfterAddedUndo();
                 }
@@ -643,48 +724,56 @@ namespace PixiEditor.ViewModels
                 new LayerChange(e.OldPixelsValues, e.ChangedLayerIndex));
             unsavedDocumentModified = true;
             if (BitmapManager.IsOperationTool())
+            {
                 AddSwatch(PrimaryColor);
+            }
         }
 
         public void SwapColors(object parameter)
         {
-            var tmp = PrimaryColor;
+            Color tmp = PrimaryColor;
             PrimaryColor = SecondaryColor;
             SecondaryColor = tmp;
         }
 
         public void MoveLayerToFront(object parameter)
         {
-            var oldIndex = (int) parameter;
+            int oldIndex = (int)parameter;
             BitmapManager.ActiveDocument.Layers.Move(oldIndex, oldIndex + 1);
-            if (BitmapManager.ActiveDocument.ActiveLayerIndex == oldIndex) BitmapManager.SetActiveLayer(oldIndex + 1);
+            if (BitmapManager.ActiveDocument.ActiveLayerIndex == oldIndex)
+            {
+                BitmapManager.SetActiveLayer(oldIndex + 1);
+            }
         }
 
         public void MoveLayerToBack(object parameter)
         {
-            var oldIndex = (int) parameter;
+            int oldIndex = (int)parameter;
             BitmapManager.ActiveDocument.Layers.Move(oldIndex, oldIndex - 1);
-            if (BitmapManager.ActiveDocument.ActiveLayerIndex == oldIndex) BitmapManager.SetActiveLayer(oldIndex - 1);
+            if (BitmapManager.ActiveDocument.ActiveLayerIndex == oldIndex)
+            {
+                BitmapManager.SetActiveLayer(oldIndex - 1);
+            }
         }
 
         public bool CanMoveToFront(object property)
         {
-            return DocumentIsNotNull(null) && BitmapManager.ActiveDocument.Layers.Count - 1 > (int) property;
+            return DocumentIsNotNull(null) && BitmapManager.ActiveDocument.Layers.Count - 1 > (int)property;
         }
 
         public bool CanMoveToBack(object property)
         {
-            return (int) property > 0;
+            return (int)property > 0;
         }
 
         public void SetActiveLayer(object parameter)
         {
-            BitmapManager.SetActiveLayer((int) parameter);
+            BitmapManager.SetActiveLayer((int)parameter);
         }
 
         public void DeleteLayer(object parameter)
         {
-            BitmapManager.RemoveLayer((int) parameter);
+            BitmapManager.RemoveLayer((int)parameter);
         }
 
         public bool CanDeleteLayer(object property)
@@ -694,14 +783,17 @@ namespace PixiEditor.ViewModels
 
         public void SetActiveTool(ToolType tool)
         {
-            var foundTool = ToolSet.First(x => x.ToolType == tool);
+            Tool foundTool = ToolSet.First(x => x.ToolType == tool);
             SetActiveTool(foundTool);
         }
 
         public void SetActiveTool(Tool tool)
         {
-            var activeTool = ToolSet.FirstOrDefault(x => x.IsActive);
-            if (activeTool != null) activeTool.IsActive = false;
+            Tool activeTool = ToolSet.FirstOrDefault(x => x.IsActive);
+            if (activeTool != null)
+            {
+                activeTool.IsActive = false;
+            }
 
             tool.IsActive = true;
             lastActionTool = BitmapManager.SelectedTool;
@@ -712,22 +804,32 @@ namespace PixiEditor.ViewModels
         private void SetToolCursor(ToolType tool)
         {
             if (tool != ToolType.None)
+            {
                 ToolCursor = BitmapManager.SelectedTool.Cursor;
+            }
             else
+            {
                 ToolCursor = Cursors.Arrow;
+            }
         }
 
         private void MouseDown(object parameter)
         {
-            if (BitmapManager.ActiveDocument.Layers.Count == 0) return;
+            if (BitmapManager.ActiveDocument.Layers.Count == 0)
+            {
+                return;
+            }
+
             if (Mouse.LeftButton == MouseButtonState.Pressed)
+            {
                 if (!BitmapManager.MouseController.IsRecordingChanges)
                 {
-                    var clickedOnCanvas = MouseXOnCanvas >= 0 && MouseXOnCanvas <= BitmapManager.ActiveDocument.Width &&
+                    bool clickedOnCanvas = MouseXOnCanvas >= 0 && MouseXOnCanvas <= BitmapManager.ActiveDocument.Width &&
                                           MouseYOnCanvas >= 0 && MouseYOnCanvas <= BitmapManager.ActiveDocument.Height;
                     BitmapManager.MouseController.StartRecordingMouseMovementChanges(clickedOnCanvas);
                     BitmapManager.MouseController.RecordMouseMovementChange(MousePositionConverter.CurrentCoordinates);
                 }
+            }
 
             // Mouse down is guaranteed to only be raised from within this application, so by subscribing here we
             // only listen for mouse up events that occurred as a result of a mouse down within this application.
@@ -748,11 +850,14 @@ namespace PixiEditor.ViewModels
         /// <param name="parameter"></param>
         private void MouseMove(object parameter)
         {
-            var cords = new Coordinates((int) MouseXOnCanvas, (int) MouseYOnCanvas);
+            Coordinates cords = new Coordinates((int)MouseXOnCanvas, (int)MouseYOnCanvas);
             MousePositionConverter.CurrentCoordinates = cords;
 
+            if (BitmapManager.MouseController.IsRecordingChanges && Mouse.LeftButton == MouseButtonState.Pressed)
+            {
+                BitmapManager.MouseController.RecordMouseMovementChange(cords);
+            }
 
-            if (BitmapManager.MouseController.IsRecordingChanges && Mouse.LeftButton == MouseButtonState.Pressed) BitmapManager.MouseController.RecordMouseMovementChange(cords);
             BitmapManager.MouseController.MouseMoved(cords);
         }
 
@@ -762,8 +867,11 @@ namespace PixiEditor.ViewModels
         /// <param name="parameter"></param>
         public void OpenNewFilePopup(object parameter)
         {
-            var newFile = new NewFileDialog();
-            if (newFile.ShowDialog()) NewDocument(newFile.Width, newFile.Height);
+            NewFileDialog newFile = new NewFileDialog();
+            if (newFile.ShowDialog())
+            {
+                NewDocument(newFile.Width, newFile.Height);
+            }
         }
 
         /// <summary>
@@ -772,10 +880,12 @@ namespace PixiEditor.ViewModels
         /// <param name="path"></param>
         public void OpenFile(string path)
         {
-            var dialog = new ImportFileDialog();
+            ImportFileDialog dialog = new ImportFileDialog();
 
             if (path != null && File.Exists(path))
+            {
                 dialog.FilePath = path;
+            }
 
             if (dialog.ShowDialog())
             {
@@ -788,7 +898,10 @@ namespace PixiEditor.ViewModels
         {
             BitmapManager.ActiveDocument = new Document(width, height);
             if (addBaseLayer)
+            {
                 BitmapManager.AddNewLayer("Base Layer");
+            }
+
             ResetProgramStateValues();
         }
 
@@ -867,7 +980,7 @@ namespace PixiEditor.ViewModels
         /// <param name="parameter"></param>
         private void ExportFile(object parameter)
         {
-            var bitmap = BitmapManager.GetCombinedLayersBitmap();
+            System.Windows.Media.Imaging.WriteableBitmap bitmap = BitmapManager.GetCombinedLayersBitmap();
             Exporter.Export(bitmap, new Size(bitmap.PixelWidth, bitmap.PixelHeight));
         }
 

+ 13 - 8
PixiEditor/Views/AnchorPointPicker.xaml.cs

@@ -14,8 +14,7 @@ namespace PixiEditor.Views
         public static readonly DependencyProperty AnchorPointProperty =
             DependencyProperty.Register("AnchorPoint", typeof(AnchorPoint), typeof(AnchorPointPicker),
                 new PropertyMetadata());
-
-
+
         private ToggleButton selectedToggleButton;
 
         public AnchorPointPicker()
@@ -25,22 +24,28 @@ namespace PixiEditor.Views
 
         public AnchorPoint AnchorPoint
         {
-            get => (AnchorPoint) GetValue(AnchorPointProperty);
+            get => (AnchorPoint)GetValue(AnchorPointProperty);
             set => SetValue(AnchorPointProperty, value);
         }
 
         private void ToggleButton_Checked(object sender, RoutedEventArgs e)
         {
-            var btn = (ToggleButton) sender;
-            AnchorPoint = (AnchorPoint) (1 << (Grid.GetRow(btn) + 3)) | (AnchorPoint) (1 << Grid.GetColumn(btn));
-            if (selectedToggleButton != null) selectedToggleButton.IsChecked = false;
+            ToggleButton btn = (ToggleButton)sender;
+            AnchorPoint = (AnchorPoint)(1 << (Grid.GetRow(btn) + 3)) | (AnchorPoint)(1 << Grid.GetColumn(btn));
+            if (selectedToggleButton != null)
+            {
+                selectedToggleButton.IsChecked = false;
+            }
+
             selectedToggleButton = btn;
         }
 
         private void ToggleButton_Click(object sender, RoutedEventArgs e)
         {
-            if ((sender as ToggleButton).IsChecked.Value)
-                e.Handled = true;
+            if ((sender as ToggleButton).IsChecked.Value)
+            {
+                e.Handled = true;
+            }
         }
     }
 }

+ 5 - 5
PixiEditor/Views/ConfirmationPopup.xaml.cs

@@ -26,24 +26,24 @@ namespace PixiEditor.Views
         }
 
         public RelayCommand CancelCommand { get; set; }
+
         public RelayCommand SetResultAndCloseCommand { get; set; }
 
         public bool Result
         {
-            get => (bool) GetValue(SaveChangesProperty);
+            get => (bool)GetValue(SaveChangesProperty);
             set => SetValue(SaveChangesProperty, value);
         }
-
-
+
         public string Body
         {
-            get => (string) GetValue(BodyProperty);
+            get => (string)GetValue(BodyProperty);
             set => SetValue(BodyProperty, value);
         }
 
         private void SetResultAndClose(object property)
         {
-            var result = (bool) property;
+            bool result = (bool)property;
             Result = result;
             DialogResult = true;
             Close();

+ 13 - 11
PixiEditor/Views/EditableTextBlock.xaml.cs

@@ -15,7 +15,6 @@ namespace PixiEditor.Views
             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),
@@ -33,29 +32,27 @@ namespace PixiEditor.Views
 
         public Visibility TextBlockVisibility
         {
-            get => (Visibility) GetValue(TextBlockVisibilityProperty);
+            get => (Visibility)GetValue(TextBlockVisibilityProperty);
             set => SetValue(TextBlockVisibilityProperty, value);
         }
 
-
         public bool IsEditing
         {
-            get => (bool) GetValue(EnableEditingProperty);
+            get => (bool)GetValue(EnableEditingProperty);
             set => SetValue(EnableEditingProperty, value);
         }
 
-
         public string Text
         {
-            get => (string) GetValue(TextProperty);
+            get => (string)GetValue(TextProperty);
             set => SetValue(TextProperty, value);
         }
 
         private static void OnIsEditingChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
         {
-            if ((bool) e.NewValue)
+            if ((bool)e.NewValue)
             {
-                var tb = (EditableTextBlock) d;
+                EditableTextBlock tb = (EditableTextBlock)d;
                 tb.EnableEditing();
             }
         }
@@ -76,15 +73,20 @@ namespace PixiEditor.Views
             IsEditing = false;
         }
 
-
         private void TextBlock_MouseDown(object sender, MouseButtonEventArgs e)
         {
-            if (e.ChangedButton == MouseButton.Left && e.ClickCount == 2) EnableEditing();
+            if (e.ChangedButton == MouseButton.Left && e.ClickCount == 2)
+            {
+                EnableEditing();
+            }
         }
 
         private void TextBox_KeyDown(object sender, KeyEventArgs e)
         {
-            if (e.Key == Key.Enter) DisableEditing();
+            if (e.Key == Key.Enter)
+            {
+                DisableEditing();
+            }
         }
 
         private void TextBox_LostFocus(object sender, RoutedEventArgs e)

+ 3 - 6
PixiEditor/Views/ImportFilePopup.xaml.cs

@@ -15,22 +15,19 @@ namespace PixiEditor.Views
             InitializeComponent();
             DataContext = dc;
         }
-
-
+
         public int ImportHeight
         {
             get => dc.ImportHeight;
             set => dc.ImportWidth = value;
         }
-
-
+
         public int ImportWidth
         {
             get => dc.ImportWidth;
             set => dc.ImportWidth = value;
         }
-
-
+
         public string FilePath
         {
             get => dc.FilePath;

+ 10 - 12
PixiEditor/Views/LayerItem.xaml.cs

@@ -42,54 +42,52 @@ namespace PixiEditor.Views
 
         public bool IsRenaming
         {
-            get => (bool) GetValue(IsRenamingProperty);
+            get => (bool)GetValue(IsRenamingProperty);
             set => SetValue(IsRenamingProperty, value);
         }
 
         public bool IsActive
         {
-            get => (bool) GetValue(IsActiveProperty);
+            get => (bool)GetValue(IsActiveProperty);
             set => SetValue(IsActiveProperty, value);
         }
 
         public RelayCommand SetActiveLayerCommand
         {
-            get => (RelayCommand) GetValue(SetActiveLayerCommandProperty);
+            get => (RelayCommand)GetValue(SetActiveLayerCommandProperty);
             set => SetValue(SetActiveLayerCommandProperty, value);
         }
 
         public int LayerIndex
         {
-            get => (int) GetValue(LayerIndexProperty);
+            get => (int)GetValue(LayerIndexProperty);
             set => SetValue(LayerIndexProperty, value);
         }
 
         public string LayerName
         {
-            get => (string) GetValue(LayerNameProperty);
+            get => (string)GetValue(LayerNameProperty);
             set => SetValue(LayerNameProperty, value);
         }
 
         public Visibility ControlButtonsVisible
         {
-            get => (Visibility) GetValue(ControlButtonsVisibleProperty);
+            get => (Visibility)GetValue(ControlButtonsVisibleProperty);
             set => SetValue(ControlButtonsVisibleProperty, value);
         }
-
-
+
         public RelayCommand MoveToBackCommand
         {
-            get => (RelayCommand) GetValue(MoveToBackCommandProperty);
+            get => (RelayCommand)GetValue(MoveToBackCommandProperty);
             set => SetValue(MoveToBackCommandProperty, value);
         }
 
         public RelayCommand MoveToFrontCommand
         {
-            get => (RelayCommand) GetValue(MoveToFrontCommandProperty);
+            get => (RelayCommand)GetValue(MoveToFrontCommandProperty);
             set => SetValue(MoveToFrontCommandProperty, value);
         }
-
-
+
         private void LayerItem_OnMouseEnter(object sender, MouseEventArgs e)
         {
             ControlButtonsVisible = Visibility.Visible;

+ 47 - 34
PixiEditor/Views/MainDrawingPanel.xaml.cs

@@ -54,50 +54,45 @@ namespace PixiEditor.Views
         public MainDrawingPanel()
         {
             InitializeComponent();
-            Zoombox.ZoomToSelectionModifiers = new KeyModifierCollection {KeyModifier.RightAlt};
+            Zoombox.ZoomToSelectionModifiers = new KeyModifierCollection { KeyModifier.RightAlt };
         }
-
-
+
         public double ZoomPercentage
         {
-            get => (double) GetValue(ZoomPercentageProperty);
+            get => (double)GetValue(ZoomPercentageProperty);
             set => SetValue(ZoomPercentageProperty, value);
         }
-
-
+
         public bool Center
         {
-            get => (bool) GetValue(CenterProperty);
+            get => (bool)GetValue(CenterProperty);
             set => SetValue(CenterProperty, value);
         }
 
         public double MouseX
         {
-            get => (double) GetValue(MouseXProperty);
+            get => (double)GetValue(MouseXProperty);
             set => SetValue(MouseXProperty, value);
         }
 
         public double MouseY
         {
-            get => (double) GetValue(MouseYProperty);
+            get => (double)GetValue(MouseYProperty);
             set => SetValue(MouseYProperty, value);
         }
-
-
+
         public ICommand MouseMoveCommand
         {
-            get => (ICommand) GetValue(MouseMoveCommandProperty);
+            get => (ICommand)GetValue(MouseMoveCommandProperty);
             set => SetValue(MouseMoveCommandProperty, value);
         }
-
-
+
         public bool CenterOnStart
         {
-            get => (bool) GetValue(CenterOnStartProperty);
+            get => (bool)GetValue(CenterOnStartProperty);
             set => SetValue(CenterOnStartProperty, value);
         }
-
-
+
         public object Item
         {
             get => GetValue(ItemProperty);
@@ -106,54 +101,72 @@ namespace PixiEditor.Views
 
         public bool IsUsingZoomTool
         {
-            get => (bool) GetValue(IsUsingZoomToolProperty);
+            get => (bool)GetValue(IsUsingZoomToolProperty);
             set => SetValue(IsUsingZoomToolProperty, value);
         }
 
         private static void ZoomPercentegeChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
         {
-            var panel = (MainDrawingPanel) d;
-            var percentage = (double) e.NewValue;
-            if (percentage == 100) panel.SetClickValues();
-            panel.Zoombox.ZoomTo(panel.ClickScale * ((double) e.NewValue / 100.0));
+            MainDrawingPanel panel = (MainDrawingPanel)d;
+            double percentage = (double)e.NewValue;
+            if (percentage == 100)
+            {
+                panel.SetClickValues();
+            }
+
+            panel.Zoombox.ZoomTo(panel.ClickScale * ((double)e.NewValue / 100.0));
         }
 
         private void Zoombox_CurrentViewChanged(object sender, ZoomboxViewChangedEventArgs e)
         {
-            Zoombox.MinScale = 32 / ((FrameworkElement) Item).Width;
+            Zoombox.MinScale = 32 / ((FrameworkElement)Item).Width;
             Zoombox.KeepContentInBounds = !(Zoombox.Scale > Zoombox.MinScale * 35.0);
         }
 
         private void Zoombox_PreviewMouseDown(object sender, MouseButtonEventArgs e)
         {
-            if (ZoomPercentage == 100) SetClickValues();
+            if (ZoomPercentage == 100)
+            {
+                SetClickValues();
+            }
         }
 
         private void SetClickValues()
         {
-            if (!IsUsingZoomTool) return;
+            if (!IsUsingZoomTool)
+            {
+                return;
+            }
+
             ClickScale = Zoombox.Scale;
             SetZoomOrigin();
         }
 
         private void SetZoomOrigin()
         {
-            var item = (FrameworkElement) Item;
-            if (item == null) return;
-            var mousePos = Mouse.GetPosition(item);
+            FrameworkElement item = (FrameworkElement)Item;
+            if (item == null)
+            {
+                return;
+            }
+
+            Point mousePos = Mouse.GetPosition(item);
             Zoombox.ZoomOrigin = new Point(Math.Clamp(mousePos.X / item.Width, 0, 1), Math.Clamp(mousePos.Y / item.Height, 0, 1));
         }
 
         private static void OnCenterChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
         {
-            var panel = (MainDrawingPanel) d;
+            MainDrawingPanel panel = (MainDrawingPanel)d;
             panel.Zoombox.CenterContent();
         }
-
-
+
         private void Zoombox_Loaded(object sender, RoutedEventArgs e)
         {
-            if (CenterOnStart) ((Zoombox) sender).CenterContent();
+            if (CenterOnStart)
+            {
+                ((Zoombox)sender).CenterContent();
+            }
+
             ClickScale = Zoombox.Scale;
         }
 
@@ -165,13 +178,13 @@ namespace PixiEditor.Views
         private void mainDrawingPanel_MouseDown(object sender, MouseButtonEventArgs e)
         {
             IsUsingZoomTool = ViewModelMain.Current.BitmapManager.SelectedTool is ZoomTool;
-            Mouse.Capture((IInputElement) sender, CaptureMode.SubTree);
+            Mouse.Capture((IInputElement)sender, CaptureMode.SubTree);
             SetClickValues();
         }
 
         private void mainDrawingPanel_PreviewMouseUp(object sender, MouseButtonEventArgs e)
         {
-            ((IInputElement) sender).ReleaseMouseCapture();
+            ((IInputElement)sender).ReleaseMouseCapture();
         }
     }
 }

+ 4 - 8
PixiEditor/Views/MainWindow.xaml.cs

@@ -19,7 +19,7 @@ namespace PixiEditor
             InitializeComponent();
             StateChanged += MainWindowStateChangeRaised;
             MaxHeight = SystemParameters.MaximizedPrimaryScreenHeight;
-            viewModel = (ViewModelMain) DataContext;
+            viewModel = (ViewModelMain)DataContext;
             viewModel.CloseAction = Close;
         }
 
@@ -28,19 +28,16 @@ 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);
@@ -51,7 +48,6 @@ namespace PixiEditor
             SystemCommands.CloseWindow(this);
         }
 
-
         private void MainWindowStateChangeRaised(object sender, EventArgs e)
         {
             if (WindowState == WindowState.Maximized)
@@ -68,9 +64,9 @@ namespace PixiEditor
 
         private void mainWindow_Initialized(object sender, EventArgs e)
         {
-            var dir = AppDomain.CurrentDomain.BaseDirectory;
-            var updateFileExists = Directory.GetFiles(dir, "update-*.zip").Length > 0;
-            var updaterPath = Path.Join(dir, "PixiEditor.UpdateInstaller.exe");
+            string dir = AppDomain.CurrentDomain.BaseDirectory;
+            bool updateFileExists = Directory.GetFiles(dir, "update-*.zip").Length > 0;
+            string updaterPath = Path.Join(dir, "PixiEditor.UpdateInstaller.exe");
             if (updateFileExists && File.Exists(updaterPath))
             {
                 Process.Start(updaterPath);

+ 2 - 3
PixiEditor/Views/MenuButton.xaml.cs

@@ -27,11 +27,10 @@ namespace PixiEditor.Views
 
         public string Text
         {
-            get => (string) GetValue(MenuButtonTextProperty);
+            get => (string)GetValue(MenuButtonTextProperty);
             set => SetValue(MenuButtonTextProperty, value);
         }
-
-
+
         public object Item
         {
             get => GetValue(ItemProperty);

+ 4 - 6
PixiEditor/Views/NewFilePopup.xaml.cs

@@ -19,18 +19,16 @@ namespace PixiEditor.Views
         {
             InitializeComponent();
         }
-
-
+
         public int FileHeight
         {
-            get => (int) GetValue(FileHeightProperty);
+            get => (int)GetValue(FileHeightProperty);
             set => SetValue(FileHeightProperty, value);
         }
-
-
+
         public int FileWidth
         {
-            get => (int) GetValue(FileWidthProperty);
+            get => (int)GetValue(FileWidthProperty);
             set => SetValue(FileWidthProperty, value);
         }
     }

+ 8 - 10
PixiEditor/Views/NumberInput.xaml.cs

@@ -25,8 +25,7 @@ namespace PixiEditor.Views
         public static readonly DependencyProperty MaxProperty =
             DependencyProperty.Register("Max", typeof(float), typeof(NumberInput),
                 new PropertyMetadata(float.PositiveInfinity));
-
-
+
         public NumberInput()
         {
             InitializeComponent();
@@ -34,32 +33,31 @@ namespace PixiEditor.Views
 
         public float Value
         {
-            get => (float) GetValue(ValueProperty);
+            get => (float)GetValue(ValueProperty);
             set => SetValue(ValueProperty, value);
         }
 
         public float Min
         {
-            get => (float) GetValue(MinProperty);
+            get => (float)GetValue(MinProperty);
             set => SetValue(MinProperty, value);
         }
-
-
+
         public float Max
         {
-            get => (float) GetValue(MaxProperty);
+            get => (float)GetValue(MaxProperty);
             set => SetValue(MaxProperty, value);
         }
 
         private static void OnValueChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
         {
-            var input = (NumberInput) d;
-            input.Value = Math.Clamp((float) e.NewValue, input.Min, input.Max);
+            NumberInput input = (NumberInput)d;
+            input.Value = Math.Clamp((float)e.NewValue, input.Min, input.Max);
         }
 
         private void TextBox_PreviewTextInput(object sender, TextCompositionEventArgs e)
         {
-            var regex = new Regex("^[.][0-9]+$|^[0-9]*[.]{0,1}[0-9]*$");
+            Regex regex = new Regex("^[.][0-9]+$|^[0-9]*[.]{0,1}[0-9]*$");
             e.Handled = !regex.IsMatch((sender as TextBox).Text.Insert((sender as TextBox).SelectionStart, e.Text));
         }
     }

+ 7 - 11
PixiEditor/Views/ResizeCanvasPopup.xaml.cs

@@ -26,29 +26,25 @@ namespace PixiEditor.Views
         {
             InitializeComponent();
         }
-
-
+
         public AnchorPoint SelectedAnchorPoint
         {
-            get => (AnchorPoint) GetValue(SelectedAnchorPointProperty);
+            get => (AnchorPoint)GetValue(SelectedAnchorPointProperty);
             set => SetValue(SelectedAnchorPointProperty, value);
         }
-
-
+
         public int NewHeight
         {
-            get => (int) GetValue(NewHeightProperty);
+            get => (int)GetValue(NewHeightProperty);
             set => SetValue(NewHeightProperty, value);
         }
-
-
+
         public int NewWidth
         {
-            get => (int) GetValue(NewWidthProperty);
+            get => (int)GetValue(NewWidthProperty);
             set => SetValue(NewWidthProperty, value);
         }
-
-
+
         private void CommandBinding_CanExecute(object sender, CanExecuteRoutedEventArgs e)
         {
             e.CanExecute = true;

+ 5 - 8
PixiEditor/Views/ResizeDocumentPopup.xaml.cs

@@ -21,22 +21,19 @@ namespace PixiEditor.Views
             InitializeComponent();
             DataContext = this;
         }
-
-
+
         public int NewHeight
         {
-            get => (int) GetValue(NewHeightProperty);
+            get => (int)GetValue(NewHeightProperty);
             set => SetValue(NewHeightProperty, value);
         }
-
-
+
         public int NewWidth
         {
-            get => (int) GetValue(NewWidthProperty);
+            get => (int)GetValue(NewWidthProperty);
             set => SetValue(NewWidthProperty, value);
         }
-
-
+
         private void CommandBinding_CanExecute(object sender, CanExecuteRoutedEventArgs e)
         {
             e.CanExecute = true;

+ 9 - 7
PixiEditor/Views/Rotatebox.xaml.cs

@@ -27,11 +27,10 @@ namespace PixiEditor.Views
 
         public double Angle
         {
-            get => (double) GetValue(AngleProperty);
+            get => (double)GetValue(AngleProperty);
             set => SetValue(AngleProperty, value);
         }
-
-
+
         private void OnMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
         {
             Mouse.Capture(this);
@@ -49,19 +48,22 @@ namespace PixiEditor.Views
             if (Equals(Mouse.Captured, this))
             {
                 // Get the current mouse position relative to the control
-                var currentLocation = Mouse.GetPosition(this);
+                Point currentLocation = Mouse.GetPosition(this);
 
                 // We want to rotate around the center of the knob, not the top corner
-                var knobCenter = new Point(width / 2, height / 2);
+                Point knobCenter = new Point(width / 2, height / 2);
 
                 // Calculate an angle
-                var radians = Math.Atan((currentLocation.Y - knobCenter.Y) /
+                double radians = Math.Atan((currentLocation.Y - knobCenter.Y) /
                                         (currentLocation.X - knobCenter.X));
                 Angle = radians * 180 / Math.PI + offset;
 
                 // Apply a 180 degree shift when X is negative so that we can rotate
                 // all of the way around
-                if (currentLocation.X - knobCenter.X < 0) Angle += 180;
+                if (currentLocation.X - knobCenter.X < 0)
+                {
+                    Angle += 180;
+                }
             }
         }
     }

+ 5 - 8
PixiEditor/Views/SaveFilePopup.xaml.cs

@@ -11,8 +11,7 @@ namespace PixiEditor.Views
         // Using a DependencyProperty as the backing store for SaveHeight.  This enables animation, styling, binding, etc...
         public static readonly DependencyProperty SaveHeightProperty =
             DependencyProperty.Register("SaveHeight", typeof(int), typeof(SaveFilePopup), new PropertyMetadata(32));
-
-
+
         // Using a DependencyProperty as the backing store for SaveWidth.  This enables animation, styling, binding, etc...
         public static readonly DependencyProperty SaveWidthProperty =
             DependencyProperty.Register("SaveWidth", typeof(int), typeof(SaveFilePopup), new PropertyMetadata(32));
@@ -24,18 +23,16 @@ namespace PixiEditor.Views
             InitializeComponent();
             DataContext = dataContext;
         }
-
-
+
         public int SaveWidth
         {
-            get => (int) GetValue(SaveWidthProperty);
+            get => (int)GetValue(SaveWidthProperty);
             set => SetValue(SaveWidthProperty, value);
         }
-
-
+
         public int SaveHeight
         {
-            get => (int) GetValue(SaveHeightProperty);
+            get => (int)GetValue(SaveHeightProperty);
             set => SetValue(SaveHeightProperty, value);
         }
 

+ 9 - 11
PixiEditor/Views/SizeInput.xaml.cs

@@ -31,36 +31,34 @@ namespace PixiEditor.Views
         {
             InitializeComponent();
         }
-
-
+
         public int Size
         {
-            get => (int) GetValue(SizeProperty);
+            get => (int)GetValue(SizeProperty);
             set => SetValue(SizeProperty, value);
         }
 
         public bool PreserveAspectRatio
         {
-            get => (bool) GetValue(PreserveAspectRatioProperty);
+            get => (bool)GetValue(PreserveAspectRatioProperty);
             set => SetValue(PreserveAspectRatioProperty, value);
         }
-
-
+
         public int AspectRatioValue
         {
-            get => (int) GetValue(AspectRatioValueProperty);
+            get => (int)GetValue(AspectRatioValueProperty);
             set => SetValue(AspectRatioValueProperty, value);
         }
 
         private static void AspectRatioValChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
         {
-            var input = (SizeInput) d;
+            SizeInput input = (SizeInput)d;
 
             if (input.PreserveAspectRatio && input.loadedSize != -1)
             {
-                var newVal = (int) e.NewValue;
-                var ratio = newVal / Math.Clamp(input.loadedAspectRatioSize, 1f, float.MaxValue);
-                input.Size = (int) (input.loadedSize * ratio);
+                int newVal = (int)e.NewValue;
+                float ratio = newVal / Math.Clamp(input.loadedAspectRatioSize, 1f, float.MaxValue);
+                input.Size = (int)(input.loadedSize * ratio);
             }
         }
 

Some files were not shown because too many files changed in this diff