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.Testing;
11using osuTK;
12using osuTK.Graphics;
13
14namespace osu.Framework.Tests.Visual.Drawables
15{
16 [System.ComponentModel.Description("sprite stretching")]
17 public class TestSceneFillModes : GridTestScene
18 {
19 public TestSceneFillModes()
20 : base(3, 3)
21 {
22 }
23
24 protected override void LoadComplete()
25 {
26 base.LoadComplete();
27
28 FillMode[] fillModes =
29 {
30 FillMode.Stretch,
31 FillMode.Fit,
32 FillMode.Fill,
33 };
34
35 float[] aspects = { 1, 2, 0.5f };
36
37 for (int i = 0; i < Rows; ++i)
38 {
39 for (int j = 0; j < Cols; ++j)
40 {
41 Cell(i, j).AddRange(new Drawable[]
42 {
43 new SpriteText
44 {
45 Text = $"{nameof(FillMode)}=FillMode.{fillModes[i]}, {nameof(FillAspectRatio)}={aspects[j]}",
46 Font = new FontUsage(size: 20),
47 },
48 new Container
49 {
50 RelativeSizeAxes = Axes.Both,
51 Size = new Vector2(0.5f),
52 Anchor = Anchor.Centre,
53 Origin = Anchor.Centre,
54 Masking = true,
55 Children = new Drawable[]
56 {
57 new Box
58 {
59 RelativeSizeAxes = Axes.Both,
60 Colour = Color4.Blue,
61 },
62 new Sprite
63 {
64 RelativeSizeAxes = Axes.Both,
65 Texture = texture,
66 Anchor = Anchor.Centre,
67 Origin = Anchor.Centre,
68 FillMode = fillModes[i],
69 FillAspectRatio = aspects[j],
70 }
71 }
72 }
73 });
74 }
75 }
76 }
77
78 private Texture texture;
79
80 [BackgroundDependencyLoader]
81 private void load(TextureStore store)
82 {
83 texture = store.Get(@"sample-texture");
84 }
85 }
86}