Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
color_utils.hpp
Go to the documentation of this file.
1// -------------------------------------------------------//
2//
3// SHAMROCK code for hydrodynamics
4// Copyright (c) 2021-2026 Timothée David--Cléris <tim.shamrock@proton.me>
5// SPDX-License-Identifier: CeCILL Free Software License Agreement v2.1
6// Shamrock is licensed under the CeCILL 2.1 License, see LICENSE for more information
7//
8// -------------------------------------------------------//
9
10#pragma once
11
19
20#include "imgui.h"
21
22namespace sham::gui {
23
25 constexpr int hexv(char c) { return c <= '9' ? c - '0' : (c | 32) - 'a' + 10; }
26
28 constexpr ImU32 rgb_u32(int r, int g, int b, int a = 255) {
29 return (ImU32(a) << 24) | (ImU32(b) << 16) | (ImU32(g) << 8) | ImU32(r);
30 }
31
33 constexpr ImU32 rgba(const char *h, double a = 1.0) {
34 return rgb_u32(
35 hexv(h[1]) * 16 + hexv(h[2]),
36 hexv(h[3]) * 16 + hexv(h[4]),
37 hexv(h[5]) * 16 + hexv(h[6]),
38 int(a * 255 + 0.5));
39 }
40
41} // namespace sham::gui
constexpr ImU32 rgba(const char *h, double a=1.0)
Colour from a "#rrggbb" string, with alpha a in [0, 1].
constexpr int hexv(char c)
Value of one hexadecimal digit ('0'-'9', 'a'-'f' or 'A'-'F').
constexpr ImU32 rgb_u32(int r, int g, int b, int a=255)
Pack 8-bit components into an ImU32 (ImGui's IM_COL32 layout).