Browse Source

Fixed open images other than .pixi

flabbet 2 years ago
parent
commit
882753dda6

+ 3 - 4
src/PixiEditor/Models/DocumentModels/Public/DocumentOperationsModule.cs

@@ -236,12 +236,11 @@ internal class DocumentOperationsModule
 
 
     private void DrawImage(Surface image, ShapeCorners corners, Guid memberGuid, bool ignoreClipSymmetriesEtc, bool drawOnMask, bool finish)
     private void DrawImage(Surface image, ShapeCorners corners, Guid memberGuid, bool ignoreClipSymmetriesEtc, bool drawOnMask, bool finish)
     {
     {
-        if (Internals.ChangeController.IsChangeActive || Document.SelectedStructureMember is null)
+        if (Internals.ChangeController.IsChangeActive)
             return;
             return;
         Internals.ActionAccumulator.AddActions(
         Internals.ActionAccumulator.AddActions(
-            new PasteImage_Action(image, corners, Document.SelectedStructureMember.GuidValue, ignoreClipSymmetriesEtc, drawOnMask),
-            new EndPasteImage_Action()
-            );
+            new PasteImage_Action(image, corners, memberGuid, ignoreClipSymmetriesEtc, drawOnMask),
+            new EndPasteImage_Action());
         if (finish)
         if (finish)
             Internals.ActionAccumulator.AddFinishedActions();
             Internals.ActionAccumulator.AddFinishedActions();
     }
     }

+ 6 - 3
src/PixiEditor/ViewModels/SubViewModels/Main/FileViewModel.cs

@@ -1,5 +1,6 @@
 using System.IO;
 using System.IO;
 using System.Windows.Input;
 using System.Windows.Input;
+using ChunkyImageLib;
 using ChunkyImageLib.DataHolders;
 using ChunkyImageLib.DataHolders;
 using Microsoft.Win32;
 using Microsoft.Win32;
 using Newtonsoft.Json.Linq;
 using Newtonsoft.Json.Linq;
@@ -111,9 +112,11 @@ internal class FileViewModel : SubViewModel<ViewModelMain>
         {
         {
             DocumentViewModel doc = NewDocument(new(dialog.FileWidth, dialog.FileHeight), false);
             DocumentViewModel doc = NewDocument(new(dialog.FileWidth, dialog.FileHeight), false);
             doc.FullFilePath = path;
             doc.FullFilePath = path;
-            /*doc.AddNewLayer(
-                "Image",
-                Importer.ImportImage(dialog.FilePath, dialog.FileWidth, dialog.FileHeight));*/
+
+            Guid? guid = doc.Operations.CreateStructureMember(StructureMemberType.Layer, "Image");
+            Surface surface = Importer.ImportImage(dialog.FilePath, new VecI(dialog.FileWidth, dialog.FileHeight));
+            RectD corners = RectD.FromTwoPoints(new VecD(0, 0), new VecD(dialog.FileWidth, dialog.FileHeight));
+            doc.Operations.DrawImage(surface, new ShapeCorners(corners), guid.Value, true, false);
         }
         }
     }
     }