Browse Source

Force update the final image after rendering

Equbuxu 3 years ago
parent
commit
c7b1995f77

+ 1 - 0
src/PixiEditorPrototype/Models/ActionAccumulator.cs

@@ -66,6 +66,7 @@ namespace PixiEditorPrototype.Models
                 }
                 document.FinalBitmap.Unlock();
             }
+            document.View?.ForceRefreshFinalImage();
 
             executing = false;
         }

+ 2 - 0
src/PixiEditorPrototype/ViewModels/DocumentViewModel.cs

@@ -7,6 +7,7 @@ using ChangeableDocument.Actions.Structure;
 using ChangeableDocument.Actions.Undo;
 using ChunkyImageLib.DataHolders;
 using PixiEditorPrototype.Models;
+using PixiEditorPrototype.Views;
 using SkiaSharp;
 using System;
 using System.Collections.Generic;
@@ -38,6 +39,7 @@ namespace PixiEditorPrototype.ViewModels
         public ActionAccumulator ActionAccumulator { get; }
         public DocumentChangeTracker Tracker { get; }
         public DocumentStructureHelper StructureHelper { get; }
+        public IDocumentView? View { get; set; }
         private DocumentUpdater Updater { get; }
 
 

+ 1 - 1
src/PixiEditorPrototype/Views/DocumentView.xaml

@@ -111,7 +111,7 @@
             </StackPanel>
         </Border>
         <Border BorderThickness="1" Background="Transparent" BorderBrush="Black" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="5">
-            <Image Margin="5" Source="{Binding FinalBitmap}" Width="400" Height="400" RenderOptions.BitmapScalingMode="NearestNeighbor">
+            <Image Margin="5" Source="{Binding FinalBitmap}" Width="400" Height="400" RenderOptions.BitmapScalingMode="NearestNeighbor" x:Name="mainImage">
                 <i:Interaction.Triggers>
                     <i:EventTrigger EventName="MouseDown">
                         <i:InvokeCommandAction Command="{Binding MouseDownCommand}" PassEventArgsToCommand="True"/>

+ 13 - 2
src/PixiEditorPrototype/Views/DocumentView.xaml.cs

@@ -1,15 +1,26 @@
-using System.Windows.Controls;
+using PixiEditorPrototype.ViewModels;
+using System.Windows.Controls;
 
 namespace PixiEditorPrototype.Views
 {
     /// <summary>
     /// Interaction logic for DocumentView.xaml
     /// </summary>
-    internal partial class DocumentView : UserControl
+    internal partial class DocumentView : UserControl, IDocumentView
     {
         public DocumentView()
         {
             InitializeComponent();
+            DataContextChanged += (_, e) =>
+            {
+                if (e.NewValue != null)
+                    ((DocumentViewModel)e.NewValue).View = this;
+            };
+        }
+
+        public void ForceRefreshFinalImage()
+        {
+            mainImage.InvalidateVisual();
         }
     }
 }

+ 7 - 0
src/PixiEditorPrototype/Views/IDocumentView.cs

@@ -0,0 +1,7 @@
+namespace PixiEditorPrototype.Views
+{
+    internal interface IDocumentView
+    {
+        void ForceRefreshFinalImage();
+    }
+}