Skip to content

Commit

Permalink
Apply the position of the wallpaper to preview.
Browse files Browse the repository at this point in the history
  • Loading branch information
mntone committed Aug 11, 2020
1 parent 3bb2a0b commit 1dd0c11
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 9 deletions.
1 change: 1 addition & 0 deletions source/SylphyHorn/Application.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<converters:EnumToBooleanConverter x:Key="EnumToBooleanConverter" />
<controls:UnlockImageConverter x:Key="UnlockImageConverter" />
<controls:MultiBooleanAndConverter x:Key="MultiBooleanAndConverter" />
<controls:WallpaperPositionConverter x:Key="WallpaperPositionConverter" />
</ResourceDictionary>
</Application.Resources>
</Application>
6 changes: 4 additions & 2 deletions source/SylphyHorn/Services/WallpaperService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ private void Set(WallpaperFile[] files)
if (first != null) dw.SetPosition((DesktopWallpaperPosition)first.Item2.Position);
}

public static Tuple<Color, string> GetCurrentColorAndWallpaper()
public static (Color BackgroundColor, string Path, WallpaperPosition Position) GetCurrentColorAndWallpaperAndPosition()
{
var dw = DesktopWallpaperFactory.Create();
var colorref = dw.GetBackgroundColor();
Expand All @@ -100,7 +100,9 @@ public static Tuple<Color, string> 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);
}
}

Expand Down
1 change: 1 addition & 0 deletions source/SylphyHorn/SylphyHorn.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@
<Compile Include="UI\Controls\Keytop.cs" />
<Compile Include="UI\Controls\MultiBooleanAndConverter.cs" />
<Compile Include="UI\Controls\UnlockImageConverter.cs" />
<Compile Include="UI\Controls\WallpaperPositionConverter.cs" />
<Compile Include="UI\DynamicInfoTrayIcon.cs" />
<Compile Include="UI\NotificationWindow.cs" />
<Compile Include="UI\PinWindow.xaml.cs">
Expand Down
27 changes: 24 additions & 3 deletions source/SylphyHorn/UI/Bindings/SettingsWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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,
Expand Down
37 changes: 37 additions & 0 deletions source/SylphyHorn/UI/Controls/WallpaperPositionConverter.cs
Original file line number Diff line number Diff line change
@@ -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();
}
}
}
6 changes: 2 additions & 4 deletions source/SylphyHorn/UI/SettingsWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -495,8 +495,7 @@
Width="480"
Height="270" />
<Image Source="{Binding PreviewBackgroundPath, Converter={StaticResource UnlockImageConverter}, IsAsync=True}"
Stretch="Uniform"
VerticalAlignment="Top"
Stretch="{Binding PreviewBackgroundPosition, Converter={StaticResource WallpaperPositionConverter}, Mode=OneWay}"
Width="480"
Height="270" />

Expand All @@ -513,8 +512,7 @@
</ContentControl.CacheMode>
<Image x:Name="PreviewBlurImage"
Source="{Binding PreviewBackgroundPath, Converter={StaticResource UnlockImageConverter}, IsAsync=True}"
Stretch="Uniform"
VerticalAlignment="Top"
Stretch="{Binding PreviewBackgroundPosition, Converter={StaticResource WallpaperPositionConverter}, Mode=OneWay}"
Width="480"
Height="270"
Visibility="{Binding HasWallpaper, Converter={StaticResource BooleanToVisibilityConverter}}"
Expand Down

0 comments on commit 1dd0c11

Please sign in to comment.