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 NUnit.Framework;
5using osu.Framework.Graphics;
6using osu.Framework.Graphics.Containers;
7using osu.Framework.Graphics.Shapes;
8using osu.Framework.Graphics.Sprites;
9using osu.Framework.Input.Events;
10using osu.Framework.Tests.Visual.Containers;
11using osuTK;
12using osuTK.Graphics;
13
14namespace osu.Framework.Tests.Visual.Sprites
15{
16 public class TestSceneBufferedContainerView : FrameworkTestScene
17 {
18 [TestCase(false)]
19 [TestCase(true)]
20 public void TestNoEffects(bool originalEffects) => createTest(0, 0, originalEffects);
21
22 [Test]
23 public void TestSubtractOriginalBlur() => createTest(10, 0, false);
24
25 [Test]
26 public void TestCopyOriginalBlur() => createTest(10, 0, true);
27
28 [TestCase(false)]
29 [TestCase(true)]
30 public void TestBlurViewOnly(bool originalEffects) => createTest(0, 10, originalEffects);
31
32 [TestCase(false)]
33 [TestCase(true)]
34 public void TestBlurBoth(bool originalEffects) => createTest(10, 20, originalEffects);
35
36 [Test]
37 public void TestNonSynchronisedQuad() => createTest(10, 0, false, false);
38
39 private void createTest(float originalBlur, float viewBlur, bool originalEffects, bool synchronisedQuad = true)
40 {
41 AddStep("create container", () =>
42 {
43 BufferedContainer container = new BufferedContainer
44 {
45 Anchor = Anchor.Centre,
46 Origin = Anchor.Centre,
47 RelativeSizeAxes = Axes.Both,
48 Scale = new Vector2(0.75f),
49 BlurSigma = new Vector2(originalBlur),
50 Child = new TestSceneCachedBufferedContainer()
51 };
52
53 Children = new Drawable[]
54 {
55 container,
56 new BlurView(container, viewBlur, originalEffects, synchronisedQuad)
57 {
58 Position = new Vector2(100, 100)
59 }
60 };
61 });
62 }
63
64 private class BlurView : CompositeDrawable
65 {
66 public BlurView(BufferedContainer buffer, float blur, bool displayEffects, bool synchronisedQuad)
67 {
68 Size = new Vector2(200);
69 Masking = true;
70 CornerRadius = 20;
71 BorderColour = Color4.Magenta;
72 BorderThickness = 2;
73
74 InternalChildren = new Drawable[]
75 {
76 new GridContainer
77 {
78 RelativeSizeAxes = Axes.Both,
79 Content = new[]
80 {
81 new Drawable[]
82 {
83 new Container
84 {
85 RelativeSizeAxes = Axes.Both,
86 Children = new Drawable[]
87 {
88 new Box
89 {
90 RelativeSizeAxes = Axes.Both,
91 Colour = Color4.Magenta
92 },
93 new SpriteText
94 {
95 Anchor = Anchor.Centre,
96 Origin = Anchor.Centre,
97 Text = "You can drag this view.",
98 Font = new FontUsage(size: 16),
99 }
100 }
101 }
102 },
103 new Drawable[]
104 {
105 new BufferedContainer
106 {
107 RelativeSizeAxes = Axes.Both,
108 BackgroundColour = Color4.Black,
109 BlurSigma = new Vector2(blur),
110 Child = buffer.CreateView().With(d =>
111 {
112 d.RelativeSizeAxes = Axes.Both;
113 d.SynchronisedDrawQuad = synchronisedQuad;
114 d.DisplayOriginalEffects = displayEffects;
115 })
116 }
117 },
118 },
119 RowDimensions = new[]
120 {
121 new Dimension(GridSizeMode.Absolute, 20),
122 }
123 }
124 };
125 }
126
127 protected override void OnDrag(DragEvent e)
128 {
129 Position += e.Delta;
130 }
131
132 protected override bool OnDragStart(DragStartEvent e) => true;
133 }
134 }
135}