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.Collections.Generic;
5using NUnit.Framework;
6using osu.Framework.Graphics;
7using osu.Framework.Graphics.Containers;
8using osu.Framework.Graphics.Lines;
9using osu.Framework.Graphics.Shapes;
10using osu.Framework.Graphics.Textures;
11using osu.Framework.Utils;
12using osuTK;
13using osuTK.Graphics;
14using SixLabors.ImageSharp;
15using SixLabors.ImageSharp.PixelFormats;
16
17namespace osu.Framework.Tests.Visual.UserInterface
18{
19 public class TestSceneDrawablePath : FrameworkTestScene
20 {
21 private const int texture_width = 20;
22
23 private readonly Texture gradientTexture = new Texture(texture_width, 1, true);
24
25 public TestSceneDrawablePath()
26 {
27 var image = new Image<Rgba32>(texture_width, 1);
28
29 for (int i = 0; i < texture_width; ++i)
30 {
31 var brightnessByte = (byte)((float)i / (texture_width - 1) * 255);
32 image[i, 0] = new Rgba32(255, 255, 255, brightnessByte);
33 }
34
35 gradientTexture.SetData(new TextureUpload(image));
36 }
37
38 [Test]
39 public void TestSimplePath()
40 {
41 AddStep("create path", () =>
42 {
43 Child = new TexturedPath
44 {
45 Anchor = Anchor.Centre,
46 Origin = Anchor.Centre,
47 Vertices = new List<Vector2> { Vector2.Zero, new Vector2(300, 300) },
48 Texture = gradientTexture,
49 };
50 });
51 }
52
53 [Test]
54 public void TestMultiplePointPath()
55 {
56 AddStep("create path", () =>
57 {
58 Child = new TexturedPath
59 {
60 Anchor = Anchor.Centre,
61 Origin = Anchor.Centre,
62 Vertices = new List<Vector2>
63 {
64 new Vector2(50, 50),
65 new Vector2(50, 150),
66 new Vector2(150, 150),
67 new Vector2(150, 50),
68 new Vector2(50, 50),
69 },
70 Texture = gradientTexture,
71 };
72 });
73 }
74
75 [Test]
76 public void TestSelfOverlappingPath()
77 {
78 AddStep("create path", () =>
79 {
80 Child = new TexturedPath
81 {
82 Anchor = Anchor.Centre,
83 Origin = Anchor.Centre,
84 Vertices = new List<Vector2>
85 {
86 new Vector2(50, 50),
87 new Vector2(50, 150),
88 new Vector2(150, 150),
89 new Vector2(150, 100),
90 new Vector2(20, 100),
91 },
92 Texture = gradientTexture,
93 };
94 });
95 }
96
97 [Test]
98 public void TestSmoothPath()
99 {
100 AddStep("create path", () =>
101 {
102 Child = new SmoothPath
103 {
104 Anchor = Anchor.Centre,
105 Origin = Anchor.Centre,
106 PathRadius = 10,
107 Vertices = new List<Vector2>
108 {
109 Vector2.Zero,
110 new Vector2(200)
111 },
112 };
113 });
114 }
115
116 [Test]
117 public void TestUnsmoothPath()
118 {
119 AddStep("create path", () =>
120 {
121 Child = new Path
122 {
123 Anchor = Anchor.Centre,
124 Origin = Anchor.Centre,
125 PathRadius = 10,
126 Vertices = new List<Vector2>
127 {
128 Vector2.Zero,
129 new Vector2(200)
130 },
131 };
132 });
133 }
134
135 [Test]
136 public void TestPathBlending()
137 {
138 AddStep("create path", () =>
139 {
140 Children = new Drawable[]
141 {
142 new Box
143 {
144 Anchor = Anchor.Centre,
145 Origin = Anchor.Centre,
146 Size = new Vector2(200)
147 },
148 new TexturedPath
149 {
150 Anchor = Anchor.Centre,
151 Origin = Anchor.Centre,
152 Colour = Color4.Red,
153 Vertices = new List<Vector2>
154 {
155 new Vector2(50, 50),
156 new Vector2(50, 150),
157 new Vector2(150, 150),
158 new Vector2(150, 100),
159 new Vector2(20, 100),
160 },
161 Texture = gradientTexture,
162 }
163 };
164 });
165 }
166
167 [Test]
168 public void TestSizing()
169 {
170 Path path = null;
171
172 AddStep("create autosize path", () =>
173 {
174 Child = new Container
175 {
176 Anchor = Anchor.Centre,
177 Origin = Anchor.Centre,
178 Size = new Vector2(200),
179 Child = path = new Path
180 {
181 Anchor = Anchor.Centre,
182 Origin = Anchor.Centre,
183 PathRadius = 10,
184 Vertices = new List<Vector2>
185 {
186 Vector2.Zero,
187 new Vector2(100, 0)
188 },
189 }
190 };
191 });
192
193 AddAssert("size = (120, 20)", () => Precision.AlmostEquals(new Vector2(120, 20), path.DrawSize));
194
195 AddStep("make path relative-sized", () =>
196 {
197 path.AutoSizeAxes = Axes.None;
198 path.RelativeSizeAxes = Axes.Both;
199 path.Size = Vector2.One;
200 });
201
202 AddAssert("size = (200, 200)", () => Precision.AlmostEquals(new Vector2(200), path.DrawSize));
203
204 AddStep("make path absolute-sized", () =>
205 {
206 path.RelativeSizeAxes = Axes.None;
207 path.Size = new Vector2(100);
208 });
209
210 AddAssert("size = (100, 100)", () => Precision.AlmostEquals(new Vector2(100), path.DrawSize));
211 }
212 }
213}