Browse Source

Refactor, misc

Ruben 1 year ago
parent
commit
6b65f8d712

+ 60 - 19
src/PicView.Avalonia/ColorManagement/BackgroundManager.cs

@@ -4,23 +4,17 @@ using PicView.Avalonia.ViewModels;
 using PicView.Core.Config;
 
 namespace PicView.Avalonia.ColorManagement;
+
+/// <summary>
+/// Manages the background appearance for the image viewer.
+/// It provides methods to change and set the background color or pattern.
+/// </summary>
 public static class BackgroundManager
 {
-    public static void ChangeBackground(MainViewModel vm)
-    {
-        if (vm.ImageSource is null)
-        {
-            return;
-        }
-        SettingsHelper.Settings.UIProperties.BgColorChoice = (SettingsHelper.Settings.UIProperties.BgColorChoice + 1) % 10;
-        vm.ImageBackground = BackgroundColorBrush;
-    }
-    
-    public static void SetBackground(MainViewModel vm)
-    {
-        vm.ImageBackground = BackgroundColorBrush;
-    }
-    
+    /// <summary>
+    /// Returns a brush corresponding to the current background color choice.
+    /// Choices include solid colors, transparency, noise texture, and checkerboard patterns.
+    /// </summary>
     private static Brush BackgroundColorBrush => SettingsHelper.Settings.UIProperties.BgColorChoice switch
     {
         0 => new SolidColorBrush(Colors.Transparent),
@@ -30,12 +24,46 @@ public static class BackgroundManager
         4 => new SolidColorBrush(Colors.White),
         5 => new SolidColorBrush(Color.FromRgb(200, 200, 200)),
         6 => new SolidColorBrush(Color.FromRgb(155, 155, 155)),
-        7 => new SolidColorBrush(Color.FromArgb(90,35, 35, 35)),
+        7 => new SolidColorBrush(Color.FromArgb(90, 35, 35, 35)),
         8 => new SolidColorBrush(Color.FromArgb(90, 15, 15, 15)),
         9 => new SolidColorBrush(Color.FromRgb(5, 5, 5)),
-        _ => new SolidColorBrush(Colors.Transparent),
+        _ => new SolidColorBrush(Colors.Transparent)
     };
 
+    /// <summary>
+    /// Changes the background based on the current background color choice stored in the settings.
+    /// Cycles through predefined background styles and updates the view model's ImageBackground property.
+    /// </summary>
+    /// <param name="vm">The main view model where the background is updated.</param>
+    public static void ChangeBackground(MainViewModel vm)
+    {
+        if (vm.CurrentView != vm.ImageViewer)
+        {
+            return;
+        }
+
+        // Cycle through background choices (0 to 9)
+        SettingsHelper.Settings.UIProperties.BgColorChoice =
+            (SettingsHelper.Settings.UIProperties.BgColorChoice + 1) % 10;
+
+        // Update the background in the view model
+        vm.ImageBackground = BackgroundColorBrush;
+    }
+
+    /// <summary>
+    /// Sets the background of the view model based on the current background choice.
+    /// </summary>
+    /// <param name="vm">The main view model where the background is set.</param>
+    public static void SetBackground(MainViewModel vm)
+    {
+        vm.ImageBackground = BackgroundColorBrush;
+    }
+
+    /// <summary>
+    /// Retrieves the noise texture brush from the application resources.
+    /// If the texture is not available, returns a transparent brush.
+    /// </summary>
+    /// <returns>A brush containing the noise texture or a transparent brush if unavailable.</returns>
     private static Brush GetNoiseTextureBrush()
     {
         if (!Application.Current.TryGetResource("NoisyTexture", Application.Current.RequestedThemeVariant,
@@ -51,12 +79,22 @@ public static class BackgroundManager
         return new SolidColorBrush(Colors.Transparent);
     }
 
-    private static DrawingBrush CreateCheckerboardBrush(Color primaryColor = default, Color secondaryColor = default, int size = 30)
+    /// <summary>
+    /// Creates a checkerboard brush with two alternating colors.
+    /// </summary>
+    /// <param name="primaryColor">The primary color for the checkerboard squares. Defaults to white.</param>
+    /// <param name="secondaryColor">The secondary color for the checkerboard squares. Defaults to a dark gray.</param>
+    /// <param name="size">The size of the checkerboard squares in pixels. Defaults to 30.</param>
+    /// <returns>A drawing brush representing the checkerboard pattern.</returns>
+    private static DrawingBrush CreateCheckerboardBrush(Color primaryColor = default, Color secondaryColor = default,
+        int size = 30)
     {
+        // Default colors if not provided
         if (primaryColor == default)
         {
             primaryColor = Colors.White;
         }
+
         if (secondaryColor == default)
         {
             secondaryColor = Color.Parse("#F81F1F1F");
@@ -71,6 +109,7 @@ public static class BackgroundManager
 
         var drawingGroup = new DrawingGroup();
 
+        // Primary color rectangles
         var primaryGeometry = new GeometryDrawing
         {
             Brush = new SolidColorBrush(primaryColor),
@@ -84,6 +123,7 @@ public static class BackgroundManager
             }
         };
 
+        // Secondary color rectangles
         var secondaryGeometry = new GeometryDrawing
         {
             Brush = new SolidColorBrush(secondaryColor),
@@ -97,10 +137,11 @@ public static class BackgroundManager
             }
         };
 
+        // Add geometries to the drawing group
         drawingGroup.Children.Add(primaryGeometry);
         drawingGroup.Children.Add(secondaryGeometry);
         checkerboardBrush.Drawing = drawingGroup;
 
         return checkerboardBrush;
     }
-}
+}

+ 13 - 3
src/PicView.Avalonia/UI/DragAndDropHelper.cs

@@ -8,6 +8,7 @@ using PicView.Avalonia.ImageHandling;
 using PicView.Avalonia.Navigation;
 using PicView.Avalonia.ViewModels;
 using PicView.Avalonia.Views.UC;
+using PicView.Core.Calculations;
 using PicView.Core.Config;
 using PicView.Core.FileHandling;
 using PicView.Core.ProcessHandling;
@@ -143,10 +144,19 @@ public static class DragAndDropHelper
             }
             else if (path.IsSupported())
             {
-                var thumb = await GetThumbnails.GetThumbAsync(path, 340).ConfigureAwait(false);
-
-                if (thumb is not null)
+                var ext = Path.GetExtension(path);
+                if (ext.Equals(".svg", StringComparison.InvariantCultureIgnoreCase) || ext.Equals(".svgz", StringComparison.InvariantCultureIgnoreCase))
+                {
+                    await Dispatcher.UIThread.InvokeAsync(() =>
+                    {
+                        _dragDropView?.UpdateSvgThumbnail(path);
+                    });
+                }
+                else
                 {
+                    var thumb = await GetThumbnails.GetThumbAsync(path, SizeDefaults.WindowMinSize - 30)
+                        .ConfigureAwait(false);
+
                     await Dispatcher.UIThread.InvokeAsync(() => { _dragDropView?.UpdateThumbnail(thumb); });
                 }
             }

File diff suppressed because it is too large
+ 290 - 147
src/PicView.Avalonia/Views/ExifView.axaml


Some files were not shown because too many files changed in this diff