Browse Source

Fix eracer tool and the dirty rect of line tool

Equbuxu 3 years ago
parent
commit
b9f98176e6

+ 1 - 2
PixiEditor/Models/Tools/Tools/EraserTool.cs

@@ -1,5 +1,4 @@
 using PixiEditor.Models.Controllers;
-using PixiEditor.Models.DataHolders;
 using PixiEditor.Models.Layers;
 using PixiEditor.Models.Position;
 using PixiEditor.Models.Tools.ToolSettings.Settings;
@@ -32,7 +31,7 @@ namespace PixiEditor.Models.Tools.Tools
         public void Erase(Layer layer, List<Coordinates> coordinates, int toolSize)
         {
             Coordinates startingCords = coordinates.Count > 1 ? coordinates[1] : coordinates[0];
-            pen.Draw(layer, startingCords, coordinates[0], SKColors.Transparent, toolSize);
+            pen.Draw(layer, startingCords, coordinates[0], SKColors.Transparent, toolSize, false, null, SKBlendMode.Src);
         }
     }
 }

+ 17 - 16
PixiEditor/Models/Tools/Tools/LineTool.cs

@@ -1,18 +1,13 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Windows;
-using System.Windows.Input;
-using System.Windows.Media;
-using System.Windows.Media.Imaging;
-using PixiEditor.Helpers.Extensions;
-using PixiEditor.Models.DataHolders;
-using PixiEditor.Models.Enums;
+using PixiEditor.Helpers.Extensions;
 using PixiEditor.Models.Layers;
 using PixiEditor.Models.Position;
 using PixiEditor.Models.Tools.ToolSettings.Settings;
 using PixiEditor.Models.Tools.ToolSettings.Toolbars;
 using SkiaSharp;
+using System;
+using System.Collections.Generic;
+using System.Windows;
+using System.Windows.Input;
 
 namespace PixiEditor.Models.Tools.Tools
 {
@@ -53,21 +48,26 @@ namespace PixiEditor.Models.Tools.Tools
             Coordinates start = coordinates[0];
             Coordinates end = coordinates[^1];
 
-            DrawLine(layer, start, end, color, thickness);
+            DrawLine(layer, start, end, color, thickness, SKBlendMode.SrcOver);
         }
 
-        public void DrawLine(Layer layer, Coordinates start, Coordinates end, SKColor color, int thickness, SKStrokeCap strokeCap = SKStrokeCap.Butt)
+        public void DrawLine(
+            Layer layer, Coordinates start, Coordinates end, SKColor color, int thickness, SKBlendMode blendMode,
+            SKStrokeCap strokeCap = SKStrokeCap.Butt)
         {
             int x = start.X;
             int y = start.Y;
             int x1 = end.X;
             int y1 = end.Y;
 
+            int dirtyX = Math.Min(x, x1) - thickness;
+            int dirtyY = Math.Min(y, y1) - thickness;
+
             Int32Rect dirtyRect = new Int32Rect(
-                Math.Min(x, x1) - thickness,
-                Math.Min(y, y1) - thickness,
-                Math.Max(x1, x) + thickness,
-                Math.Max(y1, y) + thickness);
+                dirtyX,
+                dirtyY,
+                Math.Max(x1, x) + thickness - dirtyX,
+                Math.Max(y1, y) + thickness - dirtyY);
             Int32Rect curLayerRect = new(layer.OffsetX, layer.OffsetY, layer.Width, layer.Height);
             Int32Rect expanded = dirtyRect.Expand(curLayerRect);
 
@@ -78,6 +78,7 @@ namespace PixiEditor.Models.Tools.Tools
                 paint.StrokeWidth = thickness;
                 paint.Style = SKPaintStyle.Stroke;
                 paint.Color = color;
+                paint.BlendMode = blendMode;
                 paint.StrokeCap = strokeCap;
                 layer.LayerBitmap.SkiaSurface.Canvas.DrawLine(x, y, x1, y1, paint);
             }

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

@@ -1,5 +1,4 @@
-using PixiEditor.Helpers.Extensions;
-using PixiEditor.Models.Controllers;
+using PixiEditor.Models.Controllers;
 using PixiEditor.Models.DataHolders;
 using PixiEditor.Models.Layers;
 using PixiEditor.Models.Position;
@@ -64,11 +63,15 @@ namespace PixiEditor.Models.Tools.Tools
                 BitmapManager.ActiveDocument.PreviewLayer);
         }
 
-        public void Draw(Layer layer, Coordinates startingCoords, Coordinates latestCords, SKColor color, int toolSize, bool pixelPerfect = false, Layer previewLayer = null)
+        public void Draw(
+            Layer layer, Coordinates startingCoords, Coordinates latestCords, SKColor color, int toolSize,
+            bool pixelPerfect = false,
+            Layer previewLayer = null,
+            SKBlendMode blendMode = SKBlendMode.SrcOver)
         {
             if (!pixelPerfect)
             {
-                lineTool.DrawLine(layer, startingCoords, latestCords, color, toolSize, SKStrokeCap.Square);
+                lineTool.DrawLine(layer, startingCoords, latestCords, color, toolSize, blendMode, SKStrokeCap.Square);
                 return;
             }
 
@@ -77,7 +80,7 @@ namespace PixiEditor.Models.Tools.Tools
                 confirmedPixels.Add(latestCords);
             }
 
-            lineTool.DrawLine(layer, startingCoords, latestCords, color, 1, SKStrokeCap.Square);
+            lineTool.DrawLine(layer, startingCoords, latestCords, color, 1, blendMode, SKStrokeCap.Square);
             //SetPixelToCheck(latestPixels);
 
             /*if (changedPixelsindex == 2)