A game framework written with osu! in mind.
at master 245 lines 10 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.Graphics; 5using osu.Framework.Graphics.Colour; 6using osu.Framework.Graphics.Containers; 7using osu.Framework.Graphics.Effects; 8using osu.Framework.Graphics.Shapes; 9using osu.Framework.Graphics.Sprites; 10using osuTK; 11using osuTK.Graphics; 12 13namespace osu.Framework.Tests.Visual.Drawables 14{ 15 [System.ComponentModel.Description("implementing the IEffect interface")] 16 public class TestSceneEffects : FrameworkTestScene 17 { 18 private readonly SpriteText changeColourText; 19 20 public TestSceneEffects() 21 { 22 var effect = new EdgeEffect 23 { 24 CornerRadius = 3f, 25 Parameters = new EdgeEffectParameters 26 { 27 Colour = Color4.LightBlue, 28 Hollow = true, 29 Radius = 5f, 30 Type = EdgeEffectType.Glow 31 } 32 }; 33 Add(new FillFlowContainer 34 { 35 Position = new Vector2(10f, 10f), 36 Spacing = new Vector2(25f, 25f), 37 RelativeSizeAxes = Axes.Both, 38 Children = new Drawable[] 39 { 40 new SpriteText 41 { 42 Text = "Blur Test", 43 Font = new FontUsage(size: 32), 44 }.WithEffect(new BlurEffect 45 { 46 Sigma = new Vector2(2f, 0f), 47 Strength = 2f, 48 Rotation = 45f, 49 }), 50 new SpriteText 51 { 52 Text = "EdgeEffect Test", 53 Font = new FontUsage(size: 32), 54 }.WithEffect(new EdgeEffect 55 { 56 CornerRadius = 3f, 57 Parameters = new EdgeEffectParameters 58 { 59 Colour = Color4.Yellow, 60 Hollow = true, 61 Radius = 5f, 62 Type = EdgeEffectType.Shadow 63 } 64 }), 65 new SpriteText 66 { 67 Text = "Repeated usage of same effect test", 68 Font = new FontUsage(size: 32), 69 }.WithEffect(effect), 70 new SpriteText 71 { 72 Text = "Repeated usage of same effect test", 73 Font = new FontUsage(size: 32), 74 }.WithEffect(effect), 75 new SpriteText 76 { 77 Text = "Repeated usage of same effect test", 78 Font = new FontUsage(size: 32), 79 }.WithEffect(effect), 80 new SpriteText 81 { 82 Text = "Multiple effects Test", 83 Font = new FontUsage(size: 32), 84 }.WithEffect(new BlurEffect 85 { 86 Sigma = new Vector2(2f, 2f), 87 Strength = 2f 88 }).WithEffect(new EdgeEffect 89 { 90 CornerRadius = 3f, 91 Parameters = new EdgeEffectParameters 92 { 93 Colour = Color4.Yellow, 94 Hollow = true, 95 Radius = 5f, 96 Type = EdgeEffectType.Shadow 97 } 98 }), 99 new Container 100 { 101 AutoSizeAxes = Axes.Both, 102 Children = new Drawable[] 103 { 104 new Box 105 { 106 Colour = Color4.CornflowerBlue, 107 RelativeSizeAxes = Axes.Both, 108 }, 109 new SpriteText 110 { 111 Text = "Outlined Text", 112 Font = new FontUsage(size: 32), 113 }.WithEffect(new OutlineEffect 114 { 115 BlurSigma = new Vector2(3f), 116 Strength = 3f, 117 Colour = Color4.Red, 118 PadExtent = true, 119 }) 120 } 121 }, 122 new Container 123 { 124 AutoSizeAxes = Axes.Both, 125 Children = new Drawable[] 126 { 127 new Box 128 { 129 Colour = Color4.CornflowerBlue, 130 RelativeSizeAxes = Axes.Both, 131 }, 132 new SpriteText 133 { 134 Text = "Glowing Text", 135 Font = new FontUsage(size: 32), 136 }.WithEffect(new GlowEffect 137 { 138 BlurSigma = new Vector2(3f), 139 Strength = 3f, 140 Colour = ColourInfo.GradientHorizontal(new Color4(1.2f, 0, 0, 1f), new Color4(0, 1f, 0, 1f)), 141 PadExtent = true, 142 }), 143 } 144 }, 145 new Container 146 { 147 AutoSizeAxes = Axes.Both, 148 Children = new Drawable[] 149 { 150 new Box 151 { 152 Anchor = Anchor.Centre, 153 Origin = Anchor.Centre, 154 Colour = Color4.White, 155 Size = new Vector2(150, 40), 156 }.WithEffect(new GlowEffect 157 { 158 BlurSigma = new Vector2(3f), 159 Strength = 3f, 160 Colour = ColourInfo.GradientHorizontal(new Color4(1.2f, 0, 0, 1f), new Color4(0, 1f, 0, 1f)), 161 PadExtent = true, 162 }), 163 changeColourText = new SpriteText 164 { 165 Anchor = Anchor.Centre, 166 Origin = Anchor.Centre, 167 Text = "Absolute Size", 168 Font = new FontUsage(size: 32), 169 Colour = Color4.Red, 170 Shadow = true, 171 } 172 } 173 }, 174 new Container 175 { 176 AutoSizeAxes = Axes.Both, 177 Children = new Drawable[] 178 { 179 new Box 180 { 181 Anchor = Anchor.Centre, 182 Origin = Anchor.Centre, 183 Colour = Color4.White, 184 RelativeSizeAxes = Axes.Both, 185 Size = new Vector2(1.1f, 1.1f), 186 }.WithEffect(new GlowEffect 187 { 188 BlurSigma = new Vector2(3f), 189 Strength = 3f, 190 Colour = ColourInfo.GradientHorizontal(new Color4(1.2f, 0, 0, 1f), new Color4(0, 1f, 0, 1f)), 191 PadExtent = true, 192 }), 193 new SpriteText 194 { 195 Anchor = Anchor.Centre, 196 Origin = Anchor.Centre, 197 Text = "Relative Size", 198 Font = new FontUsage(size: 32), 199 Colour = Color4.Red, 200 Shadow = true, 201 }, 202 } 203 }, 204 new Container 205 { 206 AutoSizeAxes = Axes.Both, 207 Children = new Drawable[] 208 { 209 new Box 210 { 211 Anchor = Anchor.Centre, 212 Origin = Anchor.Centre, 213 Colour = Color4.White, 214 RelativeSizeAxes = Axes.Both, 215 Size = new Vector2(1.1f, 1.1f), 216 Rotation = 10, 217 }.WithEffect(new GlowEffect 218 { 219 BlurSigma = new Vector2(3f), 220 Strength = 3f, 221 Colour = ColourInfo.GradientHorizontal(new Color4(1.2f, 0, 0, 1f), new Color4(0, 1f, 0, 1f)), 222 PadExtent = true, 223 }), 224 new SpriteText 225 { 226 Anchor = Anchor.Centre, 227 Origin = Anchor.Centre, 228 Text = "Rotation", 229 Font = new FontUsage(size: 32), 230 Colour = Color4.Red, 231 Shadow = true, 232 }, 233 } 234 }, 235 } 236 }); 237 } 238 239 protected override void LoadComplete() 240 { 241 base.LoadComplete(); 242 changeColourText.FadeColour(Color4.Black, 1000).Then().FadeColour(Color4.Red, 1000).Loop(); 243 } 244 } 245}