1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-15 13:23:22 +08:00

Update with spritetext text builder changes

This commit is contained in:
smoogipoo 2019-06-21 20:47:43 +09:00
parent 9ea4921e2b
commit 0de219dda4

View File

@ -15,6 +15,7 @@ using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.Textures; using osu.Framework.Graphics.Textures;
using osu.Framework.IO.Stores; using osu.Framework.IO.Stores;
using osu.Framework.Text;
using osu.Game.Database; using osu.Game.Database;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Graphics.Sprites; using osu.Game.Graphics.Sprites;
@ -234,21 +235,31 @@ namespace osu.Game.Skinning
private class LegacySpriteText : OsuSpriteText private class LegacySpriteText : OsuSpriteText
{ {
private readonly TextureStore textures; private readonly LegacyGlyphStore glyphStore;
private readonly string font;
public LegacySpriteText(TextureStore textures, string font) public LegacySpriteText(TextureStore textures, string font)
{ {
this.textures = textures;
this.font = font;
Shadow = false; Shadow = false;
UseFullGlyphHeight = false; UseFullGlyphHeight = false;
Font = new FontUsage(font, 16);
glyphStore = new LegacyGlyphStore(textures);
} }
protected override Texture GetTextureForCharacter(char c) protected override TextBuilder CreateTextBuilder(ITexturedGlyphLookupStore store) => base.CreateTextBuilder(glyphStore);
private class LegacyGlyphStore : ITexturedGlyphLookupStore
{ {
string textureName = $"{font}-{c}"; private readonly TextureStore textures;
public LegacyGlyphStore(TextureStore textures)
{
this.textures = textures;
}
public ITexturedCharacterGlyph Get(string fontName, char character)
{
string textureName = $"{fontName}-{character}";
// Approximate value that brings character sizing roughly in-line with stable // Approximate value that brings character sizing roughly in-line with stable
float ratio = 36; float ratio = 36;
@ -264,7 +275,10 @@ namespace osu.Game.Skinning
if (texture != null) if (texture != null)
texture.ScaleAdjust = ratio; texture.ScaleAdjust = ratio;
return texture; return new TexturedCharacterGlyph(new CharacterGlyph(character, 0, 0, texture?.Width ?? 0, null), texture, 1f / ratio);
}
public Task<ITexturedCharacterGlyph> GetAsync(string fontName, char character) => Task.Run(() => Get(fontName, character));
} }
} }