forked from ppy/osu-framework
/
TestCaseScreen.cs
119 lines (109 loc) · 4.12 KB
/
TestCaseScreen.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
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu-framework/master/LICENCE
using System;
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.UserInterface;
using osu.Framework.MathUtils;
using osu.Framework.Screens;
using osu.Framework.Testing;
using OpenTK;
using OpenTK.Graphics;
namespace osu.Framework.Tests.Visual
{
[TestFixture]
public class TestCaseScreen : TestCase
{
public TestCaseScreen()
{
Add(new TestScreen());
}
private class TestScreen : Screen
{
public int Sequence;
private Button popButton;
private const int transition_time = 500;
protected override void OnEntering(Screen last)
{
if (last != null)
{
//only show the pop button if we are entered form another screen.
popButton.Alpha = 1;
}
Content.MoveTo(new Vector2(0, -DrawSize.Y));
Content.MoveTo(Vector2.Zero, transition_time, Easing.OutQuint);
}
protected override bool OnExiting(Screen next)
{
Content.MoveTo(new Vector2(0, -DrawSize.Y), transition_time, Easing.OutQuint);
return base.OnExiting(next);
}
protected override void OnSuspending(Screen next)
{
Content.MoveTo(new Vector2(0, DrawSize.Y), transition_time, Easing.OutQuint);
}
protected override void OnResuming(Screen last)
{
Content.MoveTo(Vector2.Zero, transition_time, Easing.OutQuint);
}
[BackgroundDependencyLoader]
private void load()
{
Children = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Size = new Vector2(1),
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Colour = new Color4(
Math.Max(0.5f, RNG.NextSingle()),
Math.Max(0.5f, RNG.NextSingle()),
Math.Max(0.5f, RNG.NextSingle()),
1),
},
new SpriteText
{
Text = $@"Mode {Sequence}",
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
TextSize = 50,
},
popButton = new Button
{
Text = @"Pop",
RelativeSizeAxes = Axes.Both,
Size = new Vector2(0.1f),
Anchor = Anchor.TopLeft,
Origin = Anchor.TopLeft,
BackgroundColour = Color4.Red,
Alpha = 0,
Action = Exit
},
new Button
{
Text = @"Push",
RelativeSizeAxes = Axes.Both,
Size = new Vector2(0.1f),
Anchor = Anchor.TopRight,
Origin = Anchor.TopRight,
BackgroundColour = Color4.YellowGreen,
Action = delegate
{
Push(new TestScreen
{
Sequence = Sequence + 1,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
});
}
}
};
}
}
}
}