From 13a0f1f83ae17c26d2e936bff49bf6fa7659f474 Mon Sep 17 00:00:00 2001 From: Ruben Date: Wed, 8 Jan 2025 00:53:12 +0100 Subject: [PATCH] Update image effects --- .../Views/EffectsWindow.axaml.cs | 6 + .../Views/EffectsWindow.axaml.cs | 6 + .../PicViewTheme/Controls/Slider.axaml | 73 ++++++- src/PicView.Avalonia/PicViewTheme/Icons.axaml | 24 +++ .../ViewModels/ViewModelBase.cs | 16 +- src/PicView.Avalonia/Views/EffectsView.axaml | 199 +++++++++++++++++- .../Views/EffectsView.axaml.cs | 26 ++- 7 files changed, 339 insertions(+), 11 deletions(-) diff --git a/src/PicView.Avalonia.MacOS/Views/EffectsWindow.axaml.cs b/src/PicView.Avalonia.MacOS/Views/EffectsWindow.axaml.cs index 7c7e3660..7ecd20ef 100644 --- a/src/PicView.Avalonia.MacOS/Views/EffectsWindow.axaml.cs +++ b/src/PicView.Avalonia.MacOS/Views/EffectsWindow.axaml.cs @@ -1,6 +1,7 @@ using Avalonia.Controls; using Avalonia.Input; using Avalonia.Media; +using PicView.Avalonia.WindowBehavior; using PicView.Core.Config; using PicView.Core.Localization; @@ -19,6 +20,11 @@ public EffectsWindow() { MinWidth = MaxWidth = Width; Title = $"{TranslationHelper.Translation.Effects} - PicView"; + + ClientSizeProperty.Changed.Subscribe(size => + { + WindowResizing.HandleWindowResize(this, size); + }); }; KeyDown += (_, e) => { diff --git a/src/PicView.Avalonia.Win32/Views/EffectsWindow.axaml.cs b/src/PicView.Avalonia.Win32/Views/EffectsWindow.axaml.cs index 1793cf92..05d1a345 100644 --- a/src/PicView.Avalonia.Win32/Views/EffectsWindow.axaml.cs +++ b/src/PicView.Avalonia.Win32/Views/EffectsWindow.axaml.cs @@ -3,6 +3,7 @@ using Avalonia.Input; using Avalonia.Interactivity; using Avalonia.Media; +using PicView.Avalonia.WindowBehavior; using PicView.Core.Config; using PicView.Core.Localization; @@ -47,6 +48,11 @@ public EffectsWindow() { MinWidth = MaxWidth = Width; Title = $"{TranslationHelper.Translation.Effects} - PicView"; + + ClientSizeProperty.Changed.Subscribe(size => + { + WindowResizing.HandleWindowResize(this, size); + }); }; KeyDown += (_, e) => { diff --git a/src/PicView.Avalonia/PicViewTheme/Controls/Slider.axaml b/src/PicView.Avalonia/PicViewTheme/Controls/Slider.axaml index b103a398..8013b126 100644 --- a/src/PicView.Avalonia/PicViewTheme/Controls/Slider.axaml +++ b/src/PicView.Avalonia/PicViewTheme/Controls/Slider.axaml @@ -7,7 +7,7 @@ - + @@ -16,7 +16,10 @@ - + @@ -75,4 +78,70 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/PicView.Avalonia/PicViewTheme/Icons.axaml b/src/PicView.Avalonia/PicViewTheme/Icons.axaml index 2a1b322a..922a1546 100644 --- a/src/PicView.Avalonia/PicViewTheme/Icons.axaml +++ b/src/PicView.Avalonia/PicViewTheme/Icons.axaml @@ -1076,4 +1076,28 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/PicView.Avalonia/ViewModels/ViewModelBase.cs b/src/PicView.Avalonia/ViewModels/ViewModelBase.cs index fe8a4990..d1eaf8cf 100644 --- a/src/PicView.Avalonia/ViewModels/ViewModelBase.cs +++ b/src/PicView.Avalonia/ViewModels/ViewModelBase.cs @@ -259,13 +259,27 @@ public void UpdateLanguage() ImageAliasing = TranslationHelper.Translation.ImageAliasing; HighQuality = TranslationHelper.Translation.HighQuality; Lighting = TranslationHelper.Translation.Lighting; - Emboss = TranslationHelper.Translation.Embossed; // Should change to Emboss + Emboss = TranslationHelper.Translation.Embossed; BlackAndWhite = TranslationHelper.Translation.BlackAndWhite; NegativeColors = TranslationHelper.Translation.NegativeColors; + Blur = TranslationHelper.Translation.Blur; + DirectionalBlur = TranslationHelper.Translation.DirectionalBlur; } #region Strings + public string? DirectionalBlur + { + get; + set => this.RaiseAndSetIfChanged(ref field, value); + } + + public string? Blur + { + get; + set => this.RaiseAndSetIfChanged(ref field, value); + } + public string? NegativeColors { get; diff --git a/src/PicView.Avalonia/Views/EffectsView.axaml b/src/PicView.Avalonia/Views/EffectsView.axaml index dfa76558..5bb19232 100644 --- a/src/PicView.Avalonia/Views/EffectsView.axaml +++ b/src/PicView.Avalonia/Views/EffectsView.axaml @@ -25,10 +25,144 @@ HorizontalAlignment="Left" Text="{CompiledBinding Brightness}" VerticalAlignment="Center" /> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -42,19 +176,20 @@ SmallChange="1" TickFrequency="1" Value="0" - x:Name="BrightnessSlider" /> + x:Name="BlurSlider" /> - + + @@ -68,14 +203,64 @@ SmallChange="1" TickFrequency="1" Value="0" - x:Name="ContrastSlider" /> + x:Name="GaussianBlurSlider" /> + + + + + + + + + + + + + + + - { + ResetContrastBtn.Click += delegate + { + ContrastSlider.Value = 0; + }; + ResetBrightnessBtn.Click += delegate + { + BrightnessSlider.Value = 0; + }; + BrightnessSlider.ValueChanged += async (_, e) => await BrightnessChanged(e).ConfigureAwait(false); ContrastSlider.ValueChanged += async (_, e) => await ContrastChanged(e).ConfigureAwait(false); + DirectionalBlurSlider.ValueChanged += async (_, e) => await DirectionalBlurChanged(e).ConfigureAwait(false); BlackAndWhiteToggleButton.Click += async (_, _) => { if (!BlackAndWhiteToggleButton.IsChecked.HasValue) @@ -99,6 +109,20 @@ private async Task ContrastChanged(RangeBaseValueChangedEventArgs e) } await ApplyEffects(vm); } + + private async Task DirectionalBlurChanged(RangeBaseValueChangedEventArgs e) + { + if (DataContext is not MainViewModel vm) + { + return; + } + + if (!NavigationHelper.CanNavigate(vm)) + { + return; + } + await ApplyEffects(vm); + } private async Task ApplyEffects(MainViewModel vm) { @@ -134,7 +158,7 @@ private async Task ApplyEffects(MainViewModel vm) vm.ImageSource = bitmap; } - private async Task RemoveEffects(MainViewModel vm) + private static async Task RemoveEffects(MainViewModel vm) { using var magick = new MagickImage(); await magick.ReadAsync(vm.FileInfo.FullName).ConfigureAwait(false);