From ffef5634edde53594d210f08c3821f88cebcaf46 Mon Sep 17 00:00:00 2001 From: Jon Kazama Date: Tue, 26 May 2026 15:25:31 +0200 Subject: [PATCH] feat(util): add RgbaToVector4 and Vector4ToRgba helpers for color picker --- HellionChat/Util/ColourUtil.cs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/HellionChat/Util/ColourUtil.cs b/HellionChat/Util/ColourUtil.cs index 31b08c4..5ece96b 100755 --- a/HellionChat/Util/ColourUtil.cs +++ b/HellionChat/Util/ColourUtil.cs @@ -30,6 +30,30 @@ internal static class ColourUtil ); } + internal static Vector4 RgbaToVector4(uint rgba) + { + var (r, g, b) = RgbaToRgbComponents(rgba); + var a = (byte)(rgba & 0xFFu); + return new Vector4(r / 255f, g / 255f, b / 255f, a / 255f); + } + + internal static uint Vector4ToRgba(Vector4 col) + { + // Clamp guards against future ImGuiColorEditFlags.HDR feeding out-of-range + // components: a raw byte-cast would wrap (e.g. (byte)Math.Round(2.0f*255)=254). + // Mirrors the ApplyAlpha clamping pattern in this file. + var r = Math.Clamp(col.X, 0f, 1f); + var g = Math.Clamp(col.Y, 0f, 1f); + var b = Math.Clamp(col.Z, 0f, 1f); + var a = Math.Clamp(col.W, 0f, 1f); + return ComponentsToRgba( + (byte)Math.Round(r * 255), + (byte)Math.Round(g * 255), + (byte)Math.Round(b * 255), + (byte)Math.Round(a * 255) + ); + } + internal static uint Vector4ToAbgr(Vector4 col) { return RgbaToAbgr(