Browse Source

Export animation preview generation

flabbet 1 year ago
parent
commit
968affb0d4

+ 2 - 2
src/PixiEditor.AvaloniaUI/Views/Dialogs/ExportFilePopup.axaml

@@ -66,9 +66,9 @@
                         </Grid.RowDefinitions>
                         </Grid.RowDefinitions>
                         
                         
                         <TextBlock Text="Export Preview"/>
                         <TextBlock Text="Export Preview"/>
-                        <indicators:LoadingIndicator Grid.Row="1" IsVisible="{Binding IsPreviewGenerating, ElementName=saveFilePopup}"
+                        <indicators:LoadingIndicator Grid.Row="1" IsVisible="{Binding IsGeneratingPreview, ElementName=saveFilePopup}"
                                           Margin="0, 10, 0, 0"/>
                                           Margin="0, 10, 0, 0"/>
-                        <Border Grid.Row="1" BorderThickness="1" Height="200" Width="150" IsVisible="{Binding !IsPreviewGenerating, ElementName=saveFilePopup}">
+                        <Border Grid.Row="1" BorderThickness="1" Height="200" Width="150" IsVisible="{Binding !IsGeneratingPreview, ElementName=saveFilePopup}">
                             <Border RenderOptions.BitmapInterpolationMode="None">
                             <Border RenderOptions.BitmapInterpolationMode="None">
                                 <visuals:SurfaceControl x:Name="surfaceControl"
                                 <visuals:SurfaceControl x:Name="surfaceControl"
                                                         Surface="{Binding ExportPreview, ElementName=saveFilePopup}"
                                                         Surface="{Binding ExportPreview, ElementName=saveFilePopup}"

+ 15 - 19
src/PixiEditor.AvaloniaUI/Views/Dialogs/ExportFilePopup.axaml.cs

@@ -49,6 +49,16 @@ internal partial class ExportFilePopup : PixiEditorPopup
         AvaloniaProperty.Register<ExportFilePopup, int>(
         AvaloniaProperty.Register<ExportFilePopup, int>(
             nameof(SelectedExportIndex), 0);
             nameof(SelectedExportIndex), 0);
 
 
+    public static readonly StyledProperty<bool> IsGeneratingPreviewProperty =
+        AvaloniaProperty.Register<ExportFilePopup, bool>(
+            nameof(IsGeneratingPreview), false);
+
+    public bool IsGeneratingPreview
+    {
+        get => GetValue(IsGeneratingPreviewProperty);
+        set => SetValue(IsGeneratingPreviewProperty, value);
+    }
+
     public int SelectedExportIndex
     public int SelectedExportIndex
     {
     {
         get => GetValue(SelectedExportIndexProperty);
         get => GetValue(SelectedExportIndexProperty);
@@ -106,27 +116,12 @@ internal partial class ExportFilePopup : PixiEditorPopup
 
 
     public bool IsVideoExport => SelectedExportIndex == 1;
     public bool IsVideoExport => SelectedExportIndex == 1;
     public string SizeHint => new LocalizedString("EXPORT_SIZE_HINT", GetBestPercentage());
     public string SizeHint => new LocalizedString("EXPORT_SIZE_HINT", GetBestPercentage());
-    public bool IsPreviewGenerating
-    {
-        get
-        {
-            return isPreviewGenerating;
-        }
-        private set
-        {
-            isPreviewGenerating = value;
-            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(IsPreviewGenerating)));
-        }
-    }
 
 
     private DocumentViewModel document;
     private DocumentViewModel document;
     private Image[] videoPreviewFrames = [];
     private Image[] videoPreviewFrames = [];
     private DispatcherTimer videoPreviewTimer = new DispatcherTimer();
     private DispatcherTimer videoPreviewTimer = new DispatcherTimer();
     private int activeFrame = 0;
     private int activeFrame = 0;
     private CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
     private CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
-    private bool isPreviewGenerating = false;
-    
-    public event PropertyChangedEventHandler? PropertyChanged;
 
 
     static ExportFilePopup()
     static ExportFilePopup()
     {
     {
@@ -201,8 +196,8 @@ internal partial class ExportFilePopup : PixiEditorPopup
         {
         {
             return;
             return;
         }
         }
-        
-        IsPreviewGenerating = true;
+
+        IsGeneratingPreview = true;
 
 
         videoPreviewTimer.Stop();
         videoPreviewTimer.Stop();
         if (IsVideoExport)
         if (IsVideoExport)
@@ -218,7 +213,7 @@ internal partial class ExportFilePopup : PixiEditorPopup
                 VecI previewSize = CalculatePreviewSize(rendered.AsT1.Size);
                 VecI previewSize = CalculatePreviewSize(rendered.AsT1.Size);
                 ExportPreview = rendered.AsT1.ResizeNearestNeighbor(previewSize);
                 ExportPreview = rendered.AsT1.ResizeNearestNeighbor(previewSize);
                 rendered.AsT1.Dispose();
                 rendered.AsT1.Dispose();
-                IsPreviewGenerating = false;
+                IsGeneratingPreview = false;
             }
             }
         }
         }
     }
     }
@@ -267,9 +262,10 @@ internal partial class ExportFilePopup : PixiEditorPopup
                     ExportPreview?.Dispose();
                     ExportPreview?.Dispose();
                     ExportPreview = new Surface(previewSize);
                     ExportPreview = new Surface(previewSize);
                 }
                 }
+
+                IsGeneratingPreview = false;
             });
             });
 
 
-            IsPreviewGenerating = false;
             videoPreviewTimer.Start();
             videoPreviewTimer.Start();
         });
         });
     }
     }