Browse Source

Added a new option to toggle between having background color option to fill the entire window or just behind the image. Enabled by default.

Ruben 6 months ago
parent
commit
18d04336db
29 changed files with 106 additions and 6 deletions
  1. 11 1
      src/PicView.Avalonia/ColorManagement/BackgroundManager.cs
  2. 4 0
      src/PicView.Avalonia/Functions/FunctionsMapper.cs
  3. 20 0
      src/PicView.Avalonia/SettingsManagement/SettingsUpdater.cs
  4. 1 0
      src/PicView.Avalonia/StartUp/StartUpHelper.cs
  5. 16 0
      src/PicView.Avalonia/ViewModels/MainViewModel.cs
  6. 19 0
      src/PicView.Avalonia/Views/AppearanceView.axaml
  7. 4 2
      src/PicView.Avalonia/Views/ImageViewer.axaml
  8. 1 0
      src/PicView.Core/Config/AppSettings.cs
  9. 1 0
      src/PicView.Core/Config/Languages/da.json
  10. 1 0
      src/PicView.Core/Config/Languages/de.json
  11. 1 0
      src/PicView.Core/Config/Languages/en.json
  12. 1 0
      src/PicView.Core/Config/Languages/es.json
  13. 1 0
      src/PicView.Core/Config/Languages/fr.json
  14. 1 0
      src/PicView.Core/Config/Languages/it.json
  15. 1 0
      src/PicView.Core/Config/Languages/ja.json
  16. 1 0
      src/PicView.Core/Config/Languages/ko.json
  17. 1 0
      src/PicView.Core/Config/Languages/nl.json
  18. 1 0
      src/PicView.Core/Config/Languages/pl.json
  19. 1 0
      src/PicView.Core/Config/Languages/pt-br.json
  20. 1 0
      src/PicView.Core/Config/Languages/ro.json
  21. 1 0
      src/PicView.Core/Config/Languages/ru.json
  22. 1 0
      src/PicView.Core/Config/Languages/sv.json
  23. 1 0
      src/PicView.Core/Config/Languages/tr.json
  24. 1 0
      src/PicView.Core/Config/Languages/zh-CN.json
  25. 1 0
      src/PicView.Core/Config/Languages/zh-TW.json
  26. 1 0
      src/PicView.Core/Localization/LanguageModel.cs
  27. 7 0
      src/PicView.Core/ViewModels/TranslationViewModel.cs
  28. 4 3
      src/PicView.Tests/LanguageTests/DanishUnitTest.cs
  29. 1 0
      src/PicView.Tests/LanguageTests/DutchUnitTest.cs

+ 11 - 1
src/PicView.Avalonia/ColorManagement/BackgroundManager.cs

@@ -103,7 +103,17 @@ public static class BackgroundManager
     public static void SetBackground(MainViewModel vm, int choice)
     {
         Settings.UIProperties.BgColorChoice = choice;
-        vm.ImageBackground = GetBackgroundBrush((BackgroundType)choice);
+        if (Settings.UIProperties.IsConstrainBackgroundColorEnabled)
+        {
+            vm.ImageBackground = new SolidColorBrush(Colors.Transparent);
+            vm.ConstrainedImageBackground = GetBackgroundBrush((BackgroundType)choice);
+        }
+        else
+        {
+            vm.ImageBackground = GetBackgroundBrush((BackgroundType)choice);
+            vm.ConstrainedImageBackground = new SolidColorBrush(Colors.Transparent);
+        }
+        
         vm.BackgroundChoice = choice;
     }
 

+ 4 - 0
src/PicView.Avalonia/Functions/FunctionsMapper.cs

@@ -369,6 +369,10 @@ public static class FunctionsMapper
     public static async Task ToggleTaskbarProgress() =>
         await SettingsUpdater.ToggleTaskbarProgress(Vm).ConfigureAwait(false);
     
+    /// <inheritdoc cref="SettingsUpdater.ToggleConstrainBackgroundColor(MainViewModel)" />
+    public static async Task ToggleConstrainBackgroundColor() =>
+        await SettingsUpdater.ToggleConstrainBackgroundColor(Vm).ConfigureAwait(false);
+    
     #endregion
 
     #region Gallery functions

+ 20 - 0
src/PicView.Avalonia/SettingsManagement/SettingsUpdater.cs

@@ -170,6 +170,26 @@ public static class SettingsUpdater
         await SaveSettingsAsync();
     }
     
+    public static async Task ToggleConstrainBackgroundColor(MainViewModel vm)
+    {
+        if (Settings.UIProperties.IsConstrainBackgroundColorEnabled)
+        {
+            Settings.UIProperties.IsConstrainBackgroundColorEnabled = false;
+            vm.IsConstrainingBackgroundColor = false;
+        }
+        else
+        {
+            Settings.UIProperties.IsConstrainBackgroundColorEnabled = true;
+            vm.IsConstrainingBackgroundColor = true;
+        }
+        
+        await Dispatcher.UIThread.InvokeAsync(() =>
+        {
+            BackgroundManager.SetBackground(vm);
+        });
+        await SaveSettingsAsync();
+    }
+    
     #region Image settings
 
     public static async Task ToggleSideBySide(MainViewModel vm)

+ 1 - 0
src/PicView.Avalonia/StartUp/StartUpHelper.cs

@@ -346,6 +346,7 @@ public static class StartUpHelper
         vm.IsUsingTouchpad  = Settings.Zoom.IsUsingTouchPad;
         vm.IsAscending  = Settings.Sorting.Ascending;
         vm.BackgroundChoice = Settings.UIProperties.BgColorChoice;
+        vm.IsConstrainingBackgroundColor = Settings.UIProperties.IsConstrainBackgroundColorEnabled;
     }
 
     private static void SetWindowEventHandlers(Window w)

+ 16 - 0
src/PicView.Avalonia/ViewModels/MainViewModel.cs

@@ -267,6 +267,8 @@ public class MainViewModel : ReactiveObject
         SlideshowCommand = FunctionsHelper.CreateReactiveCommand<int>(StartSlideShowTask);
 
         ToggleTaskbarProgressCommand = FunctionsHelper.CreateReactiveCommand(FunctionsMapper.ToggleTaskbarProgress);
+        
+        ToggleConstrainBackgroundColorCommand = FunctionsHelper.CreateReactiveCommand(FunctionsMapper.ToggleConstrainBackgroundColor);
 
         #endregion UI Commands
 
@@ -676,6 +678,8 @@ public class MainViewModel : ReactiveObject
     public ReactiveCommand<Unit, Unit>? ShowSettingsFileCommand { get; }
     
     public ReactiveCommand<Unit, Unit>? ShowKeybindingsFileCommand { get; }
+    
+    public ReactiveCommand<Unit, Unit>? ToggleConstrainBackgroundColorCommand { get; }
 
     #endregion Commands
 
@@ -797,6 +801,12 @@ public class MainViewModel : ReactiveObject
         set => this.RaiseAndSetIfChanged(ref field, value);
     }
 
+    public bool IsConstrainingBackgroundColor
+    {
+        get;
+        set => this.RaiseAndSetIfChanged(ref field, value);
+    }
+
     public bool IsIncludingSubdirectories
     {
         get;
@@ -886,6 +896,12 @@ public class MainViewModel : ReactiveObject
         set => this.RaiseAndSetIfChanged(ref field, value);
     }
     
+    public Brush? ConstrainedImageBackground
+    {
+        get;
+        set => this.RaiseAndSetIfChanged(ref field, value);
+    }
+    
     public Thickness RightControlOffSetMargin
     {
         get;

+ 19 - 0
src/PicView.Avalonia/Views/AppearanceView.axaml

@@ -264,6 +264,25 @@
                 x:Name="BlackBgButton" />
 
         </WrapPanel>
+        
+        
+        <ToggleButton
+            Background="Transparent"
+            BorderThickness="0"
+            Classes="altHover"
+            Command="{CompiledBinding ToggleConstrainBackgroundColorCommand}"
+            IsChecked="{CompiledBinding IsConstrainingBackgroundColor}"
+            Margin="0,0,0,10"
+            Width="300">
+            <TextBlock
+                Classes="txt"
+                Foreground="{StaticResource SecondaryTextColor}"
+                Margin="0"
+                MaxWidth="240"
+                Padding="0,1,5,0"
+                Text="{CompiledBinding Translation.ConstrainBackgroundToImage,
+                                           Mode=OneWay}" />
+        </ToggleButton>
 
         <TextBlock
             Classes="txt"

+ 4 - 2
src/PicView.Avalonia/Views/ImageViewer.axaml

@@ -25,13 +25,15 @@
             Width="{CompiledBinding PicViewer.ScrollViewerWidth,
                                     Mode=OneWay}"
             x:Name="ImageScrollViewer">
-            <Border
+            <Border     
+                Background="{CompiledBinding ConstrainedImageBackground,
+                                 Mode=OneWay}"
                 Height="{CompiledBinding PicViewer.ImageHeight,
                                          Mode=OneWay}"
                 Width="{CompiledBinding PicViewer.ImageWidth,
                                         Mode=OneWay}"
                 x:Name="MainBorder">
-                <customControls:PicBox
+                <customControls:PicBox 
                     ImageType="{CompiledBinding PicViewer.ImageType,
                                                 Mode=OneWay}"
                     PointerMoved="MainImage_OnPointerMoved"

+ 1 - 0
src/PicView.Core/Config/AppSettings.cs

@@ -41,6 +41,7 @@ public class UIProperties
     public bool ShowConfirmationOnEsc { get; set; } = false;
     public bool ShowRecycleConfirmation { get; set; } = false;
     public bool ShowPermanentDeletionConfirmation { get; set; } = true;
+    public bool IsConstrainBackgroundColorEnabled { get; set; } = true;
 }
 
 public class Theme

+ 1 - 0
src/PicView.Core/Config/Languages/da.json

@@ -59,6 +59,7 @@
   "ColorTone": "Farve Tone",
   "CompressedBitsPixel": "Komprimerede bits pr. pixel",
   "Compression": "Kompression",
+  "ConstrainBackgroundToImage": "Begræns baggrundsfarve til billedet",
   "Contrast": "Kontrast",
   "ConvertTo": "Konverter til",
   "ConvertedToBase64": "Konverteret til base64",

+ 1 - 0
src/PicView.Core/Config/Languages/de.json

@@ -59,6 +59,7 @@
   "ColorTone": "Farbton",
   "CompressedBitsPixel": "Komprimierte Bits pro Pixel",
   "Compression": "Komprimierung",
+  "ConstrainBackgroundToImage": "Hintergrundfarbe auf Bild beschränken",
   "Contrast": "Kontrast",
   "ConvertTo": "Konvertieren zu",
   "ConvertedToBase64": "In Base64 umgewandelt",

+ 1 - 0
src/PicView.Core/Config/Languages/en.json

@@ -59,6 +59,7 @@
   "ColorTone": "Color Tone",
   "CompressedBitsPixel": "Compressed bits per pixel",
   "Compression": "Compression",
+  "ConstrainBackgroundToImage": "Constrain background color to image",
   "Contrast": "Contrast",
   "ConvertTo": "Convert to",
   "ConvertedToBase64": "Converted to base64",

+ 1 - 0
src/PicView.Core/Config/Languages/es.json

@@ -59,6 +59,7 @@
   "ColorTone": "Tono de Color",
   "CompressedBitsPixel": "Bits por píxel comprimidos",
   "Compression": "Compresión",
+  "ConstrainBackgroundToImage": "Restringir color de fondo a la imagen",
   "Contrast": "Contraste",
   "ConvertTo": "Convertir a",
   "ConvertedToBase64": "Convertido a base64",

+ 1 - 0
src/PicView.Core/Config/Languages/fr.json

@@ -59,6 +59,7 @@
   "ColorTone": "Tonalité des couleurs",
   "CompressedBitsPixel": "Bits de pixel compressés",
   "Compression": "Compression",
+  "ConstrainBackgroundToImage": "Limiter la couleur d’arrière-plan à l’image",
   "Contrast": "Contraste",
   "ConvertTo": "Convertir en",
   "ConvertedToBase64": "Converti en base64",

+ 1 - 0
src/PicView.Core/Config/Languages/it.json

@@ -59,6 +59,7 @@
   "ColorTone": "Tonalità di colore",
   "CompressedBitsPixel": "Bit per pixel compressi",
   "Compression": "Compressione",
+  "ConstrainBackgroundToImage": "Limita il colore di sfondo all'immagine",
   "Contrast": "Contrasto",
   "ConvertTo": "Convertire in",
   "ConvertedToBase64": "Convertito in base64",

+ 1 - 0
src/PicView.Core/Config/Languages/ja.json

@@ -59,6 +59,7 @@
   "ColorTone": "色調",
   "CompressedBitsPixel": "圧縮されたピクセルあたりのビット数",
   "Compression": "圧縮",
+  "ConstrainBackgroundToImage": "背景色を画像に制限する",
   "Contrast": "コントラスト",
   "ConvertTo": "変換形式",
   "ConvertedToBase64": "base64 に変換",

+ 1 - 0
src/PicView.Core/Config/Languages/ko.json

@@ -59,6 +59,7 @@
   "ColorTone": "색조",
   "CompressedBitsPixel": "픽셀당 압축 비트",
   "Compression": "압축",
+  "ConstrainBackgroundToImage": "배경색을 이미지에만 적용",
   "Contrast": "대비",
   "ConvertTo": "변환",
   "ConvertedToBase64": "base64로 변환",

+ 1 - 0
src/PicView.Core/Config/Languages/nl.json

@@ -59,6 +59,7 @@
   "ColorTone": "Kleurtoon",
   "CompressedBitsPixel": "Gecomprimeerde bits per pixel",
   "Compression": "Compressie",
+  "ConstrainBackgroundToImage": "Beperk achtergrondkleur tot afbeelding",
   "Contrast": "Contrast",
   "ConvertTo": "Converteren naar",
   "ConvertedToBase64": "Geconverteerd naar base64",

+ 1 - 0
src/PicView.Core/Config/Languages/pl.json

@@ -59,6 +59,7 @@
   "ColorTone": "Odcień",
   "CompressedBitsPixel": "Kompresja bitów na piksel",
   "Compression": "Kompresja",
+  "ConstrainBackgroundToImage": "Ogranicz kolor tła do obrazu",
   "Contrast": "Kontrast",
   "ConvertTo": "Konwertuj na",
   "ConvertedToBase64": "Zamieniono na Base64",

+ 1 - 0
src/PicView.Core/Config/Languages/pt-br.json

@@ -59,6 +59,7 @@
   "ColorTone": "Tonalidade da cor",
   "CompressedBitsPixel": "Bits compactados por pixel",
   "Compression": "Compressão",
+  "ConstrainBackgroundToImage": "Restringir cor de fundo à imagem",
   "Contrast": "Contraste",
   "ConvertTo": "Converter para",
   "ConvertedToBase64": "Convertido para base64",

+ 1 - 0
src/PicView.Core/Config/Languages/ro.json

@@ -59,6 +59,7 @@
   "ColorTone": "Ton de culoare",
   "CompressedBitsPixel": "Biți compresați pe pixel",
   "Compression": "Compresie",
+  "ConstrainBackgroundToImage": "Restricționează culoarea de fundal la imagine",
   "Contrast": "Contrast",
   "ConvertTo": "Conversie în",
   "ConvertedToBase64": "CConvertit în base64",

+ 1 - 0
src/PicView.Core/Config/Languages/ru.json

@@ -59,6 +59,7 @@
   "ColorTone": "Цветовой тон",
   "CompressedBitsPixel": "Сжатые биты на пиксель",
   "Compression": "Сжатие",
+  "ConstrainBackgroundToImage": "Ограничить цвет фона изображением",
   "Contrast": "Контраст",
   "ConvertTo": "Преобразовать в",
   "ConvertedToBase64": "Преобразовано в base64",

+ 1 - 0
src/PicView.Core/Config/Languages/sv.json

@@ -59,6 +59,7 @@
   "ColorTone": "Färgton",
   "CompressedBitsPixel": "Komprimerade bitar per pixel",
   "Compression": "Kompression",
+  "ConstrainBackgroundToImage": "Begränsa bakgrundsfärg till bilden",
   "Contrast": "Kontrast",
   "ConvertTo": "Konvertera till",
   "ConvertedToBase64": "Konverterad till base64",

+ 1 - 0
src/PicView.Core/Config/Languages/tr.json

@@ -59,6 +59,7 @@
   "ColorTone": "Renk Tonu",
   "CompressedBitsPixel": "Piksel başına sıkıştırılmış bit",
   "Compression": "Sıkıştırma",
+  "ConstrainBackgroundToImage": "Arka plan rengini yalnızca görselle sınırla",
   "Contrast": "Kontrast",
   "ConvertTo": "Dönüştür",
   "ConvertedToBase64": "Base64'e dönüştürüldü",

+ 1 - 0
src/PicView.Core/Config/Languages/zh-CN.json

@@ -59,6 +59,7 @@
   "ColorTone": "色调",
   "CompressedBitsPixel": "压缩位像素",
   "Compression": "压缩",
+  "ConstrainBackgroundToImage": "将背景颜色限制为图像区域",
   "Contrast": "对比度",
   "ConvertTo": "转换为",
   "ConvertedToBase64": "已复制为 base64",

+ 1 - 0
src/PicView.Core/Config/Languages/zh-TW.json

@@ -59,6 +59,7 @@
   "ColorTone": "色調",
   "CompressedBitsPixel": "壓縮位元像素",
   "Compression": "壓縮",
+  "ConstrainBackgroundToImage": "將背景顏色限制為圖片區域",
   "Contrast": "對比度",
   "ConvertTo": "轉換成",
   "ConvertedToBase64": "已複製為 base64",

+ 1 - 0
src/PicView.Core/Localization/LanguageModel.cs

@@ -70,6 +70,7 @@ public class LanguageModel
     public string? ColorTone { get; set; }
     public string? CompressedBitsPixel { get; set; }
     public string? Compression { get; set; }
+    public string? ConstrainBackgroundToImage { get; set; }
     public string? Contrast { get; set; }
     public string? ConvertedToBase64 { get; set; }
     public string? ConvertTo { get; set; }

+ 7 - 0
src/PicView.Core/ViewModels/TranslationViewModel.cs

@@ -282,10 +282,17 @@ public class TranslationViewModel : ReactiveObject
         Pin = TranslationManager.Translation.Pin;
         Clear = TranslationManager.Translation.Clear;
         OpenFileHistory = TranslationManager.Translation.OpenFileHistory;
+        ConstrainBackgroundToImage = TranslationManager.Translation.ConstrainBackgroundToImage;
     }
 
     #region Static Translation Strings
     
+    public string? ConstrainBackgroundToImage
+    {
+        get;
+        set => this.RaiseAndSetIfChanged(ref field, value);
+    }
+    
     public string? Pinned
     {
         get;

+ 4 - 3
src/PicView.Tests/LanguageTests/DanishUnitTest.cs

@@ -15,14 +15,14 @@ public static class DanishUnitTest
         Assert.Equal(TranslationManager.Translation.ActionProgram, "Action program");
         Assert.Equal(TranslationManager.Translation.AddedToClipboard, "Tilføjet til udklipsholderen");
         Assert.Equal(TranslationManager.Translation.AdditionalFunctions, "Diverse funktioner");
-        Assert.Equal(TranslationManager.Translation.AdjustNavSpeed, "Juster hastighed, når tasten holdes nede");
+        Assert.Equal(TranslationManager.Translation.AdjustNavSpeed, "Juster hastigheden når tasten holdes nede");
         Assert.Equal(TranslationManager.Translation.AdjustTimingForSlideshow, "Juster timing for slideshowet");
         Assert.Equal(TranslationManager.Translation.AdjustTimingForZoom, "Justér zooming hastighed");
         Assert.Equal(TranslationManager.Translation.AdjustZoomLevel, "Juster zoom niveau");
         Assert.Equal(TranslationManager.Translation.AdvanceBy100Images, "Gå 100 billeder frem");
         Assert.Equal(TranslationManager.Translation.AdvanceBy10Images, "Gå 10 billeder frem");
         Assert.Equal(TranslationManager.Translation.AllowZoomOut,
-            "Undgå at zoome billedet ud, når det allerede er i maksimal størrelse");
+            "Undgå at zoome billedet ud, når billedet allerede er i maksimal størrelse");
         Assert.Equal(TranslationManager.Translation.Alt, "Alt");
         Assert.Equal(TranslationManager.Translation.Altitude, "Højde");
         Assert.Equal(TranslationManager.Translation.AperturePriority, "Blænde prioritet");
@@ -38,7 +38,7 @@ public static class DanishUnitTest
         Assert.Equal(TranslationManager.Translation.AutoFitWindow, "Auto tilpas vindue");
         Assert.Equal(TranslationManager.Translation.BadArchive, "Arkivet kunne ikke behandles");
         Assert.Equal(TranslationManager.Translation.Base64Image, "Base64 billede");
-        Assert.Equal(TranslationManager.Translation.BatchResize, "Batch Billedstørrelse");
+        Assert.Equal(TranslationManager.Translation.BatchResize, "Batch størrelse");
         Assert.Equal(TranslationManager.Translation.BitDepth, "Bit dybde");
         Assert.Equal(TranslationManager.Translation.BlackAndWhite, "Sort/hvid");
         Assert.Equal(TranslationManager.Translation.Blur, "Sløring");
@@ -72,6 +72,7 @@ public static class DanishUnitTest
         Assert.Equal(TranslationManager.Translation.ColorTone, "Farve Tone");
         Assert.Equal(TranslationManager.Translation.CompressedBitsPixel, "Komprimerede bits pr. pixel");
         Assert.Equal(TranslationManager.Translation.Compression, "Kompression");
+        Assert.Equal(TranslationManager.Translation.ConstrainBackgroundToImage, "Begræns baggrundsfarve til billedet");
         Assert.Equal(TranslationManager.Translation.Contrast, "Kontrast");
         Assert.Equal(TranslationManager.Translation.ConvertTo, "Konverter til");
         Assert.Equal(TranslationManager.Translation.ConvertedToBase64, "Konverteret til base64");

+ 1 - 0
src/PicView.Tests/LanguageTests/DutchUnitTest.cs

@@ -73,6 +73,7 @@ public static class DutchUnitTest
         Assert.Equal(TranslationManager.Translation.ColorTone, "Kleurtoon");
         Assert.Equal(TranslationManager.Translation.CompressedBitsPixel, "Gecomprimeerde bits per pixel");
         Assert.Equal(TranslationManager.Translation.Compression, "Compressie");
+        Assert.Equal(TranslationManager.Translation.ConstrainBackgroundToImage, "Beperk achtergrondkleur tot afbeelding");
         Assert.Equal(TranslationManager.Translation.Contrast, "Contrast");
         Assert.Equal(TranslationManager.Translation.ConvertTo, "Converteren naar");
         Assert.Equal(TranslationManager.Translation.ConvertedToBase64, "Geconverteerd naar base64");