Skip to content

Commit

Permalink
Merge pull request #2293 from peppy/farmework-sprite-icon
Browse files Browse the repository at this point in the history
Add SpriteIcon class and include FontAwesome font

Co-authored-by: Dan Balasescu <1329837+smoogipoo@users.noreply.github.com>
  • Loading branch information
peppy and smoogipoo authored Mar 27, 2019
2 parents d361fc4 + 4f70815 commit a261ba6
Show file tree
Hide file tree
Showing 21 changed files with 1,125 additions and 10 deletions.
3 changes: 2 additions & 1 deletion SampleGame.Desktop/SampleGame.Desktop.csproj
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup Label="Project">
<TargetFramework>netcoreapp2.2</TargetFramework>
<OutputType>WinExe</OutputType>
<PlatformTarget>AnyCPU</PlatformTarget>
<LangVersion>7.3</LangVersion>
</PropertyGroup>
<ItemGroup Label="Project References">
<ProjectReference Include="..\osu.Framework\osu.Framework.csproj" />
Expand Down
3 changes: 2 additions & 1 deletion SampleGame/SampleGame.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<LangVersion>7.3</LangVersion>
</PropertyGroup>
<ItemGroup Label="Project References">
<ProjectReference Include="..\osu.Framework\osu.Framework.csproj" />
Expand Down
3 changes: 2 additions & 1 deletion osu.Framework.NativeLibs/osu.Framework.NativeLibs.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup Label="Project">
<TargetFramework>netstandard2.0</TargetFramework>
<OutputType>Library</OutputType>
Expand All @@ -9,6 +9,7 @@
<AssemblyName>osu.Framework.NativeLibs</AssemblyName>
<Description>Native libraries for osu!framework</Description>
<Product>osu!framework Libraries</Product>
<LangVersion>7.3</LangVersion>
</PropertyGroup>
<PropertyGroup Label="Nuget">
<Title>osu!framework Libraries</Title>
Expand Down
76 changes: 76 additions & 0 deletions osu.Framework.Tests/Visual/Sprites/TestCaseSpriteIcon.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

using System.Reflection;
using NUnit.Framework;
using osu.Framework.Extensions.IEnumerableExtensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Cursor;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Testing;
using osuTK;
using osuTK.Graphics;

namespace osu.Framework.Tests.Visual.Sprites
{
[TestFixture]
public class TestCaseSpriteIcon : TestCase
{
public TestCaseSpriteIcon()
{
FillFlowContainer<Icon> flow;

Add(new TooltipContainer
{
RelativeSizeAxes = Axes.Both,
Children = new Drawable[]
{
new Box
{
Colour = Color4.Teal,
RelativeSizeAxes = Axes.Both,
},
new ScrollContainer
{
RelativeSizeAxes = Axes.Both,
Child = flow = new FillFlowContainer<Icon>
{
Anchor = Anchor.TopRight,
Origin = Anchor.TopRight,
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Direction = FillDirection.Full,
},
}
}
});

foreach (var p in typeof(FontAwesome).GetProperties(BindingFlags.Public | BindingFlags.Static))
flow.Add(new Icon($"{nameof(FontAwesome)}.{p.Name}", (IconUsage)p.GetValue(null)));

AddStep("toggle shadows", () => flow.Children.ForEach(i => i.SpriteIcon.Shadow = !i.SpriteIcon.Shadow));
AddStep("change icons", () => flow.Children.ForEach(i => i.SpriteIcon.Icon = new IconUsage((char)(i.SpriteIcon.Icon.Icon + 1))));
}

private class Icon : Container, IHasTooltip
{
public string TooltipText { get; }

public SpriteIcon SpriteIcon { get; }

public Icon(string name, IconUsage icon)
{
TooltipText = name;

AutoSizeAxes = Axes.Both;
Child = SpriteIcon = new SpriteIcon
{
Icon = icon,
Size = new Vector2(60),
};
}
}
}
}
1 change: 1 addition & 0 deletions osu.Framework.Tests/osu.Framework.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<PropertyGroup Label="Project">
<TargetFramework>netcoreapp2.2</TargetFramework>
<OutputType>WinExe</OutputType>
<LangVersion>7.3</LangVersion>
</PropertyGroup>
<PropertyGroup>
<GenerateProgramFile>false</GenerateProgramFile>
Expand Down
2 changes: 2 additions & 0 deletions osu.Framework/Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ private void load(FrameworkConfigManager config)
Fonts.AddStore(new GlyphStore(Resources, @"Fonts/OpenSans/OpenSans-Italic"));
Fonts.AddStore(new GlyphStore(Resources, @"Fonts/OpenSans/OpenSans-BoldItalic"));

Fonts.AddStore(new GlyphStore(Resources, @"Fonts/FontAwesome/FontAwesome"));

dependencies.Cache(Fonts);

Localisation = new LocalisationManager(config);
Expand Down
2 changes: 1 addition & 1 deletion osu.Framework/Graphics/Containers/CompositeDrawable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,7 @@ internal override void UnbindAllBindables()
internal void DisposeChildAsync(Drawable drawable)
{
drawable.UnbindAllBindables();
Task.Run(() => drawable.Dispose());
Task.Run(drawable.Dispose);
}

internal override void UpdateClock(IFrameBasedClock clock)
Expand Down
Loading

0 comments on commit a261ba6

Please sign in to comment.