A game framework written with osu! in mind.
at master 119 lines 4.2 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 osu.Framework.Allocation; 5using osu.Framework.Extensions.Color4Extensions; 6using osu.Framework.Graphics; 7using osu.Framework.Graphics.Containers; 8using osu.Framework.Graphics.Shapes; 9using osu.Framework.Graphics.UserInterface; 10using osuTK; 11using osuTK.Graphics; 12 13namespace osu.Framework.Tests.Visual.Drawables 14{ 15 public class TestSceneBorderSmoothing : FrameworkTestScene 16 { 17 public TestSceneBorderSmoothing() 18 { 19 Children = new Drawable[] 20 { 21 new FillFlowContainer 22 { 23 RelativeSizeAxes = Axes.Both, 24 Anchor = Anchor.Centre, 25 Origin = Anchor.Centre, 26 Direction = FillDirection.Full, 27 Spacing = new Vector2(0, 10), 28 Children = new Drawable[] 29 { 30 new IssueButton 31 { 32 Text = "no fill" 33 }, 34 new IssueButton 35 { 36 OverlayColour = Color4.White.Opacity(0.0001f), 37 Text = "very transparent fill" 38 }, 39 new IssueButton 40 { 41 OverlayColour = Color4.Gray, 42 Text = "gray bg" 43 }, 44 new IssueButton 45 { 46 OverlayColour = Color4.White.Opacity(0.5f), 47 Text = "0.5 white bg" 48 }, 49 new IssueButton 50 { 51 OverlayColour = Color4.White, 52 Text = "white bg" 53 }, 54 new IssueButton(false) 55 { 56 BackgroundColour = Color4.Gray, 57 Text = "gray should match 1", 58 }, 59 new IssueButton(false) 60 { 61 BackgroundColour = Color4.White, 62 Text = "gray should match 2", 63 Alpha = 0.5f, 64 }, 65 new IssueButton(borderColour: Color4.Gray) 66 { 67 OverlayColour = Color4.Gray, 68 Text = "gray to gray bg" 69 }, 70 new IssueButton(borderColour: Color4.Gray) 71 { 72 OverlayColour = Color4.White.Opacity(0.5f), 73 Text = "gray to transparent white bg" 74 }, 75 } 76 } 77 }; 78 79 AddSliderStep("adjust alpha", 0f, 1f, 1, val => Child.Alpha = val); 80 } 81 82 private class IssueButton : BasicButton 83 { 84 public Color4? OverlayColour; 85 86 public IssueButton(bool drawBorder = true, Color4? borderColour = null) 87 { 88 AutoSizeAxes = Axes.None; 89 Size = new Vector2(200); 90 91 BackgroundColour = Color4.Black; 92 93 if (drawBorder) 94 { 95 Content.Masking = true; 96 Content.MaskingSmoothness = 20; 97 Content.BorderThickness = 40; 98 99 Content.BorderColour = borderColour ?? Color4.Red; 100 } 101 } 102 103 [BackgroundDependencyLoader] 104 private void load() 105 { 106 Add(new Container 107 { 108 RelativeSizeAxes = Axes.Both, 109 Child = new Box 110 { 111 Alpha = OverlayColour.HasValue ? 1 : 0, 112 RelativeSizeAxes = Axes.Both, 113 Colour = OverlayColour ?? Color4.Transparent, 114 } 115 }); 116 } 117 } 118 } 119}