From 2ca4bc88b902d27e9a7a0ea9d51113a101529ce3 Mon Sep 17 00:00:00 2001 From: Get Date: Mon, 27 Jun 2022 20:06:39 +0700 Subject: [PATCH] Improve Export Video GUI --- PhotoToys/Custom UI/SimpleUI.cs | 44 +++++++++++++++++++++++++++------ PhotoToys/PhotoToys.csproj | 2 +- 2 files changed, 37 insertions(+), 9 deletions(-) diff --git a/PhotoToys/Custom UI/SimpleUI.cs b/PhotoToys/Custom UI/SimpleUI.cs index ad6734e..9470599 100644 --- a/PhotoToys/Custom UI/SimpleUI.cs +++ b/PhotoToys/Custom UI/SimpleUI.cs @@ -251,12 +251,31 @@ where pa is ImageParameter impa && impa.IsVideoMode var totalFrames = vidcapture.FrameCount; var dialog = new ContentDialog { - Content = new ProgressBar + Content = new FluentVerticalStack { - //Value = 50, - }.Assign(out var progressRing), + Children = + { + new ProgressBar + { + //Value = 50, + }.Assign(out var progressBar), + new TextBlock + { + + }.Assign(out var PercentageProgress), + new TextBlock + { + + }.Assign(out var AverageRenderSpeed), + new TextBlock + { + + }.Assign(out var EstimatedTime) + } + }, XamlRoot = Result.XamlRoot, }; + DateTime dateTime; async Task RunLoop() { await Task.Run(async delegate @@ -267,11 +286,19 @@ await Task.Run(async delegate for (int i = 0; i < totalFrames; i++) { video.PosFrames = i; - if (i % 10 == 0) - dialog.DispatcherQueue.TryEnqueue(delegate - { - progressRing.Value = (double)(i+1) / totalFrames * 100; - }); + //if (i % 10 == 0) + dialog.DispatcherQueue.TryEnqueue(delegate + { + var progress = (double)(i + 1) / totalFrames * 100; + progressBar.Value = progress; + var renderFPS = i / (DateTime.Now - dateTime).TotalSeconds; + var estimatedseconds = (totalFrames - i) / (renderFPS + 1e-3); + const double onedayinseconds = 60 * 60 * 24; + + PercentageProgress.Text = $"{progress:N2}% ({i + 1}/{totalFrames})"; + AverageRenderSpeed.Text = $"Average Render Speed: {renderFPS:N2} frames per second"; + EstimatedTime.Text = $"Estimated Time left: {(estimatedseconds > onedayinseconds ? "More than a day" : TimeSpan.FromSeconds((totalFrames - i) / (renderFPS + 1e-3))):c}"; + }); if (video.Result is null) break; TaskCompletionSource result = new(); OnExecute?.Invoke(x => @@ -284,6 +311,7 @@ await Task.Run(async delegate writer.Release(); }); }; + dateTime = DateTime.Now; _ = dialog.ShowAsync(); await RunLoop(); diff --git a/PhotoToys/PhotoToys.csproj b/PhotoToys/PhotoToys.csproj index b582520..6d96ce3 100644 --- a/PhotoToys/PhotoToys.csproj +++ b/PhotoToys/PhotoToys.csproj @@ -18,7 +18,7 @@ False True True - Auto + Always x86|x64|arm64 0 True