A game framework written with osu! in mind.
at master 109 lines 4.1 kB view raw
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; 5using NUnit.Framework; 6using osu.Framework.Allocation; 7using osu.Framework.Graphics; 8using osu.Framework.Graphics.Containers; 9using osu.Framework.Graphics.OpenGL.Textures; 10using osu.Framework.Graphics.Primitives; 11using osu.Framework.Graphics.Shapes; 12using osu.Framework.Graphics.Sprites; 13using osu.Framework.Graphics.Textures; 14using osu.Framework.Testing; 15using osuTK; 16using osuTK.Graphics; 17 18namespace osu.Framework.Tests.Visual.Sprites 19{ 20 [System.ComponentModel.Description("texture wrap modes")] 21 public class TestSceneWrapModes : GridTestScene 22 { 23 private readonly WrapMode[] wrapModes = { WrapMode.None, WrapMode.ClampToEdge, WrapMode.ClampToBorder, WrapMode.Repeat }; 24 25 public TestSceneWrapModes() 26 : base(4, 4) 27 { 28 } 29 30 private readonly Texture[] textures = new Texture[4 * 4]; 31 32 [BackgroundDependencyLoader] 33 private void load(TextureStore store) 34 { 35 for (int i = 0; i < 4; ++i) 36 { 37 for (int j = 0; j < 4; ++j) 38 textures[i * 4 + j] = store.Get(@"sample-texture", wrapModes[i], wrapModes[j]); 39 } 40 } 41 42 [Test] 43 public void TestSprites() => createTest(tex => new Sprite 44 { 45 Texture = tex, 46 TextureRectangle = new RectangleF(0.25f, 0.25f, 0.5f, 0.5f), 47 }); 48 49 [Test] 50 public void TestTriangles() => createTest(tex => new EquilateralTriangle 51 { 52 Texture = tex, 53 TextureRectangle = new RectangleF(0.25f, 0.25f, 0.5f, 0.5f), 54 }); 55 56 [Test, Ignore("not implemented yet")] 57 public void TestVideos() => createTest(_ => new TestVideo()); 58 59 private void createTest(Func<Texture, Drawable> creatorFunc) => AddStep("create test", () => 60 { 61 for (int i = 0; i < Rows; ++i) 62 { 63 for (int j = 0; j < Cols; ++j) 64 { 65 Cell(i, j).Children = new Drawable[] 66 { 67 new SpriteText 68 { 69 Text = $"S={wrapModes[i]},T={wrapModes[j]}", 70 Font = new FontUsage(size: 20), 71 }, 72 new Container 73 { 74 RelativeSizeAxes = Axes.Both, 75 Size = new Vector2(0.5f), 76 Anchor = Anchor.Centre, 77 Origin = Anchor.Centre, 78 Children = new[] 79 { 80 creatorFunc(textures[i * 4 + j]).With(d => 81 { 82 d.RelativeSizeAxes = Axes.Both; 83 d.Size = Vector2.One; 84 d.Anchor = Anchor.Centre; 85 d.Origin = Anchor.Centre; 86 }), 87 new Container 88 { 89 RelativeSizeAxes = Axes.Both, 90 Size = new Vector2(0.5f), 91 Anchor = Anchor.Centre, 92 Origin = Anchor.Centre, 93 Masking = true, 94 BorderColour = Color4.Red, 95 BorderThickness = 2, 96 Child = new Box 97 { 98 RelativeSizeAxes = Axes.Both, 99 Colour = new Color4(0, 0, 0, 0), 100 } 101 } 102 } 103 } 104 }; 105 } 106 } 107 }); 108 } 109}