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.Graphics;
5using osu.Framework.Graphics.Containers;
6using osu.Framework.Graphics.Shapes;
7using osu.Framework.Graphics.Sprites;
8using osuTK;
9using osuTK.Graphics;
10
11namespace osu.Framework.Tests.Visual.Containers
12{
13 [System.ComponentModel.Description("changing depth of child dynamically")]
14 public class TestSceneDynamicDepth : FrameworkTestScene
15 {
16 private void addDepthSteps(DepthBox box, Container container)
17 {
18 AddStep($@"bring forward {box.Name}", () => container.ChangeChildDepth(box, box.Depth - 1));
19 AddStep($@"send backward {box.Name}", () => container.ChangeChildDepth(box, box.Depth + 1));
20 }
21
22 public TestSceneDynamicDepth()
23 {
24 DepthBox red, blue, green, purple;
25 Container container;
26
27 AddRange(new[]
28 {
29 container = new Container
30 {
31 Anchor = Anchor.Centre,
32 Origin = Anchor.Centre,
33 Size = new Vector2(340),
34 Children = new[]
35 {
36 red = new DepthBox(Color4.Red, Anchor.TopLeft) { Name = "red" },
37 blue = new DepthBox(Color4.Blue, Anchor.TopRight) { Name = "blue" },
38 green = new DepthBox(Color4.Green, Anchor.BottomRight) { Name = "green" },
39 purple = new DepthBox(Color4.Purple, Anchor.BottomLeft) { Name = "purple" },
40 }
41 }
42 });
43
44 addDepthSteps(red, container);
45 addDepthSteps(blue, container);
46 addDepthSteps(green, container);
47 addDepthSteps(purple, container);
48 }
49
50 private class DepthBox : Container
51 {
52 private readonly SpriteText depthText;
53
54 public DepthBox(Color4 colour, Anchor anchor)
55 {
56 Size = new Vector2(240);
57 Anchor = Origin = anchor;
58
59 AddRange(new Drawable[]
60 {
61 new Box
62 {
63 RelativeSizeAxes = Axes.Both,
64 Colour = colour,
65 },
66 depthText = new SpriteText
67 {
68 Anchor = anchor,
69 Origin = anchor,
70 }
71 });
72 }
73
74 protected override void Update()
75 {
76 base.Update();
77
78 depthText.Text = $@"Depth: {Depth}";
79 }
80 }
81 }
82}