Browse Source

Fixed line with thickness even line

flabbet 4 years ago
parent
commit
5f029d5bc4
1 changed files with 31 additions and 3 deletions
  1. 31 3
      PixiEditor/Models/Controllers/BitmapOperationsUtility.cs

+ 31 - 3
PixiEditor/Models/Controllers/BitmapOperationsUtility.cs

@@ -11,6 +11,7 @@ using PixiEditor.Models.ImageManipulation;
 using PixiEditor.Models.Layers;
 using PixiEditor.Models.Layers;
 using PixiEditor.Models.Position;
 using PixiEditor.Models.Position;
 using PixiEditor.Models.Tools;
 using PixiEditor.Models.Tools;
+using PixiEditor.Models.Tools.ToolSettings.Settings;
 using PixiEditor.Models.Undo;
 using PixiEditor.Models.Undo;
 using PixiEditor.ViewModels;
 using PixiEditor.ViewModels;
 
 
@@ -118,10 +119,17 @@ namespace PixiEditor.Models.Controllers
 
 
         private void UseTool(List<Coordinates> mouseMoveCords, BitmapOperationTool tool, Color color)
         private void UseTool(List<Coordinates> mouseMoveCords, BitmapOperationTool tool, Color color)
         {
         {
-            if (Keyboard.IsKeyDown(Key.LeftShift) && !MouseCordsNotInLine(mouseMoveCords))
+            SizeSetting sizeSetting = tool.Toolbar.GetSetting<SizeSetting>("ToolSize");
+            int thickness = sizeSetting != null ? sizeSetting.Value : 1;
+            bool mouseInLine = MouseCordsNotInLine(mouseMoveCords, thickness);
+            if (Keyboard.IsKeyDown(Key.LeftShift) && !mouseInLine)
             {
             {
                 mouseMoveCords = GetSquareCoordiantes(mouseMoveCords);
                 mouseMoveCords = GetSquareCoordiantes(mouseMoveCords);
             }
             }
+            else if (mouseInLine)
+            {
+                mouseMoveCords = GetLineCoordinates(mouseMoveCords, thickness);
+            }
 
 
             if (!tool.RequiresPreviewLayer)
             if (!tool.RequiresPreviewLayer)
             {
             {
@@ -173,9 +181,29 @@ namespace PixiEditor.Models.Controllers
             return oldPixelValues;
             return oldPixelValues;
         }
         }
 
 
-        private bool MouseCordsNotInLine(List<Coordinates> cords)
+        private bool MouseCordsNotInLine(List<Coordinates> cords, int thickness)
         {
         {
-            return cords[0].X == cords[^1].X || cords[0].Y == cords[^1].Y;
+            return (cords[0].X > cords[^1].X - thickness && cords[0].X < cords[^1].X + thickness)
+                || (cords[0].Y > cords[^1].Y - thickness && cords[0].Y < cords[^1].Y + thickness);
+        }
+
+        private List<Coordinates> GetLineCoordinates(List<Coordinates> mouseMoveCords, int thickness)
+        {
+            int y = mouseMoveCords[0].Y;
+            int x = mouseMoveCords[0].X;
+
+
+            if (Math.Abs(mouseMoveCords[^1].X - mouseMoveCords[0].X) - thickness > 0)
+            {
+                y = mouseMoveCords[^1].Y;
+            }
+            else
+            {
+                x = mouseMoveCords[^1].X;
+            }
+
+            mouseMoveCords[0] = new Coordinates(x, y);
+            return mouseMoveCords;
         }
         }
 
 
         /// <summary>
         /// <summary>