mirror of
https://github.com/jayfunc/BetterLyrics.git
synced 2026-01-12 10:54:55 +08:00
refactor: animations easing
This commit is contained in:
@@ -63,6 +63,7 @@ namespace BetterLyrics.WinUI3.Controls
|
|||||||
);
|
);
|
||||||
private readonly ValueTransition<double> _immersiveBgOpacityTransition = new(
|
private readonly ValueTransition<double> _immersiveBgOpacityTransition = new(
|
||||||
initialValue: 1f,
|
initialValue: 1f,
|
||||||
|
EasingHelper.GetInterpolatorByEasingType<double>(EasingType.Sine),
|
||||||
defaultTotalDuration: 0.3f
|
defaultTotalDuration: 0.3f
|
||||||
);
|
);
|
||||||
private readonly ValueTransition<Color> _accentColor1Transition = new(
|
private readonly ValueTransition<Color> _accentColor1Transition = new(
|
||||||
@@ -87,13 +88,13 @@ namespace BetterLyrics.WinUI3.Controls
|
|||||||
);
|
);
|
||||||
private readonly ValueTransition<double> _canvasYScrollTransition = new(
|
private readonly ValueTransition<double> _canvasYScrollTransition = new(
|
||||||
initialValue: 0f,
|
initialValue: 0f,
|
||||||
defaultTotalDuration: 0.3f,
|
EasingHelper.GetInterpolatorByEasingType<double>(EasingType.Sine),
|
||||||
defaultEasingType: EasingType.EaseInOutSine
|
defaultTotalDuration: 0.3f
|
||||||
);
|
);
|
||||||
private readonly ValueTransition<double> _mouseYScrollTransition = new(
|
private readonly ValueTransition<double> _mouseYScrollTransition = new(
|
||||||
initialValue: 0f,
|
initialValue: 0f,
|
||||||
defaultTotalDuration: 0.3f,
|
EasingHelper.GetInterpolatorByEasingType<double>(EasingType.Sine),
|
||||||
defaultEasingType: EasingType.EaseInOutSine
|
defaultTotalDuration: 0.3f
|
||||||
);
|
);
|
||||||
|
|
||||||
private TimeSpan _songPositionWithOffset;
|
private TimeSpan _songPositionWithOffset;
|
||||||
@@ -492,7 +493,7 @@ namespace BetterLyrics.WinUI3.Controls
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
_canvasYScrollTransition.SetDurationMs(lyricsEffect.LyricsScrollDuration);
|
_canvasYScrollTransition.SetDurationMs(lyricsEffect.LyricsScrollDuration);
|
||||||
_canvasYScrollTransition.SetEasingType(lyricsEffect.LyricsScrollEasingType);
|
_canvasYScrollTransition.SetInterpolator(EasingHelper.GetInterpolatorByEasingType<double>(lyricsEffect.LyricsScrollEasingType, lyricsEffect.LyricsScrollEasingMode));
|
||||||
_canvasYScrollTransition.Start(_canvasTargetScrollOffset);
|
_canvasYScrollTransition.Start(_canvasTargetScrollOffset);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -208,6 +208,13 @@
|
|||||||
<ComboBoxItem x:Uid="SettingsPageEasingTypeEaseInOutBounce" />
|
<ComboBoxItem x:Uid="SettingsPageEasingTypeEaseInOutBounce" />
|
||||||
</ComboBox>
|
</ComboBox>
|
||||||
<dev:SettingsExpander.Items>
|
<dev:SettingsExpander.Items>
|
||||||
|
<dev:SettingsCard Header="Easing Mode">
|
||||||
|
<ComboBox SelectedIndex="{x:Bind LyricsEffectSettings.LyricsScrollEasingMode, Mode=TwoWay, Converter={StaticResource EnumToIntConverter}}">
|
||||||
|
<ComboBoxItem Content="EaseIn" />
|
||||||
|
<ComboBoxItem Content="EaseOut" />
|
||||||
|
<ComboBoxItem Content="EaseInOut" />
|
||||||
|
</ComboBox>
|
||||||
|
</dev:SettingsCard>
|
||||||
<dev:SettingsCard x:Uid="SettingsPageScrollTopDuration">
|
<dev:SettingsCard x:Uid="SettingsPageScrollTopDuration">
|
||||||
<local:ExtendedSlider
|
<local:ExtendedSlider
|
||||||
Default="500"
|
Default="500"
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
namespace BetterLyrics.WinUI3.Enums;
|
||||||
|
|
||||||
|
public enum EaseMode
|
||||||
|
{
|
||||||
|
In,
|
||||||
|
Out,
|
||||||
|
InOut,
|
||||||
|
}
|
||||||
@@ -6,15 +6,15 @@ namespace BetterLyrics.WinUI3.Enums
|
|||||||
{
|
{
|
||||||
Linear,
|
Linear,
|
||||||
SmoothStep,
|
SmoothStep,
|
||||||
EaseInOutSine,
|
Sine,
|
||||||
EaseInOutQuad,
|
Quad,
|
||||||
EaseInOutCubic,
|
Cubic,
|
||||||
EaseInOutQuart,
|
Quart,
|
||||||
EaseInOutQuint,
|
Quint,
|
||||||
EaseInOutExpo,
|
Expo,
|
||||||
EaseInOutCirc,
|
Circle,
|
||||||
EaseInOutBack,
|
Back,
|
||||||
EaseInOutElastic,
|
Elastic,
|
||||||
EaseInOutBounce,
|
Bounce,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,114 +1,170 @@
|
|||||||
// 2025/6/23 by Zhe Fang
|
// 2025/6/23 by Zhe Fang
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Numerics;
|
||||||
|
using BetterLyrics.WinUI3.Enums;
|
||||||
|
|
||||||
namespace BetterLyrics.WinUI3.Helper
|
namespace BetterLyrics.WinUI3.Helper
|
||||||
{
|
{
|
||||||
public class EasingHelper
|
public class EasingHelper
|
||||||
{
|
{
|
||||||
public static double EaseInOutSine(double t)
|
#region Interpolators
|
||||||
{
|
|
||||||
return -(Math.Cos(Math.PI * t) - 1f) / 2f;
|
|
||||||
}
|
|
||||||
public static double EaseInOutQuad(double t)
|
|
||||||
{
|
|
||||||
return t < 0.5f ? 2 * t * t : -1 + (4 - 2 * t) * t;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static double EaseInOutCubic(double t)
|
public static Func<T, T, double, T> GetInterpolatorByEasingType<T>(EasingType? type, EaseMode easingMode = EaseMode.Out)
|
||||||
|
where T : INumber<T>, IFloatingPointIeee754<T>
|
||||||
{
|
{
|
||||||
return t < 0.5f ? 4 * t * t * t : 1 - Math.Pow(-2 * t + 2, 3) / 2;
|
return (start, end, progress) =>
|
||||||
}
|
|
||||||
public static double EaseInOutQuart(double t)
|
|
||||||
{
|
|
||||||
return t < 0.5f ? 8 * t * t * t * t : 1 - Math.Pow(-2 * t + 2, 4) / 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static double EaseInOutQuint(double t)
|
|
||||||
{
|
|
||||||
return t < 0.5f ? 16 * t * t * t * t * t : 1 - Math.Pow(-2 * t + 2, 5) / 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static double EaseInOutExpo(double t)
|
|
||||||
{
|
|
||||||
return t == 0
|
|
||||||
? 0
|
|
||||||
: t == 1
|
|
||||||
? 1
|
|
||||||
: t < 0.5 ? Math.Pow(2, 20 * t - 10) / 2
|
|
||||||
: (2 - Math.Pow(2, -20 * t + 10)) / 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static double EaseInOutCirc(double t)
|
|
||||||
{
|
|
||||||
return t < 0.5f
|
|
||||||
? (1 - Math.Sqrt(1 - Math.Pow(2 * t, 2))) / 2
|
|
||||||
: (Math.Sqrt(1 - Math.Pow(-2 * t + 2, 2)) + 1) / 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static double EaseInOutBack(double t)
|
|
||||||
{
|
|
||||||
double c1 = 1.70158f;
|
|
||||||
double c2 = c1 * 1.525f;
|
|
||||||
|
|
||||||
return t < 0.5
|
|
||||||
? (Math.Pow(2 * t, 2) * ((c2 + 1) * 2 * t - c2)) / 2
|
|
||||||
: (Math.Pow(2 * t - 2, 2) * ((c2 + 1) * (t * 2 - 2) + c2) + 2) / 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static double EaseInOutElastic(double t)
|
|
||||||
{
|
|
||||||
if (t == 0 || t == 1) return t;
|
|
||||||
double p = 0.3f;
|
|
||||||
double s = p / 4;
|
|
||||||
return t < 0.5f
|
|
||||||
? -(Math.Pow(2, 20 * t - 10) * Math.Sin((20 * t - 11.125f) * (2 * Math.PI) / p)) / 2
|
|
||||||
: (Math.Pow(2, -20 * t + 10) * Math.Sin((20 * t - 11.125f) * (2 * Math.PI) / p)) / 2 + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static double EaseOutBounce(double t)
|
|
||||||
{
|
|
||||||
if (t < 4 / 11f)
|
|
||||||
{
|
{
|
||||||
return (121 * t * t) / 16f;
|
Func<T, T> easeInFunc = type switch
|
||||||
|
{
|
||||||
|
EasingType.Sine => EaseInSine,
|
||||||
|
EasingType.Quad => EaseInQuad,
|
||||||
|
EasingType.Cubic => EaseInCubic,
|
||||||
|
EasingType.Quart => EaseInQuart,
|
||||||
|
EasingType.Quint => EaseInQuint,
|
||||||
|
EasingType.Expo => EaseInExpo,
|
||||||
|
EasingType.Circle => EaseInCircle,
|
||||||
|
EasingType.Back => EaseInBack,
|
||||||
|
EasingType.Elastic => EaseInElastic,
|
||||||
|
EasingType.Bounce => EaseInBounce,
|
||||||
|
EasingType.SmoothStep => SmoothStep,
|
||||||
|
EasingType.Linear => Linear,
|
||||||
|
_ => EaseInQuad,
|
||||||
|
};
|
||||||
|
double t = Ease(progress, easingMode, easeInFunc);
|
||||||
|
return start + ((end - start) * T.CreateChecked(t));
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
public static double Ease<T>(double t, EaseMode mode, Func<T, T> easeIn)
|
||||||
|
where T : IFloatingPointIeee754<T>
|
||||||
|
{
|
||||||
|
t = Math.Clamp(t, 0.0, 1.0);
|
||||||
|
|
||||||
|
T tt = T.CreateChecked(t);
|
||||||
|
T half = T.CreateChecked(0.5);
|
||||||
|
T two = T.CreateChecked(2);
|
||||||
|
T tResult = mode switch
|
||||||
|
{
|
||||||
|
EaseMode.In => easeIn(tt),
|
||||||
|
EaseMode.Out => T.One - easeIn(T.One - tt),
|
||||||
|
EaseMode.InOut => tt < half
|
||||||
|
? easeIn(tt * two) / two
|
||||||
|
: T.One - (easeIn((T.One - tt) * two) / two),
|
||||||
|
_ => easeIn(tt),
|
||||||
|
};
|
||||||
|
|
||||||
|
return double.CreateChecked(tResult);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static T EaseInSine<T>(T t) where T : IFloatingPointIeee754<T>
|
||||||
|
{
|
||||||
|
return T.One - T.Cos((t * T.Pi) / T.CreateChecked(2));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static T EaseInQuad<T>(T t) where T : INumber<T>
|
||||||
|
{
|
||||||
|
return t * t;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static T EaseInCubic<T>(T t) where T : INumber<T>
|
||||||
|
{
|
||||||
|
return t * t * t;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static T EaseInQuart<T>(T t) where T : INumber<T>
|
||||||
|
{
|
||||||
|
return t * t * t * t;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static T EaseInQuint<T>(T t) where T : INumber<T>
|
||||||
|
{
|
||||||
|
return t * t * t * t * t;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static T EaseInExpo<T>(T t) where T : IFloatingPointIeee754<T>
|
||||||
|
{
|
||||||
|
if (t == T.Zero)
|
||||||
|
{
|
||||||
|
return T.Zero;
|
||||||
}
|
}
|
||||||
else if (t < 8 / 11f)
|
|
||||||
|
return T.Pow(T.CreateChecked(2), (T.CreateChecked(10) * t) - T.CreateChecked(10));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static T EaseInCircle<T>(T t) where T : IFloatingPointIeee754<T>
|
||||||
|
{
|
||||||
|
return T.One - T.Sqrt(T.One - (t * t));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static T EaseInBack<T>(T t) where T : IFloatingPointIeee754<T>
|
||||||
|
{
|
||||||
|
T c1 = T.CreateChecked(1.70158);
|
||||||
|
T c3 = c1 + T.One;
|
||||||
|
|
||||||
|
return (c3 * t * t * t) - (c1 * t * t);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static T EaseInElastic<T>(T t) where T : IFloatingPointIeee754<T>
|
||||||
|
{
|
||||||
|
if (t == T.Zero || t == T.One)
|
||||||
{
|
{
|
||||||
return (363 / 40f * t * t) - (99 / 10f * t) + 17 / 5f;
|
return t;
|
||||||
}
|
}
|
||||||
else if (t < 9 / 10f)
|
|
||||||
|
const double springiness = 6;
|
||||||
|
const double oscillations = 1;
|
||||||
|
|
||||||
|
double td = double.CreateChecked(t);
|
||||||
|
|
||||||
|
double expo = (Math.Exp(springiness * td) - 1.0) / (Math.Exp(springiness) - 1.0);
|
||||||
|
double result = 0.7 * expo * Math.Sin((Math.PI * 2.0 * oscillations + (Math.PI * 0.5)) * td);
|
||||||
|
|
||||||
|
return T.CreateChecked(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static T EaseOutBounce<T>(T t) where T : IFloatingPointIeee754<T>
|
||||||
|
{
|
||||||
|
if (t < T.CreateChecked(4.0 / 11.0))
|
||||||
{
|
{
|
||||||
return (4356 / 361f * t * t) - (35442 / 1805f * t) + 16061 / 1805f;
|
return (T.CreateChecked(121) * t * t) / T.CreateChecked(16);
|
||||||
|
}
|
||||||
|
else if (t < T.CreateChecked(8.0 / 11.0))
|
||||||
|
{
|
||||||
|
return ((T.CreateChecked(363.0 / 40.0) * t * t) - (T.CreateChecked(99.0 / 10.0) * t)) + T.CreateChecked(17.0 / 5.0);
|
||||||
|
}
|
||||||
|
else if (t < T.CreateChecked(9.0 / 10.0))
|
||||||
|
{
|
||||||
|
return ((T.CreateChecked(4356.0 / 361.0) * t * t) - (T.CreateChecked(35442.0 / 1805.0) * t)) + T.CreateChecked(16061.0 / 1805.0);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return (54 / 5f * t * t) - (513 / 25f * t) + 268 / 25f;
|
return ((T.CreateChecked(54.0 / 5.0) * t * t) - (T.CreateChecked(513.0 / 25.0) * t)) + T.CreateChecked(268.0 / 25.0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static double EaseInOutBounce(double t)
|
public static T EaseInBounce<T>(T t) where T : IFloatingPointIeee754<T>
|
||||||
{
|
{
|
||||||
if (t < 0.5f)
|
return T.One - EaseOutBounce(T.One - t);
|
||||||
{
|
|
||||||
return (1 - EaseOutBounce(1 - 2 * t)) / 2;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return (1 + EaseOutBounce(2 * t - 1)) / 2;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static double SmoothStep(double t)
|
public static T SmoothStep<T>(T t) where T : IFloatingPointIeee754<T>
|
||||||
{
|
{
|
||||||
return t * t * (3f - 2f * t);
|
return t * t * (T.CreateChecked(3) - (T.CreateChecked(2) * t));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static double CubicBezier(double t, double p0, double p1, double p2, double p3)
|
public static T CubicBezier<T>(T t, T p0, T p1, T p2, T p3) where T : IFloatingPointIeee754<T>
|
||||||
{
|
{
|
||||||
double u = 1 - t;
|
T u = T.One - t;
|
||||||
return u * u * u * p0 + 3 * u * u * t * p1 + 3 * u * t * t * p2 + t * t * t * p3;
|
|
||||||
|
return (u * u * u * p0)
|
||||||
|
+ (T.CreateChecked(3) * u * u * t * p1)
|
||||||
|
+ (T.CreateChecked(3) * u * t * t * p2)
|
||||||
|
+ (t * t * t * p3);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static double Linear(double t) => t;
|
public static T Linear<T>(T t) where T : INumber<T> => t;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2,6 +2,7 @@
|
|||||||
using BetterLyrics.WinUI3.Models;
|
using BetterLyrics.WinUI3.Models;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using static BetterLyrics.WinUI3.Helper.EasingHelper;
|
||||||
|
|
||||||
namespace BetterLyrics.WinUI3.Helper
|
namespace BetterLyrics.WinUI3.Helper
|
||||||
{
|
{
|
||||||
@@ -21,7 +22,6 @@ namespace BetterLyrics.WinUI3.Helper
|
|||||||
private double _configuredDelaySeconds; // 配置的延迟时长
|
private double _configuredDelaySeconds; // 配置的延迟时长
|
||||||
|
|
||||||
// 动画状态
|
// 动画状态
|
||||||
private Enums.EasingType? _easingType;
|
|
||||||
private Func<T, T, double, T> _interpolator;
|
private Func<T, T, double, T> _interpolator;
|
||||||
private bool _isTransitioning;
|
private bool _isTransitioning;
|
||||||
private double _progress; // 当前段的进度 (0.0 ~ 1.0)
|
private double _progress; // 当前段的进度 (0.0 ~ 1.0)
|
||||||
@@ -30,10 +30,11 @@ namespace BetterLyrics.WinUI3.Helper
|
|||||||
public T Value => _currentValue;
|
public T Value => _currentValue;
|
||||||
public bool IsTransitioning => _isTransitioning;
|
public bool IsTransitioning => _isTransitioning;
|
||||||
public T TargetValue => _targetValue; // 获取当前段的目标值
|
public T TargetValue => _targetValue; // 获取当前段的目标值
|
||||||
public Enums.EasingType? EasingType => _easingType;
|
|
||||||
public double DurationSeconds => _totalDurationForAutoSplit;
|
public double DurationSeconds => _totalDurationForAutoSplit;
|
||||||
|
|
||||||
public ValueTransition(T initialValue, double defaultTotalDuration = 0.3, EasingType? defaultEasingType = null, Func<T, T, double, T>? interpolator = null)
|
public Func<T, T, double, T> Interpolator => _interpolator;
|
||||||
|
|
||||||
|
public ValueTransition(T initialValue, Func<T, T, double, T>? interpolator, double defaultTotalDuration = 0.3)
|
||||||
{
|
{
|
||||||
_currentValue = initialValue;
|
_currentValue = initialValue;
|
||||||
_startValue = initialValue;
|
_startValue = initialValue;
|
||||||
@@ -43,15 +44,6 @@ namespace BetterLyrics.WinUI3.Helper
|
|||||||
if (interpolator != null)
|
if (interpolator != null)
|
||||||
{
|
{
|
||||||
_interpolator = interpolator;
|
_interpolator = interpolator;
|
||||||
_easingType = null;
|
|
||||||
}
|
|
||||||
else if (defaultEasingType != null)
|
|
||||||
{
|
|
||||||
SetEasingType(defaultEasingType);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
SetEasingType(Enums.EasingType.EaseInOutQuad);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -74,10 +66,9 @@ namespace BetterLyrics.WinUI3.Helper
|
|||||||
_configuredDelaySeconds = seconds;
|
_configuredDelaySeconds = seconds;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetEasingType(Enums.EasingType? easingType)
|
public void SetInterpolator(Func<T, T, double, T> interpolator)
|
||||||
{
|
{
|
||||||
_easingType = easingType;
|
_interpolator = interpolator;
|
||||||
_interpolator = GetInterpolatorByEasingType(easingType);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
@@ -235,7 +226,7 @@ namespace BetterLyrics.WinUI3.Helper
|
|||||||
|
|
||||||
#region Interpolators
|
#region Interpolators
|
||||||
|
|
||||||
private Func<T, T, double, T> GetInterpolatorByEasingType(Enums.EasingType? type)
|
public static Func<T, T, double, T> GetInterpolatorByEasingType(EasingType? type, EaseMode easingMode)
|
||||||
{
|
{
|
||||||
if (typeof(T) == typeof(double))
|
if (typeof(T) == typeof(double))
|
||||||
{
|
{
|
||||||
@@ -243,25 +234,24 @@ namespace BetterLyrics.WinUI3.Helper
|
|||||||
{
|
{
|
||||||
double s = (double)(object)start;
|
double s = (double)(object)start;
|
||||||
double e = (double)(object)end;
|
double e = (double)(object)end;
|
||||||
double t = progress;
|
|
||||||
|
|
||||||
// 使用 EasingHelper (假设您的项目中已有此辅助类)
|
Func<double, double> easeInFunc = type switch
|
||||||
switch (type)
|
|
||||||
{
|
{
|
||||||
case Enums.EasingType.EaseInOutSine: t = EasingHelper.EaseInOutSine(t); break;
|
Enums.EasingType.Sine => EaseInSine,
|
||||||
case Enums.EasingType.EaseInOutQuad: t = EasingHelper.EaseInOutQuad(t); break;
|
Enums.EasingType.Quad => EaseInQuad,
|
||||||
case Enums.EasingType.EaseInOutCubic: t = EasingHelper.EaseInOutCubic(t); break;
|
Enums.EasingType.Cubic => EaseInCubic,
|
||||||
case Enums.EasingType.EaseInOutQuart: t = EasingHelper.EaseInOutQuart(t); break;
|
Enums.EasingType.Quart => EaseInQuart,
|
||||||
case Enums.EasingType.EaseInOutQuint: t = EasingHelper.EaseInOutQuint(t); break;
|
Enums.EasingType.Quint => EaseInQuint,
|
||||||
case Enums.EasingType.EaseInOutExpo: t = EasingHelper.EaseInOutExpo(t); break;
|
Enums.EasingType.Expo => EaseInExpo,
|
||||||
case Enums.EasingType.EaseInOutCirc: t = EasingHelper.EaseInOutCirc(t); break;
|
Enums.EasingType.Circle => EaseInCircle,
|
||||||
case Enums.EasingType.EaseInOutBack: t = EasingHelper.EaseInOutBack(t); break;
|
Enums.EasingType.Back => EaseInBack,
|
||||||
case Enums.EasingType.EaseInOutElastic: t = EasingHelper.EaseInOutElastic(t); break;
|
Enums.EasingType.Elastic => EaseInElastic,
|
||||||
case Enums.EasingType.EaseInOutBounce: t = EasingHelper.EaseInOutBounce(t); break;
|
Enums.EasingType.Bounce => EaseInBounce,
|
||||||
case Enums.EasingType.SmoothStep: t = EasingHelper.SmoothStep(t); break;
|
Enums.EasingType.SmoothStep => SmoothStep,
|
||||||
case Enums.EasingType.Linear: t = EasingHelper.Linear(t); break;
|
Enums.EasingType.Linear => Linear,
|
||||||
default: t = EasingHelper.EaseInOutQuad(t); break;
|
_ => EaseInQuad,
|
||||||
}
|
};
|
||||||
|
double t = Ease(progress, easingMode, easeInFunc);
|
||||||
|
|
||||||
return (T)(object)(s + (e - s) * t);
|
return (T)(object)(s + (e - s) * t);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -177,7 +177,7 @@ namespace BetterLyrics.WinUI3.Logic
|
|||||||
line.ColorTransition.SetDelay(yScrollDelay);
|
line.ColorTransition.SetDelay(yScrollDelay);
|
||||||
line.ColorTransition.Start(isSecondaryLinePlaying ? fgColor : bgColor);
|
line.ColorTransition.Start(isSecondaryLinePlaying ? fgColor : bgColor);
|
||||||
|
|
||||||
line.AngleTransition.SetEasingType(canvasYScrollTransition.EasingType);
|
line.AngleTransition.SetInterpolator(canvasYScrollTransition.Interpolator);
|
||||||
line.AngleTransition.SetDuration(yScrollDuration);
|
line.AngleTransition.SetDuration(yScrollDuration);
|
||||||
line.AngleTransition.SetDelay(yScrollDelay);
|
line.AngleTransition.SetDelay(yScrollDelay);
|
||||||
line.AngleTransition.Start(
|
line.AngleTransition.Start(
|
||||||
@@ -185,7 +185,7 @@ namespace BetterLyrics.WinUI3.Logic
|
|||||||
fanAngleRad * distanceFactor * (i > primaryPlayingLineIndex ? 1 : -1) :
|
fanAngleRad * distanceFactor * (i > primaryPlayingLineIndex ? 1 : -1) :
|
||||||
0);
|
0);
|
||||||
|
|
||||||
line.YOffsetTransition.SetEasingType(canvasYScrollTransition.EasingType);
|
line.YOffsetTransition.SetInterpolator(canvasYScrollTransition.Interpolator);
|
||||||
line.YOffsetTransition.SetDuration(yScrollDuration);
|
line.YOffsetTransition.SetDuration(yScrollDuration);
|
||||||
line.YOffsetTransition.SetDelay(yScrollDelay);
|
line.YOffsetTransition.SetDelay(yScrollDelay);
|
||||||
// 设计之初是当 isLayoutChanged 为真时 jumpTo
|
// 设计之初是当 isLayoutChanged 为真时 jumpTo
|
||||||
|
|||||||
@@ -20,18 +20,18 @@ namespace BetterLyrics.WinUI3.Models.Lyrics
|
|||||||
{
|
{
|
||||||
ScaleTransition = new(
|
ScaleTransition = new(
|
||||||
initialValue: 1.0,
|
initialValue: 1.0,
|
||||||
defaultTotalDuration: Time.AnimationDuration.TotalSeconds,
|
EasingHelper.GetInterpolatorByEasingType<double>(EasingType.Sine),
|
||||||
defaultEasingType: EasingType.EaseInOutSine
|
defaultTotalDuration: Time.AnimationDuration.TotalSeconds
|
||||||
);
|
);
|
||||||
GlowTransition = new(
|
GlowTransition = new(
|
||||||
initialValue: 0,
|
initialValue: 0,
|
||||||
defaultTotalDuration: Time.AnimationDuration.TotalSeconds,
|
EasingHelper.GetInterpolatorByEasingType<double>(EasingType.Sine),
|
||||||
defaultEasingType: EasingType.EaseInOutSine
|
defaultTotalDuration: Time.AnimationDuration.TotalSeconds
|
||||||
);
|
);
|
||||||
FloatTransition = new(
|
FloatTransition = new(
|
||||||
initialValue: 0,
|
initialValue: 0,
|
||||||
defaultTotalDuration: Time.LongAnimationDuration.TotalSeconds,
|
EasingHelper.GetInterpolatorByEasingType<double>(EasingType.Sine),
|
||||||
defaultEasingType: EasingType.EaseInOutSine
|
defaultTotalDuration: Time.LongAnimationDuration.TotalSeconds
|
||||||
);
|
);
|
||||||
LayoutRect = layoutRect;
|
LayoutRect = layoutRect;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -82,43 +82,43 @@ namespace BetterLyrics.WinUI3.Models.Lyrics
|
|||||||
{
|
{
|
||||||
AngleTransition = new(
|
AngleTransition = new(
|
||||||
initialValue: 0,
|
initialValue: 0,
|
||||||
defaultTotalDuration: AnimationDuration,
|
EasingHelper.GetInterpolatorByEasingType<double>(EasingType.Sine),
|
||||||
defaultEasingType: EasingType.EaseInOutSine
|
defaultTotalDuration: AnimationDuration
|
||||||
);
|
);
|
||||||
BlurAmountTransition = new(
|
BlurAmountTransition = new(
|
||||||
initialValue: 0,
|
initialValue: 0,
|
||||||
defaultTotalDuration: AnimationDuration,
|
EasingHelper.GetInterpolatorByEasingType<double>(EasingType.Sine),
|
||||||
defaultEasingType: EasingType.EaseInOutSine
|
defaultTotalDuration: AnimationDuration
|
||||||
);
|
);
|
||||||
PhoneticOpacityTransition = new(
|
PhoneticOpacityTransition = new(
|
||||||
initialValue: 0,
|
initialValue: 0,
|
||||||
defaultTotalDuration: AnimationDuration,
|
EasingHelper.GetInterpolatorByEasingType<double>(EasingType.Sine),
|
||||||
defaultEasingType: EasingType.EaseInOutSine
|
defaultTotalDuration: AnimationDuration
|
||||||
);
|
);
|
||||||
PlayedOriginalOpacityTransition = new(
|
PlayedOriginalOpacityTransition = new(
|
||||||
initialValue: 0,
|
initialValue: 0,
|
||||||
defaultTotalDuration: AnimationDuration,
|
EasingHelper.GetInterpolatorByEasingType<double>(EasingType.Sine),
|
||||||
defaultEasingType: EasingType.EaseInOutSine
|
defaultTotalDuration: AnimationDuration
|
||||||
);
|
);
|
||||||
UnplayedOriginalOpacityTransition = new(
|
UnplayedOriginalOpacityTransition = new(
|
||||||
initialValue: 0,
|
initialValue: 0,
|
||||||
defaultTotalDuration: AnimationDuration,
|
EasingHelper.GetInterpolatorByEasingType<double>(EasingType.Sine),
|
||||||
defaultEasingType: EasingType.EaseInOutSine
|
defaultTotalDuration: AnimationDuration
|
||||||
);
|
);
|
||||||
TranslatedOpacityTransition = new(
|
TranslatedOpacityTransition = new(
|
||||||
initialValue: 0,
|
initialValue: 0,
|
||||||
defaultTotalDuration: AnimationDuration,
|
EasingHelper.GetInterpolatorByEasingType<double>(EasingType.Sine),
|
||||||
defaultEasingType: EasingType.EaseInOutSine
|
defaultTotalDuration: AnimationDuration
|
||||||
);
|
);
|
||||||
ScaleTransition = new(
|
ScaleTransition = new(
|
||||||
initialValue: 0,
|
initialValue: 0,
|
||||||
defaultTotalDuration: AnimationDuration,
|
EasingHelper.GetInterpolatorByEasingType<double>(EasingType.Sine),
|
||||||
defaultEasingType: EasingType.EaseInOutSine
|
defaultTotalDuration: AnimationDuration
|
||||||
);
|
);
|
||||||
YOffsetTransition = new(
|
YOffsetTransition = new(
|
||||||
initialValue: 0,
|
initialValue: 0,
|
||||||
defaultTotalDuration: AnimationDuration,
|
EasingHelper.GetInterpolatorByEasingType<double>(EasingType.Sine),
|
||||||
defaultEasingType: EasingType.EaseInOutSine
|
defaultTotalDuration: AnimationDuration
|
||||||
);
|
);
|
||||||
ColorTransition = new(
|
ColorTransition = new(
|
||||||
initialValue: Colors.Transparent,
|
initialValue: Colors.Transparent,
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
using BetterLyrics.WinUI3.Enums;
|
using BetterLyrics.WinUI3.Enums;
|
||||||
using CommunityToolkit.Mvvm.ComponentModel;
|
using CommunityToolkit.Mvvm.ComponentModel;
|
||||||
using System;
|
using System;
|
||||||
|
using static BetterLyrics.WinUI3.Helper.EasingHelper;
|
||||||
|
|
||||||
namespace BetterLyrics.WinUI3.Models.Settings
|
namespace BetterLyrics.WinUI3.Models.Settings
|
||||||
{
|
{
|
||||||
@@ -29,6 +30,7 @@ namespace BetterLyrics.WinUI3.Models.Settings
|
|||||||
[ObservableProperty][NotifyPropertyChangedRecipients] public partial int LyricsFloatAnimationDuration { get; set; } = 450; // 450ms
|
[ObservableProperty][NotifyPropertyChangedRecipients] public partial int LyricsFloatAnimationDuration { get; set; } = 450; // 450ms
|
||||||
|
|
||||||
[ObservableProperty][NotifyPropertyChangedRecipients] public partial EasingType LyricsScrollEasingType { get; set; }
|
[ObservableProperty][NotifyPropertyChangedRecipients] public partial EasingType LyricsScrollEasingType { get; set; }
|
||||||
|
[ObservableProperty][NotifyPropertyChangedRecipients] public partial EaseMode LyricsScrollEasingMode { get; set; } = EaseMode.Out;
|
||||||
[ObservableProperty][NotifyPropertyChangedRecipients] public partial int LyricsScrollDuration { get; set; }
|
[ObservableProperty][NotifyPropertyChangedRecipients] public partial int LyricsScrollDuration { get; set; }
|
||||||
[ObservableProperty][NotifyPropertyChangedRecipients] public partial int LyricsScrollTopDuration { get; set; }
|
[ObservableProperty][NotifyPropertyChangedRecipients] public partial int LyricsScrollTopDuration { get; set; }
|
||||||
[ObservableProperty][NotifyPropertyChangedRecipients] public partial int LyricsScrollBottomDuration { get; set; }
|
[ObservableProperty][NotifyPropertyChangedRecipients] public partial int LyricsScrollBottomDuration { get; set; }
|
||||||
@@ -79,6 +81,7 @@ namespace BetterLyrics.WinUI3.Models.Settings
|
|||||||
LyricsFloatAnimationDuration = this.LyricsFloatAnimationDuration,
|
LyricsFloatAnimationDuration = this.LyricsFloatAnimationDuration,
|
||||||
|
|
||||||
LyricsScrollEasingType = this.LyricsScrollEasingType,
|
LyricsScrollEasingType = this.LyricsScrollEasingType,
|
||||||
|
LyricsScrollEasingMode = this.LyricsScrollEasingMode,
|
||||||
LyricsScrollDuration = this.LyricsScrollDuration,
|
LyricsScrollDuration = this.LyricsScrollDuration,
|
||||||
LyricsScrollTopDuration = this.LyricsScrollTopDuration,
|
LyricsScrollTopDuration = this.LyricsScrollTopDuration,
|
||||||
LyricsScrollBottomDuration = this.LyricsScrollBottomDuration,
|
LyricsScrollBottomDuration = this.LyricsScrollBottomDuration,
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ namespace BetterLyrics.WinUI3.Models.Settings
|
|||||||
[ObservableProperty] public partial Rect DemoMonitorBounds { get; set; }
|
[ObservableProperty] public partial Rect DemoMonitorBounds { get; set; }
|
||||||
[ObservableProperty][NotifyPropertyChangedRecipients] public partial DockPlacement DockPlacement { get; set; } = DockPlacement.Top;
|
[ObservableProperty][NotifyPropertyChangedRecipients] public partial DockPlacement DockPlacement { get; set; } = DockPlacement.Top;
|
||||||
[ObservableProperty] public partial LyricsStyleSettings LyricsStyleSettings { get; set; } = new();
|
[ObservableProperty] public partial LyricsStyleSettings LyricsStyleSettings { get; set; } = new();
|
||||||
[ObservableProperty] public partial LyricsEffectSettings LyricsEffectSettings { get; set; } = new(500, 500, 500, EasingType.EaseInOutQuad);
|
[ObservableProperty] public partial LyricsEffectSettings LyricsEffectSettings { get; set; } = new(500, 500, 500, EasingType.Quad);
|
||||||
[ObservableProperty][NotifyPropertyChangedRecipients] public partial LyricsBackgroundSettings LyricsBackgroundSettings { get; set; } = new();
|
[ObservableProperty][NotifyPropertyChangedRecipients] public partial LyricsBackgroundSettings LyricsBackgroundSettings { get; set; } = new();
|
||||||
[ObservableProperty][NotifyPropertyChangedRecipients] public partial AlbumArtAreaStyleSettings AlbumArtLayoutSettings { get; set; } = new();
|
[ObservableProperty][NotifyPropertyChangedRecipients] public partial AlbumArtAreaStyleSettings AlbumArtLayoutSettings { get; set; } = new();
|
||||||
[ObservableProperty] public partial AlbumArtAreaEffectSettings AlbumArtAreaEffectSettings { get; set; } = new();
|
[ObservableProperty] public partial AlbumArtAreaEffectSettings AlbumArtAreaEffectSettings { get; set; } = new();
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ namespace BetterLyrics.WinUI3.Renderer
|
|||||||
|
|
||||||
public CoverBackgroundRenderer()
|
public CoverBackgroundRenderer()
|
||||||
{
|
{
|
||||||
_crossfadeTransition = new ValueTransition<double>(1.0, 0.7, defaultEasingType: EasingType.Linear);
|
_crossfadeTransition = new ValueTransition<double>(1.0, EasingHelper.GetInterpolatorByEasingType<double>(EasingType.Linear), 0.7);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetCoverBitmap(CanvasBitmap? newBitmap)
|
public void SetCoverBitmap(CanvasBitmap? newBitmap)
|
||||||
|
|||||||
Reference in New Issue
Block a user