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 System;
5using osu.Framework.Allocation;
6using osu.Framework.Graphics;
7using osu.Framework.Graphics.Animations;
8using osu.Framework.Graphics.Containers;
9using osu.Framework.Graphics.Shapes;
10using osu.Framework.Graphics.Sprites;
11using osu.Framework.Graphics.Textures;
12using osu.Framework.IO.Stores;
13using osu.Framework.Testing;
14using osuTK;
15using osuTK.Graphics;
16
17namespace osu.Framework.Tests.Visual.Sprites
18{
19 public class TestSceneAnimationLayout : GridTestScene
20 {
21 public TestSceneAnimationLayout()
22 : base(2, 3)
23 {
24 Cell(0, 0).Child = createTest("texture - auto size", () => new TestTextureAnimation());
25 Cell(0, 1).Child = createTest("texture - relative size + fit", () => new TestTextureAnimation
26 {
27 RelativeSizeAxes = Axes.Both,
28 FillMode = FillMode.Fit
29 });
30 Cell(0, 2).Child = createTest("texture - fixed size", () => new TestTextureAnimation { Size = new Vector2(100, 50) });
31
32 Cell(1, 0).Child = createTest("drawable - auto size", () => new TestDrawableAnimation());
33 Cell(1, 1).Child = createTest("drawable - relative size + fit", () => new TestDrawableAnimation(Axes.Both)
34 {
35 RelativeSizeAxes = Axes.Both,
36 FillMode = FillMode.Fit
37 });
38 Cell(1, 2).Child = createTest("drawable - fixed size", () => new TestDrawableAnimation(Axes.Both) { Size = new Vector2(100, 50) });
39 }
40
41 private Drawable createTest(string name, Func<Drawable> animationCreationFunc) => new Container
42 {
43 RelativeSizeAxes = Axes.Both,
44 Padding = new MarginPadding(10),
45 Child = new GridContainer
46 {
47 RelativeSizeAxes = Axes.Both,
48 Content = new[]
49 {
50 new Drawable[]
51 {
52 new SpriteText
53 {
54 Anchor = Anchor.TopCentre,
55 Origin = Anchor.TopCentre,
56 Text = name
57 },
58 },
59 new Drawable[]
60 {
61 new Container
62 {
63 RelativeSizeAxes = Axes.Both,
64 Masking = true,
65 BorderColour = Color4.OrangeRed,
66 BorderThickness = 2,
67 Children = new[]
68 {
69 new Box
70 {
71 RelativeSizeAxes = Axes.Both,
72 Alpha = 0,
73 AlwaysPresent = true
74 },
75 animationCreationFunc()
76 }
77 }
78 },
79 },
80 RowDimensions = new[] { new Dimension(GridSizeMode.AutoSize) }
81 }
82 };
83
84 private class TestDrawableAnimation : DrawableAnimation
85 {
86 public TestDrawableAnimation(Axes contentRelativeAxes = Axes.None)
87 {
88 Anchor = Anchor.Centre;
89 Origin = Anchor.Centre;
90
91 for (int i = 1; i <= 60; i++)
92 {
93 var c = new Container
94 {
95 RelativeSizeAxes = contentRelativeAxes,
96 Children = new Drawable[]
97 {
98 new Box
99 {
100 RelativeSizeAxes = Axes.Both,
101 Colour = Color4.SlateGray
102 },
103 new SpriteText
104 {
105 Anchor = Anchor.Centre,
106 Origin = Anchor.Centre,
107 Text = i.ToString()
108 }
109 }
110 };
111
112 if ((contentRelativeAxes & Axes.X) == 0)
113 c.Width = 100;
114
115 if ((contentRelativeAxes & Axes.Y) == 0)
116 c.Height = 100;
117
118 AddFrame(c);
119 }
120 }
121 }
122
123 private class TestTextureAnimation : TextureAnimation
124 {
125 [Resolved]
126 private FontStore fontStore { get; set; }
127
128 public TestTextureAnimation()
129 {
130 Anchor = Anchor.Centre;
131 Origin = Anchor.Centre;
132 }
133
134 [BackgroundDependencyLoader]
135 private void load()
136 {
137 for (int i = 0; i <= 9; i++)
138 AddFrame(new Texture(fontStore.Get(null, i.ToString()[0])?.Texture.TextureGL) { ScaleAdjust = 1 + i / 2 }, 1000.0 / 60 * 6);
139 }
140 }
141 }
142}