diff options
author | pommicket <pommicket@gmail.com> | 2022-12-22 21:23:54 -0500 |
---|---|---|
committer | pommicket <pommicket@gmail.com> | 2022-12-22 21:23:54 -0500 |
commit | c58f2247a9f9aaea86e461c176e4757e4d17292f (patch) | |
tree | ed453ed66b5e576c0029539faa0982c6c26cf31a /colors.h | |
parent | 91ff61cc22c08e2c247b6b689561e6d18cf276e7 (diff) |
symbol kind
Diffstat (limited to 'colors.h')
-rw-r--r-- | colors.h | 57 |
1 files changed, 2 insertions, 55 deletions
@@ -1,4 +1,4 @@ -ENUM_U16 { +typedef enum { COLOR_UNKNOWN, COLOR_TEXT, @@ -43,7 +43,7 @@ ENUM_U16 { COLOR_COUNT -} ENUM_U16_END(ColorSetting); +} ColorSetting; typedef struct { ColorSetting setting; @@ -91,56 +91,3 @@ static ColorName const color_names[] = { }; static_assert_if_possible(arr_count(color_names) == COLOR_COUNT) - -static ColorSetting color_setting_from_str(char const *str) { - // @OPTIMIZE: sort color_names, binary search - for (int i = 0; i < COLOR_COUNT; ++i) { - ColorName const *n = &color_names[i]; - if (streq(n->name, str)) - return n->setting; - } - return COLOR_UNKNOWN; -} - -static char const *color_setting_to_str(ColorSetting s) { - for (int i = 0; i < COLOR_COUNT; ++i) { - ColorName const *n = &color_names[i]; - if (n->setting == s) - return n->name; - } - return "???"; -} - -// converts #rrggbb/#rrggbbaa to a color. returns false if it's not in the right format. -static Status color_from_str(char const *str, u32 *color) { - uint r = 0, g = 0, b = 0, a = 0xff; - bool success = false; - switch (strlen(str)) { - case 4: - success = sscanf(str, "#%01x%01x%01x", &r, &g, &b) == 3; - // extend single hex digit to double hex digit - r |= r << 4; - g |= g << 4; - b |= b << 4; - break; - case 5: - success = sscanf(str, "#%01x%01x%01x%01x", &r, &g, &b, &a) == 4; - r |= r << 4; - g |= g << 4; - b |= b << 4; - a |= a << 4; - break; - case 7: - success = sscanf(str, "#%02x%02x%02x", &r, &g, &b) == 3; - break; - case 9: - success = sscanf(str, "#%02x%02x%02x%02x", &r, &g, &b, &a) == 4; - break; - } - if (!success || r > 0xff || g > 0xff || b > 0xff || a > 0xff) - return false; - if (color) - *color = (u32)r << 24 | (u32)g << 16 | (u32)b << 8 | (u32)a; - return true; -} - |