A game framework written with osu! in mind.
at master 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 NUnit.Framework; 5using osu.Framework.Graphics; 6using osu.Framework.Graphics.Containers; 7using osu.Framework.Graphics.Shapes; 8using osu.Framework.Utils; 9using osuTK; 10using osuTK.Graphics; 11 12namespace osu.Framework.Tests.Visual.Containers 13{ 14 public class TestSceneDrawSizePreservingFillContainer : FrameworkTestScene 15 { 16 public TestSceneDrawSizePreservingFillContainer() 17 { 18 DrawSizePreservingFillContainer fillContainer; 19 20 Child = new Container 21 { 22 Anchor = Anchor.Centre, 23 Origin = Anchor.Centre, 24 Size = new Vector2(500), 25 Children = new Drawable[] 26 { 27 new Box 28 { 29 RelativeSizeAxes = Axes.Both, 30 Colour = Color4.Red, 31 }, 32 new Container 33 { 34 RelativeSizeAxes = Axes.Both, 35 Padding = new MarginPadding(10), 36 Children = new Drawable[] 37 { 38 new Box 39 { 40 RelativeSizeAxes = Axes.Both, 41 Colour = Color4.Black, 42 }, 43 fillContainer = new DrawSizePreservingFillContainer 44 { 45 Child = new TestSceneSizing(), 46 }, 47 } 48 }, 49 } 50 }; 51 52 AddStep("Strategy: Minimum", () => fillContainer.Strategy = DrawSizePreservationStrategy.Minimum); 53 AddStep("Strategy: Maximum", () => fillContainer.Strategy = DrawSizePreservationStrategy.Maximum); 54 AddStep("Strategy: Average", () => fillContainer.Strategy = DrawSizePreservationStrategy.Average); 55 AddStep("Strategy: Separate", () => fillContainer.Strategy = DrawSizePreservationStrategy.Separate); 56 57 AddSliderStep("Width", 50, 650, 500, v => Child.Width = v); 58 AddSliderStep("Height", 50, 650, 500, v => Child.Height = v); 59 60 AddStep("Override Size to 1x1", () => Child.Size = Vector2.One); 61 } 62 63 [Test] 64 public void TestParentPadding() 65 { 66 Box fullBox = null; 67 Box innerBox = null; 68 69 AddStep("create container", () => 70 { 71 Child = new Container 72 { 73 Anchor = Anchor.Centre, 74 Origin = Anchor.Centre, 75 Size = new Vector2(512, 384), 76 Children = new Drawable[] 77 { 78 fullBox = new Box 79 { 80 RelativeSizeAxes = Axes.Both, 81 Colour = Color4.Red, 82 }, 83 new Container 84 { 85 RelativeSizeAxes = Axes.Both, 86 Padding = new MarginPadding { Left = 100 }, 87 Children = new Drawable[] 88 { 89 new DrawSizePreservingFillContainer 90 { 91 Child = innerBox = new Box 92 { 93 Size = new Vector2(1024, 768), 94 Colour = Color4.Pink, 95 Alpha = 0.3f 96 } 97 }, 98 } 99 }, 100 } 101 }; 102 }); 103 104 AddAssert("inner box stops at edge of right box", () => Precision.AlmostEquals(fullBox.ScreenSpaceDrawQuad.TopRight, innerBox.ScreenSpaceDrawQuad.TopRight)); 105 } 106 } 107}