/
TestSceneWindowFlash.cs
73 lines (66 loc) · 2.39 KB
/
TestSceneWindowFlash.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
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System.Runtime.Versioning;
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Platform;
namespace osu.Framework.Tests.Visual.Platform
{
[Ignore("This test cannot run in headless mode (a window instance is required).")]
[SupportedOSPlatform("windows")]
[SupportedOSPlatform("linux")]
[SupportedOSPlatform("macos")]
public partial class TestSceneWindowFlash : FrameworkTestScene
{
private IBindable<bool> isActive = null!;
private IWindow? window;
private SpriteText text = null!;
private readonly Bindable<bool> flashUntilFocused = new BindableBool();
[BackgroundDependencyLoader]
private void load(GameHost gameHost)
{
isActive = gameHost.IsActive.GetBoundCopy();
window = gameHost.Window;
Child = new FillFlowContainer
{
Direction = FillDirection.Vertical,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Children = new Drawable[]
{
text = new SpriteText
{
Text = "This window will flash as soon as you un-focus it.",
Anchor = Anchor.Centre,
Origin = Anchor.Centre
},
}
};
}
protected override void LoadComplete()
{
base.LoadComplete();
flashUntilFocused.BindValueChanged(e =>
{
window?.CancelFlash();
text.Text = "This window will flash "
+ (e.NewValue ? "continuously, until focused again, " : "briefly")
+ " as soon as it is unfocused.";
}, true);
isActive.BindValueChanged(e =>
{
if (!e.NewValue)
window?.Flash(flashUntilFocused.Value);
}, true);
}
[Test]
public void TestBasic()
{
AddToggleStep("Flash until focused", a => flashUntilFocused.Value = a);
}
}
}