Skip to content

Commit

Permalink
Image effects window, work in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruben2776 committed Jan 4, 2025
1 parent d38139d commit ca2d9c1
Show file tree
Hide file tree
Showing 36 changed files with 1,556 additions and 671 deletions.
33 changes: 32 additions & 1 deletion src/PicView.Avalonia.MacOS/App.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public class App : Application, IPlatformSpecificService
private AboutWindow? _aboutWindow;
private SingleImageResizeWindow? _singleImageResizeWindow;
private BatchResizeWindow? _batchResizeWindow;
private EffectsWindow? _effectsWindow;
private MainViewModel? _vm;

public override void Initialize()
Expand Down Expand Up @@ -268,7 +269,37 @@ void Set()

public void ShowEffectsWindow()
{
// TODO: Implement ShowEffectsWindow
if (Dispatcher.UIThread.CheckAccess())
{
Set();
}
else
{
Dispatcher.UIThread.InvokeAsync(Set);
}
return;
void Set()
{
if (Current?.ApplicationLifetime is not IClassicDesktopStyleApplicationLifetime desktop)
{
return;
}
if (_effectsWindow is null)
{
_effectsWindow = new EffectsWindow
{
DataContext = _vm,
WindowStartupLocation = WindowStartupLocation.CenterOwner,
};
_effectsWindow.Show(desktop.MainWindow);
_effectsWindow.Closing += (s, e) => _effectsWindow = null;
}
else
{
_effectsWindow.Activate();
}
_= FunctionsHelper.CloseMenus();
}
}

public void ShowSingleImageResizeWindow()
Expand Down
4 changes: 4 additions & 0 deletions src/PicView.Avalonia.MacOS/PicView.Avalonia.MacOS.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@
<DependentUpon>BatchResizeWindow.axaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Compile Update="Views\EffectsWindow.axaml.cs">
<DependentUpon>EffectsWindow.axaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
</ItemGroup>

<ItemGroup>
Expand Down
48 changes: 48 additions & 0 deletions src/PicView.Avalonia.MacOS/Views/EffectsWindow.axaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<Window
CanResize="False"
ExtendClientAreaChromeHints="SystemChrome"
ExtendClientAreaTitleBarHeightHint="-1"
SizeToContent="WidthAndHeight"
Title="Loading..."
d:DesignHeight="450"
d:DesignWidth="800"
mc:Ignorable="d"
x:Class="PicView.Avalonia.MacOS.Views.EffectsWindow"
x:DataType="viewModels:MainViewModel"
xmlns="https://github.com/avaloniaui"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:viewModels="clr-namespace:PicView.Avalonia.ViewModels;assembly=PicView.Avalonia"
xmlns:views="clr-namespace:PicView.Avalonia.Views;assembly=PicView.Avalonia"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Design.DataContext>
<viewModels:MainViewModel />
</Design.DataContext>
<Border
BorderBrush="{DynamicResource MainBorderColor}"
BorderThickness="1"
CornerRadius="8">
<Panel>

<DockPanel
Background="{DynamicResource SecondaryBackgroundColor}"
Height="28"
PointerPressed="MoveWindow"
VerticalAlignment="Top">

<TextBlock
Classes="txt"
Text="{CompiledBinding Effects,
Mode=OneWay}"
TextAlignment="Center" />
</DockPanel>

<views:EffectsView
Background="{DynamicResource WindowBackgroundColor}"
Margin="0,28,0,0"
Padding="10,5,5,10"
PointerPressed="MoveWindow"
x:Name="XEffectsView" />
</Panel>
</Border>
</Window>
39 changes: 39 additions & 0 deletions src/PicView.Avalonia.MacOS/Views/EffectsWindow.axaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using Avalonia.Controls;
using Avalonia.Input;
using Avalonia.Media;
using PicView.Core.Config;
using PicView.Core.Localization;

namespace PicView.Avalonia.MacOS.Views;

public partial class EffectsWindow : Window
{
public EffectsWindow()
{
InitializeComponent();
if (!SettingsHelper.Settings.Theme.Dark || SettingsHelper.Settings.Theme.GlassTheme)
{
XEffectsView.Background = Brushes.Transparent;
}
Loaded += delegate
{
MinWidth = MaxWidth = Width;
Title = $"{TranslationHelper.Translation.Effects} - PicView";
};
KeyDown += (_, e) =>
{
if (e.Key is Key.Escape)
{
Close();
}
};
}

private void MoveWindow(object? sender, PointerPressedEventArgs e)
{
if (VisualRoot is null) { return; }

var hostWindow = (Window)VisualRoot;
hostWindow?.BeginMoveDrag(e);
}
}
41 changes: 36 additions & 5 deletions src/PicView.Avalonia.Win32/App.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public partial class App : Application, IPlatformSpecificService
private AboutWindow? _aboutWindow;
private SingleImageResizeWindow? _singleImageResizeWindow;
private BatchResizeWindow? _batchResizeWindow;
private EffectsWindow? _effectsWindow;
private MainViewModel? _vm;

private TaskbarProgress? _taskbarProgress;
Expand Down Expand Up @@ -305,11 +306,6 @@ void Set()

}
}

public void ShowEffectsWindow()
{
// TODO: Implement ShowEffectsWindow
}

public void ShowSingleImageResizeWindow()
{
Expand Down Expand Up @@ -380,6 +376,41 @@ void Set()
_= FunctionsHelper.CloseMenus();
}
}

public void ShowEffectsWindow()
{
if (Dispatcher.UIThread.CheckAccess())
{
Set();
}
else
{
Dispatcher.UIThread.InvokeAsync(Set);
}
return;
void Set()
{
if (Current?.ApplicationLifetime is not IClassicDesktopStyleApplicationLifetime desktop)
{
return;
}
if (_effectsWindow is null)
{
_effectsWindow = new EffectsWindow
{
DataContext = _vm,
WindowStartupLocation = WindowStartupLocation.CenterOwner,
};
_effectsWindow.Show(desktop.MainWindow);
_effectsWindow.Closing += (s, e) => _effectsWindow = null;
}
else
{
_effectsWindow.Show();
}
_= FunctionsHelper.CloseMenus();
}
}

public void Print(string path)
{
Expand Down
4 changes: 4 additions & 0 deletions src/PicView.Avalonia.Win32/PicView.Avalonia.Win32.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@
<DependentUpon>BatchResizeResizeWindow.axaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Compile Update="Views\EffectsWindow.axaml.cs">
<DependentUpon>EffectsWindow.axaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
</ItemGroup>

<ItemGroup>
Expand Down
90 changes: 90 additions & 0 deletions src/PicView.Avalonia.Win32/Views/EffectsWindow.axaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<Window
BorderThickness="1"
CanResize="False"
CornerRadius="8"
SizeToContent="WidthAndHeight"
Title="Loading..."
x:Class="PicView.Avalonia.Win32.Views.EffectsWindow"
x:DataType="viewModels:MainViewModel"
xmlns="https://github.com/avaloniaui"
xmlns:customControls="clr-namespace:PicView.Avalonia.CustomControls;assembly=PicView.Avalonia"
xmlns:viewModels="clr-namespace:PicView.Avalonia.ViewModels;assembly=PicView.Avalonia"
xmlns:views="clr-namespace:PicView.Avalonia.Views;assembly=PicView.Avalonia"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

<Border
BorderBrush="{DynamicResource WindowBorderColor}"
BorderThickness="1"
PointerPressed="MoveWindow"
x:Name="ParentBorder">
<StackPanel>

<DockPanel Height="28" LastChildFill="True">

<Border
Background="{DynamicResource WindowButtonBackgroundColor}"
BorderBrush="{DynamicResource MainBorderColor}"
BorderThickness="0,0,1,0"
DockPanel.Dock="Left"
x:Name="IconBorder">
<Image
Height="25"
Margin="7,1,7,1"
Source="{StaticResource LogoImage}"
Width="20" />
</Border>

<customControls:IconButton
Background="{DynamicResource WindowButtonBackgroundColor}"
BorderThickness="0"
Classes="hover"
Click="Close"
ClickMode="Release"
Data="{StaticResource CloseGeometry}"
DockPanel.Dock="Right"
Foreground="{DynamicResource MainTextColor}"
IconHeight="10"
IconWidth="10"
Width="30"
x:Name="CloseButton" />

<customControls:IconButton
Background="{DynamicResource WindowButtonBackgroundColor}"
BorderBrush="{DynamicResource MainBorderColor}"
BorderThickness="1,0,1,0"
Classes="hover"
Click="Minimize"
Data="{StaticResource MinimizeGeometry}"
DockPanel.Dock="Right"
Foreground="{DynamicResource MainTextColor}"
IconHeight="12"
IconWidth="12"
Width="30"
x:Name="MinimizeButton" />

<TextBlock
Background="{DynamicResource WindowSecondaryBackgroundColor}"
Classes="txt"
Foreground="{DynamicResource MainTextColor}"
Height="28"
LineHeight="28"
Padding="30,0,0,0"
Text="{CompiledBinding Effects}"
TextAlignment="Center"
x:Name="TitleText" />
</DockPanel>

<Rectangle
Fill="{DynamicResource WindowBorderColor}"
Height="1"
x:Name="BorderRectangle" />

<views:EffectsView
Background="{DynamicResource NoisyTexture}"
Focusable="True"
Margin="0"
Padding="10,2,5,10"
PointerPressed="MoveWindow" />
</StackPanel>
</Border>
</Window>
77 changes: 77 additions & 0 deletions src/PicView.Avalonia.Win32/Views/EffectsWindow.axaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Input;
using Avalonia.Interactivity;
using Avalonia.Media;
using PicView.Core.Config;
using PicView.Core.Localization;

namespace PicView.Avalonia.Win32.Views;

public partial class EffectsWindow : Window
{
public EffectsWindow()
{
InitializeComponent();
if (SettingsHelper.Settings.Theme.GlassTheme)
{
IconBorder.Background = Brushes.Transparent;
IconBorder.BorderThickness = new Thickness(0);
MinimizeButton.Background = Brushes.Transparent;
MinimizeButton.BorderThickness = new Thickness(0);
CloseButton.Background = Brushes.Transparent;
CloseButton.BorderThickness = new Thickness(0);
BorderRectangle.Height = 0;
TitleText.Background = Brushes.Transparent;

if (!Application.Current.TryGetResource("SecondaryTextColor",
Application.Current.RequestedThemeVariant, out var textColor))
{
return;
}

if (textColor is not Color color)
{
return;
}

TitleText.Foreground = new SolidColorBrush(color);
MinimizeButton.Foreground = new SolidColorBrush(color);
CloseButton.Foreground = new SolidColorBrush(color);
}
else if (!SettingsHelper.Settings.Theme.Dark)
{
ParentBorder.Background = new SolidColorBrush(Color.FromArgb(114,132, 132, 132));
}
Loaded += delegate
{
MinWidth = MaxWidth = Width;
Title = $"{TranslationHelper.Translation.Effects} - PicView";
};
KeyDown += (_, e) =>
{
if (e.Key is Key.Escape)
{
Close();
}
};
}

private void MoveWindow(object? sender, PointerPressedEventArgs e)
{
if (VisualRoot is null) { return; }

var hostWindow = (Window)VisualRoot;
hostWindow?.BeginMoveDrag(e);
}

private void Close(object? sender, RoutedEventArgs e)
{
Close();
}

private void Minimize(object? sender, RoutedEventArgs e)
{
WindowState = WindowState.Minimized;
}
}
Loading

0 comments on commit ca2d9c1

Please sign in to comment.