Skip to content

Commit

Permalink
Image effects and style updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruben2776 committed Jan 8, 2025
1 parent bf64b2a commit 545449c
Show file tree
Hide file tree
Showing 5 changed files with 212 additions and 48 deletions.
25 changes: 25 additions & 0 deletions src/PicView.Avalonia/ImageEffects/ImageEffectsHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using Avalonia.Media.Imaging;
using ImageMagick;
using PicView.Avalonia.ImageHandling;

namespace PicView.Avalonia.ImageEffects;

public static class ImageEffectsHelper
{
public static async Task<WriteableBitmap> GetRadialBlur(string file)
{
using var magick = new MagickImage();
await magick.ReadAsync(file).ConfigureAwait(false);
// Apply radial blur
magick.AdaptiveBlur(10);

// Create a new morphology settings
var morphology = new MorphologySettings
{
Kernel = Kernel.DoG,
Method = MorphologyMethod.Convolve
};
magick.Morphology(morphology);
return magick.ToWriteableBitmap();
}
}
101 changes: 101 additions & 0 deletions src/PicView.Avalonia/PicViewTheme/Controls/ButtonSpinner.axaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<ResourceDictionary
x:ClassModifier="internal"
xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

<ControlTheme
BasedOn="{StaticResource {x:Type RepeatButton}}"
TargetType="RepeatButton"
x:Key="SimpleButtonSpinnerRepeatButton">
<Setter Property="Background" Value="Transparent" />
<Setter Property="BorderBrush" Value="Transparent" />
<Style Selector="^ /template/ RepeatButton:pointerover">
<Setter Property="Background" Value="{DynamicResource MainBackgroundColor}" />
<Setter Property="BorderBrush" Value="{DynamicResource MainBorderColor}" />
</Style>
</ControlTheme>

<ControlTheme TargetType="ButtonSpinner" x:Key="{x:Type ButtonSpinner}">
<Setter Property="Background" Value="Transparent" />
<Setter Property="BorderBrush" Value="{DynamicResource MainBorderColor}" />
<Setter Property="BorderThickness" Value="1" />
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
<Setter Property="VerticalContentAlignment" Value="Center" />
<Setter Property="Focusable" Value="True" />
<Setter Property="Template">
<ControlTemplate>
<DataValidationErrors>
<Border
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
CornerRadius="{TemplateBinding CornerRadius}"
HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
Margin="{TemplateBinding Padding}"
Name="border"
VerticalAlignment="{TemplateBinding VerticalAlignment}">
<DockPanel>
<UniformGrid
DockPanel.Dock="Right"
IsVisible="{TemplateBinding ShowButtonSpinner}"
Name="PART_SpinnerPanel"
Rows="2"
TabIndex="2">
<RepeatButton
IsTabStop="{TemplateBinding IsTabStop}"
Name="PART_IncreaseButton"
Theme="{StaticResource SimpleButtonSpinnerRepeatButton}">
<Path
Data="M0,5 L4.5,.5 9,5 6,5 4.5,3.5 3,5 z"
Fill="{DynamicResource MainTextColor}"
Height="4"
HorizontalAlignment="Center"
Stretch="Uniform"
VerticalAlignment="Center"
Width="8" />
</RepeatButton>
<RepeatButton
IsTabStop="{TemplateBinding IsTabStop}"
Name="PART_DecreaseButton"
Theme="{StaticResource SimpleButtonSpinnerRepeatButton}">
<Path
Data="M0,0 L3,0 4.5,1.5 6,0 9,0 4.5,4.5 z"
Fill="{DynamicResource MainTextColor}"
Height="4"
HorizontalAlignment="Center"
Stretch="Uniform"
VerticalAlignment="Center"
Width="8" />
</RepeatButton>
</UniformGrid>
<ContentPresenter
Content="{TemplateBinding Content}"
ContentTemplate="{TemplateBinding ContentTemplate}"
Grid.Column="1"
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
Name="PART_ContentPresenter"
Padding="{TemplateBinding Padding}"
TabIndex="1"
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}" />
</DockPanel>
</Border>
</DataValidationErrors>
</ControlTemplate>
</Setter>
<Style Selector="^:left">
<Style Selector="^ /template/ UniformGrid#PART_SpinnerPanel">
<Setter Property="DockPanel.Dock" Value="Left" />
</Style>
</Style>
<Style Selector="^:pointerover /template/ Border#border">
<Setter Property="BorderBrush" Value="{DynamicResource MainBorderColor}" />
</Style>
<Style Selector="^:focus /template/ Border#border">
<Setter Property="BorderBrush" Value="{DynamicResource SecondaryBorderColor}" />
</Style>
<Style Selector="^:error /template/ Border#border">
<Setter Property="BorderBrush" Value="{DynamicResource ErrorBrush}" />
</Style>
</ControlTheme>

</ResourceDictionary>
50 changes: 50 additions & 0 deletions src/PicView.Avalonia/PicViewTheme/Controls/NumericUpDown.axaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<ResourceDictionary
x:ClassModifier="internal"
xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ControlTheme TargetType="NumericUpDown" x:Key="{x:Type NumericUpDown}">
<Setter Property="Background" Value="{DynamicResource MainBackgroundColor}" />
<Setter Property="BorderBrush" Value="{DynamicResource MainBorderColor}" />
<Setter Property="BorderThickness" Value="1" />
<Setter Property="Padding" Value="4" />
<Setter Property="Template">
<ControlTemplate>
<DataValidationErrors>
<ButtonSpinner
AllowSpin="{TemplateBinding AllowSpin}"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
ButtonSpinnerLocation="{TemplateBinding ButtonSpinnerLocation}"
CornerRadius="{TemplateBinding CornerRadius}"
HorizontalContentAlignment="Stretch"
IsTabStop="False"
MinWidth="0"
Name="PART_Spinner"
Padding="0"
ShowButtonSpinner="{TemplateBinding ShowButtonSpinner}"
VerticalContentAlignment="Stretch">
<TextBox
AcceptsReturn="False"
Background="{TemplateBinding Background}"
BorderThickness="0"
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
InnerLeftContent="{Binding InnerLeftContent, RelativeSource={RelativeSource TemplatedParent}}"
InnerRightContent="{Binding InnerRightContent, RelativeSource={RelativeSource TemplatedParent}}"
IsReadOnly="{TemplateBinding IsReadOnly}"
Margin="4"
MinWidth="20"
Name="PART_TextBox"
Padding="{TemplateBinding Padding}"
ScrollViewer.VerticalScrollBarVisibility="Disabled"
Text="{TemplateBinding Text}"
TextAlignment="{TemplateBinding TextAlignment}"
TextWrapping="NoWrap"
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
Watermark="{TemplateBinding Watermark}" />
</ButtonSpinner>
</DataValidationErrors>
</ControlTemplate>
</Setter>
</ControlTheme>
</ResourceDictionary>
2 changes: 2 additions & 0 deletions src/PicView.Avalonia/PicViewTheme/Index.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<ResourceInclude Source="Controls/AutoScrollViewer.axaml" />
<ResourceInclude Source="Controls/Border.axaml" />
<ResourceInclude Source="Controls/Button.axaml" />
<ResourceInclude Source="Controls/ButtonSpinner.axaml" />
<ResourceInclude Source="Controls/CheckBox.axaml" />
<ResourceInclude Source="Controls/ComboBox.axaml" />
<ResourceInclude Source="Controls/ComboBoxItem.axaml" />
Expand All @@ -20,6 +21,7 @@
<ResourceInclude Source="Controls/ListBoxItem.axaml" />
<ResourceInclude Source="Controls/Menu.axaml" />
<ResourceInclude Source="Controls/MenuFlyoutPresenter.axaml" />
<ResourceInclude Source="Controls/NumericUpDown.axaml" />
<ResourceInclude Source="Controls/PathIcon.axaml" />
<ResourceInclude Source="Controls/ProgressBar.axaml" />
<ResourceInclude Source="Controls/RadioButton.axaml" />
Expand Down
82 changes: 34 additions & 48 deletions src/PicView.Avalonia/Views/EffectsView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
Fill="{DynamicResource MainBorderColor}"
Height="15"
HorizontalAlignment="Center"
Margin="0,0,120,-5"
Margin="0,0,122,-5"
Stroke="{DynamicResource MainBorderColor}"
Width="2" />
</Panel>
Expand All @@ -54,30 +54,31 @@
x:Name="BrightnessSlider">
<customControls:CustomSlider.Background>
<LinearGradientBrush EndPoint="100%,50%" StartPoint="0%,50%">
<GradientStop Color="Black" Offset="0" />
<GradientStop Color="#111111" Offset="0" />
<GradientStop Color="White" Offset="1" />
</LinearGradientBrush>
</customControls:CustomSlider.Background>
</customControls:CustomSlider>
<NumericUpDown
Background="{DynamicResource MainButtonBackgroundColor}"
BorderBrush="{DynamicResource MainBorderColor}"
Foreground="{DynamicResource MainTextColor}"
Maximum="{Binding Path=Maximum, ElementName=BrightnessSlider}"
Minimum="{Binding Path=Minimum, ElementName=BrightnessSlider}"
Value="{Binding Path=Value, ElementName=BrightnessSlider}" />
<Button
Value="{Binding Path=Value, ElementName=BrightnessSlider}"
Width="56" />
<customControls:IconButton
Background="{DynamicResource MainButtonBackgroundColor}"
BorderBrush="{DynamicResource MainBorderColor}"
BorderThickness="1"
Classes="hover"
Foreground="{DynamicResource MainTextColor}"
Icon="{StaticResource UndoImage}"
IconHeight="12"
IconWidth="12"
Margin="5,0,0,0"
Width="30"
x:Name="ResetBrightnessBtn">
<Image
Height="14"
Source="{StaticResource UndoImage}"
Width="14" />
</Button>
x:Name="ResetBrightnessBtn" />
</StackPanel>

<!-- Contrast -->
Expand All @@ -92,7 +93,7 @@
Fill="{DynamicResource MainBorderColor}"
Height="15"
HorizontalAlignment="Center"
Margin="0,0,120,-5"
Margin="0,0,122,-5"
Stroke="{DynamicResource MainBorderColor}"
Width="2" />
</Panel>
Expand All @@ -102,7 +103,6 @@
<StackPanel Orientation="Horizontal">

<customControls:CustomSlider
Background="{DynamicResource MainBackgroundColor}"
Height="30"
IsSnapToTickEnabled="True"
LargeChange="5"
Expand All @@ -114,26 +114,39 @@
TickFrequency="1"
Value="0"
Width="376"
x:Name="ContrastSlider" />
x:Name="ContrastSlider">
<customControls:CustomSlider.Background>
<LinearGradientBrush EndPoint="100%,50%" StartPoint="0%,50%">
<GradientStop Color="#0DFF0000" Offset="0" />
<GradientStop Color="#40FF7F00" Offset="0.17" />
<GradientStop Color="#60FFFF00" Offset="0.33" />
<GradientStop Color="#8000FF00" Offset="0.5" />
<GradientStop Color="#A00000FF" Offset="0.67" />
<GradientStop Color="#C04B0082" Offset="0.83" />
<GradientStop Color="#FF8F00FF" Offset="1" />
</LinearGradientBrush>
</customControls:CustomSlider.Background>
</customControls:CustomSlider>
<NumericUpDown
Background="{DynamicResource MainButtonBackgroundColor}"
BorderBrush="{DynamicResource MainBorderColor}"
Foreground="{DynamicResource MainTextColor}"
Maximum="{Binding Path=Maximum, ElementName=ContrastSlider}"
Minimum="{Binding Path=Minimum, ElementName=ContrastSlider}"
Value="{Binding Path=Value, ElementName=ContrastSlider}" />
<Button
Value="{Binding Path=Value, ElementName=ContrastSlider}"
Width="56" />
<customControls:IconButton
Background="{DynamicResource MainButtonBackgroundColor}"
BorderBrush="{DynamicResource MainBorderColor}"
BorderThickness="1"
Classes="hover"
Foreground="{DynamicResource MainTextColor}"
Icon="{StaticResource UndoImage}"
IconHeight="12"
IconWidth="12"
Margin="5,0,0,0"
Width="30"
x:Name="ResetContrastBtn">
<Image
Height="14"
Source="{StaticResource UndoImage}"
Width="14" />
</Button>
x:Name="ResetContrastBtn" />
</StackPanel>


Expand Down Expand Up @@ -178,33 +191,6 @@
Value="0"
x:Name="BlurSlider" />


<!-- GaussianBlur -->
<Panel Margin="0,10">
<TextBlock
Classes="txt"
HorizontalAlignment="Left"
Text="{CompiledBinding Blur}"
VerticalAlignment="Center" />
<TextBlock
Classes="txt"
HorizontalAlignment="Right"
Text="{Binding Path=Value, ElementName=GaussianBlurSlider}"
VerticalAlignment="Center" />
</Panel>

<customControls:CustomSlider
Height="30"
IsSnapToTickEnabled="True"
LargeChange="5"
Margin="0,1,0,1"
Maximum="100"
Minimum="-85"
SmallChange="1"
TickFrequency="1"
Value="0"
x:Name="GaussianBlurSlider" />

<!-- MotionBlur -->
<Panel Margin="0,10">
<TextBlock
Expand Down

0 comments on commit 545449c

Please sign in to comment.