ソースを参照

Fixed changed doc size not updaing

Krzysztof Krysiński 1 年間 前
コミット
5659375d20

+ 4 - 3
src/PixiEditor.AvaloniaUI/Models/DocumentModels/DocumentSizeChangedEventArgs.cs

@@ -1,11 +1,12 @@
-using PixiEditor.AvaloniaUI.ViewModels.Document;
+using PixiEditor.AvaloniaUI.Models.Handlers;
+using PixiEditor.AvaloniaUI.ViewModels.Document;
 using PixiEditor.DrawingApi.Core.Numerics;
 
 namespace PixiEditor.AvaloniaUI.Models.DocumentModels;
 
 internal class DocumentSizeChangedEventArgs
 {
-    public DocumentSizeChangedEventArgs(DocumentViewModel document, VecI oldSize, VecI newSize)
+    public DocumentSizeChangedEventArgs(IDocument document, VecI oldSize, VecI newSize)
     {
         Document = document;
         OldSize = oldSize;
@@ -14,5 +15,5 @@ internal class DocumentSizeChangedEventArgs
 
     public VecI OldSize { get; }
     public VecI NewSize { get; }
-    public DocumentViewModel Document { get; }
+    public IDocument Document { get; }
 }

+ 3 - 3
src/PixiEditor.AvaloniaUI/Models/DocumentModels/DocumentUpdater.cs

@@ -295,10 +295,10 @@ internal class DocumentUpdater
         doc.PreviewSurface = WriteableBitmapUtility.CreateDrawingSurface(doc.PreviewBitmap);
 
         // TODO: Make sure property changed events are raised internally
+        // UPDATE: I think I did, but I'll leave it commented out for now
         /*doc.OnPropertyChanged(nameof(doc.LazyBitmaps));
-        doc.OnPropertyChanged(nameof(doc.PreviewBitmap));*/
-
-        //doc.InternalRaiseSizeChanged(new(doc, oldSize, info.Size));
+        doc.OnPropertyChanged(nameof(doc.PreviewBitmap));
+        doc.InternalRaiseSizeChanged(new DocumentSizeChangedEventArgs(doc, oldSize, info.Size));*/
     }
 
     private void ProcessCreateStructureMember(CreateStructureMember_ChangeInfo info)

+ 1 - 0
src/PixiEditor.AvaloniaUI/Models/Handlers/IDocument.cs

@@ -2,6 +2,7 @@
 using Avalonia.Media.Imaging;
 using ChunkyImageLib.DataHolders;
 using PixiEditor.AvaloniaUI.Helpers;
+using PixiEditor.AvaloniaUI.Models.DocumentModels;
 using PixiEditor.AvaloniaUI.Models.DocumentModels.Public;
 using PixiEditor.AvaloniaUI.Models.Structures;
 using PixiEditor.AvaloniaUI.Models.Tools;

+ 17 - 1
src/PixiEditor.AvaloniaUI/ViewModels/Document/DocumentViewModel.cs

@@ -143,7 +143,19 @@ internal partial class DocumentViewModel : PixiObservableObject, IDocument
         [ChunkResolution.Quarter] = WriteableBitmapUtility.CreateBitmap(new VecI(16, 16)),
         [ChunkResolution.Eighth] = WriteableBitmapUtility.CreateBitmap(new VecI(8, 8)),
     };
-    public WriteableBitmap PreviewBitmap { get; set; }
+
+    private WriteableBitmap previewBitmap;
+
+    public WriteableBitmap PreviewBitmap
+    {
+        get => previewBitmap;
+        set
+        {
+            SetProperty(ref previewBitmap, value);
+            OnPropertyChanged(nameof(LazyBitmaps));
+        }
+    }
+
     public DrawingSurface PreviewSurface { get; set; }
 
     private VectorPath selectionPath = new VectorPath();
@@ -531,10 +543,14 @@ internal partial class DocumentViewModel : PixiObservableObject, IDocument
 
     public void SetSize(VecI size)
     {
+        var oldSize = size;
         this.size = size;
         OnPropertyChanged(nameof(SizeBindable));
         OnPropertyChanged(nameof(Width));
         OnPropertyChanged(nameof(Height));
+
+        // TODO: Make sure this is correct, it was in InternalRaiseSizeChanged previously, check DocumentUpdater.cs ProcessSize
+        SizeChanged?.Invoke(this, new DocumentSizeChangedEventArgs(this, oldSize, size));
     }
 
     public void UpdateSelectionPath(VectorPath vectorPath)