Browse Source

Fix fill tool behaviour outside selection

Equbuxu 2 years ago
parent
commit
2481bc7eb9

+ 3 - 0
src/PixiEditor.ChangeableDocument/Changes/Drawing/FloodFill/FloodFillHelper.cs

@@ -35,6 +35,9 @@ internal static class FloodFillHelper
         VecI startingPos,
         VecI startingPos,
         Color drawingColor)
         Color drawingColor)
     {
     {
+        if (selection is not null && !selection.Contains(startingPos.X + 0.5f, startingPos.Y + 0.5f))
+            return new();
+
         int chunkSize = ChunkResolution.Full.PixelSize();
         int chunkSize = ChunkResolution.Full.PixelSize();
 
 
         FloodFillChunkCache cache = CreateCache(membersToFloodFill, document);
         FloodFillChunkCache cache = CreateCache(membersToFloodFill, document);

+ 5 - 0
src/PixiEditor.ChangeableDocument/Changes/Drawing/FloodFill/FloodFill_Change.cs

@@ -42,6 +42,11 @@ internal class FloodFill_Change : Change
         else
         else
             membersToReference.Add(memberGuid);
             membersToReference.Add(memberGuid);
         var floodFilledChunks = FloodFillHelper.FloodFill(membersToReference, target, selection, pos, color);
         var floodFilledChunks = FloodFillHelper.FloodFill(membersToReference, target, selection, pos, color);
+        if (floodFilledChunks.Count == 0)
+        {
+            ignoreInUndo = true;
+            return new None();
+        }
 
 
         foreach (var (chunkPos, chunk) in floodFilledChunks)
         foreach (var (chunkPos, chunk) in floodFilledChunks)
         {
         {

+ 1 - 0
src/PixiEditor.DrawingApi.Core/Bridge/NativeObjectsImpl/IVectorPathImplementation.cs

@@ -36,5 +36,6 @@ public interface IVectorPathImplementation
     public void Close(VectorPath vectorPath);
     public void Close(VectorPath vectorPath);
     public VectorPath Simplify(VectorPath vectorPath);
     public VectorPath Simplify(VectorPath vectorPath);
     public string ToSvgPathData(VectorPath vectorPath);
     public string ToSvgPathData(VectorPath vectorPath);
+    public bool Contains(VectorPath vectorPath, float x, float y);
     public void AddPath(VectorPath vectorPath, VectorPath path, AddPathMode mode);
     public void AddPath(VectorPath vectorPath, VectorPath path, AddPathMode mode);
 }
 }

+ 7 - 1
src/PixiEditor.DrawingApi.Core/Surface/Vector/VectorPath.cs

@@ -1,5 +1,6 @@
 using System;
 using System;
 using System.ComponentModel;
 using System.ComponentModel;
+using System.IO;
 using PixiEditor.DrawingApi.Core.Bridge;
 using PixiEditor.DrawingApi.Core.Bridge;
 using PixiEditor.DrawingApi.Core.Numerics;
 using PixiEditor.DrawingApi.Core.Numerics;
 
 
@@ -141,7 +142,12 @@ public class VectorPath : NativeObject
     {
     {
         DrawingBackendApi.Current.PathImplementation.AddPath(this, path, mode);
         DrawingBackendApi.Current.PathImplementation.AddPath(this, path, mode);
     }
     }
-    
+
+    public bool Contains(float x, float y)
+    {
+        return DrawingBackendApi.Current.PathImplementation.Contains(this, x, y);
+    }
+
     public VectorPath Simplify()
     public VectorPath Simplify()
     {
     {
         return DrawingBackendApi.Current.PathImplementation.Simplify(this);
         return DrawingBackendApi.Current.PathImplementation.Simplify(this);

+ 5 - 0
src/PixiEditor.DrawingApi.Skia/Implementations/SkiaPathImplementation.cs

@@ -177,5 +177,10 @@ namespace PixiEditor.DrawingApi.Skia.Implementations
         {
         {
             return ManagedInstances[vectorPath.ObjectPointer].ToSvgPathData();
             return ManagedInstances[vectorPath.ObjectPointer].ToSvgPathData();
         }
         }
+
+        public bool Contains(VectorPath vectorPath, float x, float y)
+        {
+            return ManagedInstances[vectorPath.ObjectPointer].Contains(x, y);
+        }
     }
     }
 }
 }