From a9c885c960b14f978c434239ba5595619c42fc30 Mon Sep 17 00:00:00 2001 From: RedFlames Date: Sat, 8 Jan 2022 04:15:07 +0100 Subject: [PATCH 1/4] Slightly more elaborate fix for scaling emoji. --- Celeste.Mod.mm/Mod/Everest/Emoji.cs | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/Celeste.Mod.mm/Mod/Everest/Emoji.cs b/Celeste.Mod.mm/Mod/Everest/Emoji.cs index 3b17f9ba8..7015cc9e5 100644 --- a/Celeste.Mod.mm/Mod/Everest/Emoji.cs +++ b/Celeste.Mod.mm/Mod/Everest/Emoji.cs @@ -57,12 +57,28 @@ internal static void Auto() { /// /// The emoji name. /// The emoji texture. - public static void Register(string name, MTexture emoji) { + /// The height to render this emoji as. Adjusts the MTexture.ScaleFix as side-effect! + public static void Register(string name, MTexture emoji, int targetHeight) { + if(emoji != null && emoji.Height != targetHeight) + ((patch_MTexture) emoji).ScaleFix = targetHeight / (float) emoji.Height; + Register(name, emoji); + } + + /// + /// Register an emoji. + /// + /// The emoji name. + /// The emoji texture. + /// Scaling factor for the emoji spacing. Defaults to emoji.ScaleFix. + public static void Register(string name, MTexture emoji, float? scale = null) { if (!Initialized) { Queue.Enqueue(new KeyValuePair(name, emoji)); return; } + if (scale == null) + scale = emoji != null ? ((patch_MTexture) emoji).ScaleFix : 1f; + bool monochrome; if (monochrome = name.EndsWith(".m")) { name = name.Substring(0, name.Length - 2); @@ -75,7 +91,7 @@ public static void Register(string name, MTexture emoji) { xml.SetAttr("height", emoji.Height); xml.SetAttr("xoffset", 0); xml.SetAttr("yoffset", 0); - xml.SetAttr("xadvance", emoji.Width); + xml.SetAttr("xadvance", (int) (emoji.Width * scale)); int id = _Registered.IndexOf(name); if (id < 0) { From 82eb1cc37dd9c072d0a6f25fd16ee52b3fe917a5 Mon Sep 17 00:00:00 2001 From: RedFlames Date: Sat, 8 Jan 2022 16:19:03 +0100 Subject: [PATCH 2/4] Restore existing Emoji.Register method signature, just getting rid of the nullable instead. --- Celeste.Mod.mm/Mod/Everest/Emoji.cs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/Celeste.Mod.mm/Mod/Everest/Emoji.cs b/Celeste.Mod.mm/Mod/Everest/Emoji.cs index 7015cc9e5..b3edfad74 100644 --- a/Celeste.Mod.mm/Mod/Everest/Emoji.cs +++ b/Celeste.Mod.mm/Mod/Everest/Emoji.cs @@ -52,6 +52,16 @@ internal static void Auto() { Register(kvp.Key, kvp.Value); } + /// + /// Register an emoji. + /// + /// The emoji name. + /// The emoji texture. + public static void Register(string name, MTexture emoji) { + Register(name, emoji, ((patch_MTexture) emoji)?.ScaleFix ?? 1f); + } + + /// /// Register an emoji. /// @@ -70,15 +80,12 @@ public static void Register(string name, MTexture emoji, int targetHeight) { /// The emoji name. /// The emoji texture. /// Scaling factor for the emoji spacing. Defaults to emoji.ScaleFix. - public static void Register(string name, MTexture emoji, float? scale = null) { + public static void Register(string name, MTexture emoji, float scale) { if (!Initialized) { Queue.Enqueue(new KeyValuePair(name, emoji)); return; } - if (scale == null) - scale = emoji != null ? ((patch_MTexture) emoji).ScaleFix : 1f; - bool monochrome; if (monochrome = name.EndsWith(".m")) { name = name.Substring(0, name.Length - 2); From aad3f7863e988f01c6f4265e8ff6dbee852da51d Mon Sep 17 00:00:00 2001 From: RedFlames Date: Sat, 8 Jan 2022 16:20:33 +0100 Subject: [PATCH 3/4] Whitespace fix. --- Celeste.Mod.mm/Mod/Everest/Emoji.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/Celeste.Mod.mm/Mod/Everest/Emoji.cs b/Celeste.Mod.mm/Mod/Everest/Emoji.cs index b3edfad74..ac570f35e 100644 --- a/Celeste.Mod.mm/Mod/Everest/Emoji.cs +++ b/Celeste.Mod.mm/Mod/Everest/Emoji.cs @@ -61,7 +61,6 @@ public static void Register(string name, MTexture emoji) { Register(name, emoji, ((patch_MTexture) emoji)?.ScaleFix ?? 1f); } - /// /// Register an emoji. /// From f83296e2d0a89852e31abd8ae327c029913413ae Mon Sep 17 00:00:00 2001 From: RedFlames Date: Sun, 9 Jan 2022 00:46:23 +0100 Subject: [PATCH 4/4] Allow scaling to a target width, height, or both! 95% sure this works as intended. --- Celeste.Mod.mm/Mod/Everest/Emoji.cs | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/Celeste.Mod.mm/Mod/Everest/Emoji.cs b/Celeste.Mod.mm/Mod/Everest/Emoji.cs index ac570f35e..f5f723e49 100644 --- a/Celeste.Mod.mm/Mod/Everest/Emoji.cs +++ b/Celeste.Mod.mm/Mod/Everest/Emoji.cs @@ -62,14 +62,28 @@ public static void Register(string name, MTexture emoji) { } /// - /// Register an emoji. + /// Register an emoji with scaling constraints. /// /// The emoji name. /// The emoji texture. + /// The width to render this emoji as. Adjusts the MTexture.ScaleFix as side-effect! /// The height to render this emoji as. Adjusts the MTexture.ScaleFix as side-effect! - public static void Register(string name, MTexture emoji, int targetHeight) { - if(emoji != null && emoji.Height != targetHeight) - ((patch_MTexture) emoji).ScaleFix = targetHeight / (float) emoji.Height; + public static void Register(string name, MTexture emoji, int targetWidth = 0, int targetHeight = 0) { + if (emoji == null) { + Register(name, emoji); + return; + } + + float scaleFixW = targetWidth <= 0 ? 1f : targetWidth / (float) emoji.Width; + float scaleFixH = targetHeight <= 0 ? 1f : targetHeight / (float) emoji.Height; + + if (targetWidth <= 0) + ((patch_MTexture) emoji).ScaleFix = scaleFixH; + else if (targetHeight <= 0) + ((patch_MTexture) emoji).ScaleFix = scaleFixW; + else + ((patch_MTexture) emoji).ScaleFix = System.Math.Min(scaleFixW, scaleFixH); + Register(name, emoji); }