MCPcopy Create free account
hub / github.com/XorTroll/uLaunch / ParseHexColor

Function ParseHexColor

projects/uDesigner/source/main.cpp:48–74  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

46 bool g_DisplayAboutWindow = false;
47
48 inline ImColor ParseHexColor(const std::string &color) {
49 if(color.length() >= 7) {
50 std::string r = "00";
51 std::string g = "00";
52 std::string b = "00";
53 std::string a = "FF";
54
55 if(color.length() >= 9) {
56 a = color.substr(7, 2);
57 }
58 if(color.length() >= 7) {
59 r = color.substr(1, 2);
60 g = color.substr(3, 2);
61 b = color.substr(5, 2);
62 }
63
64 const auto r_val = static_cast<u8>(std::stoul(r, nullptr, 16));
65 const auto g_val = static_cast<u8>(std::stoul(g, nullptr, 16));
66 const auto b_val = static_cast<u8>(std::stoul(b, nullptr, 16));
67 const auto a_val = static_cast<u8>(std::stoul(a, nullptr, 16));
68 return ImColor(r_val, g_val, b_val, a_val);
69 }
70 else {
71 emscripten_log(EM_LOG_CONSOLE, "Invalid color '%s' (expected '#RRGGBBAA' format)", color.c_str());
72 return 0;
73 }
74 }
75
76 inline std::string GenerateHexColor(const ImColor color) {
77 std::stringstream strm;

Callers

nothing calls this directly

Calls 1

lengthMethod · 0.80

Tested by

no test coverage detected