瀏覽代碼

Fix bugs when hiding bottom gallery when hiding the UI

Ruben 1 年之前
父節點
當前提交
ccf6a9f9c2

+ 7 - 2
src/PicView.WPF/ChangeImage/QuickLoad.cs

@@ -65,13 +65,18 @@ namespace PicView.WPF.ChangeImage
 
             Pics = await Task.FromResult(FileList(fileInfo)).ConfigureAwait(false);
             FolderIndex = Pics.IndexOf(fileInfo.FullName);
+            var shouldLoadBottomGallery = Settings.Default.IsBottomGalleryShown;
+            if (Settings.Default.ShowInterface == false)
+            {
+                shouldLoadBottomGallery = Settings.Default.ShowAltInterfaceBottomGallery;
+            }
 
             await mainWindow.Dispatcher.InvokeAsync(() =>
             {
                 SetTitleString(bitmapSource.PixelWidth, bitmapSource.PixelHeight, FolderIndex, fileInfo);
                 UC.GetSpinWaiter.Visibility = Visibility.Collapsed;
                 mainWindow.MainImage.Cursor = Cursors.Arrow;
-                if (Settings.Default.IsBottomGalleryShown)
+                if (shouldLoadBottomGallery)
                 {
                     GalleryToggle.ShowBottomGallery();
                 }
@@ -90,7 +95,7 @@ namespace PicView.WPF.ChangeImage
 
             _ = AddAsync(FolderIndex, fileInfo, bitmapSource).ConfigureAwait(false);
 
-            if (Settings.Default.IsBottomGalleryShown)
+            if (shouldLoadBottomGallery)
             {
                 _ = Task.Run(async () =>
                 {

+ 1 - 0
src/PicView.WPF/PicGallery/GalleryLoad.cs

@@ -191,6 +191,7 @@ namespace PicView.WPF.PicGallery
                     };
                     await Loop(index, Navigation.Pics.Count, options).ConfigureAwait(false);
                     await Loop(0, index, options).ConfigureAwait(false);
+                    IsLoading = false;
                 }
                 catch (ObjectDisposedException exception)
                 {

+ 30 - 3
src/PicView.WPF/UILogic/HideInterfaceLogic.cs

@@ -1,8 +1,8 @@
-using System.Windows;
-using PicView.WPF.ChangeImage;
+using PicView.WPF.ChangeImage;
 using PicView.WPF.PicGallery;
 using PicView.WPF.Properties;
 using PicView.WPF.UILogic.Sizing;
+using System.Windows;
 using static PicView.WPF.Animations.FadeControls;
 using Timer = System.Timers.Timer;
 
@@ -44,7 +44,34 @@ namespace PicView.WPF.UILogic
                 AutoReset = false,
                 Enabled = true,
             };
-            timer.Elapsed += (_, _) => ScaleImage.TryFitImage();
+            timer.Elapsed += async delegate
+            {
+                ScaleImage.TryFitImage();
+                // Show gallery if needed
+                var shouldLoadBottomGallery = Settings.Default.IsBottomGalleryShown;
+                if (Settings.Default.ShowInterface == false)
+                {
+                    shouldLoadBottomGallery = Settings.Default.ShowAltInterfaceBottomGallery;
+                }
+                await ConfigureWindows.GetMainWindow.Dispatcher.InvokeAsync(() =>
+                {
+                    if (shouldLoadBottomGallery && UC.GetPicGallery is null)
+                    {
+                        shouldLoadBottomGallery = true;
+                        GalleryToggle.ShowBottomGallery();
+                        return;
+                    }
+
+                    if (UC.GetPicGallery?.Container.Children.Count > 0)
+                    {
+                        shouldLoadBottomGallery = false;
+                    }
+                });
+                if (shouldLoadBottomGallery)
+                {
+                    await GalleryLoad.LoadAsync().ConfigureAwait(false);
+                }
+            };
 
             Settings.Default.Save();
         }

+ 23 - 23
src/PicView.WPF/UILogic/Loading/StartLoading.cs

@@ -1,10 +1,4 @@
-using System.IO;
-using System.Windows;
-using System.Windows.Controls;
-using ImageMagick;
-using System.Windows.Media.Imaging;
-using System.Windows.Media;
-using System.Windows.Threading;
+using ImageMagick;
 using PicView.WPF.ChangeImage;
 using PicView.WPF.ConfigureSettings;
 using PicView.WPF.ImageHandling;
@@ -14,6 +8,11 @@ using PicView.WPF.SystemIntegration;
 using PicView.WPF.UILogic.Sizing;
 using PicView.WPF.Views.UserControls.Misc;
 using PicView.WPF.Views.Windows;
+using System.IO;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Media;
+using System.Windows.Media.Imaging;
 using static PicView.WPF.ChangeImage.Navigation;
 using static PicView.WPF.UILogic.Loading.LoadContextMenus;
 using static PicView.WPF.UILogic.Loading.LoadControls;
@@ -66,27 +65,28 @@ namespace PicView.WPF.UILogic.Loading
                     if (Settings.Default.AutoFitWindow)
                     {
                         var size = Core.Calculations.ImageSizeCalculationHelper.GetImageSize(
-                            bitmapSource.PixelWidth,
-                            bitmapSource.PixelHeight,
-                            MonitorInfo.WorkArea.Width,
-                            MonitorInfo.WorkArea.Height,
-                            0,
-                            Settings.Default.FillImage,
-                            20 * MonitorInfo.DpiScaling,
-                            MonitorInfo.DpiScaling,
-                            Settings.Default.Fullscreen,
-                            30 * MonitorInfo.DpiScaling,
-                            25 * MonitorInfo.DpiScaling,
-                            Settings.Default.IsBottomGalleryShown ? Settings.Default.BottomGalleryItemSize : 0,
-                            true,
-                            ConfigureWindows.GetMainWindow.ParentContainer.Width,
-                            ConfigureWindows.GetMainWindow.ParentContainer.Height,
+                            width: bitmapSource.PixelWidth * MonitorInfo.DpiScaling,
+                            height: bitmapSource.PixelHeight * MonitorInfo.DpiScaling,
+                            monitorWidth: MonitorInfo.WorkArea.Width * MonitorInfo.DpiScaling,
+                            monitorHeight: MonitorInfo.WorkArea.Height * MonitorInfo.DpiScaling,
+                            rotationAngle: 0,
+                            stretch: Settings.Default.FillImage,
+                            padding: 20 * MonitorInfo.DpiScaling,
+                            dpiScaling: MonitorInfo.DpiScaling,
+                            fullscreen: Settings.Default.Fullscreen,
+                            uiTopSize: ConfigureWindows.GetMainWindow.TitleBar.Height * MonitorInfo.DpiScaling,
+                            uiBottomSize: ConfigureWindows.GetMainWindow.LowerBar.Height * MonitorInfo.DpiScaling,
+                            galleryHeight: Settings.Default.IsBottomGalleryShown ? Settings.Default.BottomGalleryItemSize : 0,
+                            autoFit: true,
+                            containerWidth: ConfigureWindows.GetMainWindow.ParentContainer.Width * MonitorInfo.DpiScaling,
+                            containerHeight: ConfigureWindows.GetMainWindow.ParentContainer.Height * MonitorInfo.DpiScaling,
                             Settings.Default.ScrollEnabled
                             );
                         image.Stretch = Stretch.Fill;
                         image.Width = startupWindow.Width = size.Width;
                         image.Height = startupWindow.Height = size.Height;
                         CenterWindowOnScreen(startupWindow);
+                        ScaleImage.AspectRatio = size.AspectRatio;
                     }
                     image.Source = bitmapSource;
                 });
@@ -97,7 +97,7 @@ namespace PicView.WPF.UILogic.Loading
                 startupWindow.TheGrid.Children.Remove(spinner);
                 var mainWindow = new MainWindow();
                 ConfigureWindows.GetMainWindow = mainWindow;
-                // Determine preferred UI for startup
+
                 if (Settings.Default.AutoFitWindow == false)
                 {
                     SetLastWindowSize(mainWindow);

+ 19 - 1
src/PicView.WPF/Views/Windows/SettingsWindow.xaml.cs

@@ -227,10 +227,28 @@ namespace PicView.WPF.Views.Windows
                 };
 
                 ShowBottomWhenHiddenRadio.IsChecked = Settings.Default.ShowAltInterfaceBottomGallery;
-                ShowBottomWhenHiddenRadio.Click += delegate
+                ShowBottomWhenHiddenRadio.Click += async delegate
                 {
                     Settings.Default.ShowAltInterfaceBottomGallery =
                         !Settings.Default.ShowAltInterfaceBottomGallery;
+                    if (Settings.Default.ShowInterface == false && Settings.Default.IsBottomGalleryShown)
+                    {
+                        if (Settings.Default.ShowAltInterfaceBottomGallery)
+                        {
+                            GalleryToggle.ShowBottomGallery();
+                            await Task.Delay(TimeSpan.FromSeconds(.5)); // Need to delay to cause calculation to be correct
+                            await ConfigureWindows.GetMainWindow.Dispatcher.InvokeAsync(ScaleImage.TryFitImage);
+
+                            if (GalleryLoad.IsLoading == false)
+                            {
+                                await GalleryLoad.LoadAsync().ConfigureAwait(false);
+                            }
+                        }
+                        else
+                        {
+                            GalleryToggle.CloseBottomGallery();
+                        }
+                    }
                 };
 
                 CtrlZoom.IsChecked = Settings.Default.CtrlZoom;