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.Primitives;
8using osu.Framework.Graphics.Sprites;
9using osu.Framework.Graphics.Textures;
10using osu.Framework.Testing;
11using osuTK;
12
13namespace osu.Framework.Tests.Visual.Sprites
14{
15 public class TestSceneTextureCropping : GridTestScene
16 {
17 public TestSceneTextureCropping()
18 : base(3, 3)
19 {
20 }
21
22 protected override void LoadComplete()
23 {
24 base.LoadComplete();
25
26 for (int i = 0; i < Rows; ++i)
27 {
28 for (int j = 0; j < Cols; ++j)
29 {
30 RectangleF cropRectangle = new RectangleF(i / 3f, j / 3f, 1 / 3f, 1 / 3f);
31 Cell(i, j).AddRange(new Drawable[]
32 {
33 new SpriteText
34 {
35 Text = $"{cropRectangle}",
36 Font = new FontUsage(size: 14),
37 },
38 new Container
39 {
40 RelativeSizeAxes = Axes.Both,
41 Size = new Vector2(0.5f),
42 Anchor = Anchor.Centre,
43 Origin = Anchor.Centre,
44 Masking = true,
45 Children = new Drawable[]
46 {
47 new Sprite
48 {
49 RelativeSizeAxes = Axes.Both,
50 Texture = texture?.Crop(cropRectangle, relativeSizeAxes: Axes.Both),
51 Anchor = Anchor.Centre,
52 Origin = Anchor.Centre,
53 }
54 }
55 }
56 });
57 }
58 }
59 }
60
61 private Texture texture;
62
63 [BackgroundDependencyLoader]
64 private void load(TextureStore store)
65 {
66 texture = store.Get(@"sample-texture");
67 }
68 }
69}