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.
This commit is contained in:
2026-05-20 11:20:48 +02:00
parent a600f014eb
commit 0237602ab7
+12
View File
@@ -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);