Skip to content

Commit

Permalink
Add option to change image aliasing
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruben2776 committed Jan 1, 2025
1 parent 718a8cd commit c4c4e91
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 5 deletions.
14 changes: 14 additions & 0 deletions src/PicView.Avalonia/ViewModels/ViewModelBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -256,10 +256,24 @@ public void UpdateLanguage()
WidthAndHeight = TranslationHelper.Translation.WidthAndHeight;
CloseWindowPrompt = TranslationHelper.Translation.CloseWindowPrompt;
ShowConfirmationOnEsc = TranslationHelper.Translation.ShowConfirmationOnEsc;
ImageAliasing = TranslationHelper.Translation.ImageAliasing;
HighQuality = TranslationHelper.Translation.HighQuality;
}

#region Strings

public string? HighQuality
{
get;
set => this.RaiseAndSetIfChanged(ref field, value);
}

public string? ImageAliasing
{
get;
set => this.RaiseAndSetIfChanged(ref field, value);
}

public string? CloseWindowPrompt
{
get;
Expand Down
4 changes: 0 additions & 4 deletions src/PicView.Avalonia/Views/GeneralSettingsView.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ public GeneralSettingsView()
InitializeComponent();
Loaded += delegate
{


ApplicationStartupBox.SelectedIndex = SettingsHelper.Settings.StartUp.OpenLastFile ? 1 : 0;

ApplicationStartupBox.SelectionChanged += async delegate
Expand All @@ -30,8 +28,6 @@ public GeneralSettingsView()
ApplicationStartupBox.SelectedIndex = SettingsHelper.Settings.StartUp.OpenLastFile ? 0 : 1;
}
};


};
}
}
21 changes: 21 additions & 0 deletions src/PicView.Avalonia/Views/ImageSettingsView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,26 @@
Mode=OneWay}" />
</ToggleButton>

<TextBlock
Classes="txt"
FontFamily="/Assets/Fonts/Roboto-Bold.ttf#Roboto"
FontSize="14"
Foreground="{StaticResource SecondaryTextColor}"
Margin="0,20,0,20"
Text="{CompiledBinding ImageAliasing,
Mode=OneWay}" />
<ComboBox
Background="{DynamicResource SecondaryBackgroundColor}"
BorderBrush="{DynamicResource MainBorderColor}"
BorderThickness="1"
FontFamily="/Assets/Fonts/Roboto-Medium.ttf#Roboto"
Margin="0,6,0,10"
Padding="5,7,0,7"
Width="300"
x:Name="ImageAliasingBox">
<ComboBoxItem Content="{CompiledBinding HighQuality, Mode=OneWay}" />
<ComboBoxItem Content="{CompiledBinding None, Mode=OneWay}" />
</ComboBox>

</StackPanel>
</UserControl>
27 changes: 27 additions & 0 deletions src/PicView.Avalonia/Views/ImageSettingsView.axaml.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,37 @@
using Avalonia.Controls;
using PicView.Avalonia.ViewModels;
using PicView.Core.Config;

namespace PicView.Avalonia.Views;
public partial class ImageSettingsView : UserControl
{
public ImageSettingsView()
{
InitializeComponent();
Loaded += delegate
{
ImageAliasingBox.SelectedIndex = SettingsHelper.Settings.ImageScaling.IsScalingSetToNearestNeighbor ? 1 : 0;

ImageAliasingBox.SelectionChanged += async delegate
{
if (ImageAliasingBox.SelectedIndex == -1)
{
return;
}
SettingsHelper.Settings.ImageScaling.IsScalingSetToNearestNeighbor = ImageAliasingBox.SelectedIndex == 1;
if (DataContext is MainViewModel vm)
{
vm.ImageViewer.TriggerScalingModeUpdate(true);
}
await SettingsHelper.SaveSettingsAsync();
};
ImageAliasingBox.DropDownOpened += delegate
{
if (ImageAliasingBox.SelectedIndex == -1)
{
ImageAliasingBox.SelectedIndex = SettingsHelper.Settings.ImageScaling.IsScalingSetToNearestNeighbor ? 0 : 1;
}
};
};
}
}
1 change: 0 additions & 1 deletion src/PicView.Avalonia/Views/ImageViewer.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
PointerMoved="MainImage_OnPointerMoved"
PointerPressed="MainImage_OnPointerPressed"
PointerReleased="MainImage_OnPointerReleased"
RenderOptions.BitmapInterpolationMode="HighQuality"
SecondaryImageWidth="{CompiledBinding SecondaryImageWidth,
Mode=OneWay}"
SecondarySource="{CompiledBinding SecondaryImageSource,
Expand Down
16 changes: 16 additions & 0 deletions src/PicView.Avalonia/Views/ImageViewer.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Avalonia.Input;
using Avalonia.Interactivity;
using Avalonia.Media;
using Avalonia.Media.Imaging;
using Avalonia.Threading;
using PicView.Avalonia.Navigation;
using PicView.Avalonia.UI;
Expand Down Expand Up @@ -33,6 +34,7 @@ public partial class ImageViewer : UserControl
public ImageViewer()
{
InitializeComponent();
TriggerScalingModeUpdate(false);
AddHandler(PointerWheelChangedEvent, PreviewOnPointerWheelChanged, RoutingStrategies.Tunnel);
AddHandler(Gestures.PointerTouchPadGestureMagnifyEvent, TouchMagnifyEvent, RoutingStrategies.Bubble);

Expand All @@ -45,6 +47,19 @@ public ImageViewer()
};
};
}

public void TriggerScalingModeUpdate(bool invalidate)
{
var scalingMode = SettingsHelper.Settings.ImageScaling.IsScalingSetToNearestNeighbor
? BitmapInterpolationMode.LowQuality
: BitmapInterpolationMode.HighQuality;

RenderOptions.SetBitmapInterpolationMode(MainImage,scalingMode);
if (invalidate)
{
MainImage.InvalidateVisual();
}
}

private void TouchMagnifyEvent(object? sender, PointerDeltaEventArgs e)
{
Expand Down Expand Up @@ -256,6 +271,7 @@ public void ZoomTo(Point point, bool isZoomIn)

currentZoom += zoomSpeed;
currentZoom = Math.Max(0.09, currentZoom); // Fix for zooming out too much
TriggerScalingModeUpdate(false);
if (SettingsHelper.Settings.Zoom.AvoidZoomingOut && currentZoom < 1.0)
{
ResetZoom(true);
Expand Down

0 comments on commit c4c4e91

Please sign in to comment.