Browse Source

Merge pull request #932 from PixiEditor/fixes/08.05.25

Fixed symmetry and undo issues
Krzysztof Krysiński 3 months ago
parent
commit
a8325025d6

+ 5 - 1
src/ChunkyImageLib/Operations/DrawingSurfaceLineOperation.cs

@@ -1,5 +1,6 @@
 using ChunkyImageLib.DataHolders;
 using Drawie.Backend.Core.ColorsImpl;
+using Drawie.Backend.Core.ColorsImpl.Paintables;
 using Drawie.Backend.Core.Numerics;
 using Drawie.Backend.Core.Surfaces;
 using Drawie.Backend.Core.Surfaces.PaintImpl;
@@ -68,7 +69,10 @@ internal class DrawingSurfaceLineOperation : IMirroredDrawOperation
             newFrom = (VecI)newFrom.ReflectY((double)horAxisY).Round();
             newTo = (VecI)newTo.ReflectY((double)horAxisY).Round();
         }
-        return new DrawingSurfaceLineOperation(newFrom, newTo, paint.StrokeCap, paint.StrokeWidth, paint.Color, paint.BlendMode);
+
+        Color color = paint.Paintable is ColorPaintable colorPaintable ? colorPaintable.Color : paint.Color;
+
+        return new DrawingSurfaceLineOperation(newFrom, newTo, paint.StrokeCap, paint.StrokeWidth, color, paint.BlendMode);
     }
 
     public void Dispose()

+ 16 - 1
src/ChunkyImageLib/Operations/EllipseOperation.cs

@@ -211,7 +211,22 @@ internal class EllipseOperation : IMirroredDrawOperation
             newLocation = newLocation.ReflectX((double)verAxisX).Round();
         if (horAxisY is not null)
             newLocation = newLocation.ReflectY((double)horAxisY).Round();
-        return new EllipseOperation(newLocation, strokePaintable, fillPaintable, strokeWidth, rotation, antialiased, paint);
+
+        Paintable? finalFillPaintable = fillPaintable;
+        Paintable? finalStrokePaintable = strokePaintable;
+        if (fillPaintable.AbsoluteValues && fillPaintable is IPositionPaintable)
+        {
+            finalFillPaintable = fillPaintable.Clone();
+            ((IPositionPaintable)finalFillPaintable).Position = newLocation.Center;
+        }
+
+        if (strokePaintable.AbsoluteValues && strokePaintable is IPositionPaintable)
+        {
+            finalStrokePaintable = strokePaintable.Clone();
+            ((IPositionPaintable)finalStrokePaintable).Position = newLocation.Center;
+        }
+
+        return new EllipseOperation(newLocation, finalStrokePaintable, finalFillPaintable, strokeWidth, rotation, antialiased, paint);
     }
 
     public void Dispose()

+ 1 - 1
src/Drawie

@@ -1 +1 @@
-Subproject commit fb19e6a170698609840b6602178a26da2fc289b7
+Subproject commit 29ac832a30912042cf1f65a73eb4046ba3659309

+ 1 - 1
src/PixiEditor.ChangeableDocument/Changes/Drawing/DrawRasterLine_UpdateableChange.cs

@@ -6,7 +6,7 @@ using Drawie.Numerics;
 
 namespace PixiEditor.ChangeableDocument.Changes.Drawing;
 
-internal class DrawRasterLine_UpdateableChange : UpdateableChange
+internal class DrawRasterLine_UpdateableChange : InterruptableUpdateableChange
 {
     private readonly Guid memberGuid;
     private VecD from;

+ 35 - 23
src/PixiEditor.Extensions.Runtime/ExtensionLoader.cs

@@ -10,9 +10,11 @@ namespace PixiEditor.Extensions.Runtime;
 
 public class ExtensionLoader
 {
-    private readonly Dictionary<string, OfficialExtensionData> _officialExtensionsKeys = new Dictionary<string, OfficialExtensionData>();
+    private readonly Dictionary<string, OfficialExtensionData> _officialExtensionsKeys =
+        new Dictionary<string, OfficialExtensionData>();
+
     public List<Extension> LoadedExtensions { get; } = new();
-    
+
     public string PackagesPath { get; }
     public string UnpackedExtensionsPath { get; }
 
@@ -24,7 +26,7 @@ public class ExtensionLoader
         UnpackedExtensionsPath = unpackedExtensionsPath;
         ValidateExtensionFolder();
     }
-    
+
     public void AddOfficialExtension(string uniqueName, OfficialExtensionData data)
     {
         _officialExtensionsKeys.Add(uniqueName, data);
@@ -84,19 +86,26 @@ public class ExtensionLoader
     public Extension? LoadExtension(string extension)
     {
         var extZip = ZipFile.OpenRead(extension);
-        ExtensionMetadata metadata = ExtractMetadata(extZip);
-        if(IsDifferentThanCached(metadata, extension))
+        try
         {
-            UnpackExtension(extZip, metadata);
+            ExtensionMetadata metadata = ExtractMetadata(extZip);
+            if (IsDifferentThanCached(metadata, extension))
+            {
+                UnpackExtension(extZip, metadata);
+            }
+
+            string extensionJson = Path.Combine(UnpackedExtensionsPath, metadata.UniqueName, "extension.json");
+            if (!File.Exists(extensionJson))
+            {
+                return null;
+            }
+
+            return LoadExtensionFromCache(extensionJson);
         }
-        
-        string extensionJson = Path.Combine(UnpackedExtensionsPath, metadata.UniqueName, "extension.json");
-        if (!File.Exists(extensionJson))
+        catch (Exception ex)
         {
             return null;
         }
-            
-        return LoadExtensionFromCache(extensionJson);
     }
 
     public void UnpackExtension(ZipArchive extZip, ExtensionMetadata metadata)
@@ -124,7 +133,7 @@ public class ExtensionLoader
         var serializer = new JsonSerializer();
         return serializer.Deserialize<ExtensionMetadata>(jsonTextReader);
     }
-    
+
     private bool IsDifferentThanCached(ExtensionMetadata metadata, string extension)
     {
         string extensionJson = Path.Combine(UnpackedExtensionsPath, metadata.UniqueName, "extension.json");
@@ -135,24 +144,24 @@ public class ExtensionLoader
 
         string json = File.ReadAllText(extensionJson);
         ExtensionMetadata? cachedMetadata = JsonConvert.DeserializeObject<ExtensionMetadata>(json);
-        
-        if(cachedMetadata is null)
+
+        if (cachedMetadata is null)
         {
             return true;
         }
-        
+
         if (metadata.UniqueName != cachedMetadata.UniqueName)
         {
             return true;
         }
-        
+
         bool isDifferent = metadata.Version != cachedMetadata.Version;
-        
+
         if (isDifferent)
         {
             return true;
         }
-        
+
         return PackageWriteTimeIsBigger(Path.Combine(UnpackedExtensionsPath, metadata.UniqueName), extension);
     }
 
@@ -249,7 +258,7 @@ public class ExtensionLoader
 
         if (fixedUniqueName.StartsWith("pixieditor".Trim(), StringComparison.OrdinalIgnoreCase))
         {
-            if(!IsOfficialAssemblyLegit(fixedUniqueName, assembly))
+            if (!IsOfficialAssemblyLegit(fixedUniqueName, assembly))
             {
                 throw new ForbiddenUniqueNameExtension();
             }
@@ -319,7 +328,9 @@ public class ExtensionLoader
     private bool PublicKeysMatch(byte[] assemblyPublicKey, string pathToPublicKey)
     {
         Assembly currentAssembly = Assembly.GetExecutingAssembly();
-        using Stream? stream = currentAssembly.GetManifestResourceStream($"{currentAssembly.GetName().Name}.OfficialExtensions.{pathToPublicKey}");
+        using Stream? stream =
+            currentAssembly.GetManifestResourceStream(
+                $"{currentAssembly.GetName().Name}.OfficialExtensions.{pathToPublicKey}");
         if (stream == null) return false;
 
         using MemoryStream memoryStream = new MemoryStream();
@@ -330,8 +341,9 @@ public class ExtensionLoader
     }
 
     //TODO: uhh, other platforms dumbass?
-    [DllImport("mscoree.dll", CharSet=CharSet.Unicode)]
-    static extern bool StrongNameSignatureVerificationEx(string wszFilePath, bool fForceVerification, ref bool pfWasVerified);
+    [DllImport("mscoree.dll", CharSet = CharSet.Unicode)]
+    static extern bool StrongNameSignatureVerificationEx(string wszFilePath, bool fForceVerification,
+        ref bool pfWasVerified);
 
     private Extension LoadExtensionEntry(ExtensionEntry entry, ExtensionMetadata metadata)
     {
@@ -389,7 +401,7 @@ public class ExtensionLoader
         {
             Directory.CreateDirectory(PackagesPath);
         }
-        
+
         if (!Directory.Exists(UnpackedExtensionsPath))
         {
             Directory.CreateDirectory(UnpackedExtensionsPath);

+ 3 - 3
src/PixiEditor/Models/DocumentModels/ChangeExecutionController.cs

@@ -70,15 +70,15 @@ internal class ChangeExecutionController
     {
         if (!CanStartExecutor(force))
             return false;
-        if (force)
-            currentSession?.ForceStop();
 
+        currentSession?.ForceStop();
         return TryStartExecutorInternal(brandNewExecutor);
     }
 
     private bool CanStartExecutor(bool force)
     {
-        return (currentSession is null && _queuedExecutor is null) || force;
+        return (currentSession is null && _queuedExecutor is null) || force ||
+               currentSession is { BlocksOtherActions: false };
     }
 
     private bool TryStartExecutorInternal(UpdateableChangeExecutor executor)

+ 2 - 2
src/PixiEditor/Models/DocumentModels/UpdateableChangeExecutors/LineExecutor.cs

@@ -39,8 +39,8 @@ internal abstract class LineExecutor<T> : SimpleShapeToolExecutor where T : ILin
 
     private UndoStack<LineVectorData>? localUndoStack;
 
-    public override bool CanUndo => !UseGlobalUndo && localUndoStack is { UndoCount: > 0 };
-    public override bool CanRedo => !UseGlobalUndo && localUndoStack is { RedoCount: > 0 };
+    public override bool CanUndo => !UseGlobalUndo && ActiveMode == ShapeToolMode.Transform && localUndoStack is { UndoCount: > 0 };
+    public override bool CanRedo => !UseGlobalUndo && ActiveMode == ShapeToolMode.Transform && localUndoStack is { RedoCount: > 0 };
 
     public override ExecutionState Start()
     {