Skip to content

Commit

Permalink
Scroller
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderDotH committed May 6, 2023
1 parent 07928df commit e6e2b76
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 35 deletions.
46 changes: 40 additions & 6 deletions OpenLyricsClient/App.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
xmlns:themes="clr-namespace:Material.Styles.Themes;assembly=Material.Styles"
xmlns:local="using:OpenLyricsClient"
xmlns:converter="clr-namespace:OpenLyricsClient.Backend.Utils.Converter"

xmlns:system="clr-namespace:System;assembly=System.Runtime"

x:Class="OpenLyricsClient.App">
<Application.DataTemplates>
<local:ViewLocator/>
Expand Down Expand Up @@ -39,11 +40,44 @@
<Style>

<Style.Resources>
<SolidColorBrush x:Key="PrimaryThemeColorBrush" Color="#dc143c"></SolidColorBrush>
<SolidColorBrush x:Key="SecondaryThemeColorBrush" Color="#dc143c"></SolidColorBrush>
<SolidColorBrush x:Key="PrimaryThemeFontColorBrush" Color="#FFFFFF"></SolidColorBrush>
<SolidColorBrush x:Key="SecondaryThemeFontColorBrush" Color="#FFFFFF"></SolidColorBrush>
<SolidColorBrush x:Key="LightThemeFontColorBrush" Color="#FFFFFF"></SolidColorBrush>

<SolidColorBrush x:Key="PrimaryThemeColorBrush" Color="#dc143c">
<SolidColorBrush.Transitions>
<Transitions>
<ColorTransition Property="Color" Duration="0:0:0.5" Easing="LinearEasing"/>
</Transitions>
</SolidColorBrush.Transitions>
</SolidColorBrush>

<SolidColorBrush x:Key="SecondaryThemeColorBrush" Color="#dc143c">
<SolidColorBrush.Transitions>
<Transitions>
<ColorTransition Property="Color" Duration="0:0:0.5" Easing="CircularEaseOut"/>
</Transitions>
</SolidColorBrush.Transitions>
</SolidColorBrush>

<SolidColorBrush x:Key="PrimaryThemeFontColorBrush" Color="#FFFFFF">
<SolidColorBrush.Transitions>
<Transitions>
<ColorTransition Property="Color" Duration="0:0:0.5" Easing="CircularEaseOut"/>
</Transitions>
</SolidColorBrush.Transitions>
</SolidColorBrush>
<SolidColorBrush x:Key="SecondaryThemeFontColorBrush" Color="#FFFFFF">
<SolidColorBrush.Transitions>
<Transitions>
<ColorTransition Property="Color" Duration="0:0:0.5" Easing="CircularEaseOut"/>
</Transitions>
</SolidColorBrush.Transitions>
</SolidColorBrush>
<SolidColorBrush x:Key="LightThemeFontColorBrush" Color="#FFFFFF">
<SolidColorBrush.Transitions>
<Transitions>
<ColorTransition Property="Color" Duration="0:0:0.5" Easing="CircularEaseOut"/>
</Transitions>
</SolidColorBrush.Transitions>
</SolidColorBrush>

<SolidColorBrush x:Key="SelectedLineFontColorBrush" Color="#FFFFFF"></SolidColorBrush>
<SolidColorBrush x:Key="UnSelectedLineFontColorBrush" Color="#FFFFFF"></SolidColorBrush>
Expand Down
2 changes: 1 addition & 1 deletion OpenLyricsClient/Backend/Handler/Artwork/ArtworkHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ private void OnArtworkFoundHandler(object sender, ArtworkFoundEventArgs args)
}
color.Color = args.Artwork.ArtworkColor;
secondaryColor!.Color = args.Artwork.DarkArtworkColor;
secondaryColor.Color = args.Artwork.DarkArtworkColor;
byte light = 120;
byte primary = 22;
Expand Down
7 changes: 2 additions & 5 deletions OpenLyricsClient/Frontend/View/Custom/NewLyricsScroller.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
xmlns:custom="clr-namespace:OpenLyricsClient.Frontend.Models.Custom"
xmlns:elements="clr-namespace:OpenLyricsClient.Frontend.Models.Elements"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
Height="700"
Bounds="0,0,0,700"
x:Class="OpenLyricsClient.Frontend.View.Custom.NewLyricsScroller">

<UserControl.DataContext>
Expand All @@ -15,7 +13,7 @@

<Grid Background="{DynamicResource PrimaryThemeColorBrush}">
<custom:CustomScrollViewer Name="CTRL_Viewer">
<Panel>
<Panel Name="CTRL_Container">
<ItemsRepeater Name="HIDDEN_CTRL_Repeater"
Items="{Binding Lyrics}"
IsVisible="False">
Expand Down Expand Up @@ -48,8 +46,7 @@
</ItemsRepeater.ItemTemplate>
<ItemsRepeater.Transitions>
<Transitions>
<ThicknessTransition Property="Margin" Duration="0:0:1.0" Easing="CubicEaseOut" />
<DoubleTransition Property="Opacity" Duration="0:0:5.0" Easing="CubicEaseOut"></DoubleTransition>
<ThicknessTransition Property="Margin" Duration="0:0:3.0" Easing="LinearEasing"/>
</Transitions>
</ItemsRepeater.Transitions>
</ItemsRepeater>
Expand Down
32 changes: 9 additions & 23 deletions OpenLyricsClient/Frontend/View/Custom/NewLyricsScroller.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public partial class NewLyricsScroller : UserControl
private CustomScrollViewer _customScrollViewer;
private ItemsRepeater _repeater;
private ItemsRepeater _hiddenRepeater;
private Panel _container;

// ViewModel
private NewLyricsScrollerViewModel _viewModel;
Expand Down Expand Up @@ -64,8 +65,8 @@ public NewLyricsScroller()

this._hiddenRepeater = this.Get<ItemsRepeater>(nameof(HIDDEN_CTRL_Repeater));
this._repeater = this.Get<ItemsRepeater>(nameof(CTRL_Repeater));

this._customScrollViewer = this.Get<CustomScrollViewer>(nameof(CTRL_Viewer));
this._container = this.Get<Panel>(nameof(CTRL_Container));

this._uiThreadRenderTimer = new UiThreadRenderTimer(144);
this._uiThreadRenderTimer.Tick += UiThreadRenderTimerOnTick;
Expand All @@ -76,7 +77,7 @@ public NewLyricsScroller()
private void UiThreadRenderTimerOnTick(TimeSpan obj)
{
this._repeater.Margin = GetMargin();

if (this._isSynced)
{
double y = SmoothAnimator.Lerp(
Expand All @@ -99,10 +100,7 @@ private void SongHandlerOnSongChanged(object sender, SongChangedEventArgs songch

Dispatcher.UIThread.InvokeAsync(() =>
{
if (!DataValidator.ValidateData(this._viewModel.Lyrics, this._viewModel.Lyric))
return;
//this._repeater.Margin = new Thickness(0,2000,0,1000);
this._repeater.Margin = GetMargin() * 4;
/*this._repeater.Margin =
new Thickness(0,
Expand All @@ -111,17 +109,15 @@ private void SongHandlerOnSongChanged(object sender, SongChangedEventArgs songch
-3000 : 3000, 0, 0);*/
this._isSynced = false;
this._customScrollViewer.Offset = new Vector(0, 0);
this._repeater.Opacity = 0.0d;
this._customScrollViewer.VerticalScrollBarVisibility = ScrollBarVisibility.Hidden;
});
}

private void LyricHandlerOnLyricsFound(object sender)
{
Dispatcher.UIThread.InvokeAsync(() =>
Dispatcher.UIThread.InvokeAsync(async () =>
{
this._isSynced = true;
this._repeater.Opacity = 1.0d;
this._customScrollViewer.VerticalScrollBarVisibility = ScrollBarVisibility.Auto;
});

Expand Down Expand Up @@ -174,12 +170,9 @@ private double GetRenderedOffset(LyricPart lyricPart, LyricPart[] lyricParts)
for (int i = 0; i < index; i++)
position += GetRenderedSize(i).Height;

double halfHeight = this._customScrollViewer.Bounds.Height / 2;
double halfCurrentLineHeight = GetRenderedSize(index).Height / 2;
double halfHeight = this._customScrollViewer.Viewport.Height / 2.5d;

double item = (halfHeight - halfCurrentLineHeight);

position -= item;
position -= halfHeight;
position += margin.Top;

return position;
Expand Down Expand Up @@ -221,20 +214,13 @@ private Size GetRenderedSize(int index)

public Thickness GetMargin()
{
if (!DataValidator.ValidateData(this._viewModel.Lyrics, this._viewModel.Lyric))
return new Thickness();

double m = this._customScrollViewer.DesiredSize.Height / 2;

/*double up = GetRenderedSize(0).Height / 2;
double down = GetRenderedSize(this._viewModel.Lyrics.Length - 1).Height / 2;*/

double m = this._customScrollViewer.Viewport.Height / 2.5d;
return new Thickness(0, m, 0, m);
}

public float CalcSpeed()
{
if (!DataValidator.ValidateData(this._viewModel.Lyrics))
if (!(DataValidator.ValidateData(this._viewModel) && DataValidator.ValidateData(this._viewModel.Lyrics)))
return 15;

LyricPart lastPart = null;
Expand Down

0 comments on commit e6e2b76

Please sign in to comment.