-
Notifications
You must be signed in to change notification settings - Fork 436
/
Copy pathTestSceneLayoutDurations.cs
145 lines (115 loc) · 4.03 KB
/
TestSceneLayoutDurations.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
#nullable disable
using NUnit.Framework;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Input.Events;
using osu.Framework.Utils;
using osu.Framework.Timing;
using osuTK;
using osuTK.Graphics;
namespace osu.Framework.Tests.Visual.Layout
{
public partial class TestSceneLayoutDurations : FrameworkTestScene
{
private ManualClock manualClock;
private FillFlowContainer fillFlowContainer;
private Box box;
private const float duration = 1000;
private const float changed_value = 100;
[SetUp]
public void SetUp() => Schedule(() =>
{
manualClock = new ManualClock();
Children = new Drawable[]
{
fillFlowContainer = new FillFlowContainer
{
Clock = new FramedClock(manualClock),
Position = new Vector2(0, 200),
LayoutEasing = Easing.None,
Children = new Drawable[]
{
new Box { Colour = Color4.Red, Size = new Vector2(100) },
box = new Box { Colour = Color4.Blue, Size = new Vector2(100) },
}
}
};
paused = false;
fillFlowContainer.FinishTransforms();
fillFlowContainer.LayoutDuration = 0;
fillFlowContainer.Size = new Vector2(200, 200);
});
private void check(float ratio) =>
AddAssert($"Check @{ratio}", () => Precision.AlmostEquals(box.Position, new Vector2(changed_value * (1 - ratio), changed_value * ratio)));
private void skipTo(float ratio) => AddStep($"skip to {ratio}", () => { manualClock.CurrentTime = duration * ratio; });
[Test]
public void TestChangeAfterDuration()
{
AddStep("Start transformation", () =>
{
paused = true;
manualClock.CurrentTime = 0;
fillFlowContainer.FinishTransforms();
fillFlowContainer.LayoutDuration = duration;
fillFlowContainer.Width = 100;
});
foreach (float ratio in new[] { .25f, .5f, .75f, 1 })
{
skipTo(ratio);
check(ratio);
}
}
[Test]
public void TestInterruptExistingDuration()
{
AddStep("Start transformation", () =>
{
paused = true;
manualClock.CurrentTime = 0;
fillFlowContainer.FinishTransforms();
fillFlowContainer.LayoutDuration = duration;
box.Size = new Vector2(changed_value);
fillFlowContainer.Width = changed_value;
});
skipTo(0.5f);
check(0.5f);
AddStep("set duration 0", () =>
{
fillFlowContainer.LayoutDuration = 0;
});
// transform should still be playing
skipTo(0.75f);
check(0.75f);
// check rewind works just for fun
skipTo(0.5f);
check(0.5f);
AddStep("alter values", () =>
{
fillFlowContainer.Width = 200;
});
// fully complete
check(0);
// no remaining transform
skipTo(1);
check(0);
}
private bool paused;
protected override void Update()
{
if (fillFlowContainer != null)
{
if (!paused) manualClock.CurrentTime = Clock.CurrentTime;
fillFlowContainer.Invalidate();
}
base.Update();
}
protected override bool OnClick(ClickEvent e)
{
paused = !paused;
return base.OnClick(e);
}
}
}