Skip to content

Commit 52029f7

Browse files
MovGP0Johann Dirry
authored andcommitted
starting to implement MD3 motion library
1 parent 65c1d80 commit 52029f7

37 files changed

+1773
-1
lines changed

Directory.packages.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,6 @@
3232
<PackageVersion Include="System.Memory" Version="4.6.3" />
3333
<PackageVersion Include="System.ValueTuple" Version="4.6.1" />
3434
<PackageVersion Include="Polyfill" Version="8.8.1" />
35+
<PackageVersion Include="Microsoft.Bcl.HashCode" Version="6.0.0" />
3536
</ItemGroup>
3637
</Project>

MaterialDesignToolkit.Full.sln

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Microsoft Visual Studio Solution File, Format Version 12.00
1+
Microsoft Visual Studio Solution File, Format Version 12.00
22
# Visual Studio Version 17
33
VisualStudioVersion = 17.0.31612.314
44
MinimumVisualStudioVersion = 10.0.40219.1
@@ -67,6 +67,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MaterialColorUtilities", "s
6767
EndProject
6868
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MaterialColorUtilities.Tests", "tests\MaterialColorUtilities.Tests\MaterialColorUtilities.Tests.csproj", "{91485BEA-759F-406E-87B7-68D94CF66DE4}"
6969
EndProject
70+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MaterialDesignThemes.Motion", "src\MaterialDesign3.Motion\Motion.csproj", "{3F7E3CFD-BAE6-4DC4-9C8D-A001138BD87F}"
71+
EndProject
7072
Global
7173
GlobalSection(SolutionConfigurationPlatforms) = preSolution
7274
Debug|Any CPU = Debug|Any CPU
@@ -287,6 +289,22 @@ Global
287289
{91485BEA-759F-406E-87B7-68D94CF66DE4}.Release|x64.Build.0 = Release|Any CPU
288290
{91485BEA-759F-406E-87B7-68D94CF66DE4}.Release|x86.ActiveCfg = Release|Any CPU
289291
{91485BEA-759F-406E-87B7-68D94CF66DE4}.Release|x86.Build.0 = Release|Any CPU
292+
{3F7E3CFD-BAE6-4DC4-9C8D-A001138BD87F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
293+
{3F7E3CFD-BAE6-4DC4-9C8D-A001138BD87F}.Debug|Any CPU.Build.0 = Debug|Any CPU
294+
{3F7E3CFD-BAE6-4DC4-9C8D-A001138BD87F}.Debug|ARM.ActiveCfg = Debug|Any CPU
295+
{3F7E3CFD-BAE6-4DC4-9C8D-A001138BD87F}.Debug|ARM.Build.0 = Debug|Any CPU
296+
{3F7E3CFD-BAE6-4DC4-9C8D-A001138BD87F}.Debug|x64.ActiveCfg = Debug|Any CPU
297+
{3F7E3CFD-BAE6-4DC4-9C8D-A001138BD87F}.Debug|x64.Build.0 = Debug|Any CPU
298+
{3F7E3CFD-BAE6-4DC4-9C8D-A001138BD87F}.Debug|x86.ActiveCfg = Debug|Any CPU
299+
{3F7E3CFD-BAE6-4DC4-9C8D-A001138BD87F}.Debug|x86.Build.0 = Debug|Any CPU
300+
{3F7E3CFD-BAE6-4DC4-9C8D-A001138BD87F}.Release|Any CPU.ActiveCfg = Release|Any CPU
301+
{3F7E3CFD-BAE6-4DC4-9C8D-A001138BD87F}.Release|Any CPU.Build.0 = Release|Any CPU
302+
{3F7E3CFD-BAE6-4DC4-9C8D-A001138BD87F}.Release|ARM.ActiveCfg = Release|Any CPU
303+
{3F7E3CFD-BAE6-4DC4-9C8D-A001138BD87F}.Release|ARM.Build.0 = Release|Any CPU
304+
{3F7E3CFD-BAE6-4DC4-9C8D-A001138BD87F}.Release|x64.ActiveCfg = Release|Any CPU
305+
{3F7E3CFD-BAE6-4DC4-9C8D-A001138BD87F}.Release|x64.Build.0 = Release|Any CPU
306+
{3F7E3CFD-BAE6-4DC4-9C8D-A001138BD87F}.Release|x86.ActiveCfg = Release|Any CPU
307+
{3F7E3CFD-BAE6-4DC4-9C8D-A001138BD87F}.Release|x86.Build.0 = Release|Any CPU
290308
EndGlobalSection
291309
GlobalSection(SolutionProperties) = preSolution
292310
HideSolutionNode = FALSE
@@ -300,6 +318,7 @@ Global
300318
{B39795A7-D66A-4F2F-9F41-050838D14048} = {D34BE232-DE51-43C1-ABDC-B69003BB50FF}
301319
{2C29B80E-1689-43CE-85AC-71799666B4AC} = {9E303A4A-3712-44B9-91EE-830FDC087795}
302320
{91485BEA-759F-406E-87B7-68D94CF66DE4} = {9E303A4A-3712-44B9-91EE-830FDC087795}
321+
{3F7E3CFD-BAE6-4DC4-9C8D-A001138BD87F} = {9E303A4A-3712-44B9-91EE-830FDC087795}
303322
EndGlobalSection
304323
GlobalSection(ExtensibilityGlobals) = postSolution
305324
SolutionGuid = {730B2F9E-74AE-46CE-9E61-89AA5C6D5DD3}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
namespace MaterialDesignThemes.Motion;
2+
3+
/// <summary>
4+
/// Possible reasons for <see cref="Animatable{T, V}"/>s to end.
5+
/// </summary>
6+
public enum AnimationEndReason
7+
{
8+
/// <summary>
9+
/// Animation will be forced to end when its value reaches upper/lower bound (if they have been
10+
/// defined, e.g. via <c>Animatable.updateBounds</c>).
11+
/// Unlike <see cref="Finished"/>, when an animation ends due to <see cref="BoundReached"/>, it often falls
12+
/// short from its initial target, and the remaining velocity is often non-zero. Both the end value and the
13+
/// remaining velocity can be obtained via <c>AnimationResult</c>.
14+
/// </summary>
15+
BoundReached,
16+
17+
/// <summary>
18+
/// Animation has finished successfully without any interruption.
19+
/// </summary>
20+
Finished,
21+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
namespace MaterialDesignThemes.Motion;
2+
3+
/// <summary>
4+
/// Animation specs of duration, easing and repeat delay.
5+
/// </summary>
6+
public sealed class AnimationParameters
7+
{
8+
/// <summary>
9+
/// The duration of the animation.
10+
/// </summary>
11+
/// <remarks>
12+
/// If not set, defaults to 300ms.
13+
/// </remarks>
14+
public TimeSpan Duration { get; set; } = TimeSpan.FromMilliseconds(300);
15+
16+
/// <summary>
17+
/// The easing to be used for adjusting an animation's fraction.
18+
/// </summary>
19+
/// <remarks>
20+
/// If not set, defaults to Linear Interpolation.
21+
/// </remarks>
22+
public Easing? Easing { get; set; }
23+
24+
/// <summary>
25+
/// Animation delay in millis.
26+
/// </summary>
27+
/// <remarks>
28+
/// When used outside repeatable, this is the delay to start the animation.
29+
/// When set inside repeatable, this is the delay before repeating animation.
30+
/// If not set, no delay will be applied.
31+
/// </remarks>
32+
public TimeSpan? Delay { get; set; } = TimeSpan.FromMilliseconds(3);
33+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
namespace MaterialDesignThemes.Motion;
2+
3+
/// <summary>
4+
/// Animation parameters that can be added to any animatable node.
5+
/// </summary>
6+
public sealed class AnimationSpec
7+
{
8+
/// <summary>
9+
/// Animation parameters including duration, easing and repeat delay.
10+
/// </summary>
11+
public AnimationParameters AnimationParameters { get; set; } = new();
12+
13+
/// <summary>
14+
/// The repeatable mode to be used for specifying repetition parameters for the animation.
15+
/// </summary>
16+
/// <remarks>
17+
/// If not set, animation won't be repeated.
18+
/// </remarks>
19+
public Repeatable? Repeatable { get; set; }
20+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
namespace MaterialDesignThemes.Motion;
2+
3+
/// <summary>
4+
/// <see cref="AnimationVector"/> class that is the base class of <see cref="AnimationVector1D"/>,
5+
/// <see cref="AnimationVector2D"/>, <see cref="AnimationVector3D"/> and <see cref="AnimationVector4D"/>.
6+
/// In order to animate any arbitrary type, it is required to provide a <see cref="ITwoWayConverter{T,TAnimationVector}"/>
7+
/// that defines how to convert that arbitrary type T to an <see cref="AnimationVector"/>, and vice versa.
8+
/// </summary>
9+
public abstract class AnimationVector
10+
{
11+
internal abstract void Reset();
12+
13+
internal abstract AnimationVector NewVector();
14+
15+
internal abstract float GetValue(int index);
16+
17+
internal abstract void SetValue(int index, float value);
18+
19+
internal abstract int Size { get; }
20+
21+
public float this[int index]
22+
{
23+
get => GetValue(index);
24+
set => SetValue(index, value);
25+
}
26+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
namespace MaterialDesignThemes.Motion;
2+
3+
/// <summary>
4+
/// This class defines a 1D vector. It contains only one Float value that is initialized in the constructor.
5+
/// </summary>
6+
public sealed class AnimationVector1D : AnimationVector
7+
{
8+
public AnimationVector1D()
9+
: this(0f)
10+
{
11+
}
12+
13+
public AnimationVector1D(float value)
14+
{
15+
Value = value;
16+
}
17+
18+
public float Value { get; internal set; }
19+
20+
internal override void Reset() => Value = 0f;
21+
22+
internal override AnimationVector NewVector() => new AnimationVector1D(0f);
23+
24+
internal override float GetValue(int index) => index == 0 ? Value : 0f;
25+
26+
internal override void SetValue(int index, float value)
27+
{
28+
if (index == 0)
29+
{
30+
Value = value;
31+
}
32+
}
33+
34+
internal override int Size => 1;
35+
36+
public override string ToString() => $"AnimationVector1D(Value = {Value})";
37+
38+
public override bool Equals(object? obj) =>
39+
obj is AnimationVector1D other && other.Value.Equals(Value);
40+
41+
public override int GetHashCode() => Value.GetHashCode();
42+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
namespace MaterialDesignThemes.Motion;
2+
3+
/// <summary>
4+
/// This class defines a 2D vector that contains two Float value fields.
5+
/// </summary>
6+
public sealed class AnimationVector2D : AnimationVector
7+
{
8+
public AnimationVector2D()
9+
: this(0f, 0f)
10+
{
11+
}
12+
13+
public AnimationVector2D(float v1, float v2)
14+
{
15+
V1 = v1;
16+
V2 = v2;
17+
}
18+
19+
public float V1 { get; internal set; }
20+
21+
public float V2 { get; internal set; }
22+
23+
internal override void Reset()
24+
{
25+
V1 = 0f;
26+
V2 = 0f;
27+
}
28+
29+
internal override AnimationVector NewVector() => new AnimationVector2D(0f, 0f);
30+
31+
internal override float GetValue(int index) => index switch
32+
{
33+
0 => V1,
34+
1 => V2,
35+
_ => 0f,
36+
};
37+
38+
internal override void SetValue(int index, float value)
39+
{
40+
switch (index)
41+
{
42+
case 0:
43+
V1 = value;
44+
break;
45+
case 1:
46+
V2 = value;
47+
break;
48+
}
49+
}
50+
51+
internal override int Size => 2;
52+
53+
public override string ToString() => $"AnimationVector2D(V1 = {V1}, V2 = {V2})";
54+
55+
public override bool Equals(object? obj) =>
56+
obj is AnimationVector2D other && other.V1.Equals(V1) && other.V2.Equals(V2);
57+
58+
public override int GetHashCode() => HashCode.Combine(V1, V2);
59+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
namespace MaterialDesignThemes.Motion;
2+
3+
/// <summary>
4+
/// This class defines a 3D vector that contains three Float value fields for the three dimensions.
5+
/// </summary>
6+
public sealed class AnimationVector3D : AnimationVector
7+
{
8+
public AnimationVector3D()
9+
: this(0f, 0f, 0f)
10+
{
11+
}
12+
13+
public AnimationVector3D(float v1, float v2, float v3)
14+
{
15+
V1 = v1;
16+
V2 = v2;
17+
V3 = v3;
18+
}
19+
20+
public float V1 { get; internal set; }
21+
22+
public float V2 { get; internal set; }
23+
24+
public float V3 { get; internal set; }
25+
26+
internal override void Reset()
27+
{
28+
V1 = 0f;
29+
V2 = 0f;
30+
V3 = 0f;
31+
}
32+
33+
internal override AnimationVector NewVector() => new AnimationVector3D(0f, 0f, 0f);
34+
35+
internal override float GetValue(int index) => index switch
36+
{
37+
0 => V1,
38+
1 => V2,
39+
2 => V3,
40+
_ => 0f,
41+
};
42+
43+
internal override void SetValue(int index, float value)
44+
{
45+
switch (index)
46+
{
47+
case 0:
48+
V1 = value;
49+
break;
50+
case 1:
51+
V2 = value;
52+
break;
53+
case 2:
54+
V3 = value;
55+
break;
56+
}
57+
}
58+
59+
internal override int Size => 3;
60+
61+
public override string ToString() => $"AnimationVector3D(V1 = {V1}, V2 = {V2}, V3 = {V3})";
62+
63+
public override bool Equals(object? obj) =>
64+
obj is AnimationVector3D other &&
65+
other.V1.Equals(V1) &&
66+
other.V2.Equals(V2) &&
67+
other.V3.Equals(V3);
68+
69+
public override int GetHashCode() => HashCode.Combine(V1, V2, V3);
70+
}

0 commit comments

Comments
 (0)