A game framework written with osu! in mind.
at master 99 lines 3.4 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 System.Diagnostics; 5using System.Linq; 6using System.Reflection; 7using NUnit.Framework; 8using osu.Framework.Extensions.IEnumerableExtensions; 9using osu.Framework.Graphics; 10using osu.Framework.Graphics.Containers; 11using osu.Framework.Graphics.Cursor; 12using osu.Framework.Graphics.Shapes; 13using osu.Framework.Graphics.Sprites; 14using osu.Framework.Localisation; 15using osuTK; 16using osuTK.Graphics; 17 18namespace osu.Framework.Tests.Visual.Sprites 19{ 20 [TestFixture] 21 public class TestSceneSpriteIcon : FrameworkTestScene 22 { 23 public TestSceneSpriteIcon() 24 { 25 Box background; 26 FillFlowContainer flow; 27 28 Add(new TooltipContainer 29 { 30 RelativeSizeAxes = Axes.Both, 31 Children = new Drawable[] 32 { 33 background = new Box 34 { 35 Colour = Color4.Teal, 36 RelativeSizeAxes = Axes.Both, 37 }, 38 new BasicScrollContainer 39 { 40 RelativeSizeAxes = Axes.Both, 41 Child = flow = new FillFlowContainer 42 { 43 Anchor = Anchor.TopRight, 44 Origin = Anchor.TopRight, 45 RelativeSizeAxes = Axes.X, 46 AutoSizeAxes = Axes.Y, 47 Spacing = new Vector2(5), 48 Direction = FillDirection.Full, 49 }, 50 } 51 } 52 }); 53 54 var weights = typeof(FontAwesome).GetNestedTypes(); 55 56 foreach (var w in weights) 57 { 58 flow.Add(new SpriteText 59 { 60 Text = w.Name, 61 Scale = new Vector2(4), 62 RelativeSizeAxes = Axes.X, 63 Padding = new MarginPadding(10), 64 }); 65 66 foreach (var p in w.GetProperties(BindingFlags.Public | BindingFlags.Static)) 67 { 68 var propValue = p.GetValue(null); 69 Debug.Assert(propValue != null); 70 71 flow.Add(new Icon($"{nameof(FontAwesome)}.{w.Name}.{p.Name}", (IconUsage)propValue)); 72 } 73 } 74 75 AddStep("toggle shadows", () => flow.Children.OfType<Icon>().ForEach(i => i.SpriteIcon.Shadow = !i.SpriteIcon.Shadow)); 76 AddStep("change icons", () => flow.Children.OfType<Icon>().ForEach(i => i.SpriteIcon.Icon = new IconUsage((char)(i.SpriteIcon.Icon.Icon + 1)))); 77 AddStep("white background", () => background.FadeColour(Color4.White, 200)); 78 } 79 80 private class Icon : Container, IHasTooltip 81 { 82 public LocalisableString TooltipText { get; } 83 84 public SpriteIcon SpriteIcon { get; } 85 86 public Icon(string name, IconUsage icon) 87 { 88 TooltipText = name; 89 90 AutoSizeAxes = Axes.Both; 91 Child = SpriteIcon = new SpriteIcon 92 { 93 Icon = icon, 94 Size = new Vector2(60), 95 }; 96 } 97 } 98 } 99}