A game framework written with osu! in mind.
1// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
2// See the LICENCE file in the repository root for full licence text.
3
4using osu.Framework.Allocation;
5using osu.Framework.Bindables;
6using osu.Framework.Graphics;
7using osu.Framework.Graphics.Containers;
8using osu.Framework.Graphics.Shapes;
9using osu.Framework.Graphics.Sprites;
10using osu.Framework.Platform;
11using osuTK.Graphics;
12
13namespace osu.Framework.Tests.Visual.Platform
14{
15 public class TestSceneActiveState : FrameworkTestScene
16 {
17 private IBindable<bool> isActive;
18 private IBindable<bool> cursorInWindow;
19
20 private Drawable isActiveBox;
21 private Drawable cursorInWindowBox;
22
23 [BackgroundDependencyLoader]
24 private void load(GameHost host)
25 {
26 isActive = host.IsActive.GetBoundCopy();
27 cursorInWindow = host.Window?.CursorInWindow.GetBoundCopy();
28 }
29
30 protected override void LoadComplete()
31 {
32 base.LoadComplete();
33
34 Children = new[]
35 {
36 isActiveBox = new DisplayBox("host.IsActive")
37 {
38 Width = 0.5f,
39 RelativeSizeAxes = Axes.Both,
40 },
41 cursorInWindowBox = new DisplayBox("host.Window.CursorInWindow")
42 {
43 RelativeSizeAxes = Axes.Both,
44 Width = 0.5f,
45 Anchor = Anchor.TopRight,
46 Origin = Anchor.TopRight,
47 },
48 };
49
50 isActive.BindValueChanged(active => isActiveBox.Colour = active.NewValue ? Color4.Green : Color4.Red, true);
51 cursorInWindow?.BindValueChanged(active => cursorInWindowBox.Colour = active.NewValue ? Color4.Green : Color4.Red, true);
52 }
53
54 public class DisplayBox : CompositeDrawable
55 {
56 public DisplayBox(string label)
57 {
58 InternalChildren = new Drawable[]
59 {
60 new Box
61 {
62 Colour = Color4.White,
63 RelativeSizeAxes = Axes.Both,
64 },
65 new SpriteText
66 {
67 Text = label,
68 Colour = Color4.Black,
69 Anchor = Anchor.Centre,
70 Origin = Anchor.Centre,
71 }
72 };
73 }
74 }
75 }
76}