A game framework written with osu! in mind.

Fix triangle not supporting TextureRectangle

+42 -27
+41 -26
osu.Framework.Tests/Visual/Sprites/TestSceneWrapModes.cs
··· 1 1 // Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. 2 2 // See the LICENCE file in the repository root for full licence text. 3 3 4 + using System; 5 + using NUnit.Framework; 4 6 using osu.Framework.Allocation; 5 7 using osu.Framework.Graphics; 6 8 using osu.Framework.Graphics.Containers; ··· 25 27 { 26 28 } 27 29 28 - protected override void LoadComplete() 30 + private readonly Texture[] textures = new Texture[4 * 4]; 31 + 32 + [BackgroundDependencyLoader] 33 + private void load(TextureStore store) 29 34 { 30 - base.LoadComplete(); 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 + } 31 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 + { 32 61 for (int i = 0; i < Rows; ++i) 33 62 { 34 63 for (int j = 0; j < Cols; ++j) 35 64 { 36 - Cell(i, j).AddRange(new Drawable[] 65 + Cell(i, j).Children = new Drawable[] 37 66 { 38 67 new SpriteText 39 68 { ··· 46 75 Size = new Vector2(0.5f), 47 76 Anchor = Anchor.Centre, 48 77 Origin = Anchor.Centre, 49 - Children = new Drawable[] 78 + Children = new[] 50 79 { 51 - new Sprite 80 + creatorFunc(textures[i * 4 + j]).With(d => 52 81 { 53 - RelativeSizeAxes = Axes.Both, 54 - Size = Vector2.One, 55 - Texture = textures[i * 4 + j], 56 - Anchor = Anchor.Centre, 57 - Origin = Anchor.Centre, 58 - TextureRectangle = new RectangleF(0.25f, 0.25f, 0.5f, 0.5f), 59 - }, 82 + d.RelativeSizeAxes = Axes.Both; 83 + d.Size = Vector2.One; 84 + d.Anchor = Anchor.Centre; 85 + d.Origin = Anchor.Centre; 86 + }), 60 87 new Container 61 88 { 62 89 RelativeSizeAxes = Axes.Both, ··· 74 101 } 75 102 } 76 103 } 77 - }); 104 + }; 78 105 } 79 106 } 80 - } 81 - 82 - private readonly Texture[] textures = new Texture[4 * 4]; 83 - 84 - [BackgroundDependencyLoader] 85 - private void load(TextureStore store) 86 - { 87 - for (int i = 0; i < 4; ++i) 88 - { 89 - for (int j = 0; j < 4; ++j) 90 - textures[i * 4 + j] = store.Get(@"sample-texture", wrapModes[i], wrapModes[j]); 91 - } 92 - } 107 + }); 93 108 } 94 109 }
+1 -1
osu.Framework/Graphics/Shapes/Triangle.cs
··· 44 44 protected override void Blit(Action<TexturedVertex2D> vertexAction) 45 45 { 46 46 DrawTriangle(Texture, toTriangle(ScreenSpaceDrawQuad), DrawColourInfo.Colour, null, null, 47 - new Vector2(InflationAmount.X / DrawRectangle.Width, InflationAmount.Y / DrawRectangle.Height)); 47 + new Vector2(InflationAmount.X / DrawRectangle.Width, InflationAmount.Y / DrawRectangle.Height), TextureCoords); 48 48 } 49 49 } 50 50 }