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.Graphics;
6using osu.Framework.Graphics.Containers;
7using osu.Framework.Graphics.Shapes;
8using osu.Framework.Graphics.Sprites;
9using osu.Framework.Graphics.Textures;
10using osu.Framework.Platform;
11using osuTK;
12using osuTK.Graphics;
13
14namespace osu.Framework.Tests.Visual.Sprites
15{
16 public class TestSceneScreenshot : FrameworkTestScene
17 {
18 [Resolved]
19 private GameHost host { get; set; }
20
21 private Drawable background;
22 private Sprite display;
23
24 [BackgroundDependencyLoader]
25 private void load()
26 {
27 Child = new Container
28 {
29 Anchor = Anchor.Centre,
30 Origin = Anchor.Centre,
31 RelativeSizeAxes = Axes.Both,
32 Size = new Vector2(0.5f),
33 Masking = true,
34 BorderColour = Color4.Green,
35 BorderThickness = 2,
36 Children = new[]
37 {
38 background = new Box
39 {
40 RelativeSizeAxes = Axes.Both,
41 Colour = Color4.Red,
42 Alpha = 0
43 },
44 display = new Sprite { RelativeSizeAxes = Axes.Both }
45 }
46 };
47
48 AddStep("take screenshot", takeScreenshot);
49 }
50
51 private void takeScreenshot()
52 {
53 if (host.Window == null)
54 return;
55
56 host.TakeScreenshotAsync().ContinueWith(t => Schedule(() =>
57 {
58 var image = t.Result;
59
60 var tex = new Texture(image.Width, image.Height);
61 tex.SetData(new TextureUpload(image));
62
63 display.Texture = tex;
64 background.Show();
65 }));
66 }
67 }
68}