Skip to content

Commit

Permalink
New Scroller animations
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderDotH committed May 5, 2023
1 parent 5b36a2a commit 07928df
Show file tree
Hide file tree
Showing 8 changed files with 133 additions and 96 deletions.
24 changes: 14 additions & 10 deletions OpenLyricsClient/Backend/Handler/License/LicenseHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,23 @@ private async Task RefreshLicense()
{
while (!this._disposed)
{
string userID = Core.INSTANCE.SettingsHandler.Settings<AccountSection>()!.GetValue<string>("UserID");
string userSecret = Core.INSTANCE.SettingsHandler.Settings<AccountSection>()!.GetValue<string>("UserSecret");

JsonOpenLyricsClientSubscription subscription = new JsonOpenLyricsClientSubscription
try
{
UserID = userID,
UserSecret = userSecret
};
string userID = Core.INSTANCE.SettingsHandler.Settings<AccountSection>()!.GetValue<string>("UserID");
string userSecret = Core.INSTANCE.SettingsHandler.Settings<AccountSection>()!.GetValue<string>("UserSecret");

JsonOpenLyricsClientSubscription subscription = new JsonOpenLyricsClientSubscription
{
UserID = userID,
UserSecret = userSecret
};

JsonOpenLyricsClientSubscriptionModel model = await this._openLyricsClientApi.CheckSubscription(subscription);
this._license = model;
JsonOpenLyricsClientSubscriptionModel model = await this._openLyricsClientApi.CheckSubscription(subscription);
this._license = model;

await Core.INSTANCE.SettingsHandler.TriggerEvent(typeof(AccountSection), "UserID");
await Core.INSTANCE.SettingsHandler.TriggerEvent(typeof(AccountSection), "UserID");
}
catch (Exception e) { }

await Task.Delay((int)TimeSpan.FromMinutes(1).TotalMilliseconds);
}
Expand Down
69 changes: 47 additions & 22 deletions OpenLyricsClient/Frontend/Animation/SmoothAnimator.cs
Original file line number Diff line number Diff line change
@@ -1,35 +1,60 @@
using System;
using OpenLyricsClient.Frontend.Structure.Enum;

namespace OpenLyricsClient.Frontend.Animation
{
public class SmoothAnimator
{
public static double CalculateStep(double start, double end, double current, double speed)
public static double Lerp(double a, double b, int tMilliseconds, double speed, EnumAnimationStyle animationStyle)
{
double divisor = (end - start);

if (divisor == 0)
return end;

divisor = Math.Abs(divisor) < 0.0001 ? 0.1 : divisor;

if (current == 0)
current = 1;

double t = (current - start) / divisor;

double speedC = (1.0 / 100.0) * speed;
double sMul = 1 + speedC;

t = SmoothStep(start, end, t) / sMul;

return (start + (end - start) * t);
double min = Math.Min(a, b);
double max = Math.Max(a, b);

double range = max - min;

double elapsedTime = (tMilliseconds / 1000.0) * speed;
double t = elapsedTime % range;

t = Math.Clamp(t, 0, 1);

double progress = 0;

switch (animationStyle)
{
case EnumAnimationStyle.SIGMOID:
{
progress = Sigmoid(t, range);
break;
}
case EnumAnimationStyle.CIRCULAREASEOUT:
{
progress = CircularEaseOut(t, range);
break;
}
default:
{
progress = Linear(t);
break;
}
}

return min + progress * (max - min);
}

private static double SmoothStep(double start, double end, double t)
private static double Linear(double t)
{
t = Math.Clamp(((t - start) / ((end - start))), 0, 1);
return t * t * (3 - 2 * t);
return Math.Pow(t, 3);
}

private static double Sigmoid(double t, double range)
{
double x = (t * 6.0) / range - 3.0;
return 1.0 / (1.0 + Math.Exp(-x));
}

private static double CircularEaseOut(double t, double range) {
double x = t / range;
return Math.Sqrt(1.0 - Math.Pow(x - 1.0, 2.0));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace OpenLyricsClient.Frontend.Structure.Enum;

public enum EnumAnimationStyle
{
LINEAR, CIRCULAREASEOUT, SIGMOID
}
1 change: 0 additions & 1 deletion OpenLyricsClient/Frontend/View/Custom/LyricsScroller.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
xmlns:custom="clr-namespace:OpenLyricsClient.Frontend.View.Custom"
xmlns:elements="clr-namespace:OpenLyricsClient.Frontend.Models.Elements"
xmlns:romanization="clr-namespace:OpenLyricsClient.Backend.Romanization"
xmlns:converter="clr-namespace:OpenLyricsClient.Shared.Utils.Converter"
xmlns:custom1="clr-namespace:OpenLyricsClient.Frontend.Models.Custom"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
LyricPart="{Binding CurrentLyricPart, Mode=TwoWay}"
Expand Down
6 changes: 3 additions & 3 deletions OpenLyricsClient/Frontend/View/Custom/LyricsScroller.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,13 +187,13 @@ private void RenderTimerOnTick(TimeSpan obj)
float start = this._scrollTo;
float end = this._oldScrollY;

float y = (float)SmoothAnimator.CalculateStep(
/*float y = (float)SmoothAnimator.CalculateStep(
start,
end,
this._currentScrollOffset,
this._scrollSpeed);
this._scrollSpeed);*/

this._currentScrollOffset = y;
this._currentScrollOffset = 1;
}

if (!double.IsNaN(this._currentScrollOffset))
Expand Down
9 changes: 6 additions & 3 deletions OpenLyricsClient/Frontend/View/Custom/NewLyricsScroller.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
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>
<custom:NewLyricsScrollerViewModel/>
</UserControl.DataContext>

<Grid>
<Grid Background="{DynamicResource PrimaryThemeColorBrush}">
<custom:CustomScrollViewer Name="CTRL_Viewer">
<Panel>
<ItemsRepeater Name="HIDDEN_CTRL_Repeater"
Expand All @@ -31,7 +33,8 @@
</ItemsRepeater>

<ItemsRepeater Name="CTRL_Repeater"
Items="{Binding Lyrics}">
Items="{Binding Lyrics}"
Margin="0,0,0,0">
<ItemsRepeater.ItemTemplate>
<DataTemplate>
<elements:LyricsCard Text="{Binding Part}"
Expand All @@ -45,7 +48,7 @@
</ItemsRepeater.ItemTemplate>
<ItemsRepeater.Transitions>
<Transitions>
<ThicknessTransition Property="Margin" Duration="0:0:0.5" Easing="CubicEaseOut" />
<ThicknessTransition Property="Margin" Duration="0:0:1.0" Easing="CubicEaseOut" />
<DoubleTransition Property="Opacity" Duration="0:0:5.0" Easing="CubicEaseOut"></DoubleTransition>
</Transitions>
</ItemsRepeater.Transitions>
Expand Down
Loading

0 comments on commit 07928df

Please sign in to comment.