A game framework written with osu! in mind.
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge branch 'glyphstore-characterglyph' into spritetext-textbuilder

+58 -38
+5 -4
osu.Framework.Tests/IO/FontStoreTest.cs
··· 4 4 using NUnit.Framework; 5 5 using osu.Framework.Graphics; 6 6 using osu.Framework.IO.Stores; 7 + using osu.Framework.Text; 7 8 8 9 namespace osu.Framework.Tests.IO 9 10 { ··· 30 31 31 32 fontStore.AddStore(nestedFontStore); 32 33 33 - var normalGlyph = (FontStore.TexturedCharacterGlyph)fontStore.Get("OpenSans", 'a'); 34 - var boldGlyph = (FontStore.TexturedCharacterGlyph)fontStore.Get("OpenSans-Bold", 'a'); 34 + var normalGlyph = (TexturedCharacterGlyph)fontStore.Get("OpenSans", 'a'); 35 + var boldGlyph = (TexturedCharacterGlyph)fontStore.Get("OpenSans-Bold", 'a'); 35 36 36 - Assert.That(normalGlyph.ScaleAdjustment, Is.EqualTo(1f / 100)); 37 - Assert.That(boldGlyph.ScaleAdjustment, Is.EqualTo(1f / 10)); 37 + Assert.That(normalGlyph.Scale, Is.EqualTo(1f / 100)); 38 + Assert.That(boldGlyph.Scale, Is.EqualTo(1f / 10)); 38 39 } 39 40 40 41 [OneTimeTearDown]
+8 -5
osu.Framework/Graphics/Sprites/SpriteIcon.cs
··· 74 74 75 75 if (Equals(loadableIcon, loadedIcon)) return; 76 76 77 - var texture = store.Get(loadableIcon.FontName, Icon.Icon).Texture; 77 + var glyph = store.Get(loadableIcon.FontName, Icon.Icon); 78 78 79 - spriteMain.Texture = texture; 80 - spriteShadow.Texture = texture; 79 + if (glyph != null) 80 + { 81 + spriteMain.Texture = glyph.Texture; 82 + spriteShadow.Texture = glyph.Texture; 81 83 82 - if (Size == Vector2.Zero) 83 - Size = new Vector2(texture?.DisplayWidth ?? 0, texture?.DisplayHeight ?? 0); 84 + if (Size == Vector2.Zero) 85 + Size = new Vector2(glyph.Width, glyph.Height); 86 + } 84 87 85 88 loadedIcon = loadableIcon; 86 89 }
-29
osu.Framework/IO/Stores/FontStore.cs
··· 7 7 using System.Threading.Tasks; 8 8 using osu.Framework.Logging; 9 9 using System.Collections.Concurrent; 10 - using System.Runtime.CompilerServices; 11 10 using osu.Framework.Platform; 12 11 using osu.Framework.Text; 13 12 ··· 198 197 { 199 198 base.Dispose(disposing); 200 199 glyphStores.ForEach(g => g.Dispose()); 201 - } 202 - 203 - internal sealed class TexturedCharacterGlyph : ITexturedCharacterGlyph 204 - { 205 - public Texture Texture { get; } 206 - 207 - public float XOffset => glyph.XOffset * ScaleAdjustment; 208 - public float YOffset => glyph.YOffset * ScaleAdjustment; 209 - public float XAdvance => glyph.XAdvance * ScaleAdjustment; 210 - public char Character => glyph.Character; 211 - public float Width => Texture.Width * ScaleAdjustment; 212 - public float Height => Texture.Height * ScaleAdjustment; 213 - 214 - public readonly float ScaleAdjustment; 215 - private readonly CharacterGlyph glyph; 216 - 217 - public TexturedCharacterGlyph(CharacterGlyph glyph, Texture texture, float scaleAdjustment) 218 - { 219 - this.glyph = glyph; 220 - this.ScaleAdjustment = scaleAdjustment; 221 - 222 - Texture = texture; 223 - } 224 - 225 - [MethodImpl(MethodImplOptions.AggressiveInlining)] 226 - public float GetKerning<T>(T lastGlyph) 227 - where T : ICharacterGlyph 228 - => glyph.GetKerning(lastGlyph) * ScaleAdjustment; 229 200 } 230 201 } 231 202 }
+45
osu.Framework/Text/TexturedCharacterGlyph.cs
··· 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 + 4 + using System.Runtime.CompilerServices; 5 + using osu.Framework.Graphics.Textures; 6 + 7 + namespace osu.Framework.Text 8 + { 9 + public sealed class TexturedCharacterGlyph : ITexturedCharacterGlyph 10 + { 11 + public Texture Texture { get; } 12 + 13 + public float XOffset => glyph.XOffset * Scale; 14 + public float YOffset => glyph.YOffset * Scale; 15 + public float XAdvance => glyph.XAdvance * Scale; 16 + public char Character => glyph.Character; 17 + public float Width => Texture.Width * Scale; 18 + public float Height => Texture.Height * Scale; 19 + 20 + /// <summary> 21 + /// An adjustment factor in scale. This is applied to all other returned metric properties. 22 + /// </summary> 23 + public readonly float Scale; 24 + 25 + private readonly CharacterGlyph glyph; 26 + 27 + /// <summary> 28 + /// Create a new <see cref="TexturedCharacterGlyph"/> instance. 29 + /// </summary> 30 + /// <param name="glyph">The glyph.</param> 31 + /// <param name="texture">The texture.</param> 32 + /// <param name="scale">A scale factor to apply to exposed glyph metrics.</param> 33 + public TexturedCharacterGlyph(CharacterGlyph glyph, Texture texture, float scale = 1) 34 + { 35 + this.glyph = glyph; 36 + Scale = scale; 37 + Texture = texture; 38 + } 39 + 40 + [MethodImpl(MethodImplOptions.AggressiveInlining)] 41 + public float GetKerning<T>(T lastGlyph) 42 + where T : ICharacterGlyph 43 + => glyph.GetKerning(lastGlyph) * Scale; 44 + } 45 + }