A game framework written with osu! in mind.
at master 66 lines 2.5 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 osuTK; 5using osuTK.Graphics; 6using osu.Framework.Graphics.Colour; 7using osu.Framework.Graphics.Containers; 8 9namespace osu.Framework.Graphics.Effects 10{ 11 /// <summary> 12 /// Creates a glow around the drawable this effect gets applied to. 13 /// </summary> 14 public class GlowEffect : IEffect<BufferedContainer> 15 { 16 /// <summary> 17 /// The strength of the glow. A higher strength means that the glow fades outward slower. Default is 1. 18 /// </summary> 19 public float Strength = 1f; 20 21 /// <summary> 22 /// The sigma value for the blur of the glow. This controls how spread out the glow is. Default is 5 in both X and Y. 23 /// </summary> 24 public Vector2 BlurSigma = new Vector2(5); 25 26 /// <summary> 27 /// The color of the outline. Default is <see cref="Color4.White"/>. 28 /// </summary> 29 public ColourInfo Colour = Color4.White; 30 31 /// <summary> 32 /// The blending mode of the glow. Default is additive. 33 /// </summary> 34 public BlendingParameters Blending = BlendingParameters.Additive; 35 36 /// <summary> 37 /// Whether to draw the glow <see cref="EffectPlacement.InFront"/> or <see cref="EffectPlacement.Behind"/> the glowing 38 /// <see cref="Drawable"/>. Default is <see cref="EffectPlacement.InFront"/>. 39 /// </summary> 40 public EffectPlacement Placement = EffectPlacement.InFront; 41 42 /// <summary> 43 /// Whether to automatically pad by the glow extent such that no clipping occurs at the sides of the effect. Default is false. 44 /// </summary> 45 public bool PadExtent; 46 47 /// <summary> 48 /// True if the effect should be cached. This is an optimization, but can cause issues if the drawable changes the way it looks without changing its size. 49 /// Turned off by default. 50 /// </summary> 51 public bool CacheDrawnEffect; 52 53 public BufferedContainer ApplyTo(Drawable drawable) => drawable.WithEffect(new BlurEffect 54 { 55 Strength = Strength, 56 Sigma = BlurSigma, 57 Colour = Colour, 58 Blending = Blending, 59 Placement = Placement, 60 PadExtent = PadExtent, 61 CacheDrawnEffect = CacheDrawnEffect, 62 63 DrawOriginal = true, 64 }); 65 } 66}