From 0237602ab7875298e437e2074b4ec6a3f183a0f6 Mon Sep 17 00:00:00 2001 From: Jon Kazama Date: Wed, 20 May 2026 11:20:48 +0200 Subject: [PATCH] feat(util): add ColourUtil.ApplyAlpha for hover-lerp modulation Alpha-only modulator for ABGR colors -- RGB stays intact, factor clamped to [0, 1]. Used by the v1.5.4 PM-3 hover-lerp path. --- HellionChat/Util/ColourUtil.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/HellionChat/Util/ColourUtil.cs b/HellionChat/Util/ColourUtil.cs index 4b9fc9f..31b08c4 100755 --- a/HellionChat/Util/ColourUtil.cs +++ b/HellionChat/Util/ColourUtil.cs @@ -66,6 +66,18 @@ internal static class ColourUtil return ((uint)a << 24) | ((uint)nb << 16) | ((uint)ng << 8) | nr; } + // Modulates the alpha byte of an ABGR color by a factor in [0, 1]. + // RGB stays intact. Used by the PM-3 hover-lerp path where each + // frame produces a fractional alpha value but the colour itself + // must not shift. + internal static uint ApplyAlpha(uint abgr, float alphaFactor) + { + alphaFactor = Math.Clamp(alphaFactor, 0f, 1f); + var origAlpha = (byte)((abgr >> 24) & 0xFFu); + var newAlpha = (byte)Math.Round(origAlpha * alphaFactor); + return (abgr & 0x00FFFFFFu) | ((uint)newAlpha << 24); + } + public static uint HexToRgba(string hex) { ArgumentNullException.ThrowIfNull(hex);