Ver Fonte

Add F12 as shortcut to toggle the Fullscreen gallery, improved scaling when bottom toolbar is not shown

Ruben há 2 anos atrás
pai
commit
28bbeecb05

+ 48 - 3
PicView/PicGallery/GalleryToggle.cs

@@ -5,6 +5,7 @@ using PicView.UILogic;
 using PicView.UILogic.Sizing;
 using PicView.Views.UserControls.Gallery;
 using System.Windows;
+using System.Windows.Controls;
 using System.Windows.Media.Animation;
 using System.Windows.Threading;
 using static PicView.ChangeImage.Navigation;
@@ -58,7 +59,6 @@ internal static class GalleryToggle
 
             if (Settings.Default.FullscreenGallery)
             {
-
                 var check = from x in GetMainWindow.ParentContainer.Children.OfType<PicGalleryTopButtons>()
                             select x;
                 foreach (var item in check)
@@ -82,7 +82,7 @@ internal static class GalleryToggle
 
             GetMainWindow.Focus();
 
-            // Fix not showing up opacity bug..
+            // Fix not showing up opacity bug...
             VisualStateManager.GoToElementState(GetPicGallery, "Opacity", false);
             VisualStateManager.GoToElementState(GetPicGallery.Container, "Opacity", false);
             GetPicGallery.Opacity = GetPicGallery.Container.Opacity = 1;
@@ -144,7 +144,7 @@ internal static class GalleryToggle
 
         ConfigColors.UpdateColor();
 
-        HideInterfaceLogic.ShowStandardInterface();
+        HideInterfaceLogic.ToggleInterface();
         GetPicGallery.x2.Visibility = Visibility.Collapsed;
 
         // Restore settings
@@ -183,6 +183,51 @@ internal static class GalleryToggle
 
     #endregion Close
 
+    #region Toggle
+
+    internal static async Task ToggleFullscreenGalleryAsync()
+    {
+        if (Settings.Default.FullscreenGallery)
+        {
+            CloseFullscreenGallery();
+        }
+        else
+        {
+            Settings.Default.FullscreenGallery = true;
+            if (GetPicGallery is null) // Use timer to fix incorrect calculated size
+            {
+                var timer = new System.Timers.Timer(TimeSpan.FromSeconds(.4))
+                {
+                    AutoReset = false,
+                    Enabled = true
+                };
+                timer.Elapsed += delegate
+                {
+                    GetMainWindow.Dispatcher.Invoke(() =>
+                    {
+                        if (GetMainWindow.MainImage.Source is null) return;
+                        if (GetPicGallery == null)
+                        {
+                            GetPicGallery = new Views.UserControls.Gallery.PicGallery
+                            {
+                                Opacity = 0
+                            };
+
+                            GetMainWindow.ParentContainer.Children.Add(GetPicGallery);
+                            Panel.SetZIndex(GetPicGallery, 999);
+                        }
+                        ScaleImage.FitImage(GetMainWindow.MainImage.Source.Width, GetMainWindow.MainImage.Source.Height);
+                    });
+
+                    timer.Dispose();
+                };
+            }
+            await OpenFullscreenGalleryAsync().ConfigureAwait(false);
+        }
+    }
+
+    #endregion Toggle
+
     private static async Task LoadAndScrollToAsync()
     {
         if (GalleryLoad.IsLoading == false)

+ 5 - 0
PicView/Shortcuts/MainKeyboardShortcuts.cs

@@ -574,6 +574,11 @@ internal static class MainKeyboardShortcuts
                     WindowSizing.Fullscreen_Restore(!Settings.Default.Fullscreen);
                     break;
 
+                // F12
+                case Key.F12:
+                    await GalleryToggle.ToggleFullscreenGalleryAsync().ConfigureAwait(false);
+                    break;
+
                 // Home
                 case Key.Home:
                     GetMainWindow.Scroller.ScrollToHome();

+ 0 - 2
PicView/UILogic/HideInterfaceLogic.cs

@@ -82,8 +82,6 @@ internal static class HideInterfaceLogic
             ConfigureWindows.GetMainWindow.TitleBar.Visibility = Visibility.Collapsed;
             ConfigureWindows.GetMainWindow.LowerBar.Visibility = Visibility.Collapsed;
         }
-
-
     }
 
     /// <summary>

+ 1 - 1
PicView/UILogic/Sizing/ScaleImage.cs

@@ -78,7 +78,7 @@ internal static class ScaleImage
         var padding = MonitorInfo.DpiScaling <= 1 ? 20 * MonitorInfo.DpiScaling : 0; // Padding to make it feel more comfortable
         var isFullScreenSize = Settings.Default.Fullscreen || Settings.Default.FullscreenGallery;
 
-        var borderSpaceHeight = isFullScreenSize ? 0 : GetMainWindow.LowerBar.Height + GetMainWindow.TitleBar.Height;
+        var borderSpaceHeight = isFullScreenSize ? 0 : GetMainWindow.LowerBar.ActualHeight + GetMainWindow.TitleBar.ActualHeight;
         var borderSpaceWidth = Settings.Default.Fullscreen ? 0 : padding;
 
         var workAreaWidth = (MonitorInfo.WorkArea.Width * MonitorInfo.DpiScaling) - borderSpaceWidth;

+ 3 - 4
PicView/Views/Windows/SettingsWindow.xaml.cs

@@ -175,10 +175,9 @@ public partial class SettingsWindow
             ShowBottomRadio.Click += delegate
             {
                 Settings.Default.ShowBottomNavBar = !Settings.Default.ShowBottomNavBar;
-                if (Settings.Default.ShowInterface)
-                {
-                    HideInterfaceLogic.ShowTopAndBottom(true);
-                }
+                if (!Settings.Default.ShowInterface) return;
+                HideInterfaceLogic.ShowTopAndBottom(true);
+                ScaleImage.TryFitImage();
             };
 
             CtrlZoom.IsChecked = Settings.Default.CtrlZoom;