From 1dd0c110e0b94bdc315c9c28b2164eaadb2aedec Mon Sep 17 00:00:00 2001 From: mntone Date: Sun, 9 Aug 2020 02:47:36 +0900 Subject: [PATCH] Apply the position of the wallpaper to preview. --- source/SylphyHorn/Application.xaml | 1 + .../SylphyHorn/Services/WallpaperService.cs | 6 ++- source/SylphyHorn/SylphyHorn.csproj | 1 + .../UI/Bindings/SettingsWindowViewModel.cs | 27 ++++++++++++-- .../UI/Controls/WallpaperPositionConverter.cs | 37 +++++++++++++++++++ source/SylphyHorn/UI/SettingsWindow.xaml | 6 +-- 6 files changed, 69 insertions(+), 9 deletions(-) create mode 100644 source/SylphyHorn/UI/Controls/WallpaperPositionConverter.cs diff --git a/source/SylphyHorn/Application.xaml b/source/SylphyHorn/Application.xaml index 8467e30..85d7ca8 100644 --- a/source/SylphyHorn/Application.xaml +++ b/source/SylphyHorn/Application.xaml @@ -23,6 +23,7 @@ + diff --git a/source/SylphyHorn/Services/WallpaperService.cs b/source/SylphyHorn/Services/WallpaperService.cs index 0f0b17c..21bffc6 100644 --- a/source/SylphyHorn/Services/WallpaperService.cs +++ b/source/SylphyHorn/Services/WallpaperService.cs @@ -88,7 +88,7 @@ private void Set(WallpaperFile[] files) if (first != null) dw.SetPosition((DesktopWallpaperPosition)first.Item2.Position); } - public static Tuple GetCurrentColorAndWallpaper() + public static (Color BackgroundColor, string Path, WallpaperPosition Position) GetCurrentColorAndWallpaperAndPosition() { var dw = DesktopWallpaperFactory.Create(); var colorref = dw.GetBackgroundColor(); @@ -100,7 +100,9 @@ public static Tuple GetCurrentColorAndWallpaper() path = dw.GetWallpaper(monitorId); } - return Tuple.Create(Color.FromRgb(colorref.R, colorref.G, colorref.B), path); + var position = (WallpaperPosition)dw.GetPosition(); + + return (Color.FromRgb(colorref.R, colorref.G, colorref.B), path, position); } } diff --git a/source/SylphyHorn/SylphyHorn.csproj b/source/SylphyHorn/SylphyHorn.csproj index 095f0f8..bd479d0 100644 --- a/source/SylphyHorn/SylphyHorn.csproj +++ b/source/SylphyHorn/SylphyHorn.csproj @@ -257,6 +257,7 @@ + diff --git a/source/SylphyHorn/UI/Bindings/SettingsWindowViewModel.cs b/source/SylphyHorn/UI/Bindings/SettingsWindowViewModel.cs index fdc00c2..79fc80a 100644 --- a/source/SylphyHorn/UI/Bindings/SettingsWindowViewModel.cs +++ b/source/SylphyHorn/UI/Bindings/SettingsWindowViewModel.cs @@ -181,6 +181,26 @@ public string PreviewBackgroundPath #endregion + #region PreviewBackgroundPosition notification property + + private WallpaperPosition _PreviewBackgroundPosition = WallpaperPosition.Fill; + + public WallpaperPosition PreviewBackgroundPosition + { + get => this._PreviewBackgroundPosition; + set + { + if (this._PreviewBackgroundPosition != value) + { + this._PreviewBackgroundPosition = value; + + this.RaisePropertyChanged(); + } + } + } + + #endregion + public Brush NotificationBackground => new SolidColorBrush(WindowsTheme.ColorPrevalence.Current ? ImmersiveColor.GetColorByTypeName(ImmersiveColorNames.SystemAccentDark1) : ImmersiveColor.GetColorByTypeName(ImmersiveColorNames.DarkChromeMedium)) @@ -243,9 +263,10 @@ public SettingsWindowViewModel(HookService hookService) .Subscribe(path => this.Backgrounds = WallpaperService.Instance.GetWallpaperFiles(path)) .AddTo(this); - var colAndWall = WallpaperService.GetCurrentColorAndWallpaper(); - this.PreviewBackgroundBrush = new SolidColorBrush(colAndWall.Item1); - this.PreviewBackgroundPath = colAndWall.Item2; + var colAndWall = WallpaperService.GetCurrentColorAndWallpaperAndPosition(); + this.PreviewBackgroundBrush = new SolidColorBrush(colAndWall.BackgroundColor); + this.PreviewBackgroundPath = colAndWall.Path; + this.PreviewBackgroundPosition = colAndWall.Position; this.Logs = ViewModelHelper.CreateReadOnlyDispatcherCollection( LoggingService.Instance.Logs, diff --git a/source/SylphyHorn/UI/Controls/WallpaperPositionConverter.cs b/source/SylphyHorn/UI/Controls/WallpaperPositionConverter.cs new file mode 100644 index 0000000..fdb1753 --- /dev/null +++ b/source/SylphyHorn/UI/Controls/WallpaperPositionConverter.cs @@ -0,0 +1,37 @@ +using SylphyHorn.Services; +using System; +using System.Globalization; +using System.Windows.Data; +using System.Windows.Media; + +namespace SylphyHorn.UI.Controls +{ + public class WallpaperPositionConverter : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + var position = (WallpaperPosition)value; + switch (position) + { + case WallpaperPosition.Center: + return Stretch.None; + + case WallpaperPosition.Stretch: + return Stretch.Fill; + + case WallpaperPosition.Fill: + case WallpaperPosition.Span: + return Stretch.UniformToFill; + + case WallpaperPosition.Fit: + default: + return Stretch.Uniform; + } + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } + } +} diff --git a/source/SylphyHorn/UI/SettingsWindow.xaml b/source/SylphyHorn/UI/SettingsWindow.xaml index 28d130e..b946c2d 100644 --- a/source/SylphyHorn/UI/SettingsWindow.xaml +++ b/source/SylphyHorn/UI/SettingsWindow.xaml @@ -495,8 +495,7 @@ Width="480" Height="270" /> @@ -513,8 +512,7 @@