Pārlūkot izejas kodu

Avalonia updates

Ruben 1 gadu atpakaļ
vecāks
revīzija
c94684b55a

+ 20 - 0
src/PicView.Avalonia/Helpers/ConversionHelper.cs

@@ -19,6 +19,26 @@ internal static class ConversionHelper
         return await SaveImageFileHelper.ResizeImageAsync(fileInfo, 0, 0, 100, magickPercentage).ConfigureAwait(false);
     }
 
+    internal static async Task<bool> ResizeByWidth(FileInfo fileInfo, double width)
+    {
+        if (width <= 0)
+        {
+            return false;
+        }
+
+        return await SaveImageFileHelper.ResizeImageAsync(fileInfo, (int)width, 0).ConfigureAwait(false);
+    }
+
+    internal static async Task<bool> ResizeByHeight(FileInfo fileInfo, double height)
+    {
+        if (height <= 0)
+        {
+            return false;
+        }
+
+        return await SaveImageFileHelper.ResizeImageAsync(fileInfo, 0, (int)height).ConfigureAwait(false);
+    }
+
     internal static async Task<string> ConvertTask(FileInfo fileInfo, int selectedIndex)
     {
         var currentExtension = fileInfo.Extension;

+ 9 - 0
src/PicView.Avalonia/ViewModels/ViewModelBase.cs

@@ -135,6 +135,15 @@ public class ViewModelBase : ReactiveObject
         CopyImage = TranslationHelper.GetTranslation("CopyImage");
         FileCopyPath = TranslationHelper.GetTranslation("FileCopyPath");
         FileCut = TranslationHelper.GetTranslation("FileCut");
+        CtrlToZoom = TranslationHelper.GetTranslation("CtrlToZoom");
+    }
+
+    private string? _ctrlToZoom;
+
+    public string? CtrlToZoom
+    {
+        get => _ctrlToZoom;
+        set => this.RaiseAndSetIfChanged(ref _ctrlToZoom, value);
     }
 
     private string? _fileCut;

+ 8 - 2
src/PicView.Avalonia/Views/ExifView.axaml

@@ -168,7 +168,10 @@
                             Margin="0,8,0,0"
                             Classes="txt"
                             Text="{Binding Width}" />
-                        <TextBox Classes="hover TStyle" Text="{Binding PixelWidth}" />
+                        <TextBox
+                            x:Name="PixelWidthTextBox"
+                            Classes="hover TStyle"
+                            Text="{Binding PixelWidth}" />
                         <Button Classes="altHover BorderStyle" ToolTip.Tip="{Binding Copy}">
                             <Path
                                 Width="16"
@@ -185,7 +188,10 @@
                             Margin="0,8,0,0"
                             Classes="txt"
                             Text="{Binding Height}" />
-                        <TextBox Classes="hover TStyle" Text="{Binding PixelHeight}" />
+                        <TextBox
+                            x:Name="PixelHeightTextBox"
+                            Classes="hover TStyle"
+                            Text="{Binding PixelHeight}" />
                         <Button Classes="altHover BorderStyle" ToolTip.Tip="{Binding Copy}">
                             <Path
                                 Width="16"

+ 72 - 0
src/PicView.Avalonia/Views/ExifView.axaml.cs

@@ -1,5 +1,7 @@
 using Avalonia.Controls;
 using Avalonia.Input;
+using PicView.Avalonia.Helpers;
+using PicView.Avalonia.ViewModels;
 
 namespace PicView.Avalonia.Views;
 
@@ -8,5 +10,75 @@ public partial class ExifView : UserControl
     public ExifView()
     {
         InitializeComponent();
+        PixelHeightTextBox.KeyDown += async (s, e) => await PixelHeightTextBox_OnKeyDown(s, e);
+        PixelWidthTextBox.KeyDown += async (s, e) => await PixelWidthTextBox_OnKeyDown(s, e);
+    }
+
+    private async Task PixelHeightTextBox_OnKeyDown(object? sender, KeyEventArgs e)
+    {
+        if (DataContext is null)
+        {
+            return;
+        }
+        var vm = (MainViewModel)DataContext;
+        var textBox = (TextBox)sender!;
+        if (textBox is null)
+        {
+            return;
+        }
+        var text = ((TextBox)sender!).Text;
+        if (e.Key != Key.Enter)
+        {
+            return;
+        }
+
+        if (!double.TryParse(text, out var height))
+        {
+            return;
+        }
+
+        if (height > 0)
+        {
+            var success = await ConversionHelper.ResizeByHeight(vm.FileInfo, height).ConfigureAwait(false);
+            if (success)
+            {
+                vm.ImageIterator?.PreLoader?.Remove(vm.ImageIterator.Index, vm.ImageIterator.Pics);
+                await vm.LoadPicAtIndex(vm.ImageIterator.Index);
+            }
+        }
+    }
+
+    private async Task PixelWidthTextBox_OnKeyDown(object? sender, KeyEventArgs e)
+    {
+        if (DataContext is null)
+        {
+            return;
+        }
+        var vm = (MainViewModel)DataContext;
+        var textBox = (TextBox)sender!;
+        if (textBox is null)
+        {
+            return;
+        }
+        var text = ((TextBox)sender!).Text;
+        if (e.Key != Key.Enter)
+        {
+            return;
+        }
+
+        if (!double.TryParse(text, out var width))
+        {
+            return;
+        }
+
+        if (width > 0)
+        {
+            var success = await ConversionHelper.ResizeByWidth(vm.FileInfo, width).ConfigureAwait(false);
+            if (success)
+            {
+                vm.ImageIterator?.PreLoader?.Remove(vm.ImageIterator.Index, vm.ImageIterator.Pics);
+                await vm.LoadPicAtIndex(vm.ImageIterator.Index);
+            }
+        }
     }
 }

+ 30 - 0
src/PicView.Avalonia/Views/MainView.axaml

@@ -113,6 +113,11 @@
                         Fill="{StaticResource MainIconColor}"
                         Stretch="Fill" />
                 </MenuItem.Icon>
+                <MenuItem Header="{Binding ToggleLooping}" />
+                <MenuItem Header="{Binding ToggleScroll}" />
+                <MenuItem Command="{Binding ChangeTopMostCommand}" Header="{Binding StayTopMost}" />
+                <MenuItem Header="{Binding Stretch}" />
+                <MenuItem Header="{Binding CtrlToZoom}" />
                 <MenuItem Command="{Binding ToggleUICommand}" Header="{Binding HideShowInterface}">
                     <MenuItem.Icon>
                         <Image Width="12" Height="12">
@@ -154,6 +159,31 @@
                         </Image>
                     </MenuItem.Icon>
                 </MenuItem>
+                <MenuItem Header="{Binding GetBottomGallery}">
+                    <MenuItem.Icon>
+                        <Image Width="12" Height="12">
+                            <DrawingImage>
+                                <DrawingImage.Drawing>
+                                    <DrawingGroup ClipGeometry="M0,0 V512 H512 V0 H0 Z">
+                                        <GeometryDrawing Brush="{StaticResource MainIconColor}" Geometry="F1 M512,512z M0,0z M80,132L80,460A20,20,0,0,0,100,480L492,480A20,20,0,0,0,512,460L512,132A20,20,0,0,0,492,112L100,112A20,20,0,0,0,80,132z M373.14,173.33A46,46,0,1,1,326.86,219.33A46.19,46.19,0,0,1,373.14,173.33z M111.73,449.33L111.73,353.85 234.49,243.65 328.27,337 215.27,449.33z M480,449.33L259,449.33 403.58,305.33 480,370.59z" />
+                                        <GeometryDrawing Brush="{StaticResource MainIconColor}" Geometry="F1 M512,512z M0,0z M20,32A20,20,0,0,0,0,52L0,396A20,20,0,0,0,20,416L48,416 48,100A20,20,0,0,1,68,80L448,80 448,52A20,20,0,0,0,428,32z" />
+                                    </DrawingGroup>
+                                </DrawingImage.Drawing>
+                            </DrawingImage>
+                        </Image>
+                    </MenuItem.Icon>
+                </MenuItem>
+                <Separator />
+                <MenuItem Header="{Binding ShowAllSettingsWindow}">
+                    <MenuItem.Icon>
+                        <Path
+                            Width="12"
+                            Height="12"
+                            Data="M262.29 192.31a64 64 0 1057.4 57.4 64.13 64.13 0 00-57.4-57.4zM416.39 256a154.34 154.34 0 01-1.53 20.79l45.21 35.46a10.81 10.81 0 012.45 13.75l-42.77 74a10.81 10.81 0 01-13.14 4.59l-44.9-18.08a16.11 16.11 0 00-15.17 1.75A164.48 164.48 0 01325 400.8a15.94 15.94 0 00-8.82 12.14l-6.73 47.89a11.08 11.08 0 01-10.68 9.17h-85.54a11.11 11.11 0 01-10.69-8.87l-6.72-47.82a16.07 16.07 0 00-9-12.22 155.3 155.3 0 01-21.46-12.57 16 16 0 00-15.11-1.71l-44.89 18.07a10.81 10.81 0 01-13.14-4.58l-42.77-74a10.8 10.8 0 012.45-13.75l38.21-30a16.05 16.05 0 006-14.08c-.36-4.17-.58-8.33-.58-12.5s.21-8.27.58-12.35a16 16 0 00-6.07-13.94l-38.19-30A10.81 10.81 0 0149.48 186l42.77-74a10.81 10.81 0 0113.14-4.59l44.9 18.08a16.11 16.11 0 0015.17-1.75A164.48 164.48 0 01187 111.2a15.94 15.94 0 008.82-12.14l6.73-47.89A11.08 11.08 0 01213.23 42h85.54a11.11 11.11 0 0110.69 8.87l6.72 47.82a16.07 16.07 0 009 12.22 155.3 155.3 0 0121.46 12.57 16 16 0 0015.11 1.71l44.89-18.07a10.81 10.81 0 0113.14 4.58l42.77 74a10.8 10.8 0 01-2.45 13.75l-38.21 30a16.05 16.05 0 00-6.05 14.08c.33 4.14.55 8.3.55 12.47z"
+                            Fill="{StaticResource MainIconColor}"
+                            Stretch="Fill" />
+                    </MenuItem.Icon>
+                </MenuItem>
             </MenuItem>
             <Separator />
             <MenuItem Header="{Binding SetAsWallpaper}">