diff --git a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/BetterLyrics.WinUI3.csproj b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/BetterLyrics.WinUI3.csproj index 5c514fc..5ddf8eb 100644 --- a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/BetterLyrics.WinUI3.csproj +++ b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/BetterLyrics.WinUI3.csproj @@ -334,6 +334,11 @@ + + + MSBuild:Compile + + MSBuild:Compile diff --git a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Controls/ShadowImage.xaml b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Controls/ShadowImage.xaml new file mode 100644 index 0000000..2e06ac1 --- /dev/null +++ b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Controls/ShadowImage.xaml @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + + + + + diff --git a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Controls/ShadowImage.xaml.cs b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Controls/ShadowImage.xaml.cs new file mode 100644 index 0000000..8d6b041 --- /dev/null +++ b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Controls/ShadowImage.xaml.cs @@ -0,0 +1,103 @@ +using Microsoft.UI.Xaml; +using Microsoft.UI.Xaml.Controls; +using Microsoft.UI.Xaml.Controls.Primitives; +using Microsoft.UI.Xaml.Data; +using Microsoft.UI.Xaml.Input; +using Microsoft.UI.Xaml.Media; +using Microsoft.UI.Xaml.Navigation; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Runtime.InteropServices.WindowsRuntime; +using Windows.Foundation; +using Windows.Foundation.Collections; + +// To learn more about WinUI, the WinUI project structure, +// and more about our project templates, see: http://aka.ms/winui-project-info. + +namespace BetterLyrics.WinUI3.Controls +{ + public sealed partial class ShadowImage : UserControl + { + public int CornerRadiusAmount + { + get { return (int)GetValue(CornerRadiusAmountProperty); } + set { SetValue(CornerRadiusAmountProperty, value); } + } + + public static readonly DependencyProperty CornerRadiusAmountProperty = + DependencyProperty.Register(nameof(CornerRadiusAmount), typeof(int), typeof(ShadowImage), new PropertyMetadata(0, OnDependencyPropertyChanged)); + + public int ShadowAmount + { + get { return (int)GetValue(ShadowAmountProperty); } + set { SetValue(ShadowAmountProperty, value); } + } + + public static readonly DependencyProperty ShadowAmountProperty = + DependencyProperty.Register(nameof(ShadowAmount), typeof(int), typeof(ShadowImage), new PropertyMetadata(0, OnDependencyPropertyChanged)); + + public ImageSource? ImageSource + { + get { return (ImageSource?)GetValue(ImageSourceProperty); } + set { SetValue(ImageSourceProperty, value); } + } + + public static readonly DependencyProperty ImageSourceProperty = + DependencyProperty.Register(nameof(ImageSource), typeof(ImageSource), typeof(ShadowImage), new PropertyMetadata(null)); + + public ShadowImage() + { + InitializeComponent(); + } + + private static void OnDependencyPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) + { + if (d is ShadowImage shadowImage) + { + if (e.Property == CornerRadiusAmountProperty) + { + shadowImage.UpdateShadowCastGridCornerRadius(); + shadowImage.UpdateShadowRectCornerRadius(); + } + else if (e.Property == ShadowAmountProperty) + { + shadowImage.UpdateShadowRectShadow(); + } + } + } + + private void UpdateShadowRectShadow() + { + ShadowRect.Translation = new(0, 0, ShadowAmount); + } + + private void UpdateShadowCastGridCornerRadius() + { + var minSize = Math.Min(ShadowCastGrid.ActualHeight, ShadowCastGrid.ActualWidth); + ShadowCastGrid.CornerRadius = new(CornerRadiusAmount / 100.0 * minSize); + } + + private void UpdateShadowRectCornerRadius() + { + var minSize = Math.Min(ShadowRect.ActualHeight, ShadowRect.ActualWidth); + ShadowRect.CornerRadius = new(CornerRadiusAmount / 100.0 * minSize); + } + + private void ShadowCastGrid_SizeChanged(object sender, SizeChangedEventArgs e) + { + UpdateShadowCastGridCornerRadius(); + } + + private void ShadowRect_SizeChanged(object sender, SizeChangedEventArgs e) + { + UpdateShadowRectCornerRadius(); + } + + private void ShadowRect_Loaded(object sender, RoutedEventArgs e) + { + Shadow.Receivers.Add(ShadowCastGrid); + } + } +} diff --git a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Views/NowPlayingPage.xaml b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Views/NowPlayingPage.xaml index 1904800..7cec8e1 100644 --- a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Views/NowPlayingPage.xaml +++ b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Views/NowPlayingPage.xaml @@ -66,38 +66,22 @@ - + - - - - - - - - - - - - - - - - - + + diff --git a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Views/NowPlayingPage.xaml.cs b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Views/NowPlayingPage.xaml.cs index d5a073e..045cb44 100644 --- a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Views/NowPlayingPage.xaml.cs +++ b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Views/NowPlayingPage.xaml.cs @@ -42,15 +42,6 @@ namespace BetterLyrics.WinUI3.Views private readonly DispatcherQueueTimer _layoutChangedTimer = App.Current.Resources.DispatcherQueue.CreateTimer(); private readonly DispatcherQueueTimer _scrollChangedTimer = App.Current.Resources.DispatcherQueue.CreateTimer(); - public CornerRadius AlbumArtCornerRadius - { - get { return (CornerRadius)GetValue(AlbumArtCornerRadiusProperty); } - set { SetValue(AlbumArtCornerRadiusProperty, value); } - } - - public static readonly DependencyProperty AlbumArtCornerRadiusProperty = - DependencyProperty.Register(nameof(AlbumArtCornerRadius), typeof(double), typeof(LyricsCanvas), new PropertyMetadata(new CornerRadius(0))); - public NowPlayingPageViewModel ViewModel => (NowPlayingPageViewModel)DataContext; public NowPlayingPage() @@ -128,19 +119,6 @@ namespace BetterLyrics.WinUI3.Views } // ==== AlbumArt - - private void UpdateAlbumArtCornerRadius() - { - var factor = _liveStatesService.LiveStates.LyricsWindowStatus.AlbumArtLayoutSettings.CoverImageRadius / 100.0; - AlbumArtCornerRadius = new((AlbumArtImage.ActualHeight / 2) * factor); - } - - private void UpdateAlbumArtShadow() - { - var amount = _liveStatesService.LiveStates.LyricsWindowStatus.AlbumArtLayoutSettings.CoverImageShadowAmount; - ShadowRect.Translation = new(0, 0, amount); - } - private void UpdateAlbumArtOpacity() { switch (_liveStatesService.LiveStates.LyricsWindowStatus.LyricsDisplayType) @@ -420,15 +398,11 @@ namespace BetterLyrics.WinUI3.Views UpdateLyricsOpacity(); UpdateAlbumArtOpacity(); - UpdateAlbumArtShadow(); - UpdateTrackSummaryGridSpan(); UpdateAlbumArtGridSpan(); UpdateSongInfoStackPanelSpan(); UpdateLyricsPlaceholderSpan(); - UpdateAlbumArtCornerRadius(); - UpdateLyricsLayout(); }, Constants.Time.DebounceTimeout); } @@ -595,11 +569,6 @@ namespace BetterLyrics.WinUI3.Views SystemVolumeHook.MasterVolume = ViewModel.Volume; } - private void ShadowRect_Loaded(object sender, RoutedEventArgs e) - { - Shadow.Receivers.Add(ShadowCastGrid); - } - private void TitleAutoScrollHoverEffectView_PointerCanceled(object sender, Microsoft.UI.Xaml.Input.PointerRoutedEventArgs e) { TitleAutoScrollHoverEffectView.IsPlaying = false; @@ -660,11 +629,6 @@ namespace BetterLyrics.WinUI3.Views OnLayoutChanged(); } - private void ShadowCastGrid_SizeChanged(object sender, SizeChangedEventArgs e) - { - UpdateAlbumArtCornerRadius(); - } - private void LyricsScrollViewer_PointerWheelChanged(object sender, Microsoft.UI.Xaml.Input.PointerRoutedEventArgs e) { LyricsCanvas.IsMouseScrolling = true; @@ -730,14 +694,6 @@ namespace BetterLyrics.WinUI3.Views { RenderSongInfo(); } - else if (message.PropertyName == nameof(AlbumArtLayoutSettings.CoverImageRadius)) - { - UpdateAlbumArtCornerRadius(); - } - else if (message.PropertyName == nameof(AlbumArtLayoutSettings.CoverImageShadowAmount)) - { - UpdateAlbumArtShadow(); - } else if (message.PropertyName == nameof(AlbumArtLayoutSettings.CoverImageHeight)) { OnLayoutChanged(); @@ -796,18 +752,16 @@ namespace BetterLyrics.WinUI3.Views { if (message.PropertyName == nameof(IMediaSessionsService.AlbumArtBitmapImage)) { - LastAlbumArtImage.Source = AlbumArtImage.Source; + LastAlbumArtImage.ImageSource = AlbumArtImage.ImageSource; LastAlbumArtImage.Opacity = 1; await Task.Delay(Constants.Time.AnimationDuration); AlbumArtImage.Opacity = 0; await Task.Delay(Constants.Time.AnimationDuration); - AlbumArtImage.Source = message.NewValue; + AlbumArtImage.ImageSource = message.NewValue; LastAlbumArtImage.Opacity = 0; AlbumArtImage.Opacity = 1; - - UpdateAlbumArtCornerRadius(); } } } @@ -856,5 +810,6 @@ namespace BetterLyrics.WinUI3.Views } } } + } }